美文网首页eos
2.5 cleos-commands-transactions

2.5 cleos-commands-transactions

作者: furnace | 来源:发表于2019-07-24 15:11 被阅读0次

    交易相关的命令

    1. 查询交易的详细信息

    $ cleos get transaction b890beb84a6d1d77755f2e0cdad48e2ffcfd06ff3481917b4875cc5f3a343533 --block-hint 1000001
    {
      "id": "b890beb84a6d1d77755f2e0cdad48e2ffcfd06ff3481917b4875cc5f3a343533",
      "trx": {
        "receipt": {
          "status": "executed",
          "cpu_usage_us": 778,
          "net_usage_words": 14,
          "trx": [
            1,{
              "signatures": [
                "SIG_K1_KbzyGju8Ssn16KxRA5nJg1P4X5MfoGgs8MfBi4NuhSCrG7oCuoCGVg8vnSqsocYouDYawxpQ31BrxJGVR5xEfoVpEV5jqV"
              ],
              "compression": "none",
              "packed_context_free_data": "",
              "packed_trx": "c5ae245bf9404eadf12c0000000001a09861f648958566000000000080694a01a09861f64895856600000000a8ed3232141364646f7320656f73212073686f727420656f7300"
            }
          ]
        },
        "trx": {
          "expiration": "2018-06-16T06:31:33",
          "ref_block_num": 16633,
          "ref_block_prefix": 754036046,
          "max_net_usage_words": 0,
          "max_cpu_usage_ms": 0,
          "delay_sec": 0,
          "context_free_actions": [],
          "actions": [{
              "account": "gu2tembqgage",
              "name": "ddos",
              "authorization": [{
                  "actor": "gu2tembqgage",
                  "permission": "active"
                }
              ],
              "data": {
                "memo": "ddos eos! short eos"
              },
              "hex_data": "1364646f7320656f73212073686f727420656f73"
            }
          ],
          "transaction_extensions": [],
          "signatures": [
            "SIG_K1_KbzyGju8Ssn16KxRA5nJg1P4X5MfoGgs8MfBi4NuhSCrG7oCuoCGVg8vnSqsocYouDYawxpQ31BrxJGVR5xEfoVpEV5jqV"
          ],
          "context_free_data": []
        }
      },
      "block_time": "2018-06-16T05:59:49.500",
      "block_num": 1000001,
      "last_irreversible_block": 1892236,
      "traces": []
    }
    

    其中:

    • b890beb84a6d1d77755f2e0cdad48e2ffcfd06ff3481917b4875cc5f3a343533 是交易 hash
    • --block-hint 提示交易有可能所属的区块编号

    需要注意的是,一般来说是不知道交易属于哪个区块的。因此,--block-hint 一般都设置为 0,但是这需要 nodeos 打开插件 history-plugin 和选项 --filter-on=*,否则查询会报错。

    2. 计算给定交易对象的交易 id

    获取给定交易对象的交易 id。使用方式 cleos get transaction_id [OPTIONS] transaction。

    $ cleos get transaction_id '{
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }'
    bf2434cf3ab87418e201a2d7e4526b10fbbb0cb2ad15bd6b7000551e6cd2a9cc
    

    3. 构造交易样本

    构造一个交易,并获得其 pack 后的结果。

    通过选项 --json --dont-broadcast --return-packed 以 josn 的格式返回某个交易的 pack 结果。

    $ cleos transfer eosio alice "1 EOS" "memo" --contract eosio.token --json --dont-broadcast --return-packed
    {
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "443f395de032a6f77608000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232250000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f00"
    }
    

    当然,我们也可以不设置选项 --return-packed,这获得的是未 pack 的交易。

    需要注意的是,上面的交易信息中已经包含签名信息。实际上 pack & unpack 操作并不会涉及到签名。签名也是对于 pack 后的二进制数据进行的,如通过命令 cleos sign。因此,我们在 pack & unpack 操作时可以不用传递签名相关信息,因为即使传递了也会被过滤掉。

    4. 交易的 pack & unpack

    4.1 pack_transaction

    从纯文本签名的 json 转换成 packed 格式。使用方式 cleos convert pack_transaction [OPTIONS] transaction。

    4.1.1 不带签名信息 & 不带 action 详细信息

    $ cleos convert pack_transaction '{
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }'
    {
      "signatures": [],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "443f395de032a6f77608000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232250000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f00"
    }
    

    4.1.2 带签名信息 & 带 action 详细信息

    如果交易中包含详细的 actions,需要打开选项 --pack-action-data,否则打包交易会失败。

    $ cleos convert pack_transaction '{
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 EOS",
            "memo": "memo"
          },
          "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "context_free_data": []
    }' --pack-action-data
    {
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "443f395de032a6f77608000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232250000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f00"
    }
    

    4.2 unpack_transaction

    从 packed 转换成纯文本签名的 json 格式 。使用方式 cleos convert unpack_transaction [OPTIONS] transaction。

    4.2.1 不带签名信息 & 不解包 actions 的详细

    $ cleos convert unpack_transaction '{
      "signatures": [
      ],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "443f395de032a6f77608000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232250000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f00"
    }'
    {
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [],
      "context_free_data": []
    }
    

    4.2.2 带签名信息 & 解包 actions 的详细

    通过选项 --unpack-action-data 把交易中的 action 也解包出来。

    $ cleos convert unpack_transaction '{
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "443f395de032a6f77608000000000100a6823403ea3055000000572d3ccdcd010000000000ea305500000000a8ed3232250000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f00"
    }' --unpack-action-data
    {
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 EOS",
            "memo": "memo"
          },
          "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "context_free_data": []
    }
    

    5. 交易签名

    对一个交易进行签名。使用方式 cleos sign [OPTIONS] transaction。

    $ cleos sign '{
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }' --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
    info  2019-07-25T07:29:14.372 thread-0  main.cpp:3261                 operator()           ] grabbing chain_id from nodeos
    {
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "context_free_data": []
    }
    

    注意,--chain-id 如果不设置,需要通过和 nodeos 交互获得。同时,考虑安全,私钥也不要通过选项 --private-key 传递。

    打开选项 --push-transaction 将交易发送到链上。注意,这需要将字段 expiration 设置正确。这也就说明了,签名时有些字段并不会被包含进来,如字段 expiration。

    $ cleos sign '{
      "expiration": "2019-07-25T09:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }' --private-key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 --push-transaction
    info  2019-07-25T08:36:07.424 thread-0  main.cpp:3261                 operator()           ] grabbing chain_id from nodeos
    {
      "transaction_id": "ea822206ce3f901ed91013d1fc18fe48e7b1f0fcccdb172bde1efdf32fa1a70d",
      "processed": {
        "id": "ea822206ce3f901ed91013d1fc18fe48e7b1f0fcccdb172bde1efdf32fa1a70d",
        "block_num": 34948,
        "block_time": "2019-07-25T08:36:07.500",
        "producer_block_id": null,
        "receipt": {
          "status": "executed",
          "cpu_usage_us": 346,
          "net_usage_words": 17
        },
        "elapsed": 346,
        "net_usage": 136,
        "scheduled": false,
        "action_traces": [{
            "receipt": {
              "receiver": "eosio.token",
              "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
              "global_sequence": 35130,
              "recv_sequence": 45,
              "auth_sequence": [[
                  "eosio",
                  35101
                ]
              ],
              "code_sequence": 1,
              "abi_sequence": 1
            },
            "act": {
              "account": "eosio.token",
              "name": "transfer",
              "authorization": [{
                  "actor": "eosio",
                  "permission": "active"
                }
              ],
              "data": {
                "from": "eosio",
                "to": "alice",
                "quantity": "1.0000 EOS",
                "memo": "memo"
              },
              "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
            },
            "context_free": false,
            "elapsed": 195,
            "console": "",
            "trx_id": "ea822206ce3f901ed91013d1fc18fe48e7b1f0fcccdb172bde1efdf32fa1a70d",
            "block_num": 34948,
            "block_time": "2019-07-25T08:36:07.500",
            "producer_block_id": null,
            "account_ram_deltas": [{
                "account": "eosio",
                "delta": 240
              }
            ],
            "except": null,
            "inline_traces": [{
                "receipt": {
                  "receiver": "eosio",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 35131,
                  "recv_sequence": 35044,
                  "auth_sequence": [[
                      "eosio",
                      35102
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 12,
                "console": "",
                "trx_id": "ea822206ce3f901ed91013d1fc18fe48e7b1f0fcccdb172bde1efdf32fa1a70d",
                "block_num": 34948,
                "block_time": "2019-07-25T08:36:07.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              },{
                "receipt": {
                  "receiver": "alice",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 35132,
                  "recv_sequence": 1,
                  "auth_sequence": [[
                      "eosio",
                      35103
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 8,
                "console": "",
                "trx_id": "ea822206ce3f901ed91013d1fc18fe48e7b1f0fcccdb172bde1efdf32fa1a70d",
                "block_num": 34948,
                "block_time": "2019-07-25T08:36:07.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              }
            ]
          }
        ],
        "except": null
      }
    }
    

    6. 提交交易

    6.1 提交单个 JSON 格式描述的交易

    提交任意以 JSON 格式描述的交易。使用方式 cleos push transaction [OPTIONS] transaction。

    交易不能包含签名。

    $ cleos push transaction '{
      "expiration": "2019-07-25T09:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }'
    {
      "transaction_id": "7a44b0810c319c9868486d4f1e9505e71d8b4f8ad237ff005a2c0b2e8d3135f6",
      "processed": {
        "id": "7a44b0810c319c9868486d4f1e9505e71d8b4f8ad237ff005a2c0b2e8d3135f6",
        "block_num": 35734,
        "block_time": "2019-07-25T08:42:40.500",
        "producer_block_id": null,
        "receipt": {
          "status": "executed",
          "cpu_usage_us": 306,
          "net_usage_words": 17
        },
        "elapsed": 306,
        "net_usage": 136,
        "scheduled": false,
        "action_traces": [{
            "receipt": {
              "receiver": "eosio.token",
              "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
              "global_sequence": 35919,
              "recv_sequence": 46,
              "auth_sequence": [[
                  "eosio",
                  35890
                ]
              ],
              "code_sequence": 1,
              "abi_sequence": 1
            },
            "act": {
              "account": "eosio.token",
              "name": "transfer",
              "authorization": [{
                  "actor": "eosio",
                  "permission": "active"
                }
              ],
              "data": {
                "from": "eosio",
                "to": "alice",
                "quantity": "1.0000 EOS",
                "memo": "memo"
              },
              "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
            },
            "context_free": false,
            "elapsed": 163,
            "console": "",
            "trx_id": "7a44b0810c319c9868486d4f1e9505e71d8b4f8ad237ff005a2c0b2e8d3135f6",
            "block_num": 35734,
            "block_time": "2019-07-25T08:42:40.500",
            "producer_block_id": null,
            "account_ram_deltas": [],
            "except": null,
            "inline_traces": [{
                "receipt": {
                  "receiver": "eosio",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 35920,
                  "recv_sequence": 35831,
                  "auth_sequence": [[
                      "eosio",
                      35891
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 12,
                "console": "",
                "trx_id": "7a44b0810c319c9868486d4f1e9505e71d8b4f8ad237ff005a2c0b2e8d3135f6",
                "block_num": 35734,
                "block_time": "2019-07-25T08:42:40.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              },{
                "receipt": {
                  "receiver": "alice",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 35921,
                  "recv_sequence": 2,
                  "auth_sequence": [[
                      "eosio",
                      35892
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 12,
                "console": "",
                "trx_id": "7a44b0810c319c9868486d4f1e9505e71d8b4f8ad237ff005a2c0b2e8d3135f6",
                "block_num": 35734,
                "block_time": "2019-07-25T08:42:40.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              }
            ]
          }
        ],
        "except": null
      }
    }
    

    注意,交易不能包含签名,否则会报错。上面的交易是不包含详细 action,下面的交易包含详细 action。

    $ cleos push transaction '{
      "expiration": "2019-07-25T09:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 EOS",
            "memo": "memo"
          },
          "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }'
    {
      "transaction_id": "c66ef1c22522a2a2c67b0c7ae01b8cdc1be374de38128dd5744714da63959627",
      "processed": {
        "id": "c66ef1c22522a2a2c67b0c7ae01b8cdc1be374de38128dd5744714da63959627",
        "block_num": 36812,
        "block_time": "2019-07-25T08:51:39.500",
        "producer_block_id": null,
        "receipt": {
          "status": "executed",
          "cpu_usage_us": 315,
          "net_usage_words": 17
        },
        "elapsed": 315,
        "net_usage": 136,
        "scheduled": false,
        "action_traces": [{
            "receipt": {
              "receiver": "eosio.token",
              "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
              "global_sequence": 37000,
              "recv_sequence": 47,
              "auth_sequence": [[
                  "eosio",
                  36971
                ]
              ],
              "code_sequence": 1,
              "abi_sequence": 1
            },
            "act": {
              "account": "eosio.token",
              "name": "transfer",
              "authorization": [{
                  "actor": "eosio",
                  "permission": "active"
                }
              ],
              "data": {
                "from": "eosio",
                "to": "alice",
                "quantity": "1.0000 EOS",
                "memo": "memo"
              },
              "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
            },
            "context_free": false,
            "elapsed": 162,
            "console": "",
            "trx_id": "c66ef1c22522a2a2c67b0c7ae01b8cdc1be374de38128dd5744714da63959627",
            "block_num": 36812,
            "block_time": "2019-07-25T08:51:39.500",
            "producer_block_id": null,
            "account_ram_deltas": [],
            "except": null,
            "inline_traces": [{
                "receipt": {
                  "receiver": "eosio",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 37001,
                  "recv_sequence": 36910,
                  "auth_sequence": [[
                      "eosio",
                      36972
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 13,
                "console": "",
                "trx_id": "c66ef1c22522a2a2c67b0c7ae01b8cdc1be374de38128dd5744714da63959627",
                "block_num": 36812,
                "block_time": "2019-07-25T08:51:39.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              },{
                "receipt": {
                  "receiver": "alice",
                  "act_digest": "0417de465219905a54882b499a0a1e4835d1487fadaee214cedaec750f1e50c4",
                  "global_sequence": 37002,
                  "recv_sequence": 3,
                  "auth_sequence": [[
                      "eosio",
                      36973
                    ]
                  ],
                  "code_sequence": 1,
                  "abi_sequence": 1
                },
                "act": {
                  "account": "eosio.token",
                  "name": "transfer",
                  "authorization": [{
                      "actor": "eosio",
                      "permission": "active"
                    }
                  ],
                  "data": {
                    "from": "eosio",
                    "to": "alice",
                    "quantity": "1.0000 EOS",
                    "memo": "memo"
                  },
                  "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
                },
                "context_free": false,
                "elapsed": 10,
                "console": "",
                "trx_id": "c66ef1c22522a2a2c67b0c7ae01b8cdc1be374de38128dd5744714da63959627",
                "block_num": 36812,
                "block_time": "2019-07-25T08:51:39.500",
                "producer_block_id": null,
                "account_ram_deltas": [],
                "except": null,
                "inline_traces": []
              }
            ]
          }
        ],
        "except": null
      }
    }
    

    6.2 提交任意以 JSON 格式描述的交易列表

    提交任意以 JSON 格式描述的交易列表。使用方式 cleos push transactions [OPTIONS] transactions。

    交易不能包含签名。

    这个方法只要在上述 transaction 的基础上把一个交易换成多个交易形成的列表即可。这里就不举例了。

    Reference

    1. How to push transaction in EOS?, https://stackoverflow.com/questions/51423884/how-to-push-transaction-in-eos
    2. Using EOS RPC API to Transfer EOS, https://steemit.com/eos/@noprom/using-eos-rpc-api-to-transfer-eos
    3. Using EOS RPC API to Transfer EOS, https://github.com/EOSBlock/EOS-Tutorials/blob/master/EN/transfer-tokens-using-RPC.md

    附录 1. 交易的打包和解包以及签名等操作

    对于交易中的 action 可能还需要独立的打包操作。

    1. 交易结构

    通过 json 结构来描述交易。

    2. 交易编码成 16 进制

    将 json 结构描述的交易编码为 16 进制。

    3. 交易签名

    对交易进行签名。

    4. 打包交易

    利用命令 cleos convert pack_transaction 打包交易。注意,交易包括 json 结构,16 进制,以及签名。

    5. 解包交易

    利用命令 cleos convert unpack_transaction 解包交易。

    附录 2. 一个交易

    2.1 不带签名信息 & 不带 action 详细信息

    {
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
      ],
      "context_free_data": []
    }
    

    2.2 带签名信息 & 带 action 详细信息

    包含详细的 actions。

    {
      "expiration": "2019-07-25T05:33:56",
      "ref_block_num": 13024,
      "ref_block_prefix": 142014374,
      "max_net_usage_words": 0,
      "max_cpu_usage_ms": 0,
      "delay_sec": 0,
      "context_free_actions": [],
      "actions": [{
          "account": "eosio.token",
          "name": "transfer",
          "authorization": [{
              "actor": "eosio",
              "permission": "active"
            }
          ],
          "data": {
            "from": "eosio",
            "to": "alice",
            "quantity": "1.0000 EOS",
            "memo": "memo"
          },
          "hex_data": "0000000000ea30550000000000855c34102700000000000004454f5300000000046d656d6f"
        }
      ],
      "transaction_extensions": [],
      "signatures": [
        "SIG_K1_KX2SPX8cqDheFKgSSVDZwiwqP98uJVVJ4SLA8Pp3Kf6QEtGUgxNHhWGkgU18JEsbnngij1udE5t9NfMFkmAPa4ZQS4K4JR"
      ],
      "context_free_data": []
    }
    

    项目源代码

    项目源代码会逐步上传到 Github,地址为 https://github.com/windstamp/blockchain

    Contributor

    1. Windstamp, https://github.com/windstamp

    相关文章

      网友评论

        本文标题:2.5 cleos-commands-transactions

        本文链接:https://www.haomeiwen.com/subject/wcvxrctx.html