Smart Contract
DarkCountryStaking
A.c8c340cebd11f690.DarkCountryStaking
1
2
3pub contract DarkCountryStaking {
4
5 // Staked Items.
6 // Indicates list of NFTs staked by a user.
7 access(account) var stakedItems: { Address: [UInt64] }
8
9 // Emitted when NFTs are staked
10 pub event ItemsStaked(from: Address, ids: [UInt64])
11
12 // Emitted when NFTs are requested for staking
13 pub event ItemsRequestedForStaking(from: Address, ids: [UInt64])
14 pub event ItemsRequestedForUnstaking(from: Address, ids: [UInt64])
15
16 pub let AdminStoragePath: StoragePath
17
18 pub fun getStakedNFTsForAddress(userAddress: Address): [UInt64]? {
19
20 return self.stakedItems[userAddress]
21 }
22
23 pub fun requestSetStakedNFTsForAddress(userAddress: Address, stakedNFTs: [UInt64]) {
24
25 emit ItemsRequestedForStaking(from: userAddress, ids: stakedNFTs)
26 }
27
28 pub fun requestSetUnstakedNFTsForAddress(userAddress: Address, stakedNFTs: [UInt64]) {
29
30 emit ItemsRequestedForUnstaking(from: userAddress, ids: stakedNFTs)
31 }
32
33 // Admin is a special authorization resource that
34 // allows the owner to perform functions to modify the following:
35 // 1. Staked items
36 pub resource Admin {
37 // sets staked NFTs for a user by theirs addresss
38 //
39 // Parameters: userAddress: The address of the user's account
40 // newStakedItems: new list of items
41 //
42 // To be used to unstaked the NFTs for user
43 // only Admin/Minter can do that
44 pub fun setStakedNFTsForAddress(userAddress: Address, stakedNFTs: [UInt64]) {
45
46 DarkCountryStaking.stakedItems[userAddress] = stakedNFTs
47
48 emit ItemsStaked(from: userAddress, ids: stakedNFTs)
49 }
50
51 // createNewAdmin creates a new Admin resource
52 //
53 pub fun createNewAdmin(): @Admin {
54 return <-create Admin()
55 }
56 }
57
58 init () {
59 self.AdminStoragePath = /storage/DarkCountryStakingAdmin
60
61 self.stakedItems = {}
62
63 let admin <- create Admin()
64 self.account.save(<-admin, to: self.AdminStoragePath)
65 }
66}