Return for mempool transactions coinSpecificData #522

go1.15
Martin Boehm 2020-11-27 01:12:08 +01:00
parent 08afda91b3
commit a1e932a902
4 changed files with 9 additions and 10 deletions

View File

@ -196,8 +196,7 @@ type Tx struct {
FeesSat *Amount `json:"fees,omitempty"` FeesSat *Amount `json:"fees,omitempty"`
Hex string `json:"hex,omitempty"` Hex string `json:"hex,omitempty"`
Rbf bool `json:"rbf,omitempty"` Rbf bool `json:"rbf,omitempty"`
CoinSpecificData interface{} `json:"-"` CoinSpecificData json.RawMessage `json:"coinSpecificData,omitempty"`
CoinSpecificJSON json.RawMessage `json:"-"`
TokenTransfers []TokenTransfer `json:"tokenTransfers,omitempty"` TokenTransfers []TokenTransfer `json:"tokenTransfers,omitempty"`
EthereumSpecific *EthereumSpecific `json:"ethereumSpecific,omitempty"` EthereumSpecific *EthereumSpecific `json:"ethereumSpecific,omitempty"`
} }

View File

@ -274,7 +274,8 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
// for now do not return size, we would have to compute vsize of segwit transactions // for now do not return size, we would have to compute vsize of segwit transactions
// size:=len(bchainTx.Hex) / 2 // size:=len(bchainTx.Hex) / 2
var sj json.RawMessage var sj json.RawMessage
if specificJSON { // return CoinSpecificData for all mempool transactions or if requested
if specificJSON || bchainTx.Confirmations == 0 {
sj, err = w.chain.GetTransactionSpecific(bchainTx) sj, err = w.chain.GetTransactionSpecific(bchainTx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -299,8 +300,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
Rbf: rbf, Rbf: rbf,
Vin: vins, Vin: vins,
Vout: vouts, Vout: vouts,
CoinSpecificData: bchainTx.CoinSpecificData, CoinSpecificData: sj,
CoinSpecificJSON: sj,
TokenTransfers: tokens, TokenTransfers: tokens,
EthereumSpecific: ethSpecific, EthereumSpecific: ethSpecific,
} }
@ -758,7 +758,7 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
if ta == nil { if ta == nil {
glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses") glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses")
// as fallback, get tx from backend // as fallback, get tx from backend
tx, err = w.GetTransaction(txid, false, true) tx, err = w.GetTransaction(txid, false, false)
if err != nil { if err != nil {
return nil, errors.Annotatef(err, "GetTransaction %v", txid) return nil, errors.Annotatef(err, "GetTransaction %v", txid)
} }
@ -777,7 +777,7 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
tx = w.txFromTxAddress(txid, ta, blockInfo, bestheight) tx = w.txFromTxAddress(txid, ta, blockInfo, bestheight)
} }
} else { } else {
tx, err = w.GetTransaction(txid, false, true) tx, err = w.GetTransaction(txid, false, false)
if err != nil { if err != nil {
return nil, errors.Annotatef(err, "GetTransaction %v", txid) return nil, errors.Annotatef(err, "GetTransaction %v", txid)
} }
@ -866,7 +866,7 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option Acco
return nil, errors.Annotatef(err, "getAddressTxids %v true", addrDesc) return nil, errors.Annotatef(err, "getAddressTxids %v true", addrDesc)
} }
for _, txid := range txm { for _, txid := range txm {
tx, err := w.GetTransaction(txid, false, false) tx, err := w.GetTransaction(txid, false, true)
// mempool transaction may fail // mempool transaction may fail
if err != nil || tx == nil { if err != nil || tx == nil {
glog.Warning("GetTransaction in mempool: ", err) glog.Warning("GetTransaction in mempool: ", err)

View File

@ -416,7 +416,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
// the same tx can have multiple addresses from the same xpub, get it from backend it only once // the same tx can have multiple addresses from the same xpub, get it from backend it only once
tx, foundTx := txmMap[txid.txid] tx, foundTx := txmMap[txid.txid]
if !foundTx { if !foundTx {
tx, err = w.GetTransaction(txid.txid, false, false) tx, err = w.GetTransaction(txid.txid, false, true)
// mempool transaction may fail // mempool transaction may fail
if err != nil || tx == nil { if err != nil || tx == nil {
glog.Warning("GetTransaction in mempool: ", err) glog.Warning("GetTransaction in mempool: ", err)

View File

@ -78,7 +78,7 @@
<pre id="txSpecific"></pre> <pre id="txSpecific"></pre>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
txSpecific = {{$tx.CoinSpecificJSON}}; txSpecific = {{$tx.CoinSpecificData}};
function syntaxHighlight(json) { function syntaxHighlight(json) {
json = JSON.stringify(json, undefined, 2); json = JSON.stringify(json, undefined, 2);
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');