2022-03-31 11:19:47 +00:00
|
|
|
package ledger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
ID string
|
|
|
|
Money int64
|
|
|
|
)
|
|
|
|
|
|
|
|
var ErrNoMoney = errors.New("no money")
|
2024-06-05 17:36:34 +00:00
|
|
|
var ErrNegativeAmount = errors.New("negative amount")
|
2022-03-31 11:19:47 +00:00
|
|
|
|
|
|
|
type Ledger interface {
|
|
|
|
CreateAccount(ctx context.Context, id ID) error
|
|
|
|
GetBalance(ctx context.Context, id ID) (Money, error)
|
|
|
|
Deposit(ctx context.Context, id ID, amount Money) error
|
|
|
|
Withdraw(ctx context.Context, id ID, amount Money) error
|
|
|
|
Transfer(ctx context.Context, from, to ID, amount Money) error
|
2022-04-13 15:13:39 +00:00
|
|
|
Close() error
|
2022-03-31 11:19:47 +00:00
|
|
|
}
|