Include eth transactions in unknown status into balance history
This commit is contained in:
parent
791948623e
commit
17c9080135
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/trezor/blockbook/bchain"
|
"github.com/trezor/blockbook/bchain"
|
||||||
|
"github.com/trezor/blockbook/bchain/coins/eth"
|
||||||
"github.com/trezor/blockbook/common"
|
"github.com/trezor/blockbook/common"
|
||||||
"github.com/trezor/blockbook/db"
|
"github.com/trezor/blockbook/db"
|
||||||
)
|
)
|
||||||
@ -170,7 +171,7 @@ type TokenTransfer struct {
|
|||||||
|
|
||||||
// EthereumSpecific contains ethereum specific transaction data
|
// EthereumSpecific contains ethereum specific transaction data
|
||||||
type EthereumSpecific struct {
|
type EthereumSpecific struct {
|
||||||
Status int `json:"status"` // 1 OK, 0 Fail, -1 pending
|
Status eth.TxStatus `json:"status"` // 1 OK, 0 Fail, -1 pending
|
||||||
Nonce uint64 `json:"nonce"`
|
Nonce uint64 `json:"nonce"`
|
||||||
GasLimit *big.Int `json:"gasLimit"`
|
GasLimit *big.Int `json:"gasLimit"`
|
||||||
GasUsed *big.Int `json:"gasUsed"`
|
GasUsed *big.Int `json:"gasUsed"`
|
||||||
|
|||||||
@ -1037,8 +1037,8 @@ func (w *Worker) balanceHistoryForTxid(addrDesc bchain.AddressDescriptor, txid s
|
|||||||
} else if w.chainType == bchain.ChainEthereumType {
|
} else if w.chainType == bchain.ChainEthereumType {
|
||||||
var value big.Int
|
var value big.Int
|
||||||
ethTxData := eth.GetEthereumTxData(bchainTx)
|
ethTxData := eth.GetEthereumTxData(bchainTx)
|
||||||
// add received amount only for OK transactions
|
// add received amount only for OK or unknown status (old) transactions
|
||||||
if ethTxData.Status == 1 {
|
if ethTxData.Status == eth.TxStatusOK || ethTxData.Status == eth.TxStatusUnknown {
|
||||||
if len(bchainTx.Vout) > 0 {
|
if len(bchainTx.Vout) > 0 {
|
||||||
bchainVout := &bchainTx.Vout[0]
|
bchainVout := &bchainTx.Vout[0]
|
||||||
value = bchainVout.ValueSat
|
value = bchainVout.ValueSat
|
||||||
@ -1064,8 +1064,8 @@ func (w *Worker) balanceHistoryForTxid(addrDesc bchain.AddressDescriptor, txid s
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if bytes.Equal(addrDesc, txAddrDesc) {
|
if bytes.Equal(addrDesc, txAddrDesc) {
|
||||||
// add sent amount only for OK transactions, however fees always
|
// add received amount only for OK or unknown status (old) transactions, fees always
|
||||||
if ethTxData.Status == 1 {
|
if ethTxData.Status == eth.TxStatusOK || ethTxData.Status == eth.TxStatusUnknown {
|
||||||
(*big.Int)(bh.SentSat).Add((*big.Int)(bh.SentSat), &value)
|
(*big.Int)(bh.SentSat).Add((*big.Int)(bh.SentSat), &value)
|
||||||
if countSentToSelf {
|
if countSentToSelf {
|
||||||
if _, found := selfAddrDesc[string(txAddrDesc)]; found {
|
if _, found := selfAddrDesc[string(txAddrDesc)]; found {
|
||||||
|
|||||||
@ -461,16 +461,20 @@ func (p *EthereumParser) EthereumTypeGetErc20FromTx(tx *bchain.Tx) ([]bchain.Erc
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TxStatus is status of transaction
|
||||||
|
type TxStatus int
|
||||||
|
|
||||||
|
// statuses of transaction
|
||||||
const (
|
const (
|
||||||
txStatusUnknown = iota - 2
|
TxStatusUnknown = TxStatus(iota - 2)
|
||||||
txStatusPending
|
TxStatusPending
|
||||||
txStatusFailure
|
TxStatusFailure
|
||||||
txStatusOK
|
TxStatusOK
|
||||||
)
|
)
|
||||||
|
|
||||||
// EthereumTxData contains ethereum specific transaction data
|
// EthereumTxData contains ethereum specific transaction data
|
||||||
type EthereumTxData struct {
|
type EthereumTxData struct {
|
||||||
Status int `json:"status"` // 1 OK, 0 Fail, -1 pending, -2 unknown
|
Status TxStatus `json:"status"` // 1 OK, 0 Fail, -1 pending, -2 unknown
|
||||||
Nonce uint64 `json:"nonce"`
|
Nonce uint64 `json:"nonce"`
|
||||||
GasLimit *big.Int `json:"gaslimit"`
|
GasLimit *big.Int `json:"gaslimit"`
|
||||||
GasUsed *big.Int `json:"gasused"`
|
GasUsed *big.Int `json:"gasused"`
|
||||||
@ -485,7 +489,7 @@ func GetEthereumTxData(tx *bchain.Tx) *EthereumTxData {
|
|||||||
|
|
||||||
// GetEthereumTxDataFromSpecificData returns EthereumTxData from coinSpecificData
|
// GetEthereumTxDataFromSpecificData returns EthereumTxData from coinSpecificData
|
||||||
func GetEthereumTxDataFromSpecificData(coinSpecificData interface{}) *EthereumTxData {
|
func GetEthereumTxDataFromSpecificData(coinSpecificData interface{}) *EthereumTxData {
|
||||||
etd := EthereumTxData{Status: txStatusPending}
|
etd := EthereumTxData{Status: TxStatusPending}
|
||||||
csd, ok := coinSpecificData.(completeTransaction)
|
csd, ok := coinSpecificData.(completeTransaction)
|
||||||
if ok {
|
if ok {
|
||||||
if csd.Tx != nil {
|
if csd.Tx != nil {
|
||||||
@ -497,11 +501,11 @@ func GetEthereumTxDataFromSpecificData(coinSpecificData interface{}) *EthereumTx
|
|||||||
if csd.Receipt != nil {
|
if csd.Receipt != nil {
|
||||||
switch csd.Receipt.Status {
|
switch csd.Receipt.Status {
|
||||||
case "0x1":
|
case "0x1":
|
||||||
etd.Status = txStatusOK
|
etd.Status = TxStatusOK
|
||||||
case "": // old transactions did not set status
|
case "": // old transactions did not set status
|
||||||
etd.Status = txStatusUnknown
|
etd.Status = TxStatusUnknown
|
||||||
default:
|
default:
|
||||||
etd.Status = txStatusFailure
|
etd.Status = TxStatusFailure
|
||||||
}
|
}
|
||||||
etd.GasUsed, _ = hexutil.DecodeBig(csd.Receipt.GasUsed)
|
etd.GasUsed, _ = hexutil.DecodeBig(csd.Receipt.GasUsed)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user