Git Product home page Git Product logo

crypto-hex-decoder's Introduction

Hi I'm Anton ๐Ÿ‘‹

Just think this is cool.

crypto-hex-decoder's People

Contributors

antoncoding avatar sotatek-sinhvu avatar yordanpavlov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

crypto-hex-decoder's Issues

Proper way to find out transaction type in BNB block response

This is more of a question than a bug report. I am investigating the proper way to find out that a transaction is either Transfer, PlaceOrder or CancelOrder. For example the response for block number 1675624 looks like so:

  "data": {
    "txs": [
      "0QHwYl3uClcWbmgbChQuWkaHZ7auJklLB/2D3jU9pDqcGBIMTUlUSC1DNzZfQk5CGi0yRTVBNDY4NzY3QjZBRTI2NDk0QjA3RkQ4M0RFMzUzREE0M0E5QzE4LTEzOTMScAom61rphyEDOF/+FGN7KGHRLSAjgklqmU2HytDmBpVzSQel4mPXhK0SQJ1VWVNwyZcVP4jdU5BkmasjCvj9XXh+kVav22mbzgkIRYxRnzUQFeFr+f5g3PrJp5Muhv+m5Pf8rl8g7Bcean0Y8gUg/QogAw==",
      "4gHwYl3uCmjObcBDChQ5gxX3iAGQO700xCvwmaTWpeXTlxItMzk4MzE1Rjc4ODAxOTAzQkJEMzRDNDJCRjA5OUE0RDZBNUU1RDM5Ny0xMTI1GgxNSVRILUM3Nl9CTkIgAigBMISRDjiA0I3AkhhAARJwCibrWumHIQMsx1J1eWZeFQP1hDa5pZlEFbtWX3ZxVnAPFLQJ8TPbshJA58WuHDJfFc1Km5dxUIkT97lvByNfYyEqxTzr34BfS2IGbDl4/esmVpNUwTcCew+naYpN+uPazjFyaXjY4HpMYhjzBSDkCCAD",
      "4gHwYl3uCmjObcBDChTkgZtIllLDN+FImM1f4L0nY3PhJRItRTQ4MTlCNDg5NjUyQzMzN0UxNDg5OENENUZFMEJEMjc2MzczRTEyNS0xNjE3GgxNSVRILUM3Nl9CTkIgAigBMJnQDjiApOiujxJAARJwCibrWumHIQMuE8JaXBNga6hZX+nAihtky08q1hO5WZohXAdgwsUbGBJAi+fInpJE4dv6xR8pPnUMokRG2vgKXHDptW4Lw0pT3ApDEqKAUg6IcX5d2J12KMFCpeZdWRnBAeG0IdeHZ4LHhhj0BSDQDCAD"
    ]

Trying to decode the first of those transactions as all of the possible types returns meaningful result. The results are like so:

Transfer is { inputs: [ { address: , coins: [Array] } ],
outputs: [ { address: , coins: [Array] } ],
msgType: 'MsgSend' }
Place order is: { sender: <Buffer 2e 5a 46 87 67 b6 ae 26 49 4b 07 fd 83 de 35 3d a4 3a 9c 18>,
id: 'MITH-C76_BNB',
symbol: '2E5A468767B6AE26494B07FD83DE353DA43A9C18-1393',
ordertype: 112,
side: 38,
price: 0,
quantity: 0,
timeinforce: 0,
msgType: 'NewOrderMsg' }
Cancel order is: { sender: <Buffer 2e 5a 46 87 67 b6 ae 26 49 4b 07 fd 83 de 35 3d a4 3a 9c 18>,
symbol: 'MITH-C76_BNB',
refid: '2E5A468767B6AE26494B07FD83DE353DA43A9C18-1393',
msgType: 'CancelOrderMsg' }
{}

As there is nothing in the response specifying the type, what would be the proper way to find it out.

Thanks!

decodeTransfer doesn't return all the outputs in case of multiple outputs in a transaction

Hi @antoncoding
I am facing an issue with decodeTransfer() function in which the data hex of a transaction with multiple outputs doesn't return all the outputs but just the first one, I am trying to view both the outputs of this transaction (https://testnet-explorer.binance.org/tx/E78C83F2FC9089486ECD55F9DE48E9DAB164A9004C2302754D63465AC8601D44). I tried going through the code too, but couldn't find a solution.
Could you please help me with this?
You can get data hex of the transaction I am trying to get the data of by visiting this url:
https://testnet-dex.binance.org/api/v1/tx/E78C83F2FC9089486ECD55F9DE48E9DAB164A9004C2302754D63465AC8601D44

{"msg":[{"inputs":[{"address":"tbnb138u9djee6fwphhd2a3628q2h0j5w97yx48zqex","coins":[{"denom":"BNB","amount":40000000000}]}],"outputs":[{"address":"tbnb18u4mzgv403uxvh5249wlzxueejah8eagp7j7hs","coins":[{"den om":"BNB","amount":20000000000}]}],"msgType":"MsgSend"}],"signatures":[{"pub_key":{"type":"Buffer","data":[193,35,154,82,160,189,207,229,205,111,52,202,98,183,255,129,131,245,66,69]},"signature":{"type":"Buf fer","data":[10,3,66,78,66,16,128,144,223,192,74]},"account_number":112,"sequence":38}],"memo":"","source":0,"data":"","msgType":"StdTx"}

Cannot decode Tx memo on mainnet

Here is my transaction detail in the mainnet:

https://dex.binance.org/api/v1/tx/16908395AE595CB6D3E33F857A7E1934F3A0BD7F920F73AE90232DB5A959AB0C?format=json

As you can see, the memo is:

"data": null,
"memo": "AVA_D_021189",

But, when I tried to decode raw tx above, it is:

3gHwYl3uClgqLIf6CigKFMm3DGlwDnrl8oUv/XuUcGS9pSBjEhAKB0FWQS02NDUQgICz/8QDEigKFEVc1zZPMVGEI/wwNXGZG6jdXLDSEhAKB0FWQS02NDUQgICz/8QDEm4KJuta6YchA5DMmRpyXoWfDeEKwECe+PVqqKEJHWQmGMhNou4rSireEkBccrwLsoJk8uNcl7GTVGhdwGdeyjugUfLnU1UeWoKJYT8D3LDWt2N6BU7yKadlWvJ/Lsh44xMJl3oXWS9m1LzXGJecFBoMQVZBX0RfMDIxMTg5IAI=

And here is the response after decode:

  memo: '',
  source: 0,
  data: '',
  msgType: 'StdTx' }

