Skip to content

Commit

Permalink
Change the explorer link to respect different networks. (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
shimkiv authored Nov 3, 2023
1 parent ea509c0 commit 2024d94
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 35 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.14.1] - 2023-11-03

### Changed

- Explorer links for deployment and interaction transactions. [#516](https://github.com/o1-labs/zkapp-cli/pull/516)

## [0.14.0] - 2023-10-31

### Changed
Expand All @@ -25,7 +31,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- This PR removes Husky and the pre-commit hooks from the project templates to remove friction and create a better DX when building zkApps. [#505](https://github.com/o1-labs/zkapp-cli/pull/505).


## [0.13.0] - 2023-09-14

### Changed
Expand All @@ -40,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Both local and global installed versions are checked to determine if an update of the zkApp-cli is necessary[#448](https://github.com/o1-labs/zkapp-cli/pull/448).

### Fixed
### Fixed

- Fix to allow the zkApp-cli to be used from a projects local node_modules[#448](https://github.com/o1-labs/zkapp-cli/pull/448).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zkapp-cli",
"version": "0.14.0",
"version": "0.14.1",
"description": "CLI to create zkApps (zero-knowledge apps) for Mina Protocol",
"homepage": "https://github.com/o1-labs/zkapp-cli/",
"keywords": [
Expand Down
42 changes: 14 additions & 28 deletions src/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ export async function deploy({ alias, yes }) {
}
let { PrivateKey, Mina, AccountUpdate } = await import(o1jsImportPath);

const graphQLUrl = config.deployAliases[alias]?.url ?? DEFAULT_GRAPHQL;
const graphQlUrl = config.deployAliases[alias]?.url ?? DEFAULT_GRAPHQL;

const { data: nodeStatus } = await sendGraphQL(
graphQLUrl,
graphQlUrl,
`query {
syncStatus
}`
Expand Down Expand Up @@ -360,7 +360,7 @@ export async function deploy({ alias, yes }) {

const feepayerAddressBase58 = feepayerAddress.toBase58();
const accountQuery = getAccountQuery(feepayerAddressBase58);
const accountResponse = await sendGraphQL(graphQLUrl, accountQuery);
const accountResponse = await sendGraphQL(graphQlUrl, accountQuery);

if (!accountResponse?.data?.account) {
// No account is found, show an error message and return early
Expand All @@ -375,7 +375,7 @@ export async function deploy({ alias, yes }) {
}

let transaction = await step('Build transaction', async () => {
let Network = Mina.Network(graphQLUrl);
let Network = Mina.Network(graphQlUrl);
Mina.setActiveInstance(Network);
let tx = await Mina.transaction({ sender: feepayerAddress, fee }, () => {
AccountUpdate.fundNewAccount(feepayerAddress);
Expand Down Expand Up @@ -468,7 +468,7 @@ export async function deploy({ alias, yes }) {
const txn = await step('Send to network', async () => {
const zkAppMutation = sendZkAppQuery(transactionJson);
try {
return await sendGraphQL(graphQLUrl, zkAppMutation);
return await sendGraphQL(graphQlUrl, zkAppMutation);
} catch (error) {
return error;
}
Expand All @@ -487,38 +487,24 @@ export async function deploy({ alias, yes }) {
`\nNext step:` +
`\n Your smart contract will be live (or updated)` +
`\n as soon as the transaction is included in a block:` +
`\n ${getTxnUrl(graphQLUrl, txn)}`;
`\n ${getTxnUrl(graphQlUrl, txn)}`;

log(chalk.green(str));
process.exit(0);
}

// Get the specified blockchain explorer url with txn hash
function getTxnUrl(graphQLUrl, txn) {
const MINASCAN_BASE_URL = `https://minascan.io/berkeley/zk-transaction/`;
const MINA_EXPLORER_BASE_URL = `https://berkeley.minaexplorer.com/transaction/`;
const explorers = [MINASCAN_BASE_URL, MINA_EXPLORER_BASE_URL];
const randomExplorersIndex = Math.floor(Math.random() * explorers.length);

const explorerName = new URL(graphQLUrl).hostname
function getTxnUrl(graphQlUrl, txn) {
const txnBroadcastServiceName = new URL(graphQlUrl).hostname
.split('.')
.filter((item) => item === 'minascan' || item === 'minaexplorer')?.[0];
let txnBaseUrl;

switch (explorerName) {
case 'minascan':
txnBaseUrl = MINASCAN_BASE_URL;
break;
case 'minaexplorer':
txnBaseUrl = MINA_EXPLORER_BASE_URL;
break;
default:
// An explorer will be randomly selected from the available explorers if the developer doesn't specify
txnBaseUrl = explorers[randomExplorersIndex];
break;
const networkName = new URL(graphQlUrl).hostname
.split('.')
.filter((item) => item === 'berkeley' || item === 'testworld')?.[0];
if (txnBroadcastServiceName && networkName) {
return `https://minascan.io/${networkName}/tx/${txn.data.sendZkapp.zkapp.hash}?type=zk-tx`;
}

return `${txnBaseUrl}${txn.data.sendZkapp.zkapp.hash}`;
return `Transaction hash: ${txn.data.sendZkapp.zkapp.hash}`;
}

// Query npm registry to get the latest CLI version.
Expand Down
17 changes: 15 additions & 2 deletions templates/project-ts/src/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Build the project: `$ npm run build`
* Run with node: `$ node build/src/interact.js <deployAlias>`.
*/
import { Mina, PrivateKey } from 'o1js';
import fs from 'fs/promises';
import { Mina, PrivateKey } from 'o1js';
import { Add } from './Add.js';

// check command line arg
Expand Down Expand Up @@ -82,6 +82,19 @@ Success! Update transaction sent.
Your smart contract state will be updated
as soon as the transaction is included in a block:
https://berkeley.minaexplorer.com/transaction/${sentTx.hash()}
${getTxnUrl(config.url, sentTx.hash())}
`);
}

function getTxnUrl(graphQlUrl: string, txnHash: string | undefined) {
const txnBroadcastServiceName = new URL(graphQlUrl).hostname
.split('.')
.filter((item) => item === 'minascan' || item === 'minaexplorer')?.[0];
const networkName = new URL(graphQlUrl).hostname
.split('.')
.filter((item) => item === 'berkeley' || item === 'testworld')?.[0];
if (txnBroadcastServiceName && networkName) {
return `https://minascan.io/${networkName}/tx/${txnHash}?type=zk-tx`;
}
return `Transaction hash: ${txnHash}`;
}
3 changes: 2 additions & 1 deletion tests/cli/interact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ async function checkZkAppInteraction(
exitCode: ExitCode | null,
stdOut: string[]
): Promise<void> {
const blockchainExplorerLink =
let blockchainExplorerLink =
stdOut.at(-1)!.trim().length === 0
? stdOut.at(-2)!.trim()
: stdOut.at(-1)!.trim();
blockchainExplorerLink = blockchainExplorerLink.split('?')[0];
const transactionHash = blockchainExplorerLink.substring(
blockchainExplorerLink.length - 52
);
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/deploy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ export async function checkZkDeploy(
exitCode: ExitCode | null,
stdOut: string[]
): Promise<void> {
const blockchainExplorerLink =
let blockchainExplorerLink =
stdOut.at(-1)!.trim().length === 0
? stdOut.at(-2)!.trim()
: stdOut.at(-1)!.trim();
blockchainExplorerLink = blockchainExplorerLink.split('?')[0];
const transactionHash = blockchainExplorerLink.substring(
blockchainExplorerLink.length - 52
);
Expand Down

0 comments on commit 2024d94

Please sign in to comment.