Update the UTXO set after mining a new block

This commit is contained in:
Ivan Kuznetsov 2017-09-17 12:21:24 +07:00
parent fe34c88dfc
commit 99d1134beb
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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!")
}