mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-08 00:23:12 +00:00
move to getter for members, add init method
This commit is contained in:
parent
23abbd4244
commit
55dca38dd4
@ -48,14 +48,7 @@ rln.create().then(async rlnInstance => {
|
||||
const signature = await signer.signMessage(rln.DEFAULT_SIGNATURE_MESSAGE);
|
||||
console.log(`Got signature: ${signature}`);
|
||||
|
||||
const contract = new rln.RLNContract(rln.GOERLI_CONTRACT.address, signer);
|
||||
|
||||
console.log("Fetching members from Contract");
|
||||
await contract.fetchMembers(rlnInstance, 8261478);
|
||||
console.log(`Fetched members are ${contract.getMembers()}`);
|
||||
|
||||
contract.subscribeToMembers(rlnInstance);
|
||||
console.log("Subscribed to the contract for new members");
|
||||
const contract = await rln.RLNContract.init(rlnInstance, {address: rln.GOERLI_CONTRACT.address, provider: signer });
|
||||
|
||||
const event = await contract.registerMember(rlnInstance, signature);
|
||||
console.log(`Registered as member with ${event}`);
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
||||
import { DEFAULT_SIGNATURE_MESSAGE, DEV_CONTRACT, RLN_ABI } from "./const.js";
|
||||
import {
|
||||
DEFAULT_SIGNATURE_MESSAGE,
|
||||
GOERLI_CONTRACT,
|
||||
RLN_ABI,
|
||||
} from "./const.js";
|
||||
import { Proof, RLNInstance } from "./rln.js";
|
||||
import { MembershipKey } from "./rln.js";
|
||||
import { RLNContract } from "./rln_contract.js";
|
||||
@ -21,6 +25,6 @@ export {
|
||||
RLNDecoder,
|
||||
RLNContract,
|
||||
RLN_ABI,
|
||||
DEV_CONTRACT,
|
||||
GOERLI_CONTRACT,
|
||||
DEFAULT_SIGNATURE_MESSAGE,
|
||||
};
|
||||
|
||||
@ -8,16 +8,30 @@ type Member = {
|
||||
index: number;
|
||||
};
|
||||
|
||||
type ContractOptions = {
|
||||
address: string;
|
||||
provider: ethers.Signer | ethers.providers.Provider;
|
||||
};
|
||||
|
||||
export class RLNContract {
|
||||
private _contract: ethers.Contract;
|
||||
private membersFilter: ethers.EventFilter;
|
||||
|
||||
private members: Member[] = [];
|
||||
private _members: Member[] = [];
|
||||
|
||||
constructor(
|
||||
address: string,
|
||||
provider: ethers.Signer | ethers.providers.Provider
|
||||
) {
|
||||
public static async init(
|
||||
rlnInstance: RLNInstance,
|
||||
options: ContractOptions
|
||||
): Promise<RLNContract> {
|
||||
const rlnContract = new RLNContract(options);
|
||||
|
||||
await rlnContract.fetchMembers(rlnInstance);
|
||||
rlnContract.subscribeToMembers(rlnInstance);
|
||||
|
||||
return rlnContract;
|
||||
}
|
||||
|
||||
constructor({ address, provider }: ContractOptions) {
|
||||
this._contract = new ethers.Contract(address, RLN_ABI, provider);
|
||||
this.membersFilter = this.contract.filters.MemberRegistered();
|
||||
}
|
||||
@ -26,8 +40,8 @@ export class RLNContract {
|
||||
return this._contract;
|
||||
}
|
||||
|
||||
public getMembers(): Member[] {
|
||||
return this.members;
|
||||
public get members(): Member[] {
|
||||
return this._members;
|
||||
}
|
||||
|
||||
public async fetchMembers(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user