Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.2.x API 行为变更 #18

Closed
cssmagic opened this issue Aug 8, 2018 · 2 comments
Closed

v0.2.x API 行为变更 #18

cssmagic opened this issue Aug 8, 2018 · 2 comments
Labels

Comments

@cssmagic
Copy link
Member

cssmagic commented Aug 8, 2018

Nasa.call()

返回值

👉 原:

Promise - Fulfilled:字符串。交易流水号。

改为:

Promise - Fulfilled:对象。交易流水号和 txHash(如果有),结构如下:

{
	payId: '...pay...id...',
	txHash: '...tx...hash...',
}

⚠️ 仅在 Chrome 钱包扩展环境下,才有可能返回 txHash。

请留意 txHash 的拼写。

Nasa.query()

返回值

👉 原:

合约调用时抛错被视为 Promise - Rejected,错误消息就是执行时抛出的错误消息。

改为:

合约调用时抛错将视为 Promise - Fulfilled(因为查询动作本身并没有发生错误,而且顺利拿到了合约调用结果),错误消息会放在 Promise 返回值的一个字段中。

👉 原:

Promise - Fulfilled:就是 JSON 反序列化之后的值。

改为:

Promise - Fulfilled:对象。合约调用返回值(如果有)和合约调用时的错误消息(如果有),结构如下:

// 正常调用
{
	execResult: {},  // 👉 合约调用返回值 JSON 反序列化之后的值
	estimateGas: "20490",
}

// 调用过程中抛错
{
	execError: 'my error msg',  // 👉 合约调用过程中抛出的错误消息
	estimateGas: "20490",
}

Nasa.checkTx()

改名

⚠️ 此 API 改名为 Nasa.getTxResult()

原名仍然可用,但会在 v0.3.0 时删除。

返回值

👉 原:

合约调用时抛错被视为 Promise - Rejected,错误消息为 Nasa.error.CALL_FAILEDNasa.error.TX_FAILED

改为:

合约调用时抛错将视为 Promise - Fulfilled(因为查询动作本身并没有发生错误,而且顺利拿到了交易状态和结果),错误消息会放在交易详细信息中的一个字段中。

👉 原:

Promise - Fulfilled:把 execute_result 反序列化之后的值存放在 result 字段中。

改为:

Promise - Fulfilled:交易详细信息中提供合约调用返回值(如果有)和合约调用时的错误消息(如果有),示意结构如下:

// 正常调用
{
	"...": "...",  // from、to、gas 等基本信息,不赘述
	"execResult": {}, // 👉 "execute_result" 字段 JSON 反序列化之后的值
}

// 调用过程中抛错
{
	"...": "...",  // from、to、gas 等基本信息,不赘述
	"execError": "my error msg"  // 👉 合约调用过程中抛出的错误消息,不含前缀
}

注意,在交易详细信息中:

  • 星云官方 RPC 接口返回的各字段名如果是 “小蛇形拼写”,将一律转换为 “小驼峰拼写”(比如:gas_pricegasPrice)。

  • 不再提供 execute_resultexecute_error 字段,请直接使用 execResultexecError 字段。

👉 原:

Promise - Rejected:其中 “查询超时(一分钟内都没有得到交易结果)” 的错误消息为 Nasa.error.REQUEST_TIMEOUT

改为:

这种情况下的错误消息为 Nasa.error.TX_TIMEOUT


(完)

@cssmagic cssmagic added the Doc label Aug 8, 2018
@cssmagic cssmagic mentioned this issue Aug 9, 2018
22 tasks
@cssmagic
Copy link
Member Author

cssmagic commented Aug 14, 2018

⚠️ 注意

execResult 如果 JSON 解析失败,则直接返回原字符串。

@cssmagic
Copy link
Member Author

上述变更已由 PR #19 、PR #20 初步完成。

@cssmagic cssmagic changed the title v0.2.x API 行为变更(草案) v0.2.x API 行为变更 Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant