Smart Contract
GrantedAccountAccess
A.2d4c3caffbeab845.GrantedAccountAccess
1// MADE BY: Emerald City, Jacob Tucker
2
3// This is a very simple contract that lets users add addresses
4// to an "Info" resource signifying they want them to share their account.
5
6// This is specifically used by the
7// `pub fun borrowSharedRef(fromHost: Address): &FLOATEvents`
8// function inside FLOAT.cdc to give users access to someone elses
9// FLOATEvents if they are on this shared list.
10
11// This contract is my way of saying I hate private capabilities, so I
12// implemented an alternative solution to private access.
13
14pub contract GrantedAccountAccess {
15
16 pub let InfoStoragePath: StoragePath
17 pub let InfoPublicPath: PublicPath
18
19 pub resource interface InfoPublic {
20 pub fun getAllowed(): [Address]
21 pub fun isAllowed(account: Address): Bool
22 }
23
24 // A list of people you allow to share your
25 // account.
26 pub resource Info: InfoPublic {
27 access(account) var allowed: {Address: Bool}
28
29 // Allow someone to share your account
30 pub fun addAccount(account: Address) {
31 self.allowed[account] = true
32 }
33
34 pub fun removeAccount(account: Address) {
35 self.allowed.remove(key: account)
36 }
37
38 pub fun getAllowed(): [Address] {
39 return self.allowed.keys
40 }
41
42 pub fun isAllowed(account: Address): Bool {
43 return self.allowed.containsKey(account)
44 }
45
46 init() {
47 self.allowed = {}
48 }
49 }
50
51 pub fun createInfo(): @Info {
52 return <- create Info()
53 }
54
55 init() {
56 self.InfoStoragePath = /storage/GrantedAccountAccessInfo
57 self.InfoPublicPath = /public/GrantedAccountAccessInfo
58 }
59
60}