Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer transaction in block 56507 fails to decode #1

Closed
YordanPavlov opened this issue Jul 30, 2019 · 8 comments
Closed

Transfer transaction in block 56507 fails to decode #1

YordanPavlov opened this issue Jul 30, 2019 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@YordanPavlov
Copy link
Contributor

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));

@antoncoding antoncoding self-assigned this Jul 31, 2019
@antoncoding
Copy link
Owner

@YordanPavlov I've published v1.3.1 and successfully decode your transaction

yAHwYl3uCkwqLIf6CiIKFFaTiqCQf6Xyw8gH0ME6RCK30VlbEgoKA0JOQhCAwtcvEiIKFCMJWejjsvQCM4kYGRbXUJt/L6e9EgoKA0JOQhCAwtcvEmwKJuta6YchAztOCdLc4TZvGVFzR8Di8uWQc+wrWCiNMteTI+WOrxHZEkALKLqUsUE1yfgXLVMUqCfinHXlOp2TF3XuoQhPEVrU6SkjlmIB+IBhhJWJ4S8jEDx3ITNF9/4L9STfK3EDvhh/GBgaBHRlc3QgAQ==

Result:

{"msg":[{"inputs":[{"address":{"type":"Buffer","data":[86,147,138,160,144,127,165,242,195,200,7,208,193,58,68,34,183,209,89,91]},"coins":[{"denom":"BNB","amount":100000000}]}],"outputs":[{"address":{"type":"Buffer","data":[35,9,89,232,227,178,244,2,51,137,24,25,22,215,80,155,127,47,167,189]},"coins":[{"denom":"BNB","amount":100000000}]}],"msgType":"MsgSend"}],"signatures":[{"pub_key":{"type":"Buffer","data":[235,90,233,135,33,3,59,78,9,210,220,225,54,111,25,81,115,71,192,226,242,229,144,115,236,43,88,40,141,50,215,147,35,229,142,175,17,217]},"signature":{"type":"Buffer","data":[11,40,186,148,177,65,53,201,248,23,45,83,20,168,39,226,156,117,229,58,157,147,23,117,238,161,8,79,17,90,212,233,41,35,150,98,1,248,128,97,132,149,137,225,47,35,16,60,119,33,51,69,247,254,11,245,36,223,43,113,3,190,24,127]},"account_number":24,"sequence":4}],"memo":"signature","source":1,"data":"","msgType":"StdTx"}

I've checked the input and output addresses are the same as the record on the dex explorer.

from: bnb126fc4gys07jl9s7gqlgvzwjyy2mazk2m3afadt
to:   bnb1yvy4n68rkt6qyvufrqv3d46sndljlfaa75lur3

Still not sure why the original algorithm failed, You can start trying the new version and I'll spend some more time digging into this issue

@oom-tesla
Copy link

oom-tesla commented Aug 14, 2019

@antoncoding Do you know how to get transaction hash from your example result above as it seems missing from the result:

{"msg":[{"inputs":[{"address":{"type":"Buffer","data":[86,147,138,160,144,127,165,242,195,200,7,208,193,58,68,34,183,209,89,91]},"coins":[{"denom":"BNB","amount":100000000}]}],"outputs":[{"address":{"type":"Buffer","data":[35,9,89,232,227,178,244,2,51,137,24,25,22,215,80,155,127,47,167,189]},"coins":[{"denom":"BNB","amount":100000000}]}],"msgType":"MsgSend"}],"signatures":[{"pub_key":{"type":"Buffer","data":[235,90,233,135,33,3,59,78,9,210,220,225,54,111,25,81,115,71,192,226,242,229,144,115,236,43,88,40,141,50,215,147,35,229,142,175,17,217]},"signature":{"type":"Buffer","data":[11,40,186,148,177,65,53,201,248,23,45,83,20,168,39,226,156,117,229,58,157,147,23,117,238,161,8,79,17,90,212,233,41,35,150,98,1,248,128,97,132,149,137,225,47,35,16,60,119,33,51,69,247,254,11,245,36,223,43,113,3,190,24,127]},"account_number":24,"sequence":4}],"memo":"signature","source":1,"data":"","msgType":"StdTx"}

And what's the best way to convert from inputs Buffer data
"data":[86,147,138,160,144,127,165,242,195,200,7,208,193,58,68,34,183,209,89,91]
To
bnb126fc4gys07jl9s7gqlgvzwjyy2mazk2m3afadt

Thanks for your very useful lib

@antoncoding
Copy link
Owner

@oom-tesla
I recently added encodeBnbAddress and decodeBnbAddress, you can use it as follow:

const bnbPrefixedAddress = txHexDecoder.encodeBnbAddress(data);

@oom-tesla
Copy link

@oom-tesla
I recently added encodeBnbAddress and decodeBnbAddress, you can use it as follow:

const bnbPrefixedAddress = txHexDecoder.encodeBnbAddress(data);

Very appreciated! how about get transaction hash do you know how to get it?

@antoncoding
Copy link
Owner

Very appreciated! how about get transaction hash do you know how to get it?

I didn't include the marshalBinary function from Binance's original sdk. you can check that out at https://github.com/binance-chain/javascript-sdk/blob/master/src/decoder/index.js

@oom-tesla
Copy link

oom-tesla commented Aug 20, 2019

@oom-tesla
I recently added encodeBnbAddress and decodeBnbAddress, you can use it as follow:

const bnbPrefixedAddress = txHexDecoder.encodeBnbAddress(data);

Hi @antoncoding I got this err when using encodeBnbAddress(data)

TypeError: Exceeds length limit
at Object.encode (/Volumes/Data/Projects/TXtoken/node_modules/raw-transaction-hex-decoder/node_modules/bech32/index.js:42:57)
at Object.encodeAddress [as encodeBnbAddress] (/Volumes/Data/Projects/TXtoken/node_modules/raw-transaction-hex-decoder/src/utils/bnb_addr_util.js:12:19)

Any advise?
How do I validate data before pass to your function? what's data length encodeBnbAddress expected?

@antoncoding
Copy link
Owner

Hi @antoncoding I got this err when using encodeBnbAddress(data)

TypeError: Exceeds length limit
at Object.encode (/Volumes/Data/Projects/TXtoken/node_modules/raw-transaction-hex-decoder/node_modules/bech32/index.js:42:57)
at Object.encodeAddress [as encodeBnbAddress] (/Volumes/Data/Projects/TXtoken/node_modules/raw-transaction-hex-decoder/src/utils/bnb_addr_util.js:12:19)

Any advise?
How do I validate data before pass to your function? what's data length encodeBnbAddress expected?

Sorry for the late reply. Did you encode the buffer [86,147,138,160,144,127,165,242,195,200,7,208,193,58,68,34,183,209,89,91] successfully?

I've recently updated the repository (as a seperate npm library) and will automatically encode all the addresses. Take a look at the new decoder interface here:
https://github.com/antoncoding/crypto-hex-decoder/tree/master/packages/bnb

@antoncoding antoncoding added the bug Something isn't working label Sep 13, 2019
@antoncoding
Copy link
Owner

I'm closing this issue since the original problem is fixed and the address encoder is working properly in the new version.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants