master
1package main
2
3import (
4 "errors"
5 "fmt"
6)
7
8type Bitcoin int
9
10func (b Bitcoin) String() string {
11 return fmt.Sprintf("%d BTC", b)
12}
13
14type Wallet struct {
15 balance Bitcoin
16}
17
18var InsufficientFundsError = errors.New("cannot withdraw, insufficient funds")
19
20func (w *Wallet) Deposit(amount Bitcoin) {
21 fmt.Printf("address of balance in test is %v \n", &w.balance)
22 w.balance += amount
23}
24
25func (w *Wallet) Balance() Bitcoin {
26 fmt.Printf("address of balance in test is %v \n", &w.balance)
27 return w.balance
28}
29
30func (w *Wallet) Withdraw(amount Bitcoin) error {
31 if amount > w.balance {
32 return InsufficientFundsError
33 }
34
35 w.balance -= amount
36 return nil
37}