Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Add decimals and symbol to blockatlas.Transfer object (#190)
Browse files Browse the repository at this point in the history
* Add decimals and symbol to blockatlas.Transfer object

* Remove printing data
  • Loading branch information
vikmeup authored Jul 24, 2019
1 parent d61fd0c commit ba27e21
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 61 deletions.
2 changes: 1 addition & 1 deletion observer/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions platform/aion/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion platform/binance/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion platform/cosmos/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
4 changes: 3 additions & 1 deletion platform/ethereum/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
22 changes: 12 additions & 10 deletions platform/icon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion platform/iotex/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
6 changes: 4 additions & 2 deletions platform/nimiq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
30 changes: 16 additions & 14 deletions platform/ontology/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Platform struct {

const (
GovernanceContract = "AFmseVrdL9f9oyCzZefL9tG6UbviEH9ugK"
ONTAssetName = "ont"
ONGAssetName = "ong"
ONTAssetName = "ont"
ONGAssetName = "ong"
)

func (p *Platform) Init() error {
Expand Down Expand Up @@ -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,
}

Expand All @@ -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,
}
}

Expand All @@ -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,
}
}
6 changes: 4 additions & 2 deletions platform/ripple/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion platform/semux/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion platform/stellar/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions platform/tezos/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions platform/theta/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion platform/tron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions platform/vechain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -194,4 +196,3 @@ func NormalizeTokenTransfer(t *TokenTransfer, receipt *TransferReceipt) (tx bloc
},
}, true
}

6 changes: 4 additions & 2 deletions platform/waves/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
6 changes: 5 additions & 1 deletion platform/zilliqa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ba27e21

Please sign in to comment.