Smart Contract
FlowverseSocksMintContract
A.ce4c02539d1fabe8.FlowverseSocksMintContract
1import NonFungibleToken from 0x1d7e57aa55817448
2import FungibleToken from 0xf233dcee88fe0abe
3import FlowverseSocks from 0xce4c02539d1fabe8
4import RaribleNFT from 0x01ab36aaf654a13e
5
6pub contract FlowverseSocksMintContract {
7 pub let AdminStoragePath: StoragePath
8
9 pub var sale: Sale?
10
11 pub struct Sale {
12 pub var startTime: UFix64?
13 pub var endTime: UFix64?
14 pub var max: UInt64
15 pub var current: UInt64
16 pub var idMapping: {UInt64:UInt64}
17 init(startTime: UFix64?,
18 endTime: UFix64?,
19 max: UInt64,
20 current: UInt64,
21 idMapping: {UInt64:UInt64}){
22 self.startTime=startTime
23 self.endTime=endTime
24 self.max=max
25 self.current=current
26 self.idMapping = idMapping
27 }
28 access(contract) fun incCurrent(){
29 self.current = self.current + UInt64(1)
30 }
31 }
32
33 pub fun paymentMint(
34 toBurn: @NonFungibleToken.NFT,
35 recipient: &{NonFungibleToken.CollectionPublic}
36 ){
37 pre {
38 self.sale != nil: "sale closed"
39 self.sale!.startTime == nil || self.sale!.startTime! <= getCurrentBlock().timestamp: "sale not started yet"
40 self.sale!.endTime == nil || self.sale!.endTime! > getCurrentBlock().timestamp: "sale already ended"
41 self.sale!.max > self.sale!.current: "sale items sold out"
42 toBurn.isInstance(Type<@RaribleNFT.NFT>()): "toBurn is not requested NFT type"
43
44 }
45 let id = self.sale!.idMapping[toBurn.id]
46 if(id == nil){
47 panic("NFT id not in list")
48 }
49 destroy toBurn
50
51 let minter = self.account.borrow<&FlowverseSocks.NFTMinter>(from: FlowverseSocks.MinterStoragePath)!
52 let metadata: {String:String} = {}
53 let tokenId = id
54 // metadata code here
55
56
57 minter.mintNFTWithID(id: id!, recipient: recipient, metadata: metadata)
58
59 self.sale!.incCurrent()
60 }
61
62 pub resource Administrator {
63 pub fun setSale(sale:Sale?){
64 FlowverseSocksMintContract.sale = sale
65 }
66 }
67
68 init() {
69 self.sale = nil
70 self.AdminStoragePath = /storage/FlowverseSocksMintContractAdmin
71
72 self.account.save(<- create Administrator(), to: self.AdminStoragePath)
73 }
74}
75