Cleanup mempool usage, remove obsolete GetMempoolSpentOutput
This commit is contained in:
parent
880e3e8025
commit
7de8726979
@ -149,10 +149,6 @@ func (c *blockChainWithMetrics) GetMempoolTransactions(address string) (v []stri
|
|||||||
return c.b.GetMempoolTransactions(address)
|
return c.b.GetMempoolTransactions(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *blockChainWithMetrics) GetMempoolSpentOutput(outputTxid string, vout uint32) (v string) {
|
|
||||||
return c.b.GetMempoolSpentOutput(outputTxid, vout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *blockChainWithMetrics) GetMempoolEntry(txid string) (v *bchain.MempoolEntry, err error) {
|
func (c *blockChainWithMetrics) GetMempoolEntry(txid string) (v *bchain.MempoolEntry, err error) {
|
||||||
defer func(s time.Time) { c.observeRPCLatency("GetMempoolEntry", s, err) }(time.Now())
|
defer func(s time.Time) { c.observeRPCLatency("GetMempoolEntry", s, err) }(time.Now())
|
||||||
return c.b.GetMempoolEntry(txid)
|
return c.b.GetMempoolEntry(txid)
|
||||||
|
|||||||
@ -575,11 +575,6 @@ func (b *BitcoinRPC) GetMempoolTransactions(address string) ([]string, error) {
|
|||||||
return b.Mempool.GetTransactions(address)
|
return b.Mempool.GetTransactions(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMempoolSpentOutput returns transaction in mempool which spends given outpoint
|
|
||||||
func (b *BitcoinRPC) GetMempoolSpentOutput(outputTxid string, vout uint32) string {
|
|
||||||
return b.Mempool.GetSpentOutput(outputTxid, vout)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EstimateSmartFee returns fee estimation.
|
// EstimateSmartFee returns fee estimation.
|
||||||
func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) {
|
func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) {
|
||||||
glog.V(1).Info("rpc: estimatesmartfee ", blocks)
|
glog.V(1).Info("rpc: estimatesmartfee ", blocks)
|
||||||
|
|||||||
@ -486,10 +486,6 @@ func (b *EthereumRPC) GetMempoolTransactions(address string) ([]string, error) {
|
|||||||
return b.Mempool.GetTransactions(address)
|
return b.Mempool.GetTransactions(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *EthereumRPC) GetMempoolSpentOutput(outputTxid string, vout uint32) string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *EthereumRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) {
|
func (b *EthereumRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) {
|
||||||
return nil, errors.New("GetMempoolEntry: not implemented")
|
return nil, errors.New("GetMempoolEntry: not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,13 @@ func NewNonUTXOMempool(chain BlockChain) *NonUTXOMempool {
|
|||||||
|
|
||||||
// GetTransactions returns slice of mempool transactions for given address
|
// GetTransactions returns slice of mempool transactions for given address
|
||||||
func (m *NonUTXOMempool) GetTransactions(address string) ([]string, error) {
|
func (m *NonUTXOMempool) GetTransactions(address string) ([]string, error) {
|
||||||
m.mux.Lock()
|
|
||||||
defer m.mux.Unlock()
|
|
||||||
parser := m.chain.GetChainParser()
|
parser := m.chain.GetChainParser()
|
||||||
addrID, err := parser.GetAddrIDFromAddress(address)
|
addrID, err := parser.GetAddrIDFromAddress(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
m.mux.Lock()
|
||||||
|
defer m.mux.Unlock()
|
||||||
outpoints := m.addrIDToTx[string(addrID)]
|
outpoints := m.addrIDToTx[string(addrID)]
|
||||||
txs := make([]string, 0, len(outpoints))
|
txs := make([]string, 0, len(outpoints))
|
||||||
for _, o := range outpoints {
|
for _, o := range outpoints {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// addrIndex and outpoint are used also in nonutxo mempool
|
// addrIndex and outpoint are used also in non utxo mempool
|
||||||
type addrIndex struct {
|
type addrIndex struct {
|
||||||
addrID string
|
addrID string
|
||||||
n int32
|
n int32
|
||||||
@ -39,13 +39,13 @@ func NewUTXOMempool(chain BlockChain) *UTXOMempool {
|
|||||||
|
|
||||||
// GetTransactions returns slice of mempool transactions for given address
|
// GetTransactions returns slice of mempool transactions for given address
|
||||||
func (m *UTXOMempool) GetTransactions(address string) ([]string, error) {
|
func (m *UTXOMempool) GetTransactions(address string) ([]string, error) {
|
||||||
m.mux.Lock()
|
|
||||||
defer m.mux.Unlock()
|
|
||||||
parser := m.chain.GetChainParser()
|
parser := m.chain.GetChainParser()
|
||||||
addrID, err := parser.GetAddrIDFromAddress(address)
|
addrID, err := parser.GetAddrIDFromAddress(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
m.mux.Lock()
|
||||||
|
defer m.mux.Unlock()
|
||||||
outpoints := m.addrIDToTx[string(addrID)]
|
outpoints := m.addrIDToTx[string(addrID)]
|
||||||
txs := make([]string, 0, len(outpoints)+len(outpoints)/2)
|
txs := make([]string, 0, len(outpoints)+len(outpoints)/2)
|
||||||
for _, o := range outpoints {
|
for _, o := range outpoints {
|
||||||
|
|||||||
@ -141,7 +141,6 @@ type BlockChain interface {
|
|||||||
// mempool
|
// mempool
|
||||||
ResyncMempool(onNewTxAddr func(txid string, addr string)) error
|
ResyncMempool(onNewTxAddr func(txid string, addr string)) error
|
||||||
GetMempoolTransactions(address string) ([]string, error)
|
GetMempoolTransactions(address string) ([]string, error)
|
||||||
GetMempoolSpentOutput(outputTxid string, vout uint32) string
|
|
||||||
GetMempoolEntry(txid string) (*MempoolEntry, error)
|
GetMempoolEntry(txid string) (*MempoolEntry, error)
|
||||||
// parser
|
// parser
|
||||||
GetChainParser() BlockChainParser
|
GetChainParser() BlockChainParser
|
||||||
|
|||||||
@ -196,12 +196,6 @@ func (s *HTTPServer) transactions(w http.ResponseWriter, r *http.Request) {
|
|||||||
txList := transactionList{}
|
txList := transactionList{}
|
||||||
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
||||||
txList.Txid = append(txList.Txid, txid)
|
txList.Txid = append(txList.Txid, txid)
|
||||||
if isOutput {
|
|
||||||
input := s.chain.GetMempoolSpentOutput(txid, vout)
|
|
||||||
if input != "" {
|
|
||||||
txList.Txid = append(txList.Txid, txid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -127,7 +127,6 @@ func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
|
|||||||
type addrOpts struct {
|
type addrOpts struct {
|
||||||
Start int `json:"start"`
|
Start int `json:"start"`
|
||||||
End int `json:"end"`
|
End int `json:"end"`
|
||||||
QueryMempol bool `json:"queryMempol"`
|
|
||||||
QueryMempoolOnly bool `json:"queryMempoolOnly"`
|
QueryMempoolOnly bool `json:"queryMempoolOnly"`
|
||||||
From int `json:"from"`
|
From int `json:"from"`
|
||||||
To int `json:"to"`
|
To int `json:"to"`
|
||||||
@ -276,27 +275,17 @@ func (s *SocketIoServer) getAddressTxids(addr []string, opts *addrOpts) (res res
|
|||||||
if !opts.QueryMempoolOnly {
|
if !opts.QueryMempoolOnly {
|
||||||
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
||||||
txids = append(txids, txid)
|
txids = append(txids, txid)
|
||||||
if isOutput && opts.QueryMempol {
|
|
||||||
input := s.chain.GetMempoolSpentOutput(txid, vout)
|
|
||||||
if input != "" {
|
|
||||||
txids = append(txids, txid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if opts.QueryMempoolOnly || opts.QueryMempol {
|
m, err := s.chain.GetMempoolTransactions(address)
|
||||||
mtxids, err := s.chain.GetMempoolTransactions(address)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
txids = append(txids, mtxids...)
|
txids = append(txids, m...)
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.Result = uniqueTxidsInReverse(txids)
|
res.Result = uniqueTxidsInReverse(txids)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user