@hinkal/common 0.1.46 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +8 -8
- package/data-structures/event-service/AbstractEventService.cjs +1 -1
- package/data-structures/event-service/AbstractEventService.d.ts +1 -0
- package/data-structures/event-service/AbstractEventService.mjs +3 -2
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.d.ts +1 -1
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.mjs +7 -7
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../constants/chains.constants.cjs"),n=require("../../functions/web3/events/balanceChangedHandler.cjs");require("../../types/circom-data.types.cjs");const r=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const c=require("../snapshot/ClientAccessTokenSnapshotService.cjs"),i=require("../snapshot/ClientCommitmentsSnapshotService.cjs"),o=require("../snapshot/ClientNullifierSnapshotService.cjs"),a=async e=>{const{maxPageSize:t}=s.networkRegistry[e.getCurrentChainId()];await e.getEthereumAddress(),e.commitmentsSnapshotService?.intervalClear(),e.commitmentsSnapshotService=new i.ClientCommitmentsSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t),e.nullifierSnapshotService?.intervalClear(),e.nullifierSnapshotService=new o.ClientNullifierSnapshotService(e.getContractWithFetcher(r.ContractType.HinkalContract),t),e.accessTokenSnapshotService?.intervalClear(),e.accessTokenSnapshotService=new c.ClientAccessTokenSnapshotService(e.getContractWithFetcher(r.ContractType.CrossChainAccessTokenContract),t),await Promise.all([e.commitmentsSnapshotService.init(),e.nullifierSnapshotService.init(),e.accessTokenSnapshotService.init()]),e.merkleTreeHinkal=e.commitmentsSnapshotService.merkleTree,e.merkleTreeAccessToken=e.accessTokenSnapshotService.merkleTree,e.nullifiers=e.nullifierSnapshotService.nullifiers,e.encryptedOutputs=e.commitmentsSnapshotService.encryptedOutputs,e.commitmentsSnapshotService.onNewEvent=n.balanceChangedHandler,e.nullifierSnapshotService.onNewEvent=n.balanceChangedHandler};exports.resetMerkleTrees=a;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { networkRegistry as
|
|
1
|
+
import { networkRegistry as c } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { balanceChangedHandler as o } from "../../functions/web3/events/balanceChangedHandler.mjs";
|
|
3
3
|
import "../../types/circom-data.types.mjs";
|
|
4
4
|
import { ContractType as r } from "../../types/ethereum-network.types.mjs";
|
|
5
5
|
import "../../types/transactions.types.mjs";
|
|
6
6
|
import "../../types/curve.types.mjs";
|
|
7
|
-
import { ClientAccessTokenSnapshotService as
|
|
8
|
-
import { ClientCommitmentsSnapshotService as
|
|
9
|
-
import { ClientNullifierSnapshotService as
|
|
7
|
+
import { ClientAccessTokenSnapshotService as n } from "../snapshot/ClientAccessTokenSnapshotService.mjs";
|
|
8
|
+
import { ClientCommitmentsSnapshotService as s } from "../snapshot/ClientCommitmentsSnapshotService.mjs";
|
|
9
|
+
import { ClientNullifierSnapshotService as i } from "../snapshot/ClientNullifierSnapshotService.mjs";
|
|
10
10
|
const T = async (e) => {
|
|
11
|
-
const { maxPageSize: t } =
|
|
12
|
-
e.commitmentsSnapshotService?.intervalClear(), e.commitmentsSnapshotService = new
|
|
11
|
+
const { maxPageSize: t } = c[e.getCurrentChainId()];
|
|
12
|
+
await e.getEthereumAddress(), e.commitmentsSnapshotService?.intervalClear(), e.commitmentsSnapshotService = new s(
|
|
13
13
|
e.getContractWithFetcher(r.HinkalContract),
|
|
14
14
|
t
|
|
15
|
-
), e.nullifierSnapshotService?.intervalClear(), e.nullifierSnapshotService = new
|
|
15
|
+
), e.nullifierSnapshotService?.intervalClear(), e.nullifierSnapshotService = new i(
|
|
16
16
|
e.getContractWithFetcher(r.HinkalContract),
|
|
17
17
|
t
|
|
18
|
-
), e.accessTokenSnapshotService?.intervalClear(), e.accessTokenSnapshotService = new
|
|
18
|
+
), e.accessTokenSnapshotService?.intervalClear(), e.accessTokenSnapshotService = new n(
|
|
19
19
|
e.getContractWithFetcher(r.CrossChainAccessTokenContract),
|
|
20
20
|
t
|
|
21
21
|
), await Promise.all([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../constants/reorg-depths.constants.cjs"),c=require("../../functions/utils/resolve-sync.utils.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");const u=require("../../error-handling/logError.cjs");class g{contract;eventConfig;_latestBlockNumber;maxPageSize;isReady=!1;_onNewEvent;isServer;intervalId;inProgress;constructor(e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../constants/reorg-depths.constants.cjs"),c=require("../../functions/utils/resolve-sync.utils.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");const u=require("../../error-handling/logError.cjs");class g{contract;eventConfig;_latestBlockNumber;maxPageSize;isReady=!1;_onNewEvent;isServer;intervalId;inProgress;ethAddress;constructor(e,s,t,r,n){this.contract=e,this.eventConfig=s,this._latestBlockNumber=t,this.maxPageSize=n,this.isServer=r,this.inProgress=!1}get latestBlockNumber(){return this._latestBlockNumber}set onNewEvent(e){this._onNewEvent=e}intervalClear(){this.isReady=!1,this._onNewEvent=void 0,clearInterval(this.intervalId)}async init(){if(this.isReady)throw new Error("Already initialized");this.isReady=!0,await this.retrieveEvents(this._latestBlockNumber+1),this.intervalId=setInterval(async()=>{await this.retrieveEvents(this.latestBlockNumber)},3500)}requireReady(){if(!this.isReady)throw new Error("Not ready")}emitNewEvent(e){this._onNewEvent?.(e)}getLastBlockNumberForEventRequest=async()=>{const e=await this.contract.provider.getBlockNumber();if(!this.isServer)return e;const{chainId:s}=await this.contract.provider.getNetwork();return Math.max(this.latestBlockNumber,e-v.blockReorgDepth[s]+1)};async retrieveEvents(e,s=!1){try{if(this.requireReady(),this.inProgress&&!s)return!1;this.inProgress=!0;const t=await this.getLastBlockNumberForEventRequest();if(t<e)return this.inProgress=!1,!1;const r=c.getSequence(e,t,this.maxPageSize);return await c.resolveSync(r.map(({from:n,to:i})=>async()=>{const o=await this.contract.queryFilter(this.contract.filters[this.eventConfig.name](),n,i);let a=[];o.length>0&&(a=await this.processEventsPage(o),this.eventConfig.name==="NewCommitment"&&console.log("new events catched",this.ethAddress,{mappedEvents:a,events:o})),this._latestBlockNumber=i,await this.afterEventsAccepted(),a.length>0&&this.emitNewEvent()})),this.inProgress=!1,!0}catch(t){return u.logError("retrieveEvents error:",{err:t}),this.inProgress=!1,!1}}async processEventsPage(e){const s=[];return await c.resolveSync(e.map(t=>async()=>{const{args:r,blockNumber:n}=t;if(this.eventConfig.name==="NewCommitment"&&console.log("args",this.ethAddress,{args:r}),!r)throw new Error("Wrong event structure");const i=this.mapEvent(r);await this.acceptEvent(i,n)&&s.push(i)})),s}handleEvent=async(...e)=>{const{args:s}=this.eventConfig,{blockNumber:t}=e[e.length-1],r=e.slice(0,s.length),n=s.reduce((a,l,h)=>(a[l]=r[h],a),{});if(!t)throw new Error("Wrong event structure");const i=this.mapEvent(n);if(!await this.acceptEvent(i,t))throw new Error("Failed to retrieve events");this._latestBlockNumber=t,await this.afterEventsAccepted(),this.emitNewEvent(i)}}exports.AbstractEventService=g;
|
|
@@ -14,6 +14,7 @@ export declare abstract class AbstractEventService<EventType, SerializedEventTyp
|
|
|
14
14
|
protected isServer: boolean;
|
|
15
15
|
protected intervalId?: any;
|
|
16
16
|
protected inProgress: boolean;
|
|
17
|
+
protected ethAddress: string;
|
|
17
18
|
protected constructor(contract: ethers.Contract, eventConfig: EventConfig, initialBlockNumber: number, isServer: boolean, maxPageSize?: number);
|
|
18
19
|
get latestBlockNumber(): number;
|
|
19
20
|
set onNewEvent(value: NewEventListener<EventType>);
|
|
@@ -20,6 +20,7 @@ class C {
|
|
|
20
20
|
intervalId;
|
|
21
21
|
inProgress;
|
|
22
22
|
// to remove race conditions
|
|
23
|
+
ethAddress;
|
|
23
24
|
constructor(e, s, t, r, n) {
|
|
24
25
|
this.contract = e, this.eventConfig = s, this._latestBlockNumber = t, this.maxPageSize = n, this.isServer = r, this.inProgress = !1;
|
|
25
26
|
}
|
|
@@ -70,7 +71,7 @@ class C {
|
|
|
70
71
|
i
|
|
71
72
|
);
|
|
72
73
|
let a = [];
|
|
73
|
-
o.length > 0 && (a = await this.processEventsPage(o), this.eventConfig.name === "NewCommitment" && console.log("new events catched", { mappedEvents: a, events: o })), this._latestBlockNumber = i, await this.afterEventsAccepted(), a.length > 0 && this.emitNewEvent();
|
|
74
|
+
o.length > 0 && (a = await this.processEventsPage(o), this.eventConfig.name === "NewCommitment" && console.log("new events catched", this.ethAddress, { mappedEvents: a, events: o })), this._latestBlockNumber = i, await this.afterEventsAccepted(), a.length > 0 && this.emitNewEvent();
|
|
74
75
|
})
|
|
75
76
|
), this.inProgress = !1, !0;
|
|
76
77
|
} catch (t) {
|
|
@@ -82,7 +83,7 @@ class C {
|
|
|
82
83
|
return await c(
|
|
83
84
|
e.map((t) => async () => {
|
|
84
85
|
const { args: r, blockNumber: n } = t;
|
|
85
|
-
if (this.eventConfig.name === "NewCommitment" && console.log("args", { args: r }), !r)
|
|
86
|
+
if (this.eventConfig.name === "NewCommitment" && console.log("args", this.ethAddress, { args: r }), !r)
|
|
86
87
|
throw new Error("Wrong event structure");
|
|
87
88
|
const i = this.mapEvent(r);
|
|
88
89
|
await this.acceptEvent(i, n) && s.push(i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("circomlibjs");require("ethers");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("axios");require("../../constants/chains.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("circomlibjs");require("ethers");require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("axios");require("../../constants/chains.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const s=require("../../API/fetchCommitmentsCache.cjs"),i=require("../event-service/AbstractCommitmentsSnapshotService.cjs");class n extends i.AbstractCommitmentsSnapshotService{constructor(t,e,r){super(t,0,!1,e),this.ethAddress=r}async fetchSnapshot(){const{chainId:t}=await this.contract.provider.getNetwork(),e=await s.fetchCommitmentsSnapshot(t);if(e.hinkalAddress!==this.contract.address||e.chainId!==t)throw Error("Commitment Snapshot: incorrect contract or chain id");return{latestBlockNumber:e.latestBlockNumber,merkleTree:e.merkleTree,encryptedOutputs:e.encryptedOutputs}}persistSnapshot(t){return Promise.resolve()}}exports.ClientCommitmentsSnapshotService=n;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractCommitmentsSnapshotService, CommitmentsSerializedSnapshot } from '../event-service';
|
|
2
2
|
import { Contract } from 'ethers';
|
|
3
3
|
export declare class ClientCommitmentsSnapshotService extends AbstractCommitmentsSnapshotService {
|
|
4
|
-
constructor(contract: Contract, maxPageSize?: number);
|
|
4
|
+
constructor(contract: Contract, maxPageSize?: number, ethAddress?: string);
|
|
5
5
|
protected fetchSnapshot(): Promise<CommitmentsSerializedSnapshot>;
|
|
6
6
|
protected persistSnapshot(_serializedSnapshot: CommitmentsSerializedSnapshot): Promise<unknown>;
|
|
7
7
|
}
|
|
@@ -7,14 +7,14 @@ import "../../constants/chains.constants.mjs";
|
|
|
7
7
|
import "../../types/circom-data.types.mjs";
|
|
8
8
|
import "../../types/transactions.types.mjs";
|
|
9
9
|
import "../../types/curve.types.mjs";
|
|
10
|
-
import { fetchCommitmentsSnapshot as
|
|
11
|
-
import { AbstractCommitmentsSnapshotService as
|
|
12
|
-
class
|
|
13
|
-
constructor(r, t) {
|
|
14
|
-
super(r, 0, !1, t);
|
|
10
|
+
import { fetchCommitmentsSnapshot as o } from "../../API/fetchCommitmentsCache.mjs";
|
|
11
|
+
import { AbstractCommitmentsSnapshotService as s } from "../event-service/AbstractCommitmentsSnapshotService.mjs";
|
|
12
|
+
class k extends s {
|
|
13
|
+
constructor(r, t, e) {
|
|
14
|
+
super(r, 0, !1, t), this.ethAddress = e;
|
|
15
15
|
}
|
|
16
16
|
async fetchSnapshot() {
|
|
17
|
-
const { chainId: r } = await this.contract.provider.getNetwork(), t = await
|
|
17
|
+
const { chainId: r } = await this.contract.provider.getNetwork(), t = await o(r);
|
|
18
18
|
if (t.hinkalAddress !== this.contract.address || t.chainId !== r)
|
|
19
19
|
throw Error("Commitment Snapshot: incorrect contract or chain id");
|
|
20
20
|
return {
|
|
@@ -28,5 +28,5 @@ class f extends o {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export {
|
|
31
|
-
|
|
31
|
+
k as ClientCommitmentsSnapshotService
|
|
32
32
|
};
|