How to use the merkle-patricia-tree function in merkle-patricia-tree

To help you get started, we’ve selected a few merkle-patricia-tree 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 maticnetwork / contracts / test / helpers / proofs.js View on Github external
export async function getTxProof(tx, block) {
  const txTrie = new Trie()
  for (let i = 0; i < block.transactions.length; i++) {
    const siblingTx = block.transactions[i]
    const path = rlp.encode(siblingTx.transactionIndex)
    const rawSignedSiblingTx = getTxBytes(siblingTx)
    await new Promise((resolve, reject) => {
      txTrie.put(path, rawSignedSiblingTx, err => {
        if (err) {
          reject(err)
        } else {
          resolve()
        }
      })
    })
  }

  // promise
github trufflesuite / ganache-core / src / ledgers / ethereum / miner.ts View on Github external
// so the miner knows it should immediately mine another block once it is
      //  done with its current work.
      this.pending = pending;
      this.updatePricedHeap(pending);
      return;
    } else {
      this.setPricedHeap(pending);
    }
    this._isMining = true;

    const blockTransactions: Transaction[] = [];

    let blockGasLeft = this.options.gasLimit.toBigInt();
    
    let counter = 0;
    const transactionsTrie = new Trie(null, null);
    const receiptTrie = new Trie(null, null);
    const promises: Promise[] = [];
    const receipts: any[] = [];

    await this._checkpoint();

    const priced = this.priced;
    const rejectedTransactions: Transaction[] = [];
    const blockData = {
      blockTransactions,
      transactionsTrie,
      receiptTrie,
      gasUsed: 0n,
      receipts
    };
github maticnetwork / matic.js / src / helpers / proofs.js View on Github external
export async function getTxProof(tx, block) {
  const txTrie = new Trie()
  for (let i = 0; i < block.transactions.length; i++) {
    const siblingTx = block.transactions[i]
    const path = rlp.encode(siblingTx.transactionIndex)
    const rawSignedSiblingTx = getTxBytes(siblingTx)
    await new Promise((resolve, reject) => {
      txTrie.put(path, rawSignedSiblingTx, err => {
        if (err) {
          reject(err)
        } else {
          resolve()
        }
      })
    })
  }

  // promise
github trufflesuite / ganache-core / src / ledgers / ethereum / blockchain.ts View on Github external
database.on("ready", async () => {
      // TODO: get the latest block from the database
      // if we have a latest block, `root` will be that block's header.stateRoot
      // and we will skip creating the genesis block alltogether
      const root: Buffer = null;
      this.trie = new Trie(database.trie, root);
      this.blocks = new BlockManager(this, database.blocks);
      this.vm = this.createVmFromStateTrie(this.trie, options.hardfork, options.allowUnlimitedContractSize);

      const miner = new Miner(this.vm, options);
      this.transactions = new TransactionManager(this, database.transactions, options);
      this.accounts = new AccountManager(this);

      await this._initializeAccounts(options.accounts);
      let lastBlock = this._initializeGenesisBlock(options.timestamp, options.gasLimit);

      const readyNextBlock = async () => {
        const previousBlock = await lastBlock;
        const previousHeader = previousBlock.value.header;
        const previousNumber = Quantity.from(previousHeader.number).toBigInt() || 0n;
        return this.blocks.createBlock({
          number: Quantity.from(previousNumber + 1n).toBuffer(),
github trufflesuite / ganache-core / src / ledgers / ethereum / miner.ts View on Github external
//  done with its current work.
      this.pending = pending;
      this.updatePricedHeap(pending);
      return;
    } else {
      this.setPricedHeap(pending);
    }
    this._isMining = true;

    const blockTransactions: Transaction[] = [];

    let blockGasLeft = this.options.gasLimit.toBigInt();
    
    let counter = 0;
    const transactionsTrie = new Trie(null, null);
    const receiptTrie = new Trie(null, null);
    const promises: Promise[] = [];
    const receipts: any[] = [];

    await this._checkpoint();

    const priced = this.priced;
    const rejectedTransactions: Transaction[] = [];
    const blockData = {
      blockTransactions,
      transactionsTrie,
      receiptTrie,
      gasUsed: 0n,
      receipts
    };

    // Run until we run out of items, or until the inner loop stops us.
github maticnetwork / contracts / test / helpers / proofs.js View on Github external
export async function getReceiptProof(receipt, block, web3, receipts) {
  const receiptsTrie = new Trie()
  const receiptPromises = []
  if (!receipts) {
    block.transactions.forEach(tx => {
      receiptPromises.push(web3.eth.getTransactionReceipt(tx.hash))
    })
    receipts = await Promise.all(receiptPromises)
  }

  for (let i = 0; i < receipts.length; i++) {
    const siblingReceipt = receipts[i]
    const path = rlp.encode(siblingReceipt.transactionIndex)
    const rawReceipt = getReceiptBytes(siblingReceipt)
    await new Promise((resolve, reject) => {
      receiptsTrie.put(path, rawReceipt, err => {
        if (err) {
          reject(err)
github SoraSuegami / Vreath / core / merkle_patricia.ts View on Github external
constructor(db:any,root:string=""){
    if(root=="") this.trie = new Merkle(db);
    else this.trie = new Merkle(db,Buffer.from(root,'hex'));
  }
github 0mkara / etheratom / lib / vm / vm.js View on Github external
subscribeToVMEvents() {
		if(!this.vmSubscriptions) {
			return
		}
		let EthJSVM;
		EthJSVM = require('ethereumjs-vm');
		this.stateTrie = new Trie();
		this.vm = new EthJSVM({
			activatePrecompiles: true,
			enableHomestead: true,
			state: this.stateTrie
		});
		this.view = new View(this.vm);
		this.helpers = new VmHelpers(this.vm);
		this.view.createCompilerOptionsView();
		this.view.createCoinbaseView();
		this.view.createButtonsView();
		this.vmSubscriptions.add(atom.workspace.observeTextEditors((editor) => {
			if(!editor || !editor.getBuffer()) {
				return
			}

			this.vmSubscriptions.add(atom.config.observe('etheratom.compileOnSave', (compileOnSave) => {
github SoraSuegami / Vreath / core / merkle_patricia.ts View on Github external
constructor(db:any,root:string=""){
    if(root=="") this.trie = new Merkle(db);
    else this.trie = new Merkle(db,Buffer.from(root,'hex'));
  }