type.gno
1.32 Kb ยท 44 lines
1package referral
2
3import "chain/runtime"
4
5var (
6 zeroAddress = address("")
7 // selfAddress is cached at package initialization to ensure consistent comparison.
8 selfAddress address
9)
10
11func init() {
12 selfAddress = runtime.CurrentRealm().Address()
13}
14
15// contractAddress returns the address of the referral contract.
16// This is used as a sentinel value for removing referrals.
17func contractAddress() address {
18 return selfAddress
19}
20
21// isRemovalRequest checks if the given address indicates a removal request.
22// Removal is indicated by passing the contract's own address as the referral.
23func isRemovalRequest(refAddr address) bool {
24 return refAddr == selfAddress
25}
26
27// ReferralKeeper defines the interface for managing referral relationships.
28type ReferralKeeper interface {
29 // register creates or updates a referral relationship between addresses.
30 // Setting refAddr to the contract's own address removes the referral.
31 register(addr, refAddr address) error
32
33 // has returns true if a referral exists for the given address.
34 has(addr address) bool
35
36 // get retrieves the referral address for a given address.
37 get(addr address) (address, error)
38
39 // isEmpty returns true if no referrals exist in the system.
40 isEmpty() bool
41
42 // getLastOpTimestamp returns the last operation timestamp for an address.
43 getLastOpTimestamp(addr address) (int64, error)
44}