This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parameterized database and updated storage consumers
- Loading branch information
1 parent
c1d1f19
commit cd69254
Showing
20 changed files
with
221 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
import level from "level"; | ||
import sub from "subleveldown"; | ||
import { LevelUp } from "levelup"; | ||
|
||
const db = level("./leveldb", { valueEncoding: "json" }); | ||
import { mkdir, stat } from "fs"; | ||
import { promisify } from "util"; | ||
|
||
export const close = async (): Promise<void> => { | ||
await db.close(); | ||
}; | ||
const mkdirAsync = promisify(mkdir); | ||
const existsAsync = promisify(stat); | ||
|
||
export const pubkeyDB = sub(db, "pubkey"); | ||
export const stateDB = sub(db, "state"); | ||
export const nodeDB = sub(db, "node"); | ||
// export const batchDB = sub(db, "batch"); | ||
export const txDB = sub(db, "tx"); | ||
export const pubkey2statesDB = sub(db, "pubkey2states"); | ||
export class Connection { | ||
public readonly pubkeyDB: LevelUp; | ||
public readonly stateDB: LevelUp; | ||
public readonly txDB: LevelUp; | ||
public readonly pubkey2statesDB: LevelUp; | ||
|
||
private db: LevelUp; | ||
|
||
constructor(path: string) { | ||
this.db = level(`${path}`, { valueEncoding: "json" }); | ||
|
||
this.pubkeyDB = sub(this.db, "pubkey"); | ||
this.stateDB = sub(this.db, "state"); | ||
this.txDB = sub(this.db, "tx"); | ||
this.pubkey2statesDB = sub(this.db, "pubkey2states"); | ||
} | ||
|
||
public static async create(path: string) { | ||
try { | ||
await existsAsync(path); | ||
} catch (error) { | ||
await mkdirAsync(path, { recursive: true }); | ||
} | ||
|
||
return new Connection(path); | ||
} | ||
|
||
public async close(): Promise<void> { | ||
await this.db.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { Pubkey } from "../../pubkey"; | ||
import { PubkeyLeafFactory } from "../../tree/leaves/PubkeyLeaf"; | ||
import { StorageEngine } from "../storageEngine/interfaces"; | ||
import { Connection } from "./connection"; | ||
import { DatabaseEngine } from "./databaseEngine"; | ||
|
||
export interface PubkeyStorageEngine extends StorageEngine<Pubkey> {} | ||
|
||
export class PubkeyDatabaseEngine extends DatabaseEngine<Pubkey> | ||
implements PubkeyStorageEngine { | ||
constructor(depth: number) { | ||
super(depth, PubkeyLeafFactory()); | ||
constructor(depth: number, connections: Connection) { | ||
super( | ||
depth, | ||
connections.pubkeyDB, | ||
PubkeyLeafFactory(connections.pubkeyDB) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.