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.
This commit is contained in:
Wei Yang 2017-10-18 11:54:35 +08:00
parent 8ea4bc859d
commit 29099f0c02
2 changed files with 7 additions and 3 deletions

View File

@ -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, "")

View File

@ -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