origin.gno
1.56 Kb · 42 lines
1package escrow_v4
2
3// The only chain/runtime/unsafe uses in this realm. Nothing here reads a
4// caller from the stack and no crossing entrypoint is declared in this file:
5// entrypoints authenticate with cur.IsCurrent() and cur.Previous(), and
6// requireExactSend only checks the kind of the frame-verified caller it is
7// handed.
8
9import (
10 "chain/runtime/unsafe"
11
12 "gno.land/p/nt/ufmt/v0"
13)
14
15// publisherAtLoad captures the AddPackage signer during package
16// initialization; it seeds admin and the fallback fee recipient.
17func publisherAtLoad() address { return unsafe.OriginCaller() }
18
19// requireExactSend panics unless caller (the entrypoint's cur.Previous()) is
20// a direct user call and the transaction's send envelope holds exactly amount
21// ugnot and no other denom. Only for a direct user call is the envelope
22// credited to this realm, the message target; any other denom would be
23// stranded here. The guard sits in this function, before the read, so the
24// deployer's per-function fund-safety scan (lib/deploy.sh) sees it.
25func requireExactSend(amount int64, caller realm) {
26 if !caller.IsUserCall() {
27 panic("FundMilestone must be a direct user call")
28 }
29 sent := int64(0)
30 for _, coin := range unsafe.OriginSend() {
31 if coin.Denom != "ugnot" {
32 panic("only ugnot is accepted, got " + coin.Denom)
33 }
34 sent += coin.Amount
35 }
36 if sent != amount {
37 panic(ufmt.Sprintf("must send exactly %d ugnot (sent %d)", amount, sent))
38 }
39}
40
41// realmAddress is this realm's own address, for the NF-2 solvency getter.
42func realmAddress() address { return unsafe.CurrentRealm().Address() }