How to use the levelup function in levelup

To help you get started, we’ve selected a few levelup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iov-one / iov-core / packages / iov-keycontrol / src / userprofile.spec.ts View on Github external
it("can load format version 1 profile with password", async () => {
      const db = levelup(MemDownConstructor());

      // Storage data created with IOV-Core 0.14 cli
      await db.put("format_version", userprofileData.serializations.version1.db.format_version);
      await db.put("created_at", userprofileData.serializations.version1.db.created_at);
      await db.put("keyring", userprofileData.serializations.version1.db.keyring);

      const loaded = await UserProfile.loadFrom(db, userprofileData.serializations.version1.password);

      expect(loaded.createdAt).toEqual(new ReadonlyDate("2019-05-27T16:40:44.522Z"));
      expect(loaded.wallets.value.length).toEqual(2);
      expect(loaded.wallets.value[0].label).toEqual("ed");
      expect(loaded.wallets.value[1].label).toEqual("secp");
      expect(loaded.printableSecret(loaded.wallets.value[0].id)).toEqual(
        "degree tackle suggest window test behind mesh extra cover prepare oak script",
      );
      expect(loaded.printableSecret(loaded.wallets.value[1].id)).toEqual(
github polkadot-js / common / packages / trie-db-old / src / BaseTrie.ts View on Github external
constructor (db: any, root: Uint8Array = EMPTY_ROOT_U8A, hashing: HashFn = keccakAsU8a) {
    this.putRaw = this._putRaw;

    this.semaphore = semaphore(1);
    this.dbDown = db || memdown();
    this.db = levelup(encoder(this.dbDown));
    this._getDBs = [this.db];
    this._putDBs = [this.db];
    this.hashing = hashing;
    this.nodeFactory = createFactory(hashing);
    this.root = root;

    // l.debug(() => ['Created BaseTrie', typeof db, u8aToHex(root)]);
  }
github trufflesuite / ganache-core / src / ledgers / ethereum / database.ts View on Github external
let db;
    if (store) {
      db = await levelup(store as any, levelupOptions);
    } else {
      let directory = this.options.dbPath;
      if (!directory) {
        const dirInfo = await dir(tmpOptions);
        directory = dirInfo.path;
        this._cleanupDirectory = dirInfo.cleanup;

        // don't continue if we closed while we were waiting for the dir
        if (this.closed) return this._cleanup();
      }
      this.directory = directory;
      const store = encode(leveldown(directory), levelupOptions);
      db = await levelup(store, {});
    }

    // don't continue if we closed while we were waiting for the db
    if (this.closed) return this._cleanup();

    const open = db.open();
    this.trie = sub(db, "trie", levelupOptions);

    this.db = db;
    await open;

    // don't continue if we closed while we were waiting for it to open
    if (this.closed) return this._cleanup();
    
    this.blocks = sub(db, "blocks", levelupOptions);
    this.transactions = sub(db, "transactions", levelupOptions);
github SoraSuegami / Vreath / server / server.ts View on Github external
(async ()=>{
const app = express();
const server = new http.Server(app);
const io = socket(server);

const port = process.env.vreath_port || "57750";
const ip = process.env.vreath_port || "localhost";
server.listen(port,()=>{
    console.log(port);
});

let db = levelup(leveldown('./server/db'));

const my_private = "a611b2b5da5da90b280475743675dd36444fde49d3166d614f5d9d7e1763768a"
const my_public = "03a3faee4aa614d1725801681b246fdf778c7b23102e8e5113e0e3e5e18100db3f"
const my_address = CryptoSet.GenereateAddress(native,my_public);

type Roots = {
    stateroot:string;
    locationroot:string;
}
let roots:Roots = JSON.parse(fs.readFileSync("./json/root.json","utf-8")) || {stateroot:_.toHash(''),locationroot:_.toHash('')};
let StateData:Trie;
let LocationData:Trie;
if(roots.stateroot!=_.toHash('')){
    StateData = new Trie(db,roots.stateroot);
}
else{
github iov-one / iov-core / packages / iov-keycontrol / src / userprofile.spec.ts View on Github external
it("can be stored with password", async () => {
      const db = levelup(MemDownConstructor());

      const createdAt = new ReadonlyDate("1985-04-12T23:20:50.521Z");
      const keyring = new Keyring();
      const profile = new UserProfile({ createdAt: createdAt, keyring: keyring });

      await profile.storeIn(db, defaultEncryptionPassword);
      expect(await db.get("format_version", { asBuffer: false })).toEqual("2");
      expect(await db.get("created_at", { asBuffer: false })).toEqual("1985-04-12T23:20:50.521Z");
      expect(await db.get("keyring", { asBuffer: false })).toMatch(/^[-_/=a-zA-Z0-9+]+$/);

      await db.close();
    });
github neo-one-suite / neo-one / packages / neo-one-node-browser / src / FullNode.ts View on Github external
private async startInternal(): Promise {
    const primaryPrivateKey = common.stringToPrivateKey(constants.PRIVATE_NET_PRIVATE_KEY);
    const primaryPublicKey = common.stringToECPoint(constants.PRIVATE_NET_PUBLIC_KEY);
    crypto.addPublicKey(primaryPrivateKey, primaryPublicKey);

    const settings = createMain({
      address: common.uInt160ToString(crypto.privateKeyToScriptHash(primaryPrivateKey)),
      standbyValidators: [common.ecPointToString(primaryPublicKey)],
      privateNet: true,
    });
    const storage = levelupStorage({
      db: LevelUp(this.options.type === 'persistent' ? Level(this.options.id) : MemDown()),
      context: { messageMagic: settings.messageMagic },
    });

    const blockchain = await Blockchain.create({
      settings,
      storage,
      vm,
    });
    const nodeOptions = {
      consensus: {
        privateKey: common.privateKeyToString(primaryPrivateKey),
        privateNet: true,
      },
    };
    const node = new Node({
      blockchain,
github neo-one-suite / neo-one / packages / neo-one-node / src / fullNode$.js View on Github external
const node$ = defer(async () => {
    if (environment.telemetry != null) {
      monitor.serveMetrics(environment.telemetry.port);
    }

    const storage = levelUpStorage({
      db: levelup(
        customLeveldown == null
          ? leveldown(dataPath, environment.levelDownOptions)
          : customLeveldown,
      ),
      context: { messageMagic: settings.messageMagic },
    });
    const blockchain = await Blockchain.create({
      settings,
      storage,
      vm,
      monitor,
    });
    if (chainFile != null) {
      await loadChain({
        chain: { format: 'raw', path: chainFile },
        blockchain,
github molily / universal-progressive-todos / src / data / Database.js View on Github external
constructor(filename) {
    this.db = levelup(encode(leveldown(filename), {
      valueEncoding: 'json'
    }));
  }
github neo-one-suite / neo-one / packages / neo-one-smart-contract-compiler / src / __data__ / helpers / executeScript.ts View on Github external
export const executeScript = async (
  diagnostics: ReadonlyArray,
  compiledCode: string,
  sourceMap: Promise,
  { prelude = Buffer.alloc(0, 0), ignoreWarnings = false }: ExecuteOptions = EXECUTE_OPTIONS_DEFAULT,
): Promise<{
  readonly receipt: CallReceiptJSON;
  readonly sourceMaps: SourceMaps;
}> => {
  const blockchain = await Blockchain.create({
    settings: testNet(),
    storage: storage({
      context: { messageMagic: testNet().messageMagic },
      db: LevelUp(MemDown()),
    }),
    vm,
  });

  throwOnDiagnosticErrorOrWarning(diagnostics, ignoreWarnings);

  const code = Buffer.concat([prelude, Buffer.from(compiledCode, 'hex')]);
  const [receipt, resolvedSourceMap] = await Promise.all([blockchain.invokeScript(code), sourceMap]);

  const address = scriptHashToAddress(common.uInt160ToString(crypto.toScriptHash(code)));
  await blockchain.stop();

  return {
    receipt: {
      result: receipt.result.serializeJSON(blockchain.serializeJSONContext),
      actions: receipt.actions.map((action) => action.serializeJSON(blockchain.serializeJSONContext)),

levelup

Fast & simple storage - a Node.js-style LevelDB wrapper

MIT
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis