From ba27e2180ae89a46783ec6feaf872d27ddbd8cd2 Mon Sep 17 00:00:00 2001 From: Viktor Radchenko <1641795+vikmeup@users.noreply.github.com> Date: Wed, 24 Jul 2019 11:15:41 -0700 Subject: [PATCH] Add decimals and symbol to blockatlas.Transfer object (#190) * Add decimals and symbol to blockatlas.Transfer object * Remove printing data --- observer/dispatcher.go | 2 +- platform/aion/api.go | 6 ++++-- platform/binance/api.go | 4 +++- platform/cosmos/api.go | 4 +++- platform/ethereum/api.go | 4 +++- platform/icon/api.go | 22 ++++++++++++---------- platform/iotex/api.go | 4 +++- platform/nimiq/api.go | 6 ++++-- platform/ontology/api.go | 30 ++++++++++++++++-------------- platform/ripple/api.go | 6 ++++-- platform/semux/api.go | 4 +++- platform/stellar/api.go | 4 +++- platform/tezos/api.go | 6 ++++-- platform/theta/api.go | 26 ++++++++++++++------------ platform/tron/api.go | 4 +++- platform/vechain/api.go | 11 ++++++----- platform/waves/api.go | 6 ++++-- platform/zilliqa/api.go | 6 +++++- tx.go | 4 +++- 19 files changed, 98 insertions(+), 61 deletions(-) diff --git a/observer/dispatcher.go b/observer/dispatcher.go index 11ba7b635..f5de40644 100644 --- a/observer/dispatcher.go +++ b/observer/dispatcher.go @@ -51,5 +51,5 @@ func (d *Dispatcher) postWebhook(hook string, data []byte, log *logrus.Entry) { if err != nil { log.WithError(err).Errorf("Failed to dispatch event %s: %s", hook, err) } - log.Infoln(fmt.Sprintf("Dispatch: hook = %s & data = %s", hook, bytes.NewReader(data))) + log.Info("Dispatch: hook: ", hook) } diff --git a/platform/aion/api.go b/platform/aion/api.go index 330555ed7..4f59224c1 100644 --- a/platform/aion/api.go +++ b/platform/aion/api.go @@ -48,8 +48,10 @@ func NormalizeTx(srcTx *Tx) (tx blockatlas.Tx, ok bool) { To: "0x" + srcTx.ToAddr, Fee: blockatlas.Amount(fee), Block: srcTx.BlockNumber, - Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(value), + Meta: blockatlas.Transfer{ + Value: blockatlas.Amount(value), + Symbol: coin.Coins[coin.AION].Symbol, + Decimals: coin.Coins[coin.AION].Decimals, }, }, true } diff --git a/platform/binance/api.go b/platform/binance/api.go index 9efc66d43..8c979891b 100644 --- a/platform/binance/api.go +++ b/platform/binance/api.go @@ -83,7 +83,9 @@ func NormalizeTx(srcTx *Tx, token string) (tx blockatlas.Tx, ok bool) { // Condition for native transfer (BNB) if srcTx.Asset == "BNB" && srcTx.Type == "TRANSFER" && token == "" { tx.Meta = blockatlas.Transfer{ - Value: blockatlas.Amount(value), + Value: blockatlas.Amount(value), + Symbol: coin.Coins[coin.BNB].Symbol, + Decimals: coin.Coins[coin.BNB].Decimals, } return tx, true } diff --git a/platform/cosmos/api.go b/platform/cosmos/api.go index 7c88ff81c..3bfd6cc5d 100644 --- a/platform/cosmos/api.go +++ b/platform/cosmos/api.go @@ -76,7 +76,9 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx) { Block: block, Memo: srcTx.Data.Contents.Memo, Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(value), + Value: blockatlas.Amount(value), + Symbol: coin.Coins[coin.ATOM].Symbol, + Decimals: coin.Coins[coin.ATOM].Decimals, }, } } diff --git a/platform/ethereum/api.go b/platform/ethereum/api.go index cd9afc059..396779fec 100644 --- a/platform/ethereum/api.go +++ b/platform/ethereum/api.go @@ -109,7 +109,9 @@ func AppendTxs(in []blockatlas.Tx, srcTx *Doc, coinIndex uint) (out []blockatlas if len(srcTx.Ops) == 0 && srcTx.Input == "0x" { transferTx := baseTx transferTx.Meta = blockatlas.Transfer{ - Value: blockatlas.Amount(srcTx.Value), + Value: blockatlas.Amount(srcTx.Value), + Symbol: coin.Coins[coinIndex].Symbol, + Decimals: coin.Coins[coinIndex].Decimals, } out = append(out, transferTx) } diff --git a/platform/icon/api.go b/platform/icon/api.go index ef31ccbad..6058dd0e5 100644 --- a/platform/icon/api.go +++ b/platform/icon/api.go @@ -53,17 +53,19 @@ func Normalize(trx *Tx) (tx blockatlas.Tx, b bool) { value := util.DecimalExp(string(trx.Amount), 18) return blockatlas.Tx{ - ID: trx.TxHash, - Coin : coin.ICX, - From : trx.FromAddr, - To : trx.ToAddr, - Fee : blockatlas.Amount(fee), - Status : blockatlas.StatusCompleted, - Date : date.Unix(), - Type : blockatlas.TxTransfer, - Block : trx.Height, + ID: trx.TxHash, + Coin: coin.ICX, + From: trx.FromAddr, + To: trx.ToAddr, + Fee: blockatlas.Amount(fee), + Status: blockatlas.StatusCompleted, + Date: date.Unix(), + Type: blockatlas.TxTransfer, + Block: trx.Height, Meta: blockatlas.Transfer{ - Value : blockatlas.Amount(value), + Value: blockatlas.Amount(value), + Symbol: coin.Coins[coin.ICX].Symbol, + Decimals: coin.Coins[coin.ICX].Decimals, }, }, true } diff --git a/platform/iotex/api.go b/platform/iotex/api.go index 3947e3927..ce51407f8 100644 --- a/platform/iotex/api.go +++ b/platform/iotex/api.go @@ -90,7 +90,9 @@ func Normalize(trx *ActionInfo) *blockatlas.Tx { Sequence: uint64(nonce), Type: blockatlas.TxTransfer, Meta: blockatlas.Transfer{ - Value: trx.Action.Core.Transfer.Amount, + Value: trx.Action.Core.Transfer.Amount, + Symbol: coin.Coins[coin.IOTX].Symbol, + Decimals: coin.Coins[coin.IOTX].Decimals, }, } } diff --git a/platform/nimiq/api.go b/platform/nimiq/api.go index c3b6720e2..3ea41b01c 100644 --- a/platform/nimiq/api.go +++ b/platform/nimiq/api.go @@ -51,8 +51,10 @@ func NormalizeTx(srcTx *Tx) blockatlas.Tx { To: srcTx.ToAddress, Fee: srcTx.Fee, Block: srcTx.BlockNumber, - Meta: blockatlas.Transfer{ - Value: srcTx.Value, + Meta: blockatlas.Transfer{ + Value: srcTx.Value, + Symbol: coin.Coins[coin.NIM].Symbol, + Decimals: coin.Coins[coin.NIM].Decimals, }, } } diff --git a/platform/ontology/api.go b/platform/ontology/api.go index 806d311b3..39162f9f4 100644 --- a/platform/ontology/api.go +++ b/platform/ontology/api.go @@ -16,8 +16,8 @@ type Platform struct { const ( GovernanceContract = "AFmseVrdL9f9oyCzZefL9tG6UbviEH9ugK" - ONTAssetName = "ont" - ONGAssetName = "ong" + ONTAssetName = "ont" + ONGAssetName = "ong" ) func (p *Platform) Init() error { @@ -68,11 +68,11 @@ func Normalize(srcTx *Tx, assetName string) (tx blockatlas.Tx, ok bool) { } tx = blockatlas.Tx{ - ID: srcTx.TxnHash, - Coin: coin.ONT, - Fee: blockatlas.Amount(fee), - Date: srcTx.TxnTime, - Block: srcTx.Height, + ID: srcTx.TxnHash, + Coin: coin.ONT, + Fee: blockatlas.Amount(fee), + Date: srcTx.TxnTime, + Block: srcTx.Height, Status: status, } @@ -96,7 +96,9 @@ func normalizeONT(tx *blockatlas.Tx, transfer *Transfer) { tx.To = transfer.ToAddress tx.Type = blockatlas.TxTransfer tx.Meta = blockatlas.Transfer{ - Value: blockatlas.Amount(value), + Value: blockatlas.Amount(value), + Symbol: coin.Coins[coin.ONT].Symbol, + Decimals: coin.Coins[coin.ONT].Decimals, } } @@ -114,12 +116,12 @@ func normalizeONG(tx *blockatlas.Tx, transfer *Transfer) { tx.To = to tx.Type = blockatlas.TxNativeTokenTransfer tx.Meta = blockatlas.NativeTokenTransfer{ - Name: "Ontology Gas", - Symbol: "ONG", - TokenID: "ong", + Name: "Ontology Gas", + Symbol: "ONG", + TokenID: "ong", Decimals: 9, - Value: blockatlas.Amount(value), - From: from, - To: to, + Value: blockatlas.Amount(value), + From: from, + To: to, } } diff --git a/platform/ripple/api.go b/platform/ripple/api.go index a7ed07887..f484bfadf 100644 --- a/platform/ripple/api.go +++ b/platform/ripple/api.go @@ -70,8 +70,10 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx, ok bool) { To: srcTx.Payment.Destination, Fee: srcTx.Payment.Fee, Block: srcTx.LedgerIndex, - Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(srcAmount), + Meta: blockatlas.Transfer{ + Value: blockatlas.Amount(srcAmount), + Symbol: coin.Coins[coin.XRP].Symbol, + Decimals: coin.Coins[coin.XRP].Decimals, }, }, true } diff --git a/platform/semux/api.go b/platform/semux/api.go index 51e2890cf..00db0c2bd 100644 --- a/platform/semux/api.go +++ b/platform/semux/api.go @@ -62,7 +62,9 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx, err error) { Fee: srcTx.Fee, Block: blockNumber, Meta: blockatlas.Transfer{ - Value: srcTx.Value, + Value: srcTx.Value, + Symbol: coin.Coins[coin.SEM].Symbol, + Decimals: coin.Coins[coin.SEM].Decimals, }, }, nil } diff --git a/platform/stellar/api.go b/platform/stellar/api.go index a6eea89d4..8b786d2d4 100644 --- a/platform/stellar/api.go +++ b/platform/stellar/api.go @@ -115,7 +115,9 @@ func Normalize(payment *Payment, nativeCoinIndex uint) (tx blockatlas.Tx, ok boo Date: date.Unix(), Block: id, Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(value), + Value: blockatlas.Amount(value), + Symbol: coin.Coins[nativeCoinIndex].Symbol, + Decimals: coin.Coins[nativeCoinIndex].Decimals, }, }, true } diff --git a/platform/tezos/api.go b/platform/tezos/api.go index 90ffbba41..2cfb01ab0 100644 --- a/platform/tezos/api.go +++ b/platform/tezos/api.go @@ -77,8 +77,10 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx, ok bool) { To: op.Dest.Tz, Fee: op.Fee, Block: op.OpLevel, - Meta: blockatlas.Transfer{ - Value: op.Amount, + Meta: blockatlas.Transfer{ + Value: op.Amount, + Symbol: coin.Coins[coin.XTZ].Symbol, + Decimals: coin.Coins[coin.XTZ].Decimals, }, Status: status, Error: errMsg, diff --git a/platform/theta/api.go b/platform/theta/api.go index 17705c78c..b2fb1c4d5 100644 --- a/platform/theta/api.go +++ b/platform/theta/api.go @@ -53,11 +53,11 @@ func Normalize(trx *Tx, address, token string) (tx blockatlas.Tx, ok bool) { block, _ := strconv.ParseUint(trx.BlockHeight, 10, 64) tx = blockatlas.Tx{ - ID: trx.Hash, - Coin: coin.THETA, - Fee: blockatlas.Amount(trx.Data.Fee.Tfuelwei), - Date: time, - Block: block, + ID: trx.Hash, + Coin: coin.THETA, + Fee: blockatlas.Amount(trx.Data.Fee.Tfuelwei), + Date: time, + Block: block, Sequence: block, } @@ -72,7 +72,9 @@ func Normalize(trx *Tx, address, token string) (tx blockatlas.Tx, ok bool) { tx.Sequence = sequence tx.Type = blockatlas.TxTransfer tx.Meta = blockatlas.Transfer{ - Value: blockatlas.Amount(output.Coins.Thetawei), + Value: blockatlas.Amount(output.Coins.Thetawei), + Symbol: coin.Coins[coin.THETA].Symbol, + Decimals: coin.Coins[coin.THETA].Decimals, } return tx, true @@ -87,13 +89,13 @@ func Normalize(trx *Tx, address, token string) (tx blockatlas.Tx, ok bool) { tx.Sequence = sequence tx.Type = blockatlas.TxNativeTokenTransfer tx.Meta = blockatlas.NativeTokenTransfer{ - Name: "Theta Fuel", - Symbol: "TFUEL", - TokenID: "tfuel", + Name: "Theta Fuel", + Symbol: "TFUEL", + TokenID: "tfuel", Decimals: 18, - Value: blockatlas.Amount(output.Coins.Tfuelwei), - From: from, - To: to, + Value: blockatlas.Amount(output.Coins.Tfuelwei), + From: from, + To: to, } return tx, true diff --git a/platform/tron/api.go b/platform/tron/api.go index ae797b8ad..51d5e2711 100644 --- a/platform/tron/api.go +++ b/platform/tron/api.go @@ -68,7 +68,9 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx, ok bool) { To: to, Fee: "0", Meta: blockatlas.Transfer{ - Value: transfer.Value.Amount, + Value: transfer.Value.Amount, + Symbol: coin.Coins[coin.TRX].Symbol, + Decimals: coin.Coins[coin.TRX].Decimals, }, }, true default: diff --git a/platform/vechain/api.go b/platform/vechain/api.go index 70d29c717..9d2825946 100644 --- a/platform/vechain/api.go +++ b/platform/vechain/api.go @@ -64,7 +64,7 @@ func (p *Platform) getThorTxsByAddress(address string) ([]blockatlas.Tx, error) return txs, nil } -func (p *Platform)getTransactionReceipt(ids []string)(chan *TransferReceipt) { +func (p *Platform) getTransactionReceipt(ids []string) chan *TransferReceipt { receiptsChan := make(chan *TransferReceipt, len(ids)) sem := util.NewSemaphore(16) @@ -90,7 +90,7 @@ func (p *Platform)getTransactionReceipt(ids []string)(chan *TransferReceipt) { return receiptsChan } -func findTransferReceiptByTxID(receiptsChan chan *TransferReceipt, txID string) (TransferReceipt) { +func findTransferReceiptByTxID(receiptsChan chan *TransferReceipt, txID string) TransferReceipt { var transferReceipt TransferReceipt @@ -153,7 +153,9 @@ func NormalizeTransfer(receipt *TransferReceipt, clause *Clause) (tx blockatlas. Block: block, Sequence: block, Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(valueBase10), + Value: blockatlas.Amount(valueBase10), + Symbol: coin.Coins[coin.VET].Symbol, + Decimals: coin.Coins[coin.VET].Decimals, }, }, true } @@ -184,7 +186,7 @@ func NormalizeTokenTransfer(t *TokenTransfer, receipt *TransferReceipt) (tx bloc Block: block, Sequence: block, Meta: blockatlas.NativeTokenTransfer{ - Name: "VeThor Token", + Name: "VeThor Token", Symbol: "VTHO", TokenID: VeThorContract, Decimals: 18, @@ -194,4 +196,3 @@ func NormalizeTokenTransfer(t *TokenTransfer, receipt *TransferReceipt) (tx bloc }, }, true } - diff --git a/platform/waves/api.go b/platform/waves/api.go index 2a5cd4344..fe584ba10 100644 --- a/platform/waves/api.go +++ b/platform/waves/api.go @@ -49,8 +49,10 @@ func NormalizeTx(srcTx *Transaction, coinIndex uint) blockatlas.Tx { Block: srcTx.Block, Memo: srcTx.Attachment, Status: blockatlas.StatusCompleted, - Meta: blockatlas.Transfer{ - Value: blockatlas.Amount(strconv.Itoa(int(srcTx.Amount))), + Meta: blockatlas.Transfer{ + Value: blockatlas.Amount(strconv.Itoa(int(srcTx.Amount))), + Symbol: coin.Coins[coin.WAVES].Symbol, + Decimals: coin.Coins[coin.WAVES].Decimals, }, } } diff --git a/platform/zilliqa/api.go b/platform/zilliqa/api.go index 99874d520..df6296235 100644 --- a/platform/zilliqa/api.go +++ b/platform/zilliqa/api.go @@ -53,7 +53,11 @@ func Normalize(srcTx *Tx) (tx blockatlas.Tx) { Fee: blockatlas.Amount(srcTx.Fee), Block: srcTx.BlockHeight, Sequence: srcTx.Nonce, - Meta: blockatlas.Transfer{Value: blockatlas.Amount(srcTx.Value)}, + Meta: blockatlas.Transfer{ + Value: blockatlas.Amount(srcTx.Value), + Symbol: coin.Coins[coin.ZIL].Symbol, + Decimals: coin.Coins[coin.ZIL].Decimals, + }, } if !srcTx.ReceiptSuccess { tx.Status = blockatlas.StatusFailed diff --git a/tx.go b/tx.go index eed1338dc..e9801120a 100644 --- a/tx.go +++ b/tx.go @@ -58,7 +58,9 @@ type Tx struct { // Transfer describes the transfer of currency native to the platform type Transfer struct { - Value Amount `json:"value"` + Value Amount `json:"value"` + Symbol string `json:"symbol"` + Decimals uint `json:"decimals"` } // NativeTokenTransfer describes the transfer of native tokens.