Skip to content

Commit

Permalink
Retry mint check with confirmed commitment. (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur2136 authored Jun 26, 2024
1 parent 13fdf2a commit 3b18425
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
66 changes: 38 additions & 28 deletions packages/cli/src/CliUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
return new Promise(resolve => setTimeout(resolve, ms));
}

export const parseKeypair = (pathToKeypairFile: string) => {
try {
const keypairFile = fs.readFileSync(pathToKeypairFile, "utf-8");
Expand All @@ -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"
);
}
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/publish/PublishCliRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/publish/PublishCliSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/publish/PublishCliUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3b18425

Please sign in to comment.