@@ -12,40 +12,37 @@ export const nftCreatedHandler = async (event: SubstrateEvent): Promise<void> =>
12
12
const commonEventData = getCommonEventData ( event )
13
13
if ( ! commonEventData . isSuccess ) throw new Error ( "NFT created error, extrinsic isSuccess : false" )
14
14
const [ nftId , owner , offchainData , royalty , collectionId , isSoulbound , mintFee ] = event . event . data
15
- let record = await NftEntity . get ( nftId . toString ( ) )
16
- if ( record === undefined ) {
17
- record = new NftEntity ( nftId . toString ( ) )
18
- record . nftId = nftId . toString ( )
19
- record . collectionId = collectionId ?. toString ( ) || null
20
- record . owner = owner . toString ( )
21
- record . creator = owner . toString ( )
22
- record . offchainData = formatString ( offchainData . toString ( ) )
23
- record . royalty = Number ( royalty . toString ( ) ) / 10000
24
- record . isCapsule = false
25
- record . isListed = false
26
- record . typeOfListing = null
27
- record . isSecret = false
28
- record . isRented = false
29
- record . isDelegated = false
30
- record . isSoulbound = isSoulbound . toString ( ) === "true"
31
- record . isSecretSynced = false
32
- record . isCapsuleSynced = false
33
- record . isTransmission = false
34
- record . createdAt = commonEventData . timestamp
35
- record . updatedAt = commonEventData . timestamp
36
- record . timestampCreated = commonEventData . timestamp
37
- await record . save ( )
38
- if ( record . collectionId ) {
39
- let collectionRecord = await CollectionEntity . get ( record . collectionId )
40
- if ( collectionRecord === undefined ) throw new Error ( "Collection where nft is added not found in db" )
41
- collectionRecord . nfts . push ( record . nftId )
42
- collectionRecord . nbNfts = collectionRecord . nbNfts + 1
43
- if ( collectionRecord . nfts . length === collectionRecord . limit ) collectionRecord . hasReachedLimit = true
44
- await collectionRecord . save ( )
45
- }
46
- await nftOperationEntityHandler ( record , null , commonEventData , NFTOperation . Created , [ mintFee . toString ( ) ] )
47
- await genericTransferHandler ( owner , "Treasury" , mintFee , commonEventData )
15
+ const record = new NftEntity ( nftId . toString ( ) )
16
+ record . nftId = nftId . toString ( )
17
+ record . collectionId = collectionId ?. toString ( ) || null
18
+ record . owner = owner . toString ( )
19
+ record . creator = owner . toString ( )
20
+ record . offchainData = formatString ( offchainData . toString ( ) )
21
+ record . royalty = Number ( royalty . toString ( ) ) / 10000
22
+ record . isCapsule = false
23
+ record . isListed = false
24
+ record . typeOfListing = null
25
+ record . isSecret = false
26
+ record . isRented = false
27
+ record . isDelegated = false
28
+ record . isSoulbound = isSoulbound . toString ( ) === "true"
29
+ record . isSecretSynced = false
30
+ record . isCapsuleSynced = false
31
+ record . isTransmission = false
32
+ record . createdAt = commonEventData . timestamp
33
+ record . updatedAt = commonEventData . timestamp
34
+ record . timestampCreated = commonEventData . timestamp
35
+ await record . save ( )
36
+ if ( record . collectionId ) {
37
+ let collectionRecord = await CollectionEntity . get ( record . collectionId )
38
+ if ( collectionRecord === undefined ) throw new Error ( "Collection where nft is added not found in db" )
39
+ const newLength = collectionRecord . nfts . push ( record . nftId )
40
+ collectionRecord . nbNfts = newLength
41
+ if ( newLength === collectionRecord . limit ) collectionRecord . hasReachedLimit = true
42
+ await collectionRecord . save ( )
48
43
}
44
+ await nftOperationEntityHandler ( record , null , commonEventData , NFTOperation . Created , [ mintFee . toString ( ) ] )
45
+ await genericTransferHandler ( owner , "Treasury" , mintFee , commonEventData )
49
46
}
50
47
51
48
export const secretAddedToNFTHandler = async ( event : SubstrateEvent ) : Promise < void > => {
@@ -141,20 +138,17 @@ export const nftCollectionCreatedHandler = async (event: SubstrateEvent): Promis
141
138
const commonEventData = getCommonEventData ( event )
142
139
if ( ! commonEventData . isSuccess ) throw new Error ( "NFT collection creation error, extrinsic isSuccess : false" )
143
140
const [ collectionId , owner , offchainData , limit ] = event . event . data
144
- let record = await CollectionEntity . get ( collectionId . toString ( ) )
145
- if ( record === undefined ) {
146
- record = new CollectionEntity ( collectionId . toString ( ) )
147
- record . owner = owner . toString ( )
148
- record . offchainData = formatString ( offchainData . toString ( ) )
149
- record . collectionId = collectionId . toString ( )
150
- record . nfts = [ ]
151
- record . nbNfts = 0
152
- record . hasReachedLimit = false
153
- record . isClosed = false
154
- record . limit = limit ?. toString ( ) ? Number ( limit ?. toString ( ) ) : null
155
- record . timestampCreated = commonEventData . timestamp
156
- await record . save ( )
157
- }
141
+ const record = new CollectionEntity ( collectionId . toString ( ) )
142
+ record . owner = owner . toString ( )
143
+ record . offchainData = formatString ( offchainData . toString ( ) )
144
+ record . collectionId = collectionId . toString ( )
145
+ record . nfts = [ ]
146
+ record . nbNfts = 0
147
+ record . hasReachedLimit = false
148
+ record . isClosed = false
149
+ record . limit = limit ?. toString ( ) ? Number ( limit ?. toString ( ) ) : null
150
+ record . timestampCreated = commonEventData . timestamp
151
+ await record . save ( )
158
152
}
159
153
160
154
export const nftCollectionBurnedHandler = async ( event : SubstrateEvent ) : Promise < void > => {
@@ -190,6 +184,14 @@ export const nftCollectionLimitedHandler = async (event: SubstrateEvent): Promis
190
184
await record . save ( )
191
185
}
192
186
187
+ export const nftCollectionOffchainDataSetHandler = async ( event : SubstrateEvent ) : Promise < void > => {
188
+ const [ collectionId , offchainData ] = event . event . data
189
+ const record = await CollectionEntity . get ( collectionId . toString ( ) )
190
+ if ( record === undefined ) throw new Error ( "NFT collection to set offchain data not found in db" )
191
+ record . offchainData = formatString ( offchainData . toString ( ) )
192
+ await record . save ( )
193
+ }
194
+
193
195
export const nftAddedToCollectionHandler = async ( event : SubstrateEvent ) : Promise < void > => {
194
196
const commonEventData = getCommonEventData ( event )
195
197
if ( ! commonEventData . isSuccess ) throw new Error ( "NFT add to collection error, extrinsic isSuccess : false" )
0 commit comments