System Contract Error Code
当在调用系统合约接口的时候,可以通过查看交易回执中日志信息来获得具体执行过程中的错误类型。
通过 Solidity Event 实现,回执返回中包含错误码及具体的错误信息。
event ErrorLog(ErrorType indexed errorType, string msg);
其中:
errorType
: 错误类型,存储在topics
字段中msg
: 错误信息,存储在data
中,遵循 ABI规范
错误码 | 错误类型 | 错误信息 |
---|---|---|
0 | NotAdmin | Not the admin account |
1 | OutOfBaseLimit | The value is out of base limit |
2 | OutOfBlockLimit | The value is out of block limit |
3 | NoParentChain | Has no parent chain (deprecation) |
4 | NoSideChain | has no side chain |
5 | NotOneOperate | should operate one time in a block (deprecation) |
6 | NotClose | node does not close |
7 | NotStart | node does not start |
8 | NotReady | node does not start (deprecation) |
NotAdmin
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xa860fb8f185fca757029dc4fe48e4100b134756aec7c33a1e23c29b48cd9160e",
"blockNumber": "0x34f",
"contractAddress": null,
"cumulativeQuotaUsed": "0x5b61",
"errorMessage": null,
"quotaUsed": "0x5b61",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff02000c",
"blockHash": "0xa860fb8f185fca757029dc4fe48e4100b134756aec7c33a1e23c29b48cd9160e",
"blockNumber": "0x34f",
"data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000154e6f74207468652061646d696e206163636f756e740000000000000000000000",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000000"
],
"transactionHash": "0x84813121d671f9abad412c92138f7cd52e310c415bc5a15d51216dd0b25cddcc",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000001000000000000000080000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000010000000000000000000000000",
"root": null,
"transactionHash": "0x84813121d671f9abad412c92138f7cd52e310c415bc5a15d51216dd0b25cddcc",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000000
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000154e6f74207468652061646d696e206163636f756e740000000000000000000000
输出如下:
{
"string": "Not the admin account"
}
OutOfBaseLimit
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xbee7f3f7f3aa27e24dfc125d711eaf84f7fc5b36e64118846906be5c594bb4c0",
"blockNumber": "0x487",
"contractAddress": null,
"cumulativeQuotaUsed": "0x5f37",
"errorMessage": null,
"quotaUsed": "0x5f37",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff020003",
"blockHash": "0xbee7f3f7f3aa27e24dfc125d711eaf84f7fc5b36e64118846906be5c594bb4c0",
"blockNumber": "0x487",
"data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e5468652076616c7565206973206f7574206f662062617365206c696d69740000",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000001"
],
"transactionHash": "0xf94f721973d67b0263e42d6dcddd0f4da4c1dc85003faecbde271dedbe5d6bde",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000002000000000000000000000000080000000010000000000000000000000000000000000000000040000000000000000000000000100000000000000000800040000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000",
"root": null,
"transactionHash": "0xf94f721973d67b0263e42d6dcddd0f4da4c1dc85003faecbde271dedbe5d6bde",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000001
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e5468652076616c7565206973206f7574206f662062617365206c696d69740000
输出如下:
{
"string": "The value is out of base limit"
}
OutOfBlockLimit
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0x010a48e24ec63d73ab04ec00143924bfeb4a70ef25a08cd44c5e97d1575086e3",
"blockNumber": "0x61f",
"contractAddress": null,
"cumulativeQuotaUsed": "0x5f66",
"errorMessage": null,
"quotaUsed": "0x5f66",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff020003",
"blockHash": "0x010a48e24ec63d73ab04ec00143924bfeb4a70ef25a08cd44c5e97d1575086e3",
"blockNumber": "0x61f",
"data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f5468652076616c7565206973206f7574206f6620626c6f636b206c696d697400",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000002"
],
"transactionHash": "0x2e411813f5990c0889b1a752b38882636601538b9185a07ff6ebea6a7a748487",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x04000000000000000000000000000000000000000000002000000000000000000000000080000000010000000000000000000000000000000000000000000000000000000000000000000100000000000000000800000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000",
"root": null,
"transactionHash": "0x2e411813f5990c0889b1a752b38882636601538b9185a07ff6ebea6a7a748487",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000002
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f5468652076616c7565206973206f7574206f6620626c6f636b206c696d697400
输出如下:
{
"string": "The value is out of block limit"
}
NoParentChain
废弃
NoSideChain
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0x236b9896d89cbb97a918e0233c7f4a9b7883788a9663922cba4d521e79ee66f3",
"blockNumber": "0x6f",
"contractAddress": null,
"cumulativeQuotaUsed": "0x5bc7",
"errorMessage": null,
"quotaUsed": "0x5bc7",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff020002",
"blockHash": "0x236b9896d89cbb97a918e0233c7f4a9b7883788a9663922cba4d521e79ee66f3",
"blockNumber": "0x6f",
"data": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000011686173206e6f207369646520636861696e000000000000000000000000000000",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000004"
],
"transactionHash": "0xc07e9ffbabc3e21ae47450592bc94d9607c87e4c603102abbae5302c6184c96f",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000080000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000048000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000002000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": null,
"transactionHash": "0xc07e9ffbabc3e21ae47450592bc94d9607c87e4c603102abbae5302c6184c96f",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000004
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000011686173206e6f207369646520636861696e000000000000000000000000000000
输出如下:
{
"string": "has no side chain"
}
NotOneOperate
废弃
NotClose
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xbd8e9336f7d10886f90bfd49a9e7c915e8092ee3db21d641b834d2316ccd0212",
"blockNumber": "0x2a",
"contractAddress": null,
"cumulativeQuotaUsed": "0x60f9",
"errorMessage": null,
"quotaUsed": "0x60f9",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff020001",
"blockHash": "0xbd8e9336f7d10886f90bfd49a9e7c915e8092ee3db21d641b834d2316ccd0212",
"blockNumber": "0x2a",
"data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000136e6f646520646f6573206e6f7420636c6f736500000000000000000000000000",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000006"
],
"transactionHash": "0x590e663789bcfff2b49791f8793702614784174e104b6d175369a807cad90929",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x00000000000000000000000000000000000200000000000000000000000000000000000080000000010000000000000000000000000400000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000002000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": null,
"transactionHash": "0x590e663789bcfff2b49791f8793702614784174e104b6d175369a807cad90929",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000006
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000136e6f646520646f6573206e6f7420636c6f736500000000000000000000000000
输出如下:
{
"string": "node does not close"
}
NotStart
交易回执:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0x631fd5c8ee6aca8b60d74e5b3d3eed517f93004a403c2849f12d7a55b17a52c4",
"blockNumber": "0x79",
"contractAddress": null,
"cumulativeQuotaUsed": "0x5f65",
"errorMessage": null,
"quotaUsed": "0x5f65",
"logs": [
{
"address": "0xffffffffffffffffffffffffffffffffff020001",
"blockHash": "0x631fd5c8ee6aca8b60d74e5b3d3eed517f93004a403c2849f12d7a55b17a52c4",
"blockNumber": "0x79",
"data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000136e6f646520646f6573206e6f7420737461727400000000000000000000000000",
"logIndex": "0x0",
"topics": [
"0x9655ba40cfc2f0950c16e93cc6fd1acfa27ea642762ffcd4cab2c64344ad212c",
"0x0000000000000000000000000000000000000000000000000000000000000007"
],
"transactionHash": "0x07634595c9418a36ecd63d9c4ce4d5329d17ade89bb571c2f372b4fb6b269dde",
"transactionIndex": "0x0",
"transactionLogIndex": "0x0"
}
],
"logsBloom": "0x00000000000000000000000000000000000200000000000000000000000000000000000080000000010000000000000000001000000000000000000000000000000020000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000",
"root": null,
"transactionHash": "0x07634595c9418a36ecd63d9c4ce4d5329d17ade89bb571c2f372b4fb6b269dde",
"transactionIndex": "0x0"
}
}
其中:
logs.topics[1]
表示错误类型0x0000000000000000000000000000000000000000000000000000000000000007
logs.data
为错误信息。对 data 进行解码:
$ cita-cli ethabi decode params \
--type string \
--data 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000136e6f646520646f6573206e6f7420737461727400000000000000000000000000
输出如下:
{
"string": "node does not start"
}
NotReady
废弃