Compare commits

...

3 Commits

6 changed files with 25 additions and 18 deletions

View File

@ -1,3 +1,5 @@
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-07-11)
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-07-11) # [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-07-11)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@lumeweb/libethclient", "name": "@lumeweb/libethclient",
"version": "0.1.0-develop.9", "version": "0.1.0-develop.10",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lumeweb/libethclient", "name": "@lumeweb/libethclient",
"version": "0.1.0-develop.9", "version": "0.1.0-develop.10",
"dependencies": { "dependencies": {
"@chainsafe/as-sha256": "^0.3.1", "@chainsafe/as-sha256": "^0.3.1",
"@chainsafe/bls": "7.1.1", "@chainsafe/bls": "7.1.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lumeweb/libethsync", "name": "@lumeweb/libethsync",
"version": "0.1.0-develop.9", "version": "0.1.0-develop.10",
"type": "module", "type": "module",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -85,6 +85,21 @@ export default abstract class BaseClient {
this.syncMutex.release(); this.syncMutex.release();
} }
protected async subscribe(callback?: (ei: ExecutionInfo) => void) {
setInterval(async () => {
try {
await this._sync();
const ei = await this.getLatestExecution();
if (ei && ei.blockHash !== this.latestBlockHash) {
this.latestBlockHash = ei.blockHash;
return await callback?.(ei);
}
} catch (e) {
console.error(e);
}
}, POLLING_DELAY);
}
public get store(): IStore { public get store(): IStore {
return this.options.store as IStore; return this.options.store as IStore;
} }

View File

@ -101,21 +101,6 @@ export default class Client extends BaseClient {
return this.getCommittee(currentPeriod, lastCommitteeHash); return this.getCommittee(currentPeriod, lastCommitteeHash);
} }
private async subscribe(callback: (ei: ExecutionInfo) => void) {
setInterval(async () => {
try {
await this._sync();
const ei = await this.getLatestExecution();
if (ei && ei.blockHash !== this.latestBlockHash) {
this.latestBlockHash = ei.blockHash;
return await callback(ei);
}
} catch (e) {
console.error(e);
}
}, POLLING_DELAY);
}
private async getCommittee( private async getCommittee(
period: number, period: number,
expectedCommitteeHash: Uint8Array | null, expectedCommitteeHash: Uint8Array | null,

View File

@ -28,6 +28,11 @@ interface Config extends BaseClientOptions {
} }
export default class Client extends BaseClient { export default class Client extends BaseClient {
async sync(): Promise<void> {
await super.sync();
this.subscribe();
}
private beaconUrl: string; private beaconUrl: string;
private blockCache = new NodeCache({ stdTTL: 60 * 60 * 12 }); private blockCache = new NodeCache({ stdTTL: 60 * 60 * 12 });
private blockHashCache = new NodeCache({ stdTTL: 60 * 60 * 12 }); private blockHashCache = new NodeCache({ stdTTL: 60 * 60 * 12 });