Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load contract artifact from json #4352

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions yarn-project/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ContractArtifact, type FunctionArtifact } from '@aztec/aztec.js/abi';
import { type ContractArtifact, type FunctionArtifact, loadContractArtifact } from '@aztec/aztec.js/abi';
import { AztecAddress } from '@aztec/aztec.js/aztec_address';
import { type L1ContractArtifactsForDeployment } from '@aztec/aztec.js/ethereum';
import { type PXE } from '@aztec/aztec.js/interfaces/pxe';
Expand Down Expand Up @@ -111,27 +111,24 @@ export async function getExampleContractArtifacts(): Promise<ArtifactsType> {
*/
export async function getContractArtifact(fileDir: string, log: LogFn) {
// first check if it's a noir-contracts example
let contents: string;
const artifacts = await getExampleContractArtifacts();
if (artifacts[fileDir]) {
return artifacts[fileDir] as ContractArtifact;
}

let contents: string;
try {
contents = await readFile(fileDir, 'utf8');
} catch {
throw Error(`Contract ${fileDir} not found`);
}

// if not found, try reading as path directly
let contractArtifact: ContractArtifact;
try {
contractArtifact = JSON.parse(contents) as ContractArtifact;
return loadContractArtifact(JSON.parse(contents));
} catch (err) {
log('Invalid file used. Please try again.');
throw err;
}
return contractArtifact;
}

/**
Expand Down
Loading