eos icon indicating copy to clipboard operation
eos copied to clipboard

push_transaction .How to get 'signatures'?

Open xsdxf opened this issue 8 years ago • 5 comments

image

xsdxf avatar Sep 11 '18 02:09 xsdxf

In general, the following step are needed to get the signatures

  1. get the info
  2. get public keys
  3. get required key
  4. sign the transaction //to get the signatures

I suggest add " --print-request --print-response" in "cleos push xxx" to get detail info.

root@iZm5e6ig9oqpk7bxfmti1sZ:/eos/contracts# cleos --print-request --print-response push action testaccount3 hi "[testaccount3]" -p testaccount3 REQUEST:

POST /v1/chain/abi_json_to_bin HTTP/1.0 Host: 127.0.0.1:8888 content-length: 82 Accept: / Connection: close

{ "code": "testaccount3", "action": "hi", "args": [ "testaccount3" ] }

RESPONSE:

{ "binargs": "30f2d4142193b1ca" }

REQUEST:

POST /v1/chain/get_info HTTP/1.0 Host: 127.0.0.1:8888 content-length: 0 Accept: / Connection: close


RESPONSE:

{ "server_version": "75635168", "chain_id": "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", "head_block_num": 336554, "last_irreversible_block_num": 336553, "last_irreversible_block_id": "000522a97715570d9532a4e16db35ce23fea245df0890f0b3e62c2efe4bbf07a", "head_block_id": "000522aaa04fa75892d2f5c2240c66c065208a5fd71ccb873b385e7e2d8ab601", "head_block_time": "2018-09-08T07:35:54.000", "head_block_producer": "eosio", "virtual_block_cpu_limit": 200000000, "virtual_block_net_limit": 1048576000, "block_cpu_limit": 199900, "block_net_limit": 1048576 }

REQUEST:

POST /v1/wallet/get_public_keys HTTP/1.0 Host: 127.0.0.1:8900 content-length: 0 Accept: / Connection: close


RESPONSE:

