-
Notifications
You must be signed in to change notification settings - Fork 373
/
banker.gno
70 lines (60 loc) · 1.97 KB
/
banker.gno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package std
// Realm functions can call std.GetBanker(options) to get
// a banker instance. Banker objects cannot be persisted,
// but can be passed onto other functions to be transacted
// on. A banker instance can be passed onto other realm
// functions; this allows other realms to spend coins on
// behalf of the first realm.
//
// Banker panics on errors instead of returning errors.
// This also helps simplify the interface and prevent
// hidden bugs (e.g. ignoring errors)
//
// NOTE: this Gno interface is satisfied by a native go
// type, and those can't return non-primitive objects
// (without confusion).
type Banker interface {
GetCoins(addr Address) (dst Coins)
SendCoins(from, to Address, amt Coins)
TotalCoin(denom string) int64
IssueCoin(addr Address, denom string, amount int64)
RemoveCoin(addr Address, denom string, amount int64)
}
// Also available natively in stdlibs/context.go
type BankerType uint8
// Also available natively in stdlibs/context.go
const (
// Can only read state.
BankerTypeReadonly BankerType = iota
// Can only send from tx send.
BankerTypeOrigSend
// Can send from all realm coins.
BankerTypeRealmSend
// Can issue and remove realm coins.
BankerTypeRealmIssue
)
//----------------------------------------
// adapter for native banker
type bankAdapter struct {
nativeBanker Banker
}
func (ba bankAdapter) GetCoins(addr Address) (dst Coins) {
// convert native -> gno
coins := ba.nativeBanker.GetCoins(addr)
for _, coin := range coins {
dst = append(dst, (Coin)(coin))
}
return dst
}
func (ba bankAdapter) SendCoins(from, to Address, amt Coins) {
ba.nativeBanker.SendCoins(from, to, amt)
}
func (ba bankAdapter) TotalCoin(denom string) int64 {
return ba.nativeBanker.TotalCoin(denom)
}
func (ba bankAdapter) IssueCoin(addr Address, denom string, amount int64) {
ba.nativeBanker.IssueCoin(addr, denom, amount)
}
func (ba bankAdapter) RemoveCoin(addr Address, denom string, amount int64) {
ba.nativeBanker.RemoveCoin(addr, denom, amount)
}