Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

payments.gno

1.29 Kb · 43 lines
 1package mint
 2
 3import (
 4	"chain"
 5	"chain/banker"
 6	"chain/runtime/unsafe"
 7)
 8
 9// I-3: this realm holds no balance. Each paying function receives the
10// attached ugnot and pushes every unit out before returning: protocol fee,
11// creator payees, and the refund. Nothing is ever kept for later.
12
13// received returns the ugnot attached to a direct wallet call. Payments are
14// accepted only when a wallet called us: the origin-send envelope is shared
15// by every realm on the path, so a realm in between could have consumed it
16// (chain/runtime/unsafe.OriginSend).
17func received(cur realm) int64 {
18	if !cur.Previous().IsUserCall() {
19		panic("payments must come directly from a wallet, not through another realm")
20	}
21	sent := unsafe.OriginSend()
22	for _, c := range sent {
23		if c.Denom != "ugnot" && c.Amount != 0 {
24			panic("only ugnot is accepted")
25		}
26	}
27	return sent.AmountOf("ugnot")
28}
29
30// assertNoDeposit refuses coins on functions that take none (RA L-1).
31func assertNoDeposit(cur realm) {
32	if cur.Previous().IsUserCall() && !unsafe.OriginSend().IsZero() {
33		panic("this function does not accept coins")
34	}
35}
36
37func pay(cur realm, to address, amount int64) {
38	if amount <= 0 {
39		return
40	}
41	banker.NewBanker(banker.BankerTypeRealmSend, cur).
42		SendCoins(cur.Address(), to, chain.NewCoins(chain.NewCoin("ugnot", amount)))
43}