Fix parsing of erc20 properties

This commit is contained in:
Martin Boehm 2018-12-04 13:56:25 +01:00
parent ec1647c864
commit 4a216fa647
3 changed files with 7 additions and 5 deletions

View File

@ -557,6 +557,8 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
TotalReceived: w.chainParser.AmountToDecimalString(ba.ReceivedSat()),
TotalSent: w.chainParser.AmountToDecimalString(&ba.SentSat),
TxApperances: int(ba.Txs),
Erc20Contract: erc20c,
Erc20Tokens: erc20t,
}, nil
}
bestheight, _, err := w.db.GetBestBlock()

View File

@ -118,11 +118,11 @@ func parseErc20StringProperty(contractDesc bchain.AddressDescriptor, data string
if has0xPrefix(data) {
data = data[2:]
}
if len(data) == 192 {
if len(data) > 128 {
n := parseErc20NumericProperty(contractDesc, data[64:128])
if n != nil {
l := n.Uint64()
if l <= 32 {
if 2*int(l) <= len(data)-128 {
b, err := hex.DecodeString(data[128 : 128+2*l])
if err == nil {
return string(b)

View File

@ -122,9 +122,9 @@ func TestErc20_parseErc20StringProperty(t *testing.T) {
want: "XPLODDE",
},
{
name: "1",
args: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000758504c4f44444500000000000000000000000000000000000000000000000000",
want: "XPLODDE",
name: "2",
args: "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000022426974436c617665202d20436f6e73756d657220416374697669747920546f6b656e00000000000000",
want: "BitClave - Consumer Activity Token",
},
}
for _, tt := range tests {