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:
parent
8ea4bc859d
commit
29099f0c02
|
@ -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, "")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue