From 4bd5b1a43a8e5b64b9462d3048d2f8d290c7b851 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 30 May 2018 20:45:39 -0700 Subject: [PATCH] blockchain: add new FetchSpendJournal method --- blockchain/chainio.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/blockchain/chainio.go b/blockchain/chainio.go index 27b702de..84cd9b77 100644 --- a/blockchain/chainio.go +++ b/blockchain/chainio.go @@ -246,6 +246,30 @@ type spentTxOut struct { isCoinBase bool // Whether creating tx is a coinbase. } +// FetchSpendJournal attempts to retrieve the spend journal, or the set of +// outputs spent for the target block. This provides a view of all the outputs +// that will be consumed once the target block is connected to the end of the +// main chain. +// +// This function is safe for concurrent access. +func (b *BlockChain) FetchSpendJournal(targetBlock *btcutil.Block) ([]SpentTxOut, error) { + b.chainLock.RLock() + defer b.chainLock.RUnlock() + + var spendEntries []SpentTxOut + err := b.db.View(func(dbTx database.Tx) error { + var err error + + spendEntries, err = dbFetchSpendJournalEntry(dbTx, targetBlock) + return err + }) + if err != nil { + return nil, err + } + + return spendEntries, nil +} + // spentTxOutHeaderCode returns the calculated header code to be used when // serializing the provided stxo entry. func spentTxOutHeaderCode(stxo *spentTxOut) uint64 {