diff --git a/src/contract/abis/rlnv2.ts b/src/contract/abis/rlnv2.ts index 47ee866..2c1106c 100644 --- a/src/contract/abis/rlnv2.ts +++ b/src/contract/abis/rlnv2.ts @@ -1,4 +1,4 @@ -export const RLNv2ABI = [ +export const RLN_V2_ABI = [ { type: "constructor", inputs: [], diff --git a/src/contract/constants.ts b/src/contract/constants.ts index 923d666..4d7900b 100644 --- a/src/contract/constants.ts +++ b/src/contract/constants.ts @@ -1,7 +1,8 @@ -import { RLNv2ABI } from "./abis/rlnv2"; +import { RLN_V2_ABI } from "./abis/rlnv2"; +export { RLN_V2_ABI as RLN_V2_ABI }; export const SEPOLIA_CONTRACT = { chainId: 11155111, address: "0xCB33Aa5B38d79E3D9Fa8B10afF38AA201399a7e3", - abi: RLNv2ABI + abi: RLN_V2_ABI }; diff --git a/src/contract/rln_contract.ts b/src/contract/rln_contract.ts index 65ca2ed..335a280 100644 --- a/src/contract/rln_contract.ts +++ b/src/contract/rln_contract.ts @@ -6,9 +6,9 @@ import type { IdentityCredential } from "../identity.js"; import type { DecryptedCredentials } from "../keystore/index.js"; import type { RLNInstance } from "../rln.js"; import { MerkleRootTracker } from "../root_tracker.js"; -import { zeroPadLE } from "../utils/index.js"; +import { zeroPadLE } from "../utils/bytes.js"; -import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js"; +import { RLN_V2_ABI } from "./abis/rlnv2.js"; const log = debug("waku:rln:contract"); @@ -53,7 +53,6 @@ export class RLNContract { ): Promise { const rlnContract = new RLNContract(rlnInstance, options); - await rlnContract.initStorageContract(options.signer); await rlnContract.fetchMembers(rlnInstance); rlnContract.subscribeToMembers(rlnInstance); @@ -68,36 +67,12 @@ export class RLNContract { this.registryContract = new ethers.Contract( registryAddress, - RLN_REGISTRY_ABI, + RLN_V2_ABI, signer ); this.merkleRootTracker = new MerkleRootTracker(5, initialRoot); } - private async initStorageContract( - signer: Signer, - options: RLNStorageOptions = {} - ): Promise { - const storageIndex = options?.storageIndex - ? options.storageIndex - : await this.registryContract.usingStorageIndex(); - const storageAddress = await this.registryContract.storages(storageIndex); - - if (!storageAddress || storageAddress === ethers.constants.AddressZero) { - throw Error("No RLN Storage initialized on registry contract."); - } - - this.storageIndex = storageIndex; - this.storageContract = new ethers.Contract( - storageAddress, - RLN_STORAGE_ABI, - signer - ); - this._membersFilter = this.storageContract.filters.MemberRegistered(); - - this.deployBlock = await this.storageContract.deployedBlockNumber(); - } - public get registry(): ethers.Contract { if (!this.registryContract) { throw Error("Registry contract was not initialized"); @@ -345,9 +320,18 @@ function* takeN(array: T[], size: number): Iterable { } } -function ignoreErrors(promise: Promise, defaultValue: T): Promise { - return promise.catch((err) => { - log(`Ignoring an error during query: ${err?.message}`); +async function ignoreErrors( + promise: Promise, + defaultValue: T +): Promise { + try { + return await promise; + } catch (err: unknown) { + if (err instanceof Error) { + log(`Ignoring an error during query: ${err.message}`); + } else { + log(`Ignoring an unknown error during query`); + } return defaultValue; - }); + } } diff --git a/src/index.ts b/src/index.ts index efc7c3e..9c87454 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,5 @@ import { RLNDecoder, RLNEncoder } from "./codec.js"; -import { - RLN_REGISTRY_ABI, - RLN_STORAGE_ABI, - SEPOLIA_CONTRACT -} from "./contract/index.js"; +import { RLN_V2_ABI, SEPOLIA_CONTRACT } from "./contract/index.js"; import { RLNContract } from "./contract/index.js"; import { createRLN } from "./create.js"; import { IdentityCredential } from "./identity.js"; @@ -23,8 +19,7 @@ export { RLNDecoder, MerkleRootTracker, RLNContract, - RLN_STORAGE_ABI, - RLN_REGISTRY_ABI, + RLN_V2_ABI, SEPOLIA_CONTRACT, extractMetaMaskSigner };