Compare commits

...

3 Commits

Author SHA1 Message Date
semantic-release-bot 2d4f911249 chore(release): 0.1.0-develop.50 [skip ci]
# [0.1.0-develop.50](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.49...v0.1.0-develop.50) (2023-09-16)

### Features

* have Store extend EventEmitter so that it can emit set on adding an update and pass the serialized data ([295aed0](295aed0845))
2023-09-16 02:07:44 +00:00
Derrick Hammer 97510bd892
Merge remote-tracking branch 'origin/develop' into develop 2023-09-15 22:06:45 -04:00
Derrick Hammer 295aed0845
feat: have Store extend EventEmitter so that it can emit set on adding an update and pass the serialized data 2023-09-15 22:06:40 -04:00
4 changed files with 16 additions and 5 deletions

View File

@ -1,3 +1,10 @@
# [0.1.0-develop.50](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.49...v0.1.0-develop.50) (2023-09-16)
### Features
* have Store extend EventEmitter so that it can emit set on adding an update and pass the serialized data ([295aed0](https://git.lumeweb.com/LumeWeb/libethsync/commit/295aed0845249ab81852e4106de66fdca3c5885e))
# [0.1.0-develop.49](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.48...v0.1.0-develop.49) (2023-07-25) # [0.1.0-develop.49](https://git.lumeweb.com/LumeWeb/libethsync/compare/v0.1.0-develop.48...v0.1.0-develop.49) (2023-07-25)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@lumeweb/libethsync", "name": "@lumeweb/libethsync",
"version": "0.1.0-develop.49", "version": "0.1.0-develop.50",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lumeweb/libethsync", "name": "@lumeweb/libethsync",
"version": "0.1.0-develop.49", "version": "0.1.0-develop.50",
"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.49", "version": "0.1.0-develop.50",
"type": "module", "type": "module",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -5,6 +5,7 @@ import { concatBytes } from "@noble/hashes/utils";
import { LightClientUpdate } from "#types.js"; import { LightClientUpdate } from "#types.js";
import * as capella from "@lodestar/types/capella"; import * as capella from "@lodestar/types/capella";
import NodeCache from "node-cache"; import NodeCache from "node-cache";
import { EventEmitter } from "events";
export interface StoreItem { export interface StoreItem {
update: Uint8Array; update: Uint8Array;
@ -12,22 +13,25 @@ export interface StoreItem {
nextCommitteeHash: Uint8Array; nextCommitteeHash: Uint8Array;
} }
export default class Store implements IStore { export default class Store extends EventEmitter implements IStore {
private store = new NodeCache({ useClones: false }); private store = new NodeCache({ useClones: false });
constructor(expire: number = 0) { constructor(expire: number = 0) {
super();
this.store.options.stdTTL = 0; this.store.options.stdTTL = 0;
} }
addUpdate(period: number, update: LightClientUpdate) { addUpdate(period: number, update: LightClientUpdate) {
try { try {
const serialized = capella.ssz.LightClientUpdate.serialize(update);
this.store.set(period, { this.store.set(period, {
update: capella.ssz.LightClientUpdate.serialize(update), update: serialized,
nextCommittee: CommitteeSSZ.serialize(update.nextSyncCommittee.pubkeys), nextCommittee: CommitteeSSZ.serialize(update.nextSyncCommittee.pubkeys),
nextCommitteeHash: digest( nextCommitteeHash: digest(
concatBytes(...update.nextSyncCommittee.pubkeys), concatBytes(...update.nextSyncCommittee.pubkeys),
), ),
}); });
this.emit("set", period, serialized);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }