How to use memdown - 10 common examples

To help you get started, we’ve selected a few memdown 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 2 profile with key", async () => {
      const db = levelup(MemDownConstructor());

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

      let loaded: UserProfile;
      const key = await UserProfile.deriveEncryptionKey(userprofileData.serializations.version2.password);
      try {
        loaded = await UserProfile.loadFrom(db, key);
      } catch (error) {
        if (error instanceof UnexpectedFormatVersionError) {
          const key2 = await UserProfile.deriveEncryptionKey(
            userprofileData.serializations.version2.password,
            error.expectedFormatVersion,
          );
github polkadot-js / common / packages / trie-db-old / src / CheckpointTrie.ts View on Github external
_enterCpMode () {
    // l.debug(() => 'Entering checkpoint mode');

    this._scratch = levelup(encoder(memdown()));

    this._getDBs = [this._scratch].concat(this._getDBs);
    this.__putDBs = this._putDBs;
    this._putDBs = [this._scratch];
    this._putRaw = this.putRaw;
    this.putRaw = putRaw;
  }
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 neo-one-suite / neo-one / packages / neo-one-smart-contract-test / src / createNode.ts View on Github external
}),
      path: '/tmp/fakePath/',
      rpc: {
        http: {
          port,
          host: 'localhost',
        },
      },
      node: {
        consensus: {
          privateKey,
          privateNet: true,
        },
      },
    },
    leveldown: MemDown(),
  });
  await node.start();

  return {
    privateKey,
    node,
    rpcURL: `http://localhost:${port}/rpc`,
  };
};
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)),
github AugurProject / augur / packages / augur-tools / src / libs / ganache.ts View on Github external
export function createDb(): MemDown {
  return memdown("");
}
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 toolness / jsondown / jsondown.js View on Github external
JsonDOWN.prototype._del = function(key, options, cb) {
  MemDOWN.prototype._del.call(this, key, options, noop);
  this._writeToDisk(cb);
};
github toolness / jsondown / jsondown.js View on Github external
JsonDOWN.prototype._put = function(key, value, options, cb) {
  MemDOWN.prototype._put.call(this, key, value, options, noop);
  if (!this._isLoadingFromFile) this._writeToDisk(cb);
};

memdown

An drop-in replacement for LevelDOWN that works in memory only

MIT
Latest version published 3 years ago

Package Health Score

62 / 100
Full package analysis