Skip to content

Commit

Permalink
Restructure warning messages. (#255)
Browse files Browse the repository at this point in the history
1. Add checks for package names between app and release.

2. Add retries for app and publisher release.
  • Loading branch information
ankur2136 authored Apr 10, 2024
1 parent 4a68853 commit 1df8525
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 48 deletions.
60 changes: 42 additions & 18 deletions packages/cli/src/CliSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
checkForSelfUpdate,
checkSubmissionNetwork,
Constants,
dryRunSuccessMessage,
generateNetworkSuffix,
parseKeypair,
showMessage
Expand Down Expand Up @@ -104,10 +105,14 @@ export const createPublisherCliCmd = createCliCmd
if (signer) {
const result: { publisherAddress: string } = await createPublisherCommand({ signer, url, dryRun, storageParams: storageConfig, priorityFeeLamports });

const displayUrl = `https://solscan.io/token/${result.publisherAddress}${generateNetworkSuffix(url)}`;
const resultText = `Publisher NFT successfully minted:\n${displayUrl}`;
if (dryRun) {
dryRunSuccessMessage()
} else {
const displayUrl = `https://solscan.io/token/${result.publisherAddress}${generateNetworkSuffix(url)}`;
const resultText = `Publisher NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
showMessage("Success", resultText);
}
}
});
});
Expand Down Expand Up @@ -149,10 +154,13 @@ export const createAppCliCmd = createCliCmd
priorityFeeLamports: priorityFeeLamports,
});

const displayUrl = `https://solscan.io/token/${result.appAddress}${generateNetworkSuffix(url)}`;
const resultText = `App NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
if (dryRun) {
dryRunSuccessMessage()
} else {
const displayUrl = `https://solscan.io/token/${result.appAddress}${generateNetworkSuffix(url)}`;
const resultText = `App NFT successfully minted:\n${displayUrl}`;
showMessage("Success", resultText);
}
}
});
});
Expand Down Expand Up @@ -203,10 +211,14 @@ export const createReleaseCliCmd = createCliCmd
priorityFeeLamports: priorityFeeLamports
});

const displayUrl = `https://solscan.io/token/${result?.releaseAddress}${generateNetworkSuffix(url)}`;
const resultText = `Release NFT successfully minted:\n${displayUrl}`;
if (dryRun) {
dryRunSuccessMessage()
} else {
const displayUrl = `https://solscan.io/token/${result?.releaseAddress}${generateNetworkSuffix(url)}`;
const resultText = `Release NFT successfully minted:\n${displayUrl}`;

showMessage("Success", resultText);
showMessage("Success", resultText);
}
}
});
}
Expand Down Expand Up @@ -309,8 +321,11 @@ publishCommand
requestorIsAuthorized,
});

const resultText = "Successfully submitted to the Solana Mobile dApp publisher portal";
showMessage("Success", resultText);
if (dryRun) {
dryRunSuccessMessage()
} else {
showMessage("Success", "Successfully submitted to the Solana Mobile dApp publisher portal");
}
}
});
}
Expand Down Expand Up @@ -381,8 +396,11 @@ publishCommand
critical,
});

const resultText = "dApp successfully updated on the publisher portal";
showMessage("Success", resultText);
if (dryRun) {
dryRunSuccessMessage()
} else {
showMessage("Success", "dApp successfully updated on the publisher portal");
}
}
});
}
Expand Down Expand Up @@ -447,8 +465,11 @@ publishCommand
critical,
});

const resultText = "dApp successfully removed from the publisher portal";
showMessage("Success", resultText);
if (dryRun) {
dryRunSuccessMessage()
} else {
showMessage("Success", "dApp successfully removed from the publisher portal");
}
}
})
}
Expand Down Expand Up @@ -507,8 +528,11 @@ publishCommand
requestDetails,
});

const resultText = "Support request sent successfully";
showMessage("Success", resultText);
if (dryRun) {
dryRunSuccessMessage()
} else {
showMessage("Success", "Support request sent successfully");
}
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/CliUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export const generateNetworkSuffix = (rpcUrl: string): string => {
return suffix;
};

export const dryRunSuccessMessage = () => {
showMessage("Dry run", "Dry run was successful", "standard")
}

export const showMessage = (
titleMessage = "",
contentMessage = "",
Expand Down
42 changes: 38 additions & 4 deletions packages/cli/src/commands/ValidateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
validateRelease,
metaplexFileReplacer,
} from "@solana-mobile/dapp-store-publishing-tools";
import { debug } from "../CliUtils.js";
import { debug, showMessage } from "../CliUtils.js";