@antoncoding do you have any information about it?

Here is my source code:

    const bytes = Buffer.from(rawData, 'base64');
    // currently only supported transfer type
    try {
      const tx = bnbDecoder.decode(bytes.toString('hex'), config.network === 'testnet');
      console.log(`tx=========`, tx);
      return tx;
    } catch (err) {
      // if error, it mean it maybe not transfer tx
      return null;
    }

Transfer transaction in block 56507 fails to decode

I have tried to decode the transactions in the first two blocks on the BNB chain. The first non empty block is 52353 which decodes correctly. The second non empty block is 56507, which also contains one Transfer transaction, it fails to decode with error:

throw new Error(encountered fieldNum: ${fieldNum}, but we have already seen fnum: ${lastFieldNum})

I acquire both transaction hashes using an RPC request like so:

curl https://seed1.4leapbnb.com:443 -d @requestBlock.json

The RPC request looks like so:

cat requestBlock.json 
{"method": "block",
 "jsonrpc": "2.0",
 "params": [
	 "52353"
 ],
 "id": "dontcare"
}

I am then interested in this part of the response:

"data": {
        "txs": [
          "xAHwYl3uCk4qLIf6CiMKFOfWS4XKCqy2D0eDhU1Tz/okobYdEgsKA0JOQhCAyK+gJRIjChRWk4qgkH+l8sPIB9DBOkQit9FZWxILCgNCTkIQgMivoCUSbAom61rphyECPYFbIkkUUiC/tnsPu9KwAf/8PpcwSTCAE/FWqsJCQJASQJIUtRhIFVlytl+Ob5sobS7sERp7+7EmDrupYRS7N1KfOhUxoRFJCja7kbXXR9CPx5aSUJk3dCIh2Q+A7Cwf5lAYFiAB"
        ]
      }

The JS code used to do the decoding looks like this:

const txHexDecoder = require("raw-transaction-hex-decoder");


// Tx data returned for block 52353. Decodes correctly
const bufferDecoded = Buffer.from('xAHwYl3uCk4qLIf6CiMKFOfWS4XKCqy2D0eDhU1Tz/okobYdEgsKA0JOQhCAyK+gJRIjChRWk4qgkH+l8sPIB9DBOkQit9FZWxILCgNCTkIQgMivoCUSbAom61rphyECPYFbIkkUUiC/tnsPu9KwAf/8PpcwSTCAE/FWqsJCQJASQJIUtRhIFVlytl+Ob5sobS7sERp7+7EmDrupYRS7N1KfOhUxoRFJCja7kbXXR9CPx5aSUJk3dCIh2Q+A7Cwf5lAYFiAB', 'base64')

// Tx data returned for block 56507. Does NOT decode correctly instead
// raw-trx-hex-decoder/node_modules/raw-transaction-hex-decoder/src/utils/amino.js:115
// throw new Error(`encountered fieldNum: ${fieldNum}, but we have already seen fnum: ${lastFieldNum}`)
//const bufferDecoded = Buffer.from('yAHwYl3uCkwqLIf6CiIKFFaTiqCQf6Xyw8gH0ME6RCK30VlbEgoKA0JOQhCAwtcvEiIKFCMJWejjsvQCM4kYGRbXUJt/L6e9EgoKA0JOQhCAwtcvEmwKJuta6YchAztOCdLc4TZvGVFzR8Di8uWQc+wrWCiNMteTI+WOrxHZEkALKLqUsUE1yfgXLVMUqCfinHXlOp2TF3XuoQhPEVrU6SkjlmIB+IBhhJWJ4S8jEDx3ITNF9/4L9STfK3EDvhh/GBgaBHRlc3QgAQ==', 'base64')

let decodedTx = txHexDecoder.decodeBnbRawTx(bufferDecoded.toString('hex'), 'Transfer');
console.log(JSON.stringify(decodedTx));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.