EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.28k stars 3.6k forks source link

Invalid cast from type #146

Closed jcalfee closed 7 years ago

jcalfee commented 7 years ago

Copy the "processed" block output from this command (except for output):

eosc transfer eos inita 1

And send the json to the push_transaction API call. I'm getting the following error:

> eos.pushTransaction({
...     "refBlockNum": "76",
...     "refBlockPrefix": "110915365",
...     "expiration": "2017-08-08T20:55:13",
...     "scope": [
...       "eos",
...       "inita"
...     ],
...     "signatures": [],
...     "authorizations": [{
.....         "account": "eos",
.....         "permission": "active"
.....       }
...     ],
...     "messages": [{
.....         "code": "eos",
.....         "type": "transfer",
.....         "data": {
.......           "from": "eos",
.......           "to": "inita",
.......           "amount": "1"
.......         },
.....         "hex_data": "000000000000e62b000000008040934b0100000000000000"
.....       }
...     ]}, callback)
undefined
> { Error: 7 bad_cast_exception: Bad Cast
Invalid cast from object_type to string
    {"type":"object_type"}
    thread-1  variant.cpp:476 as_string
    at response.text.then.bodyResp (/home/jcalfee/eosjs/eosjs/node_modules/eosjs-api/src/apigen.js:48:25)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7) status: 500, statusText: 'Internal Server Error' }

This is the error in eosd:

3049398ms thread-1   http_plugin.cpp:134           operator()           ] {"refBlockNum":18,"refBlockPrefix":1130539283,"expiration":"2017-08-08T20:51:48","scope":["inita","initb"],"messages":[{"code":"eos","type":"transfer","data":{"from":"eos","to":"inita","amount":13}}],"signatures":["1f4fce0334cd50294659a6f07163af56ea5aec8dc3e4b447efd79f491af70089431c229c55aeaeb9b15bbd294440be860277d8bc67d4aeb225fd5e3cdb03d9cc5b"],"authorizations":[{"account":"eos","permission":"active"}]}
3049400ms thread-1   chain_api_plugin.cpp:59       operator()           ] Exception encountered while processing chain.push_transaction: {"code":7,"name":"bad_cast_exception","message":"Bad Cast","stack":[{"context":{"level":"error","file":"variant.cpp","line":565,"method":"get_string","hostname":"","thread_name":"thread-1","timestamp":"2017-08-08T20:50:49"},"format":"Invalid cast from type '${type}' to Object","data":{"type":"uint64_type"}}]}

3049398ms thread-1   http_plugin.cpp:133           operator()           ] handle http request: http://127.0.0.1:8888/v1/chain/push_transaction
3049398ms thread-1   http_plugin.cpp:134           operator()           ] {"refBlockNum":18,"refBlockPrefix":1130539283,"expiration":"2017-08-08T20:51:48","scope":["inita","initb"],"messages":[{"code":"eos","type":"transfer","data":{"from":"eos","to":"inita","amount":13}}],"signatures":["1f4fce0334cd50294659a6f07163af56ea5aec8dc3e4b447efd79f491af70089431c229c55aeaeb9b15bbd294440be860277d8bc67d4aeb225fd5e3cdb03d9cc5b"],"authorizations":[{"account":"eos","permission":"active"}]}
3049400ms thread-1   chain_api_plugin.cpp:59       operator()           ] Exception encountered while processing chain.push_transaction: {"code":7,"name":"bad_cast_exception","message":"Bad Cast","stack":[{"context":{"level":"error","file":"variant.cpp","line":565,"method":"get_string","hostname":"","thread_name":"thread-1","timestamp":"2017-08-08T20:50:49"},"format":"Invalid cast from type '${type}' to Object","data":{"type":"uint64_type"}}]}
nathanielhourt commented 7 years ago

Transaction no longer has a field "authorizations" -- this got moved down to Message::authorization. It might be dying trying to parse Message::authorization, which you don't have in your json.

jcalfee commented 7 years ago

nope

1781497ms thread-1   http_plugin.cpp:134           operator()           ] {"refBlockNum":795,"refBlockPrefix":59287120,"expiration":"2017-08-08T21:30:39","scope":["eos","inita"],"messages":[{"code":"eos","type":"transfer","data":{"from":"eos","to":"inita","amount":1}}],"signatures":["1f0563bfec4653f815b992a3f115910c472e70df018f2d783ddfe60aeffe2cf54441f69d06102260c09fe5d90b422f263f89c0cc234b933e994b8d11229f5b31a0"]}
1781497ms thread-1   chain_api_plugin.cpp:59       operator()           ] Exception encountered while processing chain.push_transaction: {"code":7,"name":"bad_cast_exception","message":"Bad Cast","stack":[{"context":{"level":"error","file":"variant.cpp","line":565,"method":"get_string","hostname":"","thread_name":"thread-1","timestamp":"2017-08-08T21:29:41"},"format":"Invalid cast from type '${type}' to Object","data":{"type":"uint64_type"}}]}
jcalfee commented 7 years ago

It might be the dreaded Message.type ..

nathanielhourt commented 7 years ago

It might be. I'm not sure how that gets serialized to json...

jcalfee commented 7 years ago

Here is my test command .. The api seems to be an issue if we assume the eosc output transaction is formatted correctly:

echo '{"refBlockNum":"18885","refBlockPrefix":"1955828998","expiration":"2017-08-09T13:05:25","scope":["eos","inita"],"signatures":[],"authorizations":[{"account":"eos","permission":"active"}],"messages":[{"code":"eos","type":"transfer","data":{"from":"eos","to":"inita","amount":"1"},"hex_data":"000000000000e62b000000008040934b0100000000000000"}]}' | curl http://127.0.0.1:8888/v1/chain/push_transaction -d @-
nathanielhourt commented 7 years ago

That transaction still has an authorizations field and the message lacks its authorization field.

jcalfee commented 7 years ago

nope

{"refBlockNum":1428,"refBlockPrefix":376491140,"expiration":"2017-08-15T18:29:09","scope":["inita","initb"],"messages":[{"code":"eos","type":"transfer","authorization":[{"account":"inita","permission":"active"}],"data":{"from":"inita","to":"initb","amount":"13"}}],"signatures":["1f095cf2fabaedd81f42e33dda85c3327bcb078f126d4993e014067f465cbad79577281a350c563ccee874546a385585885f224e1c46c1841413d28ce03fdcba8a"]}

Exception encountered while processing chain.push_transaction: {"code":7,"name":"bad_cast_exception","message":"Bad Cast","stack":[{"context":{"level":"error","file":"variant.cpp","line":565,"method":"get_string","hostname":"","thread_name":"thread-1","timestamp":"2017-08-15T18:28:11"},"format":"Invalid cast from type '${type}' to Object","data":{"type":"uint64_type"}}]}

elmato commented 7 years ago

@jcalfee just rename the hex_data field to data

{
    "refBlockNum": "111",
    "refBlockPrefix": "2018069090",
    "expiration": "2017-08-16T15:50:49",
    "scope": ["inita", "initb"],
    "messages": [
    {
        "code": "eos",
        "type": "transfer",
        "authorization": [
        {
            "account": "inita",
            "permission": "active"
        }],
        "data": "000000008040934b000000000041934b0a00000000000000"
    }],
    "signatures": []
}

Since the eos contract has the ABI defined, the output from push_transaction is prettyfied (decoded) before sending it back.

...
if( code_account.abi.size() > 4 ) { /// 4 == packsize of empty Abi
  try {
     msg_mvo( "data", message_from_binary( msg.code, msg.type, msg.data ) ); 
     msg_mvo( "hex_data", msg.data );
  } catch ( ... ) {
    SET_FIELD( msg_mvo, msg, data );
  }
}
...
jcalfee commented 7 years ago

@elmato Why is the transaction in JSON decoded but the data is not? Is it like this transaction is 1/2 decoded.

jcalfee commented 7 years ago

Dan explained to me that if it has an ABI the data could be JSON. Otherwise the "data" would be hex.

I think I see what is going on.. The EOS contract does not have an ABI.

jcalfee commented 7 years ago

moved to: https://github.com/EOSIO/eos/issues/215