From 99d1134beb8497ba487e3c6062c654989ac0742a Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Sun, 17 Sep 2017 12:21:24 +0700 Subject: [PATCH] Update the UTXO set after mining a new block --- blockchain.go | 4 +++- cli_send.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/blockchain.go b/blockchain.go index fa68abc..bbcb976 100644 --- a/blockchain.go +++ b/blockchain.go @@ -168,7 +168,7 @@ func (bc *Blockchain) Iterator() *BlockchainIterator { } // MineBlock mines a new block with the provided transactions -func (bc *Blockchain) MineBlock(transactions []*Transaction) { +func (bc *Blockchain) MineBlock(transactions []*Transaction) *Block { var lastHash []byte for _, tx := range transactions { @@ -208,6 +208,8 @@ func (bc *Blockchain) MineBlock(transactions []*Transaction) { if err != nil { log.Panic(err) } + + return newBlock } // SignTransaction signs inputs of a Transaction diff --git a/cli_send.go b/cli_send.go index 3528611..456c264 100644 --- a/cli_send.go +++ b/cli_send.go @@ -21,6 +21,7 @@ func (cli *CLI) send(from, to string, amount int) { cbTx := NewCoinbaseTX(from, "") txs := []*Transaction{cbTx, tx} - bc.MineBlock(txs) + newBlock := bc.MineBlock(txs) + UTXOSet.Update(newBlock) fmt.Println("Success!") }