types.gno

1.45 Kb ยท 49 lines
 1package treasury
 2
 3import (
 4	"errors"
 5
 6	"gno.land/p/nt/avl"
 7	"gno.land/p/nt/avl/list"
 8	"gno.land/p/nt/mux"
 9)
10
11// Treasury is the main structure that holds all bankers and their payment
12// history. It also provides a router for rendering the treasury pages.
13type Treasury struct {
14	bankers *avl.Tree // string -> *bankerRecord
15	router  *mux.Router
16}
17
18// bankerRecord holds a Banker and its payment history.
19type bankerRecord struct {
20	banker  Banker
21	history list.List // List of Payment.
22}
23
24// Banker is an interface that allows for banking operations.
25type Banker interface {
26	ID() string          // Get the ID of the banker.
27	Send(Payment) error  // Send a payment to a recipient.
28	Balances() []Balance // Get the balances of the banker.
29	Address() string     // Get the address of the banker to receive payments.
30}
31
32// Payment is an interface that allows getting details about a payment.
33type Payment interface {
34	BankerID() string // Get the ID of the banker that can process this payment.
35	String() string   // Get a string representation of the payment.
36}
37
38// Balance represents the balance of an asset held by a Banker.
39type Balance struct {
40	Denom  string // The denomination of the asset
41	Amount int64  // The amount of the asset
42}
43
44// Common Banker errors.
45var (
46	ErrCurrentRealmIsNotOwner = errors.New("current realm is not the owner of the banker")
47	ErrNoOwnerProvided        = errors.New("no owner provided")
48	ErrInvalidPaymentType     = errors.New("invalid payment type")
49)