Rename mempool to mempool_utxo
This commit is contained in:
parent
6a1748814a
commit
26de7eb384
@ -26,7 +26,7 @@ type BitcoinRPC struct {
|
|||||||
Parser bchain.BlockChainParser
|
Parser bchain.BlockChainParser
|
||||||
Testnet bool
|
Testnet bool
|
||||||
Network string
|
Network string
|
||||||
Mempool *bchain.Mempool
|
Mempool *bchain.UTXOMempool
|
||||||
ParseBlocks bool
|
ParseBlocks bool
|
||||||
mq *bchain.MQ
|
mq *bchain.MQ
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,8 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO rename
|
type addrIndex struct {
|
||||||
type scriptIndex struct {
|
addrID string
|
||||||
script string
|
|
||||||
n uint32
|
n uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,12 +18,12 @@ type outpoint struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type inputOutput struct {
|
type inputOutput struct {
|
||||||
outputs []scriptIndex
|
outputs []addrIndex
|
||||||
inputs []outpoint
|
inputs []outpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mempool is mempool handle.
|
// UTXOMempool is mempool handle.
|
||||||
type Mempool struct {
|
type UTXOMempool struct {
|
||||||
chain BlockChain
|
chain BlockChain
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
txToInputOutput map[string]inputOutput
|
txToInputOutput map[string]inputOutput
|
||||||
@ -33,12 +32,12 @@ type Mempool struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMempool creates new mempool handler.
|
// NewMempool creates new mempool handler.
|
||||||
func NewMempool(chain BlockChain) *Mempool {
|
func NewMempool(chain BlockChain) *UTXOMempool {
|
||||||
return &Mempool{chain: chain}
|
return &UTXOMempool{chain: chain}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactions returns slice of mempool transactions for given output script.
|
// GetTransactions returns slice of mempool transactions for given address
|
||||||
func (m *Mempool) GetTransactions(address string) ([]string, error) {
|
func (m *UTXOMempool) GetTransactions(address string) ([]string, error) {
|
||||||
m.mux.Lock()
|
m.mux.Lock()
|
||||||
defer m.mux.Unlock()
|
defer m.mux.Unlock()
|
||||||
parser := m.chain.GetChainParser()
|
parser := m.chain.GetChainParser()
|
||||||
@ -59,23 +58,23 @@ func (m *Mempool) GetTransactions(address string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSpentOutput returns transaction which spends given outpoint
|
// GetSpentOutput returns transaction which spends given outpoint
|
||||||
func (m *Mempool) GetSpentOutput(outputTxid string, vout uint32) string {
|
func (m *UTXOMempool) GetSpentOutput(outputTxid string, vout uint32) string {
|
||||||
o := outpoint{txid: outputTxid, vout: vout}
|
o := outpoint{txid: outputTxid, vout: vout}
|
||||||
return m.inputs[o]
|
return m.inputs[o]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mempool) updateMappings(newTxToInputOutput map[string]inputOutput, newScriptToTx map[string][]outpoint, newInputs map[outpoint]string) {
|
func (m *UTXOMempool) updateMappings(newTxToInputOutput map[string]inputOutput, newAddrIDToTx map[string][]outpoint, newInputs map[outpoint]string) {
|
||||||
m.mux.Lock()
|
m.mux.Lock()
|
||||||
defer m.mux.Unlock()
|
defer m.mux.Unlock()
|
||||||
m.txToInputOutput = newTxToInputOutput
|
m.txToInputOutput = newTxToInputOutput
|
||||||
m.addrIDToTx = newScriptToTx
|
m.addrIDToTx = newAddrIDToTx
|
||||||
m.inputs = newInputs
|
m.inputs = newInputs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resync gets mempool transactions and maps output scripts to transactions.
|
// Resync gets mempool transactions and maps outputs to transactions.
|
||||||
// Resync is not reentrant, it should be called from a single thread.
|
// Resync is not reentrant, it should be called from a single thread.
|
||||||
// Read operations (GetTransactions) are safe.
|
// Read operations (GetTransactions) are safe.
|
||||||
func (m *Mempool) Resync(onNewTxAddr func(txid string, addr string)) error {
|
func (m *UTXOMempool) Resync(onNewTxAddr func(txid string, addr string)) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
glog.V(1).Info("Mempool: resync")
|
glog.V(1).Info("Mempool: resync")
|
||||||
txs, err := m.chain.GetMempool()
|
txs, err := m.chain.GetMempool()
|
||||||
@ -94,7 +93,7 @@ func (m *Mempool) Resync(onNewTxAddr func(txid string, addr string)) error {
|
|||||||
glog.Error("cannot get transaction ", txid, ": ", err)
|
glog.Error("cannot get transaction ", txid, ": ", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
io.outputs = make([]scriptIndex, 0, len(tx.Vout))
|
io.outputs = make([]addrIndex, 0, len(tx.Vout))
|
||||||
for _, output := range tx.Vout {
|
for _, output := range tx.Vout {
|
||||||
addrID, err := parser.GetAddrIDFromVout(&output)
|
addrID, err := parser.GetAddrIDFromVout(&output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -102,7 +101,7 @@ func (m *Mempool) Resync(onNewTxAddr func(txid string, addr string)) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(addrID) > 0 {
|
if len(addrID) > 0 {
|
||||||
io.outputs = append(io.outputs, scriptIndex{string(addrID), output.N})
|
io.outputs = append(io.outputs, addrIndex{string(addrID), output.N})
|
||||||
}
|
}
|
||||||
if onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
if onNewTxAddr != nil && len(output.ScriptPubKey.Addresses) == 1 {
|
||||||
onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0])
|
onNewTxAddr(tx.Txid, output.ScriptPubKey.Addresses[0])
|
||||||
@ -118,7 +117,7 @@ func (m *Mempool) Resync(onNewTxAddr func(txid string, addr string)) error {
|
|||||||
}
|
}
|
||||||
newTxToInputOutput[txid] = io
|
newTxToInputOutput[txid] = io
|
||||||
for _, si := range io.outputs {
|
for _, si := range io.outputs {
|
||||||
newAddrIDToTx[si.script] = append(newAddrIDToTx[si.script], outpoint{txid, si.n})
|
newAddrIDToTx[si.addrID] = append(newAddrIDToTx[si.addrID], outpoint{txid, si.n})
|
||||||
}
|
}
|
||||||
for _, i := range io.inputs {
|
for _, i := range io.inputs {
|
||||||
newInputs[i] = txid
|
newInputs[i] = txid
|
||||||
Loading…
Reference in New Issue
Block a user