Fix invalid BlockHeight for unconfirmed transactions #301

pull/303/head
Martin Boehm 2019-10-09 14:49:06 +02:00
parent 83b1552dfa
commit 1c192f6d0b
2 changed files with 8 additions and 8 deletions

View File

@ -121,7 +121,7 @@ func (w *Worker) GetTransaction(txid string, spendingTxs bool, specificJSON bool
}
// GetTransactionFromBchainTx reads transaction data from txid
func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, spendingTxs bool, specificJSON bool) (*Tx, error) {
func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spendingTxs bool, specificJSON bool) (*Tx, error) {
var err error
var ta *db.TxAddresses
var tokens []TokenTransfer
@ -134,7 +134,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
return nil, errors.Annotatef(err, "GetTxAddresses %v", bchainTx.Txid)
}
}
blockhash, err = w.db.GetBlockHash(height)
blockhash, err = w.db.GetBlockHash(uint32(height))
if err != nil {
return nil, errors.Annotatef(err, "GetBlockHash %v", height)
}
@ -236,7 +236,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
if ta != nil {
vout.Spent = ta.Outputs[i].Spent
if spendingTxs && vout.Spent {
err = w.setSpendingTxToVout(vout, bchainTx.Txid, height)
err = w.setSpendingTxToVout(vout, bchainTx.Txid, uint32(height))
if err != nil {
glog.Errorf("setSpendingTxToVout error %v, %v, output %v", err, vout.AddrDesc, vout.N)
}
@ -312,7 +312,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
}
r := &Tx{
Blockhash: blockhash,
Blockheight: int(height),
Blockheight: height,
Blocktime: bchainTx.Blocktime,
Confirmations: bchainTx.Confirmations,
FeesSat: (*Amount)(&feesSat),

View File

@ -36,7 +36,7 @@ func NewTxCache(db *RocksDB, chain bchain.BlockChain, metrics *common.Metrics, i
// GetTransaction returns transaction either from RocksDB or if not present from blockchain
// it the transaction is confirmed, it is stored in the RocksDB
func (c *TxCache) GetTransaction(txid string) (*bchain.Tx, uint32, error) {
func (c *TxCache) GetTransaction(txid string) (*bchain.Tx, int, error) {
var tx *bchain.Tx
var h uint32
var err error
@ -50,7 +50,7 @@ func (c *TxCache) GetTransaction(txid string) (*bchain.Tx, uint32, error) {
_, bestheight, _ := c.is.GetSyncState()
tx.Confirmations = bestheight - h + 1
c.metrics.TxCacheEfficiency.With(common.Labels{"status": "hit"}).Inc()
return tx, h, nil
return tx, int(h), nil
}
}
tx, err = c.chain.GetTransaction(txid)
@ -97,7 +97,7 @@ func (c *TxCache) GetTransaction(txid string) (*bchain.Tx, uint32, error) {
}
}
} else {
h = 0
return tx, -1, nil
}
return tx, h, nil
return tx, int(h), nil
}