static fromJson(data) { let blocks = new Blocks(); R.forEach((block) => { blocks.push(Block.fromJson(block)); }, data); return blocks; }
syncTransactions(transactions) { // For each received transaction check if we have it, if not, add. R.forEach((transaction) => { let transactionFound = this.blockchain.getTransactionById(transaction.id); if (transactionFound == null) { console.info(`Syncing transaction '${transaction.id}'`); this.blockchain.addTransaction(transaction); } }, transactions); }
init() { // Create the genesis block if the blockchain is empty if (this.blocks.length == 0) { console.info('Blockchain empty, adding genesis block'); this.blocks.push(Block.genesis); this.blocksDb.write(this.blocks); } // Remove transactions that are in the blockchain console.info('Removing transactions that are in the blockchain'); R.forEach(this.removeBlockTransactionsFromTransactions.bind(this), this.blocks); }
replaceChain(newBlockchain) { // It doesn't make sense to replace this blockchain by a smaller one if (newBlockchain.length <= this.blocks.length) { console.error('Blockchain shorter than the current blockchain'); throw new BlockchainAssertionError('Blockchain shorter than the current blockchain'); } // Verify if the new blockchain is correct this.checkChain(newBlockchain); // Get the blocks that diverges from our blockchain console.info('Received blockchain is valid. Replacing current blockchain with received blockchain'); let newBlocks = R.takeLast(newBlockchain.length - this.blocks.length, newBlockchain); // Add each new block to the blockchain R.forEach((block) => { this.addBlock(block, false); }, newBlocks); this.emitter.emit('blockchainReplaced', newBlocks); }
R.forEach(this.checkTransaction.bind(this), newBlock.transactions, referenceBlockchain);
let index = 0; R.forEach((txOutput) => { if (address && txOutput.address == address) { txOutputs.push({ R.forEach((txInput) => { if (address && txInput.address != address) return; R.forEach(R.pipe(R.prop('transactions'), R.forEach(selectTxs)), this.blocks); R.forEach(selectTxs, this.transactions); R.forEach((txOutput) => { if (!R.any((txInput) => txInput.transaction == txOutput.transaction && txInput.index == txOutput.index, txInputs)) { unspentTransactionOutput.push(txOutput);
R.forEach((transaction) => { let negativeOutputsFound = 0; let i = 0;
static fromJson(data) { let transactions = new Transactions(); R.forEach((transaction) => { transactions.push(Transaction.fromJson(transaction)); }, data); return transactions; }
static fromJson(data) { let wallets = new Wallets(); R.forEach((wallet) => { wallets.push(Wallet.fromJson(wallet)); }, data); return wallets; }
storage.on('logLastValidationErrors', () => { storage.localSession.lastValidationErrors && R.forEach((err) => { this.log(err) }, storage.localSession.lastValidationErrors) })
logDev(...data) { R.forEach((line) => { this.devBoxes.console.pushLine(line) }, data) const extraLines = this.devBoxes.console.getScreenLines().length - this.screen.height + 2 if (extraLines > 0) { for (let i = 0; i < extraLines; i++) { this.devBoxes.console.shiftLine(0) } } this.screen.render() }
logMiner(...data) { R.forEach((line) => { this.boxes.miner.pushLine(line) }, data) const extraLines = this.boxes.miner.getScreenLines().length - this.screen.height + 2 if (extraLines > 0) { for (let i = 0; i < extraLines; i++) { this.boxes.miner.shiftLine(0) } } this.screen.render() }
logWallet(...data) { R.forEach((line) => { this.boxes.wallet.pushLine(line) }, data) const extraLines = this.boxes.wallet.getScreenLines().length - this.screen.height + 2 if (extraLines > 0) { for (let i = 0; i < extraLines; i++) { this.boxes.wallet.shiftLine(0) } } this.screen.render() }