blockchain_go/cli_send.go

26 lines
464 B
Go
Raw Normal View History

package main
2017-09-10 01:53:14 -05:00
import (
"fmt"
"log"
)
func (cli *CLI) send(from, to string, amount int) {
2017-09-10 01:53:14 -05:00
if !ValidateAddress(from) {
log.Panic("ERROR: Sender address is not valid")
}
if !ValidateAddress(to) {
log.Panic("ERROR: Recipient address is not valid")
}
bc := NewBlockchain()
defer bc.db.Close()
tx := NewUTXOTransaction(from, to, amount, bc)
2017-09-16 21:16:50 -05:00
cbTx := NewCoinbaseTX(from, "")
txs := []*Transaction{cbTx, tx}
bc.MineBlock(txs)
fmt.Println("Success!")
}