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

feat(storage): add storage path and function to get deployment args #1775

Merged
merged 1 commit into from
Aug 19, 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
30 changes: 26 additions & 4 deletions packages/contracts/tasks/helpers/ContractStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ export class ContractStorage {
/**
* Initialize class properties only once
*/
private constructor() {
private constructor(storagePath?: string) {
this.db = low(
typeof window !== "undefined"
? new LocalStorageSync<TStorage>("deployed-contracts")
: new FileSync<TStorage>(path.resolve(__dirname, "..", "..", "./deployed-contracts.json")),
: new FileSync<TStorage>(storagePath ?? path.resolve(__dirname, "..", "..", "./deployed-contracts.json")),
);
}

/**
* Get singleton object
*
* @param storagePath - path to the storage file
* @returns {ContractStorage} singleton object
*/
static getInstance(): ContractStorage {
static getInstance(storagePath?: string): ContractStorage {
if (!ContractStorage.INSTANCE) {
ContractStorage.INSTANCE = new ContractStorage();
ContractStorage.INSTANCE = new ContractStorage(storagePath);
}

return ContractStorage.INSTANCE;
Expand Down Expand Up @@ -146,6 +147,27 @@ export class ContractStorage {
this.db.set(`${network}.verified.${address}`, verified).write();
};

/**
* Get deployment arguments from the json file
*
* @param id - contract name
* @param network - selected network
* @param key - contract key
* @returns deployment arguments
*/
getContractArgs(id: EContracts, network: string, key?: string): string[] | undefined {
const address = this.getAddress(id, network, key);

const collection = this.db.get(`${network}.instance.${address}`);
const instanceEntry = collection.value() as IStorageInstanceEntry | undefined;

if (!instanceEntry?.verify?.args) {
return undefined;
}

return JSON.parse(instanceEntry.verify.args) as string[];
}

/**
* Get contract address by name from the json file
*
Expand Down
Loading