-
Notifications
You must be signed in to change notification settings - Fork 13
/
NFTCatalogAdmin.cdc
176 lines (144 loc) · 7.79 KB
/
NFTCatalogAdmin.cdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import "NFTCatalog"
// NFTCatalogAdmin
//
// An admin contract that defines an admin resource and
// a proxy resource to receive a capability that lets you make changes to the NFT Catalog
// and manage proposals
access(all) contract NFTCatalogAdmin {
access(all) entitlement CatalogActions
// AddProposalAccepted
// Emitted when a proposal to add a new catalog item has been approved by an admin
access(all) event AddProposalAccepted(
proposer: Address,
collectionIdentifier : String,
contractName : String,
contractAddress : Address,
displayName : String
)
// UpdateProposalAccepted
// Emitted when a proposal to update a catalog item has been approved by an admin
access(all) event UpdateProposalAccepted(
proposer: Address,
collectionIdentifier : String,
contractName : String,
contractAddress : Address,
displayName : String
)
// ProposalRejected
// Emitted when a proposal to add or update a catalog item has been rejected.
access(all) event ProposalRejected(
proposer: Address,
collectionIdentifier : String,
contractName : String,
contractAddress : Address,
displayName : String
)
access(all) let AdminPrivatePath: PrivatePath
access(all) let AdminStoragePath: StoragePath
access(all) let AdminProxyPublicPath: PublicPath
access(all) let AdminProxyStoragePath: StoragePath
// Admin
// Admin resource to manage NFT Catalog
access(all) resource Admin {
access(CatalogActions) fun addCatalogEntry(collectionIdentifier: String, metadata : NFTCatalog.NFTCatalogMetadata) {
NFTCatalog.addCatalogEntry(collectionIdentifier: collectionIdentifier, metadata : metadata)
}
access(CatalogActions) fun updateCatalogEntry(collectionIdentifier : String , metadata : NFTCatalog.NFTCatalogMetadata) {
NFTCatalog.updateCatalogEntry(collectionIdentifier: collectionIdentifier, metadata : metadata)
}
access(CatalogActions) fun removeCatalogEntry(collectionIdentifier : String) {
NFTCatalog.removeCatalogEntry(collectionIdentifier : collectionIdentifier)
}
access(CatalogActions) fun removeCatalogEntryUnsafe(collectionIdentifier : String, nftTypeIdentifier: String) {
NFTCatalog.removeCatalogEntryUnsafe(collectionIdentifier : collectionIdentifier, nftTypeIdentifier: nftTypeIdentifier)
}
access(CatalogActions) fun approveCatalogProposal(proposalID : UInt64) {
pre {
NFTCatalog.getCatalogProposalEntry(proposalID : proposalID) != nil : "Invalid Proposal ID"
NFTCatalog.getCatalogProposalEntry(proposalID : proposalID)!.status == "IN_REVIEW" : "Invalid Proposal"
}
let catalogProposalEntry = NFTCatalog.getCatalogProposalEntry(proposalID : proposalID)!
let newCatalogProposalEntry = NFTCatalog.NFTCatalogProposal(collectionIdentifier : catalogProposalEntry.collectionIdentifier, metadata : catalogProposalEntry.metadata, message : catalogProposalEntry.message, status: "APPROVED", proposer: catalogProposalEntry.proposer)
NFTCatalog.updateCatalogProposal(proposalID : proposalID, proposalMetadata : newCatalogProposalEntry)
if NFTCatalog.getCatalogEntry(collectionIdentifier : NFTCatalog.getCatalogProposalEntry(proposalID : proposalID)!.collectionIdentifier) == nil {
NFTCatalog.addCatalogEntry(collectionIdentifier: newCatalogProposalEntry.collectionIdentifier, metadata : newCatalogProposalEntry.metadata)
emit AddProposalAccepted(
proposer: newCatalogProposalEntry.proposer,
collectionIdentifier : newCatalogProposalEntry.collectionIdentifier,
contractName : newCatalogProposalEntry.metadata.contractName,
contractAddress : newCatalogProposalEntry.metadata.contractAddress,
displayName : newCatalogProposalEntry.metadata.collectionDisplay.name
)
} else {
NFTCatalog.updateCatalogEntry(collectionIdentifier: newCatalogProposalEntry.collectionIdentifier, metadata: newCatalogProposalEntry.metadata)
emit UpdateProposalAccepted(
proposer: newCatalogProposalEntry.proposer,
collectionIdentifier : newCatalogProposalEntry.collectionIdentifier,
contractName : newCatalogProposalEntry.metadata.contractName,
contractAddress : newCatalogProposalEntry.metadata.contractAddress,
displayName : newCatalogProposalEntry.metadata.collectionDisplay.name
)
}
}
access(CatalogActions) fun rejectCatalogProposal(proposalID : UInt64) {
pre {
NFTCatalog.getCatalogProposalEntry(proposalID : proposalID) != nil : "Invalid Proposal ID"
NFTCatalog.getCatalogProposalEntry(proposalID : proposalID)!.status == "IN_REVIEW" : "Invalid Proposal"
}
let catalogProposalEntry = NFTCatalog.getCatalogProposalEntry(proposalID : proposalID)!
let newCatalogProposalEntry = NFTCatalog.NFTCatalogProposal(collectionIdentifier : catalogProposalEntry.collectionIdentifier, metadata : catalogProposalEntry.metadata, message : catalogProposalEntry.message, status: "REJECTED", proposer: catalogProposalEntry.proposer)
NFTCatalog.updateCatalogProposal(proposalID : proposalID, proposalMetadata : newCatalogProposalEntry)
emit ProposalRejected(
proposer: newCatalogProposalEntry.proposer,
collectionIdentifier : newCatalogProposalEntry.collectionIdentifier,
contractName : newCatalogProposalEntry.metadata.contractName,
contractAddress : newCatalogProposalEntry.metadata.contractAddress,
displayName : newCatalogProposalEntry.metadata.collectionDisplay.name
)
}
access(CatalogActions) fun removeCatalogProposal(proposalID : UInt64) {
pre {
NFTCatalog.getCatalogProposalEntry(proposalID : proposalID) != nil : "Invalid Proposal ID"
}
NFTCatalog.removeCatalogProposal(proposalID : proposalID)
}
init () {}
}
// AdminProxy
// A proxy resource that can store
// a capability to admin controls
access(all) resource interface IAdminProxy {
access(all) fun addCapability(capability: Capability<auth(CatalogActions) &Admin>)
access(all) fun hasCapability(): Bool
}
access(all) resource AdminProxy: IAdminProxy {
access(self) var capability: Capability<auth(CatalogActions) &Admin>?
access(all) fun addCapability(capability: Capability<auth(CatalogActions) &Admin>) {
pre {
capability.check() : "Invalid Admin Capability"
self.capability == nil : "Admin Proxy already set"
}
self.capability = capability
}
access(CatalogActions) view fun getCapability() : Capability<auth(CatalogActions) &Admin>? {
return self.capability
}
access(all) view fun hasCapability() : Bool {
return self.capability != nil
}
init() {
self.capability = nil
}
}
access(all) fun createAdminProxy() : @AdminProxy {
return <- create AdminProxy()
}
init () {
self.AdminProxyPublicPath = /public/nftCatalogAdminProxy
self.AdminProxyStoragePath = /storage/nftCatalogAdminProxy
self.AdminPrivatePath = /private/nftCatalogAdmin
self.AdminStoragePath = /storage/nftCatalogAdmin
let admin <- create Admin()
self.account.storage.save(<-admin, to: self.AdminStoragePath)
}
}