Skip to content

Commit

Permalink
add link to transactions list output
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Dec 17, 2024
1 parent 4b5b2bf commit e039e4e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ArtifactResolver } from "./types/artifact";
import findLastIndex from "lodash/findLastIndex";

import { IgnitionError } from "./errors";
import { builtinChains } from "./internal/chain-config";
import { FileDeploymentLoader } from "./internal/deployment-loader/file-deployment-loader";
import { ERRORS } from "./internal/errors-list";
import { loadDeploymentState } from "./internal/execution/deployment-state-helpers";
Expand Down Expand Up @@ -76,6 +77,10 @@ export async function listTransactions(
(tx) => tx.hash === message.transaction.hash
);

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

const transaction = networkInteraction.transactions[lastTxIndex];

switch (exState.type) {
Expand All @@ -97,6 +102,7 @@ export async function listTransactions(
: undefined,
params: exState.constructorArgs,
value: networkInteraction.value,
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand All @@ -118,6 +124,7 @@ export async function listTransactions(
to: networkInteraction.to,
params: exState.args,
value: networkInteraction.value,
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand All @@ -133,6 +140,7 @@ export async function listTransactions(
),
to: networkInteraction.to,
value: networkInteraction.value,
browserUrl: browserUrl?.urls.browserURL,
});

break;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface TransactionInfo {
address?: string;
params?: SolidityParameterType[];
value?: bigint;
browserUrl?: string;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/list-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("listTransactions", () => {
address: "0x74e720c9B362ae3A65fF356ad62866511486BBBc",
params: ["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"],
value: 0n,
browserUrl: undefined,
},
{
type: "DEPLOYMENT_EXECUTION_STATE",
Expand All @@ -33,6 +34,7 @@ describe("listTransactions", () => {
address: "0x1c947344BA932fC7f3D622600dA0199520A67EFd",
params: [],
value: 0n,
browserUrl: undefined,
},
{
type: "DEPLOYMENT_EXECUTION_STATE",
Expand All @@ -44,6 +46,7 @@ describe("listTransactions", () => {
address: "0xBdAce15b3211019E272418B8014971c1cefbC8f0",
params: [],
value: 0n,
browserUrl: undefined,
},
{
type: "CALL_EXECUTION_STATE",
Expand All @@ -55,6 +58,7 @@ describe("listTransactions", () => {
to: "0x74e720c9B362ae3A65fF356ad62866511486BBBc",
params: [40],
value: 0n,
browserUrl: undefined,
},
{
type: "DEPLOYMENT_EXECUTION_STATE",
Expand All @@ -66,6 +70,7 @@ describe("listTransactions", () => {
address: "0xD369D9aB22D85C2A12bEabc0B581a419789E3755",
params: [],
value: 0n,
browserUrl: undefined,
},
{
type: "SEND_DATA_EXECUTION_STATE",
Expand All @@ -75,6 +80,7 @@ describe("listTransactions", () => {
status: TransactionStatus.SUCCESS,
to: "0x74e720c9B362ae3A65fF356ad62866511486BBBc",
value: 123n,
browserUrl: undefined,
},
];

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,12 +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}:\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 @@ -70,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 e039e4e

Please sign in to comment.