From 47f798dbaa15a07e239eb062d9c285940dafcf6b Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 3 Apr 2019 14:02:15 +0200 Subject: [PATCH] Return mempool transactions for address in reverse order --- bchain/basemempool.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bchain/basemempool.go b/bchain/basemempool.go index 94d85fa9..01e1b90b 100644 --- a/bchain/basemempool.go +++ b/bchain/basemempool.go @@ -39,11 +39,17 @@ func (m *BaseMempool) GetTransactions(address string) ([]Outpoint, error) { return m.GetAddrDescTransactions(addrDesc) } -// GetAddrDescTransactions returns slice of mempool transactions for given address descriptor +// GetAddrDescTransactions returns slice of mempool transactions for given address descriptor, in reverse order func (m *BaseMempool) GetAddrDescTransactions(addrDesc AddressDescriptor) ([]Outpoint, error) { m.mux.Lock() defer m.mux.Unlock() - return append([]Outpoint(nil), m.addrDescToTx[string(addrDesc)]...), nil + outpoints := m.addrDescToTx[string(addrDesc)] + rv := make([]Outpoint, len(outpoints)) + for i, j := len(outpoints)-1, 0; i >= 0; i-- { + rv[j] = outpoints[i] + j++ + } + return rv, nil } func (a MempoolTxidEntries) Len() int { return len(a) } @@ -84,3 +90,12 @@ func getAllEntries(txEntries map[string]txEntry) MempoolTxidEntries { func (m *BaseMempool) GetAllEntries() MempoolTxidEntries { return getAllEntries(m.txEntries) } + +// GetTransactionTime returns first seen time of a transaction +func (m *BaseMempool) GetTransactionTime(txid string) uint32 { + e, found := m.txEntries[txid] + if !found { + return 0 + } + return e.time +}