Skip to content

Commit

Permalink
add link to explorer page for listed transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Dec 17, 2024
1 parent c56e784 commit 6678bfe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
28 changes: 4 additions & 24 deletions packages/core/src/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function listTransactions(
(tx) => tx.hash === message.transaction.hash
);

const browserURL = builtinChains.find(
const browserUrl = builtinChains.find(
({ chainId }) => chainId === deploymentState.chainId
);

Expand All @@ -102,10 +102,7 @@ export async function listTransactions(
: undefined,
params: exState.constructorArgs,
value: networkInteraction.value,
transactionLink: getTransactionLink(
transaction.hash,
browserURL?.urls.browserURL
),
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand All @@ -127,10 +124,7 @@ export async function listTransactions(
to: networkInteraction.to,
params: exState.args,
value: networkInteraction.value,
transactionLink: getTransactionLink(
transaction.hash,
browserURL?.urls.browserURL
),
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand All @@ -146,10 +140,7 @@ export async function listTransactions(
),
to: networkInteraction.to,
value: networkInteraction.value,
transactionLink: getTransactionLink(
transaction.hash,
browserURL?.urls.browserURL
),
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand Down Expand Up @@ -191,14 +182,3 @@ function getTransactionStatus(

return TransactionStatus.FAILURE;
}

function getTransactionLink(
txHash: string,
browserURL?: string
): string | undefined {
if (browserURL === undefined) {
return undefined;
}

return `\\033]8;;${browserURL}/tx/${txHash}\\\\033\\\\🔗 view on block explorer\\033]8;;\\033\\\\\\n`;
}
2 changes: 1 addition & 1 deletion packages/core/src/types/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface TransactionInfo {
address?: string;
params?: SolidityParameterType[];
value?: bigint;
transactionLink?: string;
browserUrl?: string;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/hardhat-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extendConfig((config, userConfig) => {
maxPriorityFeePerGas: userNetworkConfig.ignition?.maxPriorityFeePerGas,
gasPrice: userNetworkConfig.ignition?.gasPrice,
disableFeeBumping: userNetworkConfig.ignition?.disableFeeBumping,
explorerUrl: userNetworkConfig.ignition?.explorerUrl,
};
});

Expand Down Expand Up @@ -717,7 +718,11 @@ ignitionScope
}

console.log(
calculateListTransactionsDisplay(deploymentId, listTransactionsResult)
calculateListTransactionsDisplay(
deploymentId,
listTransactionsResult,
hre.config.networks[hre.network.name]?.ignition?.explorerUrl
)
);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/hardhat-plugin/src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare module "hardhat/types/config" {
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
};
}

Expand All @@ -28,6 +29,7 @@ declare module "hardhat/types/config" {
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
};
}

Expand All @@ -37,6 +39,7 @@ declare module "hardhat/types/config" {
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
};
}

Expand All @@ -46,6 +49,7 @@ declare module "hardhat/types/config" {
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { stringify } from "json5";

export function calculateListTransactionsDisplay(
deploymentId: string,
listTransactionsResult: ListTransactionsResult
listTransactionsResult: ListTransactionsResult,
configUrl?: string
): string {
let text = `Logging transactions for deployment ${deploymentId}\n\n`;

for (const [index, transaction] of listTransactionsResult.entries()) {
text += `Transaction ${index + 1}${
transaction.transactionLink !== undefined
? ` (${transaction.transactionLink}):`
: ":"
}\n`;
const txLink = getTransactionLink(
transaction.txHash,
configUrl ?? transaction.browserUrl
);

text += `Transaction ${index + 1}${txLink === undefined ? "" : txLink}:\n`;
text += ` - Type: ${transactionTypeToDisplayType(transaction.type)}\n`;
text += ` - Status: ${transaction.status}\n`;
text += ` - TxHash: ${transaction.txHash}\n`;
Expand Down Expand Up @@ -74,3 +76,14 @@ export function transactionDisplaySerializeReplacer(

return value;
}

function getTransactionLink(
txHash: string,
browserURL?: string
): string | undefined {
if (browserURL === undefined) {
return undefined;
}

return `\x1b]8;;${browserURL}/tx/${txHash}\x1b\\ (🔗 view on block explorer)\x1b]8;;\x1b\\`;
}

0 comments on commit 6678bfe

Please sign in to comment.