From 35a13e06478b229e2dbfe7b06697a7feffe2bcf1 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Fri, 14 Dec 2018 12:08:06 +0100 Subject: [PATCH] Handle old style ethereum transactions that do not set status --- bchain/coins/eth/ethparser.go | 22 ++++++++++++++++------ static/templates/tx.html | 8 ++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bchain/coins/eth/ethparser.go b/bchain/coins/eth/ethparser.go index 0e3afb7b..82a87604 100644 --- a/bchain/coins/eth/ethparser.go +++ b/bchain/coins/eth/ethparser.go @@ -412,9 +412,16 @@ func GetErc20FromTx(tx *bchain.Tx) ([]Erc20Transfer, error) { return r, nil } +const ( + txStatusUnknown = iota - 2 + txStatusPending + txStatusFailure + txStatusOK +) + // EthereumTxData contains ethereum specific transaction data type EthereumTxData struct { - Status int `json:"status"` // 1 OK, 0 Fail, -1 pending + Status int `json:"status"` // 1 OK, 0 Fail, -1 pending, -2 unknown Nonce uint64 `json:"nonce"` GasLimit *big.Int `json:"gaslimit"` GasUsed *big.Int `json:"gasused"` @@ -423,7 +430,7 @@ type EthereumTxData struct { // GetEthereumTxData returns EthereumTxData from bchain.Tx func GetEthereumTxData(tx *bchain.Tx) *EthereumTxData { - etd := EthereumTxData{Status: -1} + etd := EthereumTxData{Status: txStatusPending} csd, ok := tx.CoinSpecificData.(completeTransaction) if ok { if csd.Tx != nil { @@ -432,10 +439,13 @@ func GetEthereumTxData(tx *bchain.Tx) *EthereumTxData { etd.GasPrice, _ = hexutil.DecodeBig(csd.Tx.GasPrice) } if csd.Receipt != nil { - if csd.Receipt.Status == "0x1" { - etd.Status = 1 - } else { - etd.Status = 0 + switch csd.Receipt.Status { + case "0x1": + etd.Status = txStatusOK + case "": // old transactions did not set status + etd.Status = txStatusUnknown + default: + etd.Status = txStatusFailure } etd.GasUsed, _ = hexutil.DecodeBig(csd.Receipt.GasUsed) } diff --git a/static/templates/tx.html b/static/templates/tx.html index 38c9f8a7..ee4279f1 100644 --- a/static/templates/tx.html +++ b/static/templates/tx.html @@ -25,10 +25,14 @@ Status {{- if $tx.EthereumSpecific.Status -}} - {{- if ne $tx.EthereumSpecific.Status 1 -}} + {{- if eq $tx.EthereumSpecific.Status 1 -}} + Success + {{- else -}} + {{- if eq $tx.EthereumSpecific.Status -1 -}} Pending {{- else -}} - Success + Unknown + {{- end -}} {{- end -}} {{- else -}} Fail