Skip to content

Commit

Permalink
Merge pull request #1416 from privacy-scaling-explorations/feature/su…
Browse files Browse the repository at this point in the history
…pport-browser-lowdb

feat(contracts): add new adapter for lowdb to support browser env
  • Loading branch information
0xmad authored May 1, 2024
2 parents 3770a2a + a3c2371 commit 56ea48a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
9 changes: 2 additions & 7 deletions cli/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ export {
ContractStorage,
EContracts,
EMode,
PollFactory__factory as PollFactoryFactory,
MessageProcessorFactory__factory as MessageProcessorFactoryFactory,
TallyFactory__factory as TallyFactoryFactory,
MACI__factory as MACIFactory,
type MACI,
type EASGatekeeper,
type IVerifyingKeyStruct,
type VkRegistry,
} from "maci-contracts";

export * from "maci-contracts/typechain-types";

export { VerifyingKey, type IVkObjectParams } from "maci-domainobjs";

export type {
Expand Down
7 changes: 6 additions & 1 deletion contracts/tasks/helpers/ContractStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies, no-console */
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";
import LocalStorageSync from "lowdb/adapters/LocalStorage";

import path from "path";

Expand Down Expand Up @@ -40,7 +41,11 @@ export class ContractStorage {
* Initialize class properties only once
*/
private constructor() {
this.db = low(new FileSync<TStorage>(path.resolve(__dirname, "..", "..", "./deployed-contracts.json")));
this.db = low(
typeof window !== "undefined"
? new LocalStorageSync<TStorage>("deployed-contracts")
: new FileSync<TStorage>(path.resolve(__dirname, "..", "..", "./deployed-contracts.json")),
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion contracts/tasks/helpers/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { BaseContract, ContractFactory, Signer } from "ethers";
import low from "lowdb";
import FileSync from "lowdb/adapters/FileSync";
import LocalStorageSync from "lowdb/adapters/LocalStorage";

import path from "path";

Expand Down Expand Up @@ -63,7 +64,11 @@ export class Deployment {
["poll", []],
]);
this.hre = hre;
this.config = low(new FileSync<TConfig>(path.resolve(__dirname, "..", "..", "./deploy-config.json")));
this.config = low(
typeof window !== "undefined"
? new LocalStorageSync<TConfig>("deploy-config")
: new FileSync<TConfig>(path.resolve(__dirname, "..", "..", "./deploy-config.json")),
);
this.storage = ContractStorage.getInstance();
}

Expand Down
1 change: 1 addition & 0 deletions contracts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": ["dom"],
"outDir": "./build"
},
"include": ["./ts", "./scripts", "./typechain-types", "./tasks"],
Expand Down
1 change: 1 addition & 0 deletions contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": ["dom"],
"outDir": "./build"
},
"include": ["./ts", "./scripts", "./tests", "./typechain-types", "./tasks"],
Expand Down

0 comments on commit 56ea48a

Please sign in to comment.