crossrealm.gno
0.81 Kb · 41 lines
1package crossrealm_e
2
3import "chain/runtime"
4
5var (
6 balance int64
7 owner address
8)
9
10func init() {
11 balance = 1000
12 SetOwner(address("g1dao_address_here"))
13}
14
15// SetOwner is an internal helper that was exported by mistake
16// (should be setOwner). Without the pre-mutation readonly check,
17// a cross-realm caller could call SetOwner + recover to silently
18// hijack ownership in memory, then call TransferToken to steal funds.
19func SetOwner(o address) {
20 owner = o
21}
22
23func GetOwner() address {
24 return owner
25}
26
27func TransferOwnership(cur realm, o address) {
28 if runtime.PreviousRealm().Address() != owner {
29 panic("unauthorized")
30 }
31 owner = o
32}
33
34func TransferToken(cur realm) {
35 caller := runtime.PreviousRealm().Address()
36 if caller != owner {
37 panic("unauthorized")
38 }
39 balance -= 500
40 println("===send token to: ", caller)
41}