我译一下关于 RPC 的修改吧,不过我试了一下,官方 RPC 似乎还没升级。
1. estimateGasAndCollateral 的返回值
在交易发生 revert 时,estimateGasAndCollateral 函数返回的错误信息会发生变化。ConfluxScan 会对返回的错误信息做解析和加工。
升级前
Revert 但没有提供原因
{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Execution output ", data: "0x..."}
Revert 且提供了原因
{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Execution output Reason provided by the contract: 'ERC20: transfer amount exceeds allowance'", data: "0x..."}
改动后
Revert 且提供了原因
{code: -32015, code: "Estimation isn't accurate: transaction is reverted: ERC20: transfer amount exceeds allowance.", data: "0x..."}
Revert 没有提供原因。但是更内层的调用提供了一个原因。
比如说,如果一个合约调用了 USDT_contract
合约的函数 USDT_contract.transferFrom(from, to, value)
. 在执行期间,transferFrom
发生了 reverted,理由是 ‘ERC20: transfer amount exceeds allowance’. 但是调用 USDT_contract
那个合约没有提供任何理由。这种情况下的返回将是。
{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Innermost error is at cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2: ERC20: transfer amount exceeds allowance.", data: "0x..."}
cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2
是 USDT 合约的地址。
Revert 没有提供理由, 内层调用也没有提供理由
{code: -32015, code: "Estimation isn't accurate: transaction is reverted.", data: "0x..."}
Revert 提供了理由,子调用也提供了一个理由
比如说,你使用 safeTransferFrom
函数调用 USDT 合约。这个 safeTransferFrom
函数来自 OpenZeppelin, 会去调用 USDT 合约的 transferFrom
. 如果 USDT 合约 revert 了,理由是 “ERC20: transfer amount exceeds allowance”. 那么作为调用者,safeTransferFrom
也会返回一个错误原因 “SafeERC20: low-level call failed”. (详见 OpenZeppelin 的实现细节)
那么此时的返回值会是
{code: -32015, code: "Estimation isn't accurate: transaction is reverted: SafeERC20: low-level call failed. Innermost error is at cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2: ERC20: transfer amount exceeds allowance.", data: "0x..."}
2. Receipt 中的返回值
如果交易 revert, Receipt 中的 error message 会改变。
升级前
"Vm reverted, Reason provided by the contract: 'ERC20: transfer amount exceeds allowance'"
升级后
"Vm reverted, ERC20: transfer amount exceeds allowance"
3. Trace
目前没有公开的 rpc 提供 trace 访问,所以我们假定开发者不会读取和 block trace 相关的内容。如果需要了解 trace 相关的修改,请阅读原文档。