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)
|
||||
}
|
||||
|
||||
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) {
|
||||
defer func(s time.Time) { c.observeRPCLatency("GetMempoolEntry", s, err) }(time.Now())
|
||||
return c.b.GetMempoolEntry(txid)
|
||||
|
||||
@ -575,11 +575,6 @@ func (b *BitcoinRPC) GetMempoolTransactions(address string) ([]string, error) {
|
||||
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.
|
||||
func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, error) {
|
||||
glog.V(1).Info("rpc: estimatesmartfee ", blocks)
|
||||
|
||||
@ -486,10 +486,6 @@ func (b *EthereumRPC) GetMempoolTransactions(address string) ([]string, error) {
|
||||
return b.Mempool.GetTransactions(address)
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) GetMempoolSpentOutput(outputTxid string, vout uint32) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (b *EthereumRPC) GetMempoolEntry(txid string) (*bchain.MempoolEntry, error) {
|
||||
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
|
||||
func (m *NonUTXOMempool) GetTransactions(address string) ([]string, error) {
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
parser := m.chain.GetChainParser()
|
||||
addrID, err := parser.GetAddrIDFromAddress(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
outpoints := m.addrIDToTx[string(addrID)]
|
||||
txs := make([]string, 0, len(outpoints))
|
||||
for _, o := range outpoints {
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"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 {
|
||||
addrID string
|
||||
n int32
|
||||
@ -39,13 +39,13 @@ func NewUTXOMempool(chain BlockChain) *UTXOMempool {
|
||||
|
||||
// GetTransactions returns slice of mempool transactions for given address
|
||||
func (m *UTXOMempool) GetTransactions(address string) ([]string, error) {
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
parser := m.chain.GetChainParser()
|
||||
addrID, err := parser.GetAddrIDFromAddress(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.mux.Lock()
|
||||
defer m.mux.Unlock()
|
||||
outpoints := m.addrIDToTx[string(addrID)]
|
||||
txs := make([]string, 0, len(outpoints)+len(outpoints)/2)
|
||||
for _, o := range outpoints {
|
||||
|
||||
@ -141,7 +141,6 @@ type BlockChain interface {
|
||||
// mempool
|
||||
ResyncMempool(onNewTxAddr func(txid string, addr string)) error
|
||||
GetMempoolTransactions(address string) ([]string, error)
|
||||
GetMempoolSpentOutput(outputTxid string, vout uint32) string
|
||||
GetMempoolEntry(txid string) (*MempoolEntry, error)
|
||||
// parser
|
||||
GetChainParser() BlockChainParser
|
||||
|
||||
@ -196,12 +196,6 @@ func (s *HTTPServer) transactions(w http.ResponseWriter, r *http.Request) {
|
||||
txList := transactionList{}
|
||||
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
||||
txList.Txid = append(txList.Txid, txid)
|
||||
if isOutput {
|
||||
input := s.chain.GetMempoolSpentOutput(txid, vout)
|
||||
if input != "" {
|
||||
txList.Txid = append(txList.Txid, txid)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -127,7 +127,6 @@ func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
|
||||
type addrOpts struct {
|
||||
Start int `json:"start"`
|
||||
End int `json:"end"`
|
||||
QueryMempol bool `json:"queryMempol"`
|
||||
QueryMempoolOnly bool `json:"queryMempoolOnly"`
|
||||
From int `json:"from"`
|
||||
To int `json:"to"`
|
||||
@ -276,27 +275,17 @@ func (s *SocketIoServer) getAddressTxids(addr []string, opts *addrOpts) (res res
|
||||
if !opts.QueryMempoolOnly {
|
||||
err = s.db.GetTransactions(address, lower, higher, func(txid string, vout uint32, isOutput bool) error {
|
||||
txids = append(txids, txid)
|
||||
if isOutput && opts.QueryMempol {
|
||||
input := s.chain.GetMempoolSpentOutput(txid, vout)
|
||||
if input != "" {
|
||||
txids = append(txids, txid)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
if opts.QueryMempoolOnly || opts.QueryMempol {
|
||||
mtxids, err := s.chain.GetMempoolTransactions(address)
|
||||
} else {
|
||||
m, err := s.chain.GetMempoolTransactions(address)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
txids = append(txids, mtxids...)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
txids = append(txids, m...)
|
||||
}
|
||||
}
|
||||
res.Result = uniqueTxidsInReverse(txids)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user