Update the UTXO set after mining a new block
This commit is contained in:
parent
fe34c88dfc
commit
99d1134beb
|
@ -168,7 +168,7 @@ func (bc *Blockchain) Iterator() *BlockchainIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MineBlock mines a new block with the provided transactions
|
// 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
|
var lastHash []byte
|
||||||
|
|
||||||
for _, tx := range transactions {
|
for _, tx := range transactions {
|
||||||
|
@ -208,6 +208,8 @@ func (bc *Blockchain) MineBlock(transactions []*Transaction) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return newBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignTransaction signs inputs of a Transaction
|
// SignTransaction signs inputs of a Transaction
|
||||||
|
|
|
@ -21,6 +21,7 @@ func (cli *CLI) send(from, to string, amount int) {
|
||||||
cbTx := NewCoinbaseTX(from, "")
|
cbTx := NewCoinbaseTX(from, "")
|
||||||
txs := []*Transaction{cbTx, tx}
|
txs := []*Transaction{cbTx, tx}
|
||||||
|
|
||||||
bc.MineBlock(txs)
|
newBlock := bc.MineBlock(txs)
|
||||||
|
UTXOSet.Update(newBlock)
|
||||||
fmt.Println("Success!")
|
fmt.Println("Success!")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue