From 7da714bec41117dac71db648dd8fb673764c8da4 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Thu, 20 Dec 2018 13:18:38 +0100 Subject: [PATCH] Generalize erc20transfers to tokentransfers in api --- api/types.go | 12 +++++++----- api/worker.go | 13 +++++++------ static/templates/txdetail_ethereumtype.html | 6 +++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/api/types.go b/api/types.go index 6d785a5a..349cbfcc 100644 --- a/api/types.go +++ b/api/types.go @@ -115,15 +115,16 @@ type Erc20Token struct { ContractIndex string `json:"-"` } -// Erc20Transfer contains info about ERC20 transfer done in a transaction -type Erc20Transfer struct { +// TokenTransfer contains info about a token transfer done in a transaction +type TokenTransfer struct { + Type string `json:"type"` From string `json:"from"` To string `json:"to"` - Contract string `json:"contract"` + Token string `json:"token"` Name string `json:"name"` Symbol string `json:"symbol"` Decimals int `json:"decimals"` - Tokens *Amount `json:"tokens"` + Value *Amount `json:"value"` } // EthereumSpecific contains ethereum specific transaction data @@ -154,7 +155,7 @@ type Tx struct { Hex string `json:"hex,omitempty"` CoinSpecificData interface{} `json:"-"` CoinSpecificJSON json.RawMessage `json:"-"` - Erc20Transfers []Erc20Transfer `json:"erc20transfers,omitempty"` + TokenTransfers []TokenTransfer `json:"tokentransfers,omitempty"` EthereumSpecific *EthereumSpecific `json:"ethereumspecific,omitempty"` } @@ -174,6 +175,7 @@ const ( AddressFilterVoutOutputs = -3 ) +// AddressFilter is used to filter data returned from GetAddress api method type AddressFilter struct { Vout int Contract string diff --git a/api/worker.go b/api/worker.go index dfabbd3e..cb91a49b 100644 --- a/api/worker.go +++ b/api/worker.go @@ -112,7 +112,7 @@ func (w *Worker) GetTransaction(txid string, spendingTxs bool, specificJSON bool func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, spendingTxs bool, specificJSON bool) (*Tx, error) { var err error var ta *db.TxAddresses - var erc20t []Erc20Transfer + var tokens []TokenTransfer var ethSpecific *EthereumSpecific var blockhash string if bchainTx.Confirmations > 0 { @@ -222,7 +222,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, if err != nil { glog.Errorf("GetErc20FromTx error %v, %v", err, bchainTx) } - erc20t = make([]Erc20Transfer, len(ets)) + tokens = make([]TokenTransfer, len(ets)) for i := range ets { e := &ets[i] cd, err := w.chainParser.GetAddrDescFromAddress(e.Contract) @@ -237,12 +237,13 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, if erc20c == nil { erc20c = &bchain.Erc20Contract{Name: e.Contract} } - erc20t[i] = Erc20Transfer{ - Contract: e.Contract, + tokens[i] = TokenTransfer{ + Type: "ERC20", + Token: e.Contract, From: e.From, To: e.To, Decimals: erc20c.Decimals, - Tokens: (*Amount)(&e.Tokens), + Value: (*Amount)(&e.Tokens), Name: erc20c.Name, Symbol: erc20c.Symbol, } @@ -289,7 +290,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, Vout: vouts, CoinSpecificData: bchainTx.CoinSpecificData, CoinSpecificJSON: sj, - Erc20Transfers: erc20t, + TokenTransfers: tokens, EthereumSpecific: ethSpecific, } return r, nil diff --git a/static/templates/txdetail_ethereumtype.html b/static/templates/txdetail_ethereumtype.html index 8c091479..6c7bcd57 100644 --- a/static/templates/txdetail_ethereumtype.html +++ b/static/templates/txdetail_ethereumtype.html @@ -69,11 +69,11 @@ {{formatAmount $tx.ValueOutSat}} {{$cs}} - {{- if $tx.Erc20Transfers -}} + {{- if $tx.TokenTransfers -}}
ERC20 Token Transfers
- {{- range $erc20 := $tx.Erc20Transfers -}} + {{- range $erc20 := $tx.TokenTransfers -}}
@@ -106,7 +106,7 @@
-
{{formatAmountWithDecimals $erc20.Tokens $erc20.Decimals}} {{$erc20.Symbol}}
+
{{formatAmountWithDecimals $erc20.Value $erc20.Decimals}} {{$erc20.Symbol}}
{{- end -}}