Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
// 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
};
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
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(),
// 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.
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)
constructor(db:any,root:string=""){
if(root=="") this.trie = new Merkle(db);
else this.trie = new Merkle(db,Buffer.from(root,'hex'));
}
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) => {
constructor(db:any,root:string=""){
if(root=="") this.trie = new Merkle(db);
else this.trie = new Merkle(db,Buffer.from(root,'hex'));
}