Smart Contract
AuctionMetadata
A.66b60643244a7738.AuctionMetadata
1pub contract AuctionMetadata {
2 // Event definitions
3 pub event MetadataAdded(id: UInt64, userAddress: Address, auctionType: String, currentBid: UFix64, timeStamp: String, txID: String)
4 pub event MetadataRemoved(id: UInt64)
5
6 pub struct Metadata {
7 pub let id: UInt64
8 pub let userAddress: Address
9 pub let auctionType: String
10 pub let currentBid: UFix64
11 pub let timeStamp: String
12 pub let txID: String
13
14 init(id: UInt64, userAddress: Address, auctionType: String, currentBid: UFix64, timeStamp: String, txID: String) {
15 self.id = id
16 self.userAddress = userAddress
17 self.auctionType = auctionType
18 self.currentBid = currentBid
19 self.timeStamp = timeStamp
20 self.txID = txID
21 }
22 }
23
24 // Store for the metadata
25 pub var metadataRecords: {UInt64: Metadata}
26
27 // Global ID counter
28 pub var nextId: UInt64
29
30 pub fun addMetadata(userAddress: Address, auctionType: String, currentBid: UFix64, timeStamp: String, txID: String) {
31 let newMetadata = Metadata(id: self.nextId, userAddress: userAddress, auctionType: auctionType, currentBid: currentBid, timeStamp: timeStamp, txID: txID)
32 self.metadataRecords[self.nextId] = newMetadata
33
34 // Emitting an event for adding metadata
35 emit MetadataAdded(id: self.nextId, userAddress: userAddress, auctionType: auctionType, currentBid: currentBid, timeStamp: timeStamp, txID: txID)
36
37 self.nextId = self.nextId + 1
38 }
39
40 pub fun removeMetadataByTxID(txIDToRemove: String) {
41 var keyToRemove: UInt64? = nil
42 for key in self.metadataRecords.keys {
43 if self.metadataRecords[key]!.txID == txIDToRemove {
44 keyToRemove = key
45 break // Assuming you want to remove the first match
46 }
47 }
48
49 if let key = keyToRemove {
50 self.metadataRecords.remove(key: key)
51 emit MetadataRemoved(id: key)
52 }
53 }
54
55 init() {
56 self.metadataRecords = {}
57 self.nextId = 0
58 }
59}
60