From 29099f0c02077c530b62356a2494c05d3a79e3ca Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Wed, 18 Oct 2017 11:54:35 +0800 Subject: [PATCH] check wallet before sending We could only send money from our own wallet. If the parameter is not an address in our wallet, exit the program gracefully and show an error message. --- cli_send.go | 6 +++++- wallets.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli_send.go b/cli_send.go index 75a5930..67b0091 100644 --- a/cli_send.go +++ b/cli_send.go @@ -22,8 +22,12 @@ func (cli *CLI) send(from, to string, amount int, nodeID string, mineNow bool) { log.Panic(err) } wallet := wallets.GetWallet(from) + if wallet == nil { + fmt.Println("The Address doesn't belongs to you!") + return + } - tx := NewUTXOTransaction(&wallet, to, amount, &UTXOSet) + tx := NewUTXOTransaction(wallet, to, amount, &UTXOSet) if mineNow { cbTx := NewCoinbaseTX(from, "") diff --git a/wallets.go b/wallets.go index 9f376f5..a7d354f 100644 --- a/wallets.go +++ b/wallets.go @@ -49,8 +49,8 @@ func (ws *Wallets) GetAddresses() []string { } // GetWallet returns a Wallet by its address -func (ws Wallets) GetWallet(address string) Wallet { - return *ws.Wallets[address] +func (ws Wallets) GetWallet(address string) *Wallet { + return ws.Wallets[address] } // LoadFromFile loads wallets from the file