tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
413 stars 271 forks source link

feature request: deserialize `raw_data_hex` into transaction #439

Open drunkirishcoder opened 10 months ago

drunkirishcoder commented 10 months ago

Would be nice if TronWeb supports deserializing the raw_data_hex back into a transaction object. Currently, the lib supports going from transactionBuilder to a binary hex, but there's no way to go in reverse. Though all the necessary protobuf definition and transaction definitions are there. Would be nice to be able to do the reverse.

svein1010 commented 10 months ago

raw_data_hex is the hex format of transaction.raw_data and it does't include information of txID and signature. As raw_data and raw_data_hex appear together, you can get what you want through raw_data property.

drunkirishcoder commented 10 months ago

Isn't txID just sha256 of the raw data bytes? also raw_data_hex can contain signatures as well if I'm not mistaken, because this endpoint exists.

anyway, without going into details, I have an use case where I have the raw_data_hex but not raw_data, and would be nice if TronWeb can deserialize it.

svein1010 commented 10 months ago

Yes, txID is just sha256 of the raw data bytes. And raw_data_hex only contains the infomation of raw_data. When you get a transaction after deserializing the raw_data_hex, you must sign the transaction again to get signature. The raw_data interface is as following:

  message raw {
    bytes ref_block_bytes = 1;
    int64 ref_block_num = 3;
    bytes ref_block_hash = 4;
    int64 expiration = 8;
    repeated authority auths = 9;
    bytes data = 10;
    repeated Contract contract = 11;
    bytes scripts = 12;
    int64 timestamp = 14;
    int64 fee_limit = 18;
  }

We will consider to support this feature in a later version. Thanks for your suggestion.

oh-Blade commented 5 months ago

https://github.com/tronprotocol/tronweb/issues/464