8
8
import { LambdaClient , InvokeCommand , InvokeCommandOutput } from '@aws-sdk/client-lambda' ;
9
9
import { addAlert } from './alerting.utils' ;
10
10
import { Transaction , Severity } from '../types' ;
11
- import hathorLib from '@hathor/wallet-lib' ;
11
+ import { Network , constants , CreateTokenTransaction , helpersUtils } from '@hathor/wallet-lib' ;
12
12
import createDefaultLogger from '../logger' ;
13
13
14
14
/**
@@ -25,7 +25,7 @@ export class NftUtils {
25
25
* @param {string } network
26
26
* @returns {boolean }
27
27
*/
28
- static shouldInvokeNftHandlerForTx ( tx : Transaction , network : string ) : boolean {
28
+ static shouldInvokeNftHandlerForTx ( tx : Transaction , network : Network ) : boolean {
29
29
return isNftAutoReviewEnabled ( ) && this . isTransactionNFTCreation ( tx , network ) ;
30
30
}
31
31
@@ -36,13 +36,13 @@ export class NftUtils {
36
36
*
37
37
* TODO: change tx type to HistoryTransaction
38
38
*/
39
- static isTransactionNFTCreation ( tx : any , network : string ) : boolean {
39
+ static isTransactionNFTCreation ( tx : any , network : Network ) : boolean {
40
40
/*
41
41
* To fully check if a transaction is a NFT creation, we need to instantiate a new Transaction object in the lib.
42
42
* So first we do some very fast checks to filter the bulk of the requests for NFTs with minimum processing.
43
43
*/
44
44
if (
45
- tx . version !== hathorLib . constants . CREATE_TOKEN_TX_VERSION // Must be a token creation tx
45
+ tx . version !== constants . CREATE_TOKEN_TX_VERSION // Must be a token creation tx
46
46
|| ! tx . token_name // Must have a token name
47
47
|| ! tx . token_symbol // Must have a token symbol
48
48
) {
@@ -52,11 +52,11 @@ export class NftUtils {
52
52
// Continue with a deeper validation
53
53
const logger = createDefaultLogger ( ) ;
54
54
let isNftCreationTx : boolean ;
55
- let libTx : hathorLib . CreateTokenTransaction ;
55
+ let libTx : CreateTokenTransaction ;
56
56
57
57
// Transaction parsing failures should be alerted
58
58
try {
59
- libTx = hathorLib . helpersUtils . createTxFromHistoryObject ( tx ) as hathorLib . CreateTokenTransaction ;
59
+ libTx = helpersUtils . createTxFromHistoryObject ( tx ) as CreateTokenTransaction ;
60
60
} catch ( ex ) {
61
61
logger . error ( '[ALERT] Error when parsing transaction on isTransactionNFTCreation' , {
62
62
transaction : tx ,
@@ -69,7 +69,7 @@ export class NftUtils {
69
69
70
70
// Validate the token: the validateNft will throw if the transaction is not a NFT Creation
71
71
try {
72
- libTx . validateNft ( new hathorLib . Network ( network ) ) ;
72
+ libTx . validateNft ( network ) ;
73
73
isNftCreationTx = true ;
74
74
} catch ( ex ) {
75
75
isNftCreationTx = false ;
@@ -124,15 +124,16 @@ export class NftUtils {
124
124
/**
125
125
* Identifies if the metadata for a NFT needs updating and, if it does, update it.
126
126
* @param {string } nftUid
127
+ * @param {number } maxRetries
127
128
* @returns {Promise<void> } No data is returned after a successful update or skip
128
129
*/
129
- static async createOrUpdateNftMetadata ( nftUid : string ) : Promise < void > {
130
+ static async createOrUpdateNftMetadata ( nftUid : string , maxRetries : number ) : Promise < void > {
130
131
// The explorer service automatically merges the metadata content if it already exists.
131
132
const newMetadata = {
132
133
id : nftUid ,
133
134
nft : true ,
134
135
} ;
135
- await NftUtils . _updateMetadata ( nftUid , newMetadata ) ;
136
+ await NftUtils . _updateMetadata ( nftUid , newMetadata , maxRetries ) ;
136
137
}
137
138
138
139
/**
0 commit comments