From 3b18425f044b9d60d5141a5fa6b23d32b861f29a Mon Sep 17 00:00:00 2001 From: Ankur Jain Date: Wed, 26 Jun 2024 10:45:27 -0700 Subject: [PATCH] Retry mint check with confirmed commitment. (#287) --- packages/cli/src/CliUtils.ts | 66 +++++++++++-------- .../src/commands/publish/PublishCliRemove.ts | 8 ++- .../src/commands/publish/PublishCliSupport.ts | 8 ++- .../src/commands/publish/PublishCliUpdate.ts | 8 ++- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/packages/cli/src/CliUtils.ts b/packages/cli/src/CliUtils.ts index 0021eb4..708dbf3 100644 --- a/packages/cli/src/CliUtils.ts +++ b/packages/cli/src/CliUtils.ts @@ -54,37 +54,47 @@ export const checkMintedStatus = async ( appAddr: string, releaseAddr: string ) => { - const results = await conn.getMultipleAccountsInfo([ - new PublicKey(pubAddr), - new PublicKey(appAddr), - new PublicKey(releaseAddr), - ]); - - const isPublisherMinted = results[0] != undefined && results[0]?.lamports > 0 - const isAppMinted = results[1] != undefined && results[1]?.lamports > 0 - const isReleaseMinted = results[2] != undefined && results[2]?.lamports > 0 - - if (!isPublisherMinted || !isAppMinted || !isReleaseMinted) { - let errorMessage = `` - - if (!isPublisherMinted) { - errorMessage = errorMessage + `Publisher NFT fetch at address ${pubAddr} failed.\n` + for (let i = 0; i < 5; i++) { + const results = await conn.getMultipleAccountsInfo([ + new PublicKey(pubAddr), + new PublicKey(appAddr), + new PublicKey(releaseAddr), + ]); + + const isPublisherMinted = results[0] != undefined && results[0]?.lamports > 0 + const isAppMinted = results[1] != undefined && results[1]?.lamports > 0 + const isReleaseMinted = results[2] != undefined && results[2]?.lamports > 0 + + if (isPublisherMinted && isAppMinted && isReleaseMinted) { + return + } else { + let errorMessage = `` + if (!isPublisherMinted) { + errorMessage = errorMessage + `Publisher NFT fetch at address ${pubAddr} failed.\n` + } + if (!isAppMinted) { + errorMessage = errorMessage + `App NFT fetch at address ${appAddr} failed.\n` + } + if (!isReleaseMinted) { + errorMessage = errorMessage + `Release NFT fetch at address ${releaseAddr} failed.\n` + } + if (i == 4) { + throw new Error( + `Expected Publisher :: ${pubAddr}, App :: ${appAddr} and Release :: ${releaseAddr} to be minted before submission.\n + but ${errorMessage}\n + Please ensure you have minted all of your NFTs before submitting to the Solana Mobile dApp publisher portal.` + ); + } else { + sleep(2000) + } } - if (!isAppMinted) { - errorMessage = errorMessage + `App NFT fetch at address ${appAddr} failed.\n` - } - if (!isReleaseMinted) { - errorMessage = errorMessage + `Release NFT fetch at address ${releaseAddr} failed.\n` - } - - throw new Error( - `Expected Publisher :: ${pubAddr}, App :: ${appAddr} and Release :: ${releaseAddr} to be minted before submission.\n - but ${errorMessage}\n - Please ensure you have minted all of your NFTs before submitting to the Solana Mobile dApp publisher portal.` - ); } }; +export const sleep = (ms: number):Promise => { + return new Promise(resolve => setTimeout(resolve, ms)); +} + export const parseKeypair = (pathToKeypairFile: string) => { try { const keypairFile = fs.readFileSync(pathToKeypairFile, "utf-8"); @@ -93,7 +103,7 @@ export const parseKeypair = (pathToKeypairFile: string) => { showMessage( "KeyPair Error", "Something went wrong when attempting to retrieve the keypair at " + - pathToKeypairFile, + pathToKeypairFile, "error" ); } diff --git a/packages/cli/src/commands/publish/PublishCliRemove.ts b/packages/cli/src/commands/publish/PublishCliRemove.ts index 8761bd3..be8c0f2 100644 --- a/packages/cli/src/commands/publish/PublishCliRemove.ts +++ b/packages/cli/src/commands/publish/PublishCliRemove.ts @@ -31,7 +31,13 @@ export const publishRemoveCommand = async ({ return; } - const connection = new Connection(url); + const connection = new Connection( + url, + { + commitment: "confirmed", + } + ); + const { publisher: publisherDetails, app: appDetails, diff --git a/packages/cli/src/commands/publish/PublishCliSupport.ts b/packages/cli/src/commands/publish/PublishCliSupport.ts index a225995..7ac8b24 100644 --- a/packages/cli/src/commands/publish/PublishCliSupport.ts +++ b/packages/cli/src/commands/publish/PublishCliSupport.ts @@ -31,7 +31,13 @@ export const publishSupportCommand = async ({ return; } - const connection = new Connection(url); + const connection = new Connection( + url, + { + commitment: "confirmed", + } + ); + const { publisher: publisherDetails, app: appDetails, diff --git a/packages/cli/src/commands/publish/PublishCliUpdate.ts b/packages/cli/src/commands/publish/PublishCliUpdate.ts index efb9d69..d70d619 100644 --- a/packages/cli/src/commands/publish/PublishCliUpdate.ts +++ b/packages/cli/src/commands/publish/PublishCliUpdate.ts @@ -45,7 +45,13 @@ export const publishUpdateCommand = async ({ return; } - const connection = new Connection(url); + const connection = new Connection( + url, + { + commitment: "confirmed", + } + ); + const { publisher: publisherDetails, app: appDetails,