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