blockchain_go/cli_send.go

27 lines
494 B
Go

package main
import (
"fmt"
"log"
)
func (cli *CLI) send(from, to string, amount int) {
if !ValidateAddress(from) {
log.Panic("ERROR: Sender address is not valid")
}
if !ValidateAddress(to) {
log.Panic("ERROR: Recipient address is not valid")
}
bc := NewBlockchain()
UTXOSet := UTXOSet{bc}
defer bc.db.Close()
tx := NewUTXOTransaction(from, to, amount, &UTXOSet)
cbTx := NewCoinbaseTX(from, "")
txs := []*Transaction{cbTx, tx}
bc.MineBlock(txs)
fmt.Println("Success!")
}