Compare commits
3 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | fd789c8133 | |
Derrick Hammer | 474c61e759 | |
Derrick Hammer | 208ca03e80 |
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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 });
|
||||||
|
|
Loading…
Reference in New Issue