Add -mine option to the 'send' command
This commit is contained in:
parent
9de40a9385
commit
150778f920
5
cli.go
5
cli.go
|
@ -19,7 +19,7 @@ func (cli *CLI) printUsage() {
|
|||
fmt.Println(" listaddresses - Lists all addresses from the wallet file")
|
||||
fmt.Println(" printchain - Print all the blocks of the blockchain")
|
||||
fmt.Println(" reindexutxo - Rebuilds the UTXO set")
|
||||
fmt.Println(" send -from FROM -to TO -amount AMOUNT - Send AMOUNT of coins from FROM address to TO")
|
||||
fmt.Println(" send -from FROM -to TO -amount AMOUNT -mine - Send AMOUNT of coins from FROM address to TO. Mine on the same node, when -mine is set.")
|
||||
fmt.Println(" startnode - Start a node with ID specified in NODE_ID env. var")
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ func (cli *CLI) Run() {
|
|||
sendFrom := sendCmd.String("from", "", "Source wallet address")
|
||||
sendTo := sendCmd.String("to", "", "Destination wallet address")
|
||||
sendAmount := sendCmd.Int("amount", 0, "Amount to send")
|
||||
sendMine := sendCmd.Bool("mine", false, "Mine immediately on the same node")
|
||||
|
||||
switch os.Args[1] {
|
||||
case "getbalance":
|
||||
|
@ -139,7 +140,7 @@ func (cli *CLI) Run() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
cli.send(*sendFrom, *sendTo, *sendAmount, nodeID)
|
||||
cli.send(*sendFrom, *sendTo, *sendAmount, nodeID, *sendMine)
|
||||
}
|
||||
|
||||
if startNodeCmd.Parsed() {
|
||||
|
|
18
cli_send.go
18
cli_send.go
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
func (cli *CLI) send(from, to string, amount int, nodeID string) {
|
||||
func (cli *CLI) send(from, to string, amount int, nodeID string, mineNow bool) {
|
||||
if !ValidateAddress(from) {
|
||||
log.Panic("ERROR: Sender address is not valid")
|
||||
}
|
||||
|
@ -25,16 +25,16 @@ func (cli *CLI) send(from, to string, amount int, nodeID string) {
|
|||
|
||||
tx := NewUTXOTransaction(&wallet, to, amount, &UTXOSet)
|
||||
cbTx := NewCoinbaseTX(from, "")
|
||||
// txs := []*Transaction{cbTx, tx}
|
||||
|
||||
// var txHashes [][]byte
|
||||
// txHashes = append(txHashes, tx.Hash())
|
||||
// txHashes = append(txHashes, cbTx.Hash())
|
||||
if mineNow {
|
||||
txs := []*Transaction{cbTx, tx}
|
||||
|
||||
sendTx(knownNodes[0], tx)
|
||||
sendTx(knownNodes[0], cbTx)
|
||||
newBlock := bc.MineBlock(txs)
|
||||
UTXOSet.Update(newBlock)
|
||||
} else {
|
||||
sendTx(knownNodes[0], tx)
|
||||
sendTx(knownNodes[0], cbTx)
|
||||
}
|
||||
|
||||
// newBlock := bc.MineBlock(txs)
|
||||
// UTXOSet.Update(newBlock)
|
||||
fmt.Println("Success!")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue