Skip to content

Commit

Permalink
Return for mempool transactions coinSpecificData trezor#522
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehm committed Dec 4, 2020
1 parent e688818 commit 0debd60
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ type Tx struct {
FeesSat *Amount `json:"fees,omitempty"`
Hex string `json:"hex,omitempty"`
Rbf bool `json:"rbf,omitempty"`
CoinSpecificData interface{} `json:"-"`
CoinSpecificJSON json.RawMessage `json:"-"`
CoinSpecificData json.RawMessage `json:"coinSpecificData,omitempty"`
TokenTransfers []TokenTransfer `json:"tokenTransfers,omitempty"`
EthereumSpecific *EthereumSpecific `json:"ethereumSpecific,omitempty"`
}
Expand Down
12 changes: 6 additions & 6 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// size:=len(bchainTx.Hex) / 2
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)
if err != nil {
return nil, err
Expand All @@ -299,8 +300,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
Rbf: rbf,
Vin: vins,
Vout: vouts,
CoinSpecificData: bchainTx.CoinSpecificData,
CoinSpecificJSON: sj,
CoinSpecificData: sj,
TokenTransfers: tokens,
EthereumSpecific: ethSpecific,
}
Expand Down Expand Up @@ -758,7 +758,7 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
if ta == nil {
glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses")
// as fallback, get tx from backend
tx, err = w.GetTransaction(txid, false, true)
tx, err = w.GetTransaction(txid, false, false)
if err != nil {
return nil, errors.Annotatef(err, "GetTransaction %v", txid)
}
Expand All @@ -777,7 +777,7 @@ func (w *Worker) txFromTxid(txid string, bestheight uint32, option AccountDetail
tx = w.txFromTxAddress(txid, ta, blockInfo, bestheight)
}
} else {
tx, err = w.GetTransaction(txid, false, true)
tx, err = w.GetTransaction(txid, false, false)
if err != nil {
return nil, errors.Annotatef(err, "GetTransaction %v", txid)
}
Expand Down Expand Up @@ -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)
}
for _, txid := range txm {
tx, err := w.GetTransaction(txid, false, false)
tx, err := w.GetTransaction(txid, false, true)
// mempool transaction may fail
if err != nil || tx == nil {
glog.Warning("GetTransaction in mempool: ", err)
Expand Down
2 changes: 1 addition & 1 deletion api/xpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
tx, foundTx := txmMap[txid.txid]
if !foundTx {
tx, err = w.GetTransaction(txid.txid, false, false)
tx, err = w.GetTransaction(txid.txid, false, true)
// mempool transaction may fail
if err != nil || tx == nil {
glog.Warning("GetTransaction in mempool: ", err)
Expand Down
2 changes: 1 addition & 1 deletion static/templates/tx.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h5>Raw Transaction</h5>
<pre id="txSpecific"></pre>
</div>
<script type="text/javascript">
txSpecific = {{$tx.CoinSpecificJSON}};
txSpecific = {{$tx.CoinSpecificData}};
function syntaxHighlight(json) {
json = JSON.stringify(json, undefined, 2);
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
Expand Down

0 comments on commit 0debd60

Please sign in to comment.