From 4a216fa6473eb2b037b34e753a259fcd208439f7 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 4 Dec 2018 13:56:25 +0100 Subject: [PATCH] Fix parsing of erc20 properties --- api/worker.go | 2 ++ bchain/coins/eth/erc20.go | 4 ++-- bchain/coins/eth/erc20_test.go | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/worker.go b/api/worker.go index ecabcfde..1e3c287c 100644 --- a/api/worker.go +++ b/api/worker.go @@ -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() diff --git a/bchain/coins/eth/erc20.go b/bchain/coins/eth/erc20.go index 6f63f666..003ee4e2 100644 --- a/bchain/coins/eth/erc20.go +++ b/bchain/coins/eth/erc20.go @@ -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) diff --git a/bchain/coins/eth/erc20_test.go b/bchain/coins/eth/erc20_test.go index 98accd00..2b0717fe 100644 --- a/bchain/coins/eth/erc20_test.go +++ b/bchain/coins/eth/erc20_test.go @@ -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 {