import type { Keypair } from "@solana/web3.js";
import type { MetaplexFile } from "@metaplex-foundation/js";
Expand Down Expand Up @@ -39,7 +39,13 @@ export const validateCommand = async ({
validatePublisher(publisherJson);
console.info(`Publisher JSON valid!`);
} catch (e) {
console.error(e);
const errorMsg = (e as Error | null)?.message ?? "";
showMessage(
"Publisher JSON invalid",
errorMsg,
"error"
)
return
}

const appJson = createAppJson(appDetails, signer.publicKey);
Expand All @@ -52,21 +58,49 @@ export const validateCommand = async ({
validateApp(appJson);
console.info(`App JSON valid!`);
} catch (e) {
console.error(e);
const errorMsg = (e as Error | null)?.message ?? "";
showMessage(
"App JSON invalid",
errorMsg,
"error"
)
return
}

const releaseJson = await createReleaseJson(
{ releaseDetails, appDetails, publisherDetails },
signer.publicKey
);


if (appDetails.android_package != releaseDetails.android_details.android_package) {
showMessage(
"App package name and release package name do not match",
"App release specifies " + appDetails.android_package + " while release specifies " + releaseDetails.android_details.android_package,
"error"
)
return
}

const objStringified = JSON.stringify(releaseJson, metaplexFileReplacer, 2);
debug("releaseJson=", objStringified);

try {
validateRelease(JSON.parse(objStringified));
console.info(`Release JSON valid!`);
} catch (e) {
console.error(e);
const errorMsg = (e as Error | null)?.message ?? "";
showMessage(
"Release JSON invalid",
errorMsg,
"error"
)
return
}

showMessage(
"Json is Valid",
"Input data is valid",
"standard"
)
};
41 changes: 28 additions & 13 deletions packages/cli/src/commands/create/CreateCliApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
Constants,
getMetaplexInstance,
showMessage,
} from "../../CliUtils.js";
import { loadPublishDetailsWithChecks, writeToPublishDetails } from "../../config/PublishDetails.js";

Expand Down Expand Up @@ -43,21 +44,35 @@ const createAppNft = async (
{ metaplex, publisher }
);

const blockhash = await connection.getLatestBlockhashAndContext();
const tx = txBuilder.toTransaction(blockhash.value);
tx.sign(mintAddress, publisher);
const maxTries = 8;
for (let i = 1; i <= maxTries; i++) {
try {
const blockhash = await connection.getLatestBlockhashAndContext();
const tx = txBuilder.toTransaction(blockhash.value);
tx.sign(mintAddress, publisher);

if (!dryRun) {
const txSig = await sendAndConfirmTransaction(connection, tx, [
publisher,
mintAddress,
], {
minContextSlot: blockhash.context.slot
});
console.info({ txSig, mintAddress: mintAddress.publicKey.toBase58() });
}
if (!dryRun) {
const txSig = await sendAndConfirmTransaction(connection, tx, [
publisher,
mintAddress,
], {
minContextSlot: blockhash.context.slot
});
console.info({ txSig, mintAddress: mintAddress.publicKey.toBase58() });
}

return { appAddress: mintAddress.publicKey.toBase58() };
return { appAddress: mintAddress.publicKey.toBase58() };
} catch (e) {
const errorMsg = (e as Error | null)?.message ?? "";
if (i == maxTries) {
showMessage("Transaction Failure", errorMsg, "error");
process.exit(-1)
} else {
const retryMsg = errorMsg + "\nWill Retry minting publisher."
showMessage("Transaction Failure", retryMsg, "standard");
}
}
}
};

type CreateAppCommandInput = {
Expand Down
40 changes: 27 additions & 13 deletions packages/cli/src/commands/create/CreateCliPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
Constants,
getMetaplexInstance,
showMessage,
} from "../../CliUtils.js";
import { loadPublishDetailsWithChecks, writeToPublishDetails } from "../../config/PublishDetails.js";

Expand Down Expand Up @@ -38,21 +39,34 @@ const createPublisherNft = async (
{ metaplex, publisher }
);

const blockhash = await connection.getLatestBlockhashAndContext();
const tx = txBuilder.toTransaction(blockhash.value);
tx.sign(mintAddress, publisher);
const maxTries = 8;
for (let i = 1; i <= maxTries; i++) {
try {
const blockhash = await connection.getLatestBlockhashAndContext();
const tx = txBuilder.toTransaction(blockhash.value);
tx.sign(mintAddress, publisher);

if (!dryRun) {
const txSig = await sendAndConfirmTransaction(connection, tx, [
publisher,
mintAddress,
], {
minContextSlot: blockhash.context.slot
});
console.info({ txSig, mintAddress: mintAddress.publicKey.toBase58() });
if (!dryRun) {
const txSig = await sendAndConfirmTransaction(connection, tx, [
publisher,
mintAddress,
], {
minContextSlot: blockhash.context.slot
});
console.info({ txSig, mintAddress: mintAddress.publicKey.toBase58() });
}
return { publisherAddress: mintAddress.publicKey.toBase58() };
} catch (e) {
const errorMsg = (e as Error | null)?.message ?? "";
if (i == maxTries) {
showMessage("Transaction Failure", errorMsg, "error");
process.exit(-1)
} else {
const retryMsg = errorMsg + "\nWill Retry minting publisher."
showMessage("Transaction Failure", retryMsg, "standard");
}
}
}

return { publisherAddress: mintAddress.publicKey.toBase58() };
};

export const createPublisherCommand = async ({
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/commands/create/CreateCliRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export const createReleaseCommand = async ({

const { release, app, publisher } = await loadPublishDetailsWithChecks(buildToolsPath);


if (app.android_package != release.android_details.android_package) {
throw new Error("App package name and release package name do not match.\nApp release specifies " + app.android_package + " while release specifies " + release.android_details.android_package)
}

if (!dryRun) {
const { releaseAddress } = await createReleaseNft({
appMintAddress: app.address ?? appMintAddress,
Expand Down

0 comments on commit 1df8525

Please sign in to comment.