/
mempool.go
46 lines (42 loc) · 1.48 KB
/
mempool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2018-2019, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.
package explorer
import "github.com/decred/dcrdata/explorer/types/v2"
// matchMempoolVins filters relevant mempool transaction inputs whose previous
// outpoints match the specified transaction id.
func matchMempoolVins(txid string, txsList []types.MempoolTx) (vins []types.MempoolVin) {
for idx := range txsList {
tx := &txsList[idx]
var inputs []types.MempoolInput
for vindex := range tx.Vin {
input := &tx.Vin[vindex]
if input.TxId != txid {
continue
}
inputs = append(inputs, *input)
}
if len(inputs) == 0 {
continue
}
vins = append(vins, types.MempoolVin{
TxId: tx.TxID,
Inputs: inputs,
})
}
return
}
// GetTxMempoolInputs grabs very simple information about mempool transaction
// inputs that spend a particular previous transaction's outputs. The returned
// slice has just enough information to match an unspent transaction output.
func (exp *explorerUI) GetTxMempoolInputs(txid string, txType string) (vins []types.MempoolVin) {
// Lock the pointer from changing, and the contents of the shared struct.
inv := exp.MempoolInventory()
inv.RLock()
defer inv.RUnlock()
vins = append(vins, matchMempoolVins(txid, inv.Transactions)...)
vins = append(vins, matchMempoolVins(txid, inv.Tickets)...)
vins = append(vins, matchMempoolVins(txid, inv.Revocations)...)
vins = append(vins, matchMempoolVins(txid, inv.Votes)...)
return
}