[ "EOS5CuHFLvDhTaU8usM1A4PW5f6m1coCHpqhSmbtPQdEo84stnJQ7", "EOS6DSK314iCC2cCDhztn37mtsbwiRcEe8aLTLtbbHfnfDytuo3k7", "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "EOS6stFR6zp4mMQ9pvJSJFj49Nb3GjaxKt32927MfBsg8owUUqmju", "EOS772JxdvxG8dykycZg9CUwuMMeVxuPHcQfpqqjGL8EdsYoibxVv", "EOS8KXh3WkcBGc4WRVGDZP6NQesGGkdqYYtmxv2myS5CeCHaKqAzF" ]

REQUEST:

POST /v1/chain/get_required_keys HTTP/1.0 Host: 127.0.0.1:8888 content-length: 912 Accept: / Connection: close

{ "transaction": { "expiration": "2018-09-08T07:36:24", "ref_block_num": 8873, "ref_block_prefix": 3785634453, "max_net_usage_words": 0, "max_cpu_usage_ms": 0, "delay_sec": 0, "context_free_actions": [], "actions": [{ "account": "testaccount3", "name": "hi", "authorization": [{ "actor": "testaccount3", "permission": "active" } ], "data": "30f2d4142193b1ca" } ], "transaction_extensions": [] }, "available_keys": [ "EOS5CuHFLvDhTaU8usM1A4PW5f6m1coCHpqhSmbtPQdEo84stnJQ7", "EOS6DSK314iCC2cCDhztn37mtsbwiRcEe8aLTLtbbHfnfDytuo3k7", "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "EOS6stFR6zp4mMQ9pvJSJFj49Nb3GjaxKt32927MfBsg8owUUqmju", "EOS772JxdvxG8dykycZg9CUwuMMeVxuPHcQfpqqjGL8EdsYoibxVv", "EOS8KXh3WkcBGc4WRVGDZP6NQesGGkdqYYtmxv2myS5CeCHaKqAzF" ] }

RESPONSE:

{ "required_keys": [ "EOS772JxdvxG8dykycZg9CUwuMMeVxuPHcQfpqqjGL8EdsYoibxVv" ] }

REQUEST:

POST /v1/wallet/sign_transaction HTTP/1.0 Host: 127.0.0.1:8900 content-length: 689 Accept: / Connection: close

[{ "expiration": "2018-09-08T07:36:24", "ref_block_num": 8873, "ref_block_prefix": 3785634453, "max_net_usage_words": 0, "max_cpu_usage_ms": 0, "delay_sec": 0, "context_free_actions": [], "actions": [{ "account": "testaccount3", "name": "hi", "authorization": [{ "actor": "testaccount3", "permission": "active" } ], "data": "30f2d4142193b1ca" } ], "transaction_extensions": [], "signatures": [], "context_free_data": [] },[ "EOS772JxdvxG8dykycZg9CUwuMMeVxuPHcQfpqqjGL8EdsYoibxVv" ], "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f" ]

RESPONSE:

{ "expiration": "2018-09-08T07:36:24", "ref_block_num": 8873, "ref_block_prefix": 3785634453, "max_net_usage_words": 0, "max_cpu_usage_ms": 0, "delay_sec": 0, "context_free_actions": [], "actions": [{ "account": "testaccount3", "name": "hi", "authorization": [{ "actor": "testaccount3", "permission": "active" } ], "data": "30f2d4142193b1ca" } ], "transaction_extensions": [], "signatures": [ "SIG_K1_K23QRajZH3mXuFf4YmaVq5C7YHYxYmL7DpQvuoEj4DR9wRdA8DWPUr1H3QM4KMLLYR63D1cWQqURmRdKYydaFdstwiPFQs" ], "context_free_data": [] }

REQUEST:

POST /v1/chain/push_transaction HTTP/1.0 Host: 127.0.0.1:8888 content-length: 328 Accept: / Connection: close

{ "signatures": [ "SIG_K1_K23QRajZH3mXuFf4YmaVq5C7YHYxYmL7DpQvuoEj4DR9wRdA8DWPUr1H3QM4KMLLYR63D1cWQqURmRdKYydaFdstwiPFQs" ], "compression": "none", "packed_context_free_data": "", "packed_trx": "f87b935ba9229532a4e1000000000130f2d4142193b1ca000000000000806b0130f2d4142193b1ca00000000a8ed32320830f2d4142193b1ca00" }

RESPONSE:

{ "transaction_id": "563cff73db0ba46bc8777b30701da354d7964f4a5df49c2c07bf389eb6e660fa", "processed": { "id": "563cff73db0ba46bc8777b30701da354d7964f4a5df49c2c07bf389eb6e660fa", "receipt": { "status": "executed", "cpu_usage_us": 324, "net_usage_words": 13 }, "elapsed": 324, "net_usage": 104, "scheduled": false, "action_traces": [{ "receipt": { "receiver": "testaccount3", "act_digest": "6639f2f8849cfdd418665ba38d8b75a837ff26d6f602b1c66cfbce08c84649e7", "global_sequence": 336567, "recv_sequence": 1, "auth_sequence": [[ "testaccount3", 3 ] ], "code_sequence": 1, "abi_sequence": 1 }, "act": { "account": "testaccount3", "name": "hi", "authorization": [{ "actor": "testaccount3", "permission": "active" } ], "data": { "user": "testaccount3" }, "hex_data": "30f2d4142193b1ca" }, "elapsed": 139, "cpu_usage": 0, "console": "Hello %s, welcome to EOStestaccount3", "total_cpu_usage": 0, "trx_id": "563cff73db0ba46bc8777b30701da354d7964f4a5df49c2c07bf389eb6e660fa", "inline_traces": [] } ], "except": null } }

readygo586 avatar Sep 11 '18 03:09 readygo586

Please use "cleos sign" to sign transaction which produces correct signature:

Usage: ./cleos sign [OPTIONS] transaction

Positionals:
  transaction TEXT            The JSON string or filename defining the transaction to sign (required)

Options:
  -k,--private-key TEXT       The private key that will be used to sign the transaction
  -c,--chain-id TEXT          The chain id that will be used to sign the transaction
  -p,--push-transaction       Push transaction after signing

taokayan avatar Sep 11 '18 07:09 taokayan

The signature generated using this format is not accepted.

I'm sending the format suggested here to the sign_transaction endpoint:

[
  {
    "expiration": "2018-11-30T16:58:12.000",
    "ref_block_num": 1189284,
    "ref_block_prefix": 1800129830,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [
      
    ],
    "actions": [
      {
        "account": "habobhabob12",
        "name": "transfer",
        "authorization": [
          {
            "actor": "habobhabob12",
            "permission": "active"
          }
        ],
        "data": "20c2a1c7b4438f6930c2a1c7b4438f693c8601000000000005454f5300000000046e6f6e65"
      }
    ],
    "transaction_extensions": [
      
    ],
    "signatures": [
      
    ],
    "context_free_data": [
      
    ]
  },
  [
    "EOS57YCcBHPYidnEugAmh9Xpve9m5vovB6p6e2h4k6jLRLAFadoS8"
  ],
  ""
]

But when I use the returned signature in the chain/push_transaction endpoint, I get:

{
  "code": 500,
  "message": "Internal Service Error",
  "error": {
    "code": 3090003,
    "name": "unsatisfied_authorization",
    "what": "Provided keys, permissions, and delays do not satisfy declared authorizations",
    "details": [
      {
        "message": "transaction declares authority '{\"actor\":\"habobhabob12\",\"permission\":\"active\"}', but does not have signatures for it under a provided delay of 1000 ms, provided permissions [], provided keys [\"EOS8DKZ69EwdFeKxKEVa9rBiC4YFWJPajDmDWnWHJR7YT2qHrfNod\"], and a delay max limit of 3888000000 ms",
        "file": "authorization_manager.cpp",
        "line_number": 517,
        "method": "check_authorization"
      }
    ]
  }
}

In this response, the provided_key is different every time, which means that the format that was sent to the wallet/sign_transaction is not correct, because it is not receiving the keys parameter at all.

Please advise, as there is not a single working example of wallet/sign_transaction that I can find using the RPC. I have already looked at the keosd API docs, but there is no example of what the parameters should contain, and the docs don't detect my local keosd instance, even if I run it on port 8888.

mbassan avatar Nov 30 '18 16:11 mbassan

@mbassan Use cleos to sign your transaction with --print-request --print-response to see the input data and the sequence of RPC calls required to successfully compose and sign a transaction.

If you still have the problem and wish to discuss further, please post it in https://eosio.stackexchange.com. To keep things organized, Github issues are intended for bug reporting and feature tracking, and Stack Exchange is the right place for any technical support discussions. Thanks!

jgiszczak avatar Nov 30 '18 17:11 jgiszczak

packed_trx 如何获取

lingbaeryi-strong avatar Jul 15 '19 12:07 lingbaeryi-strong