eos icon indicating copy to clipboard operation
eos copied to clipboard

push_transaction RPC API, Invalid packed transaction [error unpacking]

Open kristieguo opened this issue 8 years ago • 24 comments

Hi, I am trying to create a transaction and broadcast it to local node. I use push_transaction(signed_transaction) api but I was getting the error below:

{  
   "code":500,
   "message":"Internal Service Error",
   "error":{  
      "code":3010010,
      "name":"packed_transaction_type_exception",
      "what":"Invalid packed transaction",
      "details":[  
         {  
            "message":"Missing signatures",
            "file":"abi_serializer.hpp",
            "line_number":393,
            "method":"extract"
         },
         {  
            "message":"Failed to deserialize variant",
            "file":"abi_serializer.hpp",
            "line_number":487,
            "method":"from_variant"
         },
         {  
            "message":"Invalid packed transaction",
            "file":"chain_plugin.cpp",
            "line_number":455,
            "method":"push_transaction"
         }
      ]
   }
}

The signed transaction I created is like below:

{  
   "actions":[  
      {  
         "account":"eosio.token",
         "name":"transfer",
         "authorization":[  
            {  
               "actor":"tester",
               "permission":"active"
            }
         ],
         "data":{  
            "from":"tester",
            "to":"kris",
            "quantity":"1 EOS"
         }
      }
   ],
   "signatures":[  
      "SIG_K1_KeH6wCsnUWRjrfGtqPpXFK4BJArfQ4FwuZARnpVyWkfgdrbrKMgH1msyvrvGyxABYj5UyNpMmipWhpyaruRaRFQbcuDBb4"
   ]
}

I am running node locally on dawn 4.0 version. I read the source code and I think I am giving the correct format of the signed transaction, wondering what the problem is. Thanks.

kristieguo avatar May 17 '18 11:05 kristieguo

Likely due to quantity not being "1.0000 EOS" and/or missing "memo" in data section.

bytemaster avatar May 17 '18 21:05 bytemaster

I added memo but the error still occurs. I don't think the problem is about the data section. The error message is "Missing signatures". The code below is how I get signature:

let signature = eosjs.modules.ecc.sign('signing tx', privateKey)

I tried to use v1/chain/abi_json_to_bin to get a packed_trx, input params is like below:

"code":"eosio.token",
"action":"transfer",
"args":{  
   "from":"tester",
   "to":"user",
   "quantity":"1 EOS",
   "memo":"transfer"
}

And then give the below params to push_transaction, it is still not working.

{  
   "signatures":[    "SIG_K1_KeH6wCsnUWRjrfGtqPpXFK4BJArfQ4FwuZARnpVyWkfgdrbrKMgH1msyvrvGyxABYj5UyNpMmipWhpyaruRaRFQbcuDBb4"
   ],
   "compression":"none",
   "packed_context_free_data":"",
 "packed_trx":"000000005c95b1ca00000000007015d6010000000000000000454f5300000000087472616e73666572"
}

kristieguo avatar May 18 '18 06:05 kristieguo

The precision of quantity HAS TO BE 1 / 10000, here should be 1.0000 EOS, not 1 EOS. Maybe EOSDevHelper will help you.

spartucus avatar May 18 '18 08:05 spartucus

ok, I use 1.0000 EOS and generate a hex of the transaction, and then put it as a packed_trx, I got the below error. I think the way I pack the transaction is wrong. How should I pack a transaction and which contract should I use to pack it?

{  
   "code":500,
   "message":"Internal Service Error",
   "error":{  
      "code":3010010,
      "name":"packed_transaction_type_exception",
      "what":"Invalid packed transaction",
      "details":[  
         {  
            "message":"Invalid packed transaction",
            "file":"chain_plugin.cpp",
            "line_number":455,
            "method":"push_transaction"
         },
         {  
            "message":"read datastream of length 41 over by 0",
            "file":"datastream.cpp",
            "line_number":6,
            "method":"throw_datastream_range_error"
         },
         {  
            "message":"error unpacking uint64_t",
            "file":"raw.hpp",
            "line_number":602,
            "method":"unpack"
         },
         {  
            "message":"Error unpacking field value",
            "file":"raw.hpp",
            "line_number":361,
            "method":"operator()"
         },
         {  
            "message":"error unpacking eosio::chain::name",
            "file":"raw.hpp",
            "line_number":602,
            "method":"unpack"
         },
         {  
            "message":"Error unpacking field name",
            "file":"raw.hpp",
            "line_number":361,
            "method":"operator()"
         },
         {  
            "message":"error unpacking eosio::chain::action",
            "file":"raw.hpp",
            "line_number":602,
            "method":"unpack"
         },
         {  
            "message":"Error unpacking field context_free_actions",
            "file":"raw.hpp",
            "line_number":361,
            "method":"operator()"
         },
         {  
            "message":"error unpacking eosio::chain::transaction",
            "file":"raw.hpp",
            "line_number":602,
            "method":"unpack"
         },
         {  
            "message":"error unpacking eosio::chain::transaction",
            "file":"raw.hpp",
            "line_number":646,
            "method":"unpack"
         }
      ]
   }
}

The way I do it is as below:

➜ ~ curl http://127.0.0.1:8888/v1/chain/abi_json_to_bin -X POST -d '{"code":"eosio.token", "action":"transfer", "args":{"from":"tester", "to":"user", "quantity":"1.0000 EOS", "memo":"transfer"}}'

{"binargs":"000000005c95b1ca00000000007015d6102700000000000004454f5300000000087472616e73666572"}%

➜ ~ curl http://127.0.0.1:8888/v1/chain/push_transaction -X POST -d '{ "signatures":[ "SIG_K1_KeH6wCsnUWRjrfGtqPpXFK4BJArfQ4FwuZARnpVyWkfgdrbrKMgH1msyvrvGyxABYj5UyNpMmipWhpyaruRaRFQbcuDBb4" ], "compression":"none", "packed_context_free_data":"", "packed_trx": "000000005c95b1ca00000000007015d6102700000000000004454f5300000000087472616e73666572" }'

kristieguo avatar May 18 '18 09:05 kristieguo

+1 getting the same error

outdoteth avatar May 19 '18 09:05 outdoteth

+1

>>> response = requests.post('http://127.0.0.1:8890/v1/wallet/sign_transaction', data='[{"ref_block_prefix": 1683692525, "signatures": [], "messages": [{"data": {"binargs": "00000000007015d6000000005c95b1caa08601000000000004454f53000000001034303732343439323732323433323732"}, "code": "eosio.token", "type": "transfer", "authorization": [{"account": "user", "permission": "active"}]}], "ref_block_num": 18195, "expiration": "2018-05-23T12:34:46", "scope": ["user", "tester"], "read_scope": []}, ["EOS4uSuSJTE9r8e1uLMCtFwLTLcY72MtSaJDnorPPzfbe4RQfkAbZ"], ""]').json()

>>>print(response)
{u'actions': [],
 u'context_free_actions': [],
 u'context_free_data': [],
 u'delay_sec': 0,
 u'expiration': u'2018-05-23T12:34:46',
 u'max_cpu_usage_ms': 0,
 u'max_net_usage_words': 0,
 u'ref_block_num': 18195,
 u'ref_block_prefix': 1683692525,
 u'signatures': [u'SIG_K1_JuS6ME3m1xwzvDRM3rb8yBrhFby9AJrGprHfqJ2MNyEzc7gH7EjoPEjATpfpTgX8zT8W1sdtTxePhaD5TgHCHyPHVMG85E'],
 u'transaction_extensions': []}

>>> transaction = {"compression": "none",
                   "packed_context_free_data": "",
                   "packed_trx": "00000000007015d6000000005c95b1caa08601000000000004454f53000000001034303732343439323732323433323732",
                   "signatures": "SIG_K1_JuS6ME3m1xwzvDRM3rb8yBrhFby9AJrGprHfqJ2MNyEzc7gH7EjoPEjATpfpTgX8zT8W1sdtTxePhaD5TgHCHyPHVMG85E"}

>>> response = requests.post('http://127.0.0.1:8888/v1/chain/push_transaction', json=transaction).json()
>>> print(response)
{u'code': 500,
 u'error': {u'code': 3010010,
            u'details': [{u'file': u'chain_plugin.cpp',
                          u'line_number': 545,
                          u'message': u'Invalid packed transaction',
                          u'method': u'push_transaction'},
                         {u'file': u'variant.cpp',
                          u'line_number': 535,
                          u'message': u'Invalid cast from string_type to Array',
                          u'method': u'get_array'},
                         {u'file': u'abi_serializer.hpp',
                          u'line_number': 517,
                          u'message': u'Failed to deserialize variant',
                          u'method': u'from_variant'}],
            u'name': u'packed_transaction_type_exception',
            u'what': u'Invalid packed transaction'},
 u'message': u'Internal Service Error'}

yupasik avatar May 23 '18 12:05 yupasik

same error, version dawn v4.1.0 my signed-transaction is:

{ "expiration": "2018-05-25T03:00:00", "ref_block_num": 48582, "ref_block_prefix": 983774172, "max_net_usage_words": 0, "max_cpu_usage_ms": 0, "delay_sec": 0, "context_free_actions": [], "actions": [{ "account": "eosio.token", "name": "transfer", "authorization": [{ "actor": "user", "permission": "active" } ], "data": "00000000007015d6000000005c95b1ca80841e00000000000453595300000000046d656d6f" } ], "transaction_extensions": [], "signatures": [ "SIG_K1_K51Xy3JBhLgsVoyk9Ks57EPLiYCvsaasw22LemQrAznnzFFeNUyR8pGnKd11ptGGaLfcD3yipTpDpNU4f4GBc4rqrfWNC2" ], "context_free_data": [] }

data field curl http://127.0.0.1:8888/v1/chain/abi_json_to_bin -X POST -d '{"code":"eosio.token","action":"transfer", "args":{"from":"user", "to":"tester", "quantity":"200.0000 SYS", "memo":"memo"}}'

I could push transaction using cleos push transaction <signed-transaction.txt> When I use http api, error below: { "code": 500, "error": { "code": 3010010, "details": [ { "file": "abi_serializer.hpp", "line_number": 425, "message": "Missing compression", "method": "extract" }, { "file": "abi_serializer.hpp", "line_number": 518, "message": "Failed to deserialize variant", "method": "from_variant" }, { "file": "chain_plugin.cpp", "line_number": 526, "message": "Invalid packed transaction", "method": "push_transaction" } ], "name": "packed_transaction_type_exception", "what": "Invalid packed transaction" }, "message": "Internal Service Error" }

guaiguaihw avatar May 25 '18 03:05 guaiguaihw

I think fc's unpack buffer is too small:

         {  
            "message":"read datastream of length 41 over by 0",
            "file":"datastream.cpp",
            "line_number":6,
            "method":"throw_datastream_range_error"
         },
  // Stream adapter for use with the fc unpack functionality
  template <uint32_t buffer_len>
  class mb_datastream {
     public:
        mb_datastream( message_buffer<buffer_len>& m ) : mb(m) {}

        inline void skip( size_t s ) { mb.advance_read_ptr(s); }
        inline bool read( char* d, size_t s ) {
          if (mb.bytes_to_read() >= s) {
            mb.read(d, s);
            return true;
          }
          fc::detail::throw_datastream_range_error( "read", mb.bytes_to_read(), s - mb.bytes_to_read());
        }

        inline bool   get( unsigned char& c ) { return mb.read(&c, 1); }
        inline bool   get( char& c ) { return mb.read(&c, 1); }

      private:
        message_buffer<buffer_len>& mb;
  };

I'm getting this same error after deploying eosio.token then trying to read it back:

> api error => { message: 'read datastream of length 14 over by -12',
  file: 'datastream.cpp',
  line_number: 6,
  method: 'throw_datastream_range_error' } http://127.0.0.1:8888/v1/chain/get_code {"account_name":"inita"}

jcalfee avatar May 25 '18 21:05 jcalfee

Got the same error when trying to read a contract

api error => { message: 'read datastream of length 14 over by -12',
  file: 'datastream.cpp',
  line_number: 6,
  method: 'throw_datastream_range_error' } 

Any progress on this?

WeijiaChe avatar May 28 '18 06:05 WeijiaChe

I have solve the problem, the struct of unbroadcast transaction has changed in dawn4.1/4.2 Like the struct below: { "transaction": transaction struct, "signatures": xxxx, "compression": "none" } For example: image @kristieguo

guaiguaihw avatar May 28 '18 07:05 guaiguaihw

Does this problem still exist?

taokayan avatar Jun 20 '18 10:06 taokayan

Im still having this issue. Below is the format I'm using on push transaction. Is this correct?

{
  "compression": "none",
  "signatures": [
    "SIG_K1_K2C2qKLbwQ3vGjrYQp89fTNkqHmnbiWPPw6Gg2AxD35o8s3PPrzfFdG7v8v9VpojHFwykt2rZze1BFfP3QQdjppsyQzHsD"
  ],
  "transaction": {
    "ref_block_prefix": 2793985123,
    "net_usage_words": 0,
    "expiration": "2018-06-29T18:45:44.0000",
    "ref_block_num": 3300265,
    "delay_sec": 0,
    "context_free_actions": [
      
    ],
    "transaction_extensions": [
      
    ],
    "actions": [
      {
        "name": "transfer",
        "account": "eosio.token",
        "data": "10b0db269d43917990d45dd351042fe5010000000000000004535953000000000e746573742066726f6d206c796e78",
        "authorization": {
          "actor": "<username>",
          "permission": "active"
        }
      }
    ],
    "context_free_data": [
      
    ],
    "max_cpu_usage_ms": 0
  }
}

Always fails with:

{
  "code": 500,
  "message": "Internal Service Error",
  "error": {
    "code": 3010011,
    "name": "packed_transaction_type_exception",
    "what": "Invalid packed transaction",
    "details": [
      
    ]
  }
}

ismyhc avatar Jun 29 '18 18:06 ismyhc

I was told I need to do a packed transaction if Im using signing offline and user the rpc interface. I think I've successfully packed the trx, but im still getting the same message. Its hard to tell by the error message. I guess its saying that the packed_trx is invalid? Is that the correct assumption?

{
  "packed_context_free_data" : [

  ],
  "compression" : "none",
  "signatures" : [
    "SIG_K1_Kida3zYdhCu2JcXzu7S27SgL89y4eJTbfEE6YQum4x2vzBfszbnzozByHxay5SBMHAoQ9f8569Mq1HexyYBboLm1e7uYAL"
  ],
  "packed_trx" : "1ce3365b00000b7320000032f763f0000000010a682343ea3055000572d3ccdcd110b0db269d4391790000a8ed32322f10b0db269d43917990d45dd35142fe5100000004454f530000e746573742066726f6d206c796e78100000000000000000000000000000000"
}

ismyhc avatar Jun 29 '18 22:06 ismyhc

@ismyhc where can i find the "packed_trx"?

destiny008 avatar Jul 04 '18 03:07 destiny008

I packed the tx via rpc call 'v1/chain/abi_json_to_bin' but still getting the same error 3010010. Full response below

<Response [500]> {'code': 500, 'message': 'Internal Service Error', 'error': {'code': 3010010, 'name': 'packed_transaction_type_exception', 'what': 'Invalid packed transaction', 'details': [{'message': 'Invalid packed transaction', 'file': 'chain_plugin.cpp', 'line_number': 1457, 'method': 'push_transaction'}, {'message': 'read datastream of length 37 over by -4', 'file': 'datastream.cpp', 'line_number': 6, 'method': 'throw_datastream_range_error'}, {'message': 'error unpacking uint64_t', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field value', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::name', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field account', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::action', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field context_free_actions', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::transaction', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'error unpacking eosio::chain::transaction', 'file': 'raw.hpp', 'line_number': 660, 'method': 'unpack'}]}}

silvercondor avatar Sep 20 '18 12:09 silvercondor

I packed the tx via rpc call 'v1/chain/abi_json_to_bin' but still getting the same error 3010010. Full response below

<Response [500]> {'code': 500, 'message': 'Internal Service Error', 'error': {'code': 3010010, 'name': 'packed_transaction_type_exception', 'what': 'Invalid packed transaction', 'details': [{'message': 'Invalid packed transaction', 'file': 'chain_plugin.cpp', 'line_number': 1457, 'method': 'push_transaction'}, {'message': 'read datastream of length 37 over by -4', 'file': 'datastream.cpp', 'line_number': 6, 'method': 'throw_datastream_range_error'}, {'message': 'error unpacking uint64_t', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field value', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::name', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field account', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::action', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'Error unpacking field context_free_actions', 'file': 'raw.hpp', 'line_number': 368, 'method': 'operator()'}, {'message': 'error unpacking eosio::chain::transaction', 'file': 'raw.hpp', 'line_number': 616, 'method': 'unpack'}, {'message': 'error unpacking eosio::chain::transaction', 'file': 'raw.hpp', 'line_number': 660, 'method': 'unpack'}]}}

Resolved. packed transction is not json_to_abi call but a separate action done on the local machine

silvercondor avatar Sep 22 '18 09:09 silvercondor

@silvercondor Could you give me more detail on packed transaction?How could we make those packed_trx with rpc?

essemfly avatar Oct 22 '18 02:10 essemfly

@silvercondor Could you give me more detail on packed transaction?How could we make those packed_trx with rpc?

from what I know, packing of transaction will not be supported via rpc and has to be done on local machine. You may use a library like eosjs/eosjs2 to pack your transaction or study the library for your own implementation

silvercondor avatar Oct 24 '18 09:10 silvercondor

I have solved this problem. I do a packed transaction using signing offline, my problem is on the local signature with 'EosByteWriter'. If you need help, you can ask me questions.

choiceyou avatar Oct 25 '18 01:10 choiceyou

I have solved this problem. I do a packed transaction using signing offline, my problem is on the local signature with 'EosByteWriter'. If you need help, you can ask me questions.

How can I create a packed transaction?

RishalEP avatar Oct 26 '18 09:10 RishalEP