Compare commits

...

5 Commits

4 changed files with 32 additions and 6 deletions

View File

@ -1,3 +1,10 @@
# [0.1.0-develop.32](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.31...v0.1.0-develop.32) (2023-07-13)
### Features
* add getCurrentBlock and getLastBlock methods ([661e146](https://git.lumeweb.com/LumeWeb/libethsync/commit/661e146636a9f685e8cbae04c52b1d0a1ede3bff))
# [0.1.0-develop.31](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.30...v0.1.0-develop.31) (2023-07-13)
# [0.1.0-develop.30](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.29...v0.1.0-develop.30) (2023-07-13)

4
npm-shrinkwrap.json generated
View File

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

View File

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

View File

@ -58,7 +58,10 @@ export default abstract class BaseClient {
}
public get isSynced() {
return this._latestPeriod === this.getCurrentPeriod();
return (
this._latestPeriod === this.getCurrentPeriod() &&
this.getLastBlock() === this.getCurrentBlock()
);
}
public get store(): IStore {
@ -69,6 +72,7 @@ export default abstract class BaseClient {
await init("herumi");
await this._sync();
await this.getLatestExecution(false);
}
public getCurrentPeriod(): number {
@ -77,6 +81,19 @@ export default abstract class BaseClient {
);
}
public getCurrentBlock(): number {
return getCurrentSlot(this.config.chainConfig, this.genesisTime);
}
public getLastBlock(): number | null {
if (this._latestOptimisticUpdate) {
return capella.ssz.LightClientOptimisticUpdate.deserialize(
this._latestOptimisticUpdate,
).attestedHeader.beacon.slot;
}
return null;
}
public async getNextValidExecutionInfo(
retry: number = 10,
): Promise<ExecutionInfo> {
@ -171,8 +188,10 @@ export default abstract class BaseClient {
}
}
async getLatestExecution(): Promise<ExecutionInfo | null> {
await this._sync();
async getLatestExecution(sync = true): Promise<ExecutionInfo | null> {
if (sync) {
await this._sync();
}
const getExecInfo = (u: OptimisticUpdate) => {
return {