Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public getLastBlock(): Interfaces.IBlock | undefined {
return Blocks.BlockFactory.fromData(this.lastDownloadedBlock) || undefined;
}
import { Blocks, Managers } from "@arkecosystem/crypto";
import { genesisBlock as GB } from "../../config/unitnet/genesisBlock";
Managers.configManager.setFromPreset("unitnet");
export const genesisBlock = Blocks.BlockFactory.fromData(GB);
import { Blocks, Managers } from "@arkecosystem/crypto";
import { genesisBlock as GB } from "../../config/testnet/genesisBlock";
Managers.configManager.setFromPreset("testnet");
export const genesisBlock = Blocks.BlockFactory.fromData(GB);
return this.processBlocks(blockList.blocks.map(b => Blocks.BlockFactory.fromData(b)), cb);
} catch (error) {
private async verifyPeerBlock(
blockData: Interfaces.IBlockData,
expectedHeight: number,
delegatesByPublicKey: IDelegateWallets,
): Promise {
if (PeerVerifier.verifiedBlocks.has(blockData.id)) {
this.log(
Severity.DEBUG_EXTRA,
`accepting block at height ${blockData.height}, already successfully verified before`,
);
return true;
}
const block = Blocks.BlockFactory.fromData(blockData);
if (!block.verifySignature()) {
this.log(
Severity.DEBUG_EXTRA,
`failure: peer's block at height ${expectedHeight} does not pass crypto-validation`,
);
return false;
}
const height = block.data.height;
if (height !== expectedHeight) {
this.log(
Severity.DEBUG_EXTRA,
`failure: asked for block at height ${expectedHeight}, but got a block with height ${height} instead`,
);
return false;
return blocks.map((block: Interfaces.IBlockData) => Blocks.BlockFactory.fromData(block));
}
const block: Interfaces.IBlockData = await this.connection.blocksRepository.findById(id);
if (!block) {
return undefined;
}
const transactions: Array<{
serialized: Buffer;
id: string;
}> = await this.connection.transactionsRepository.findByBlockId(block.id);
block.transactions = transactions.map(
({ serialized, id }) => Transactions.TransactionFactory.fromBytesUnsafe(serialized, id).data,
);
return Blocks.BlockFactory.fromData(block);
}
private async processGenesisBlock(): Promise {
const genesisBlock: Interfaces.IBlock = Blocks.BlockFactory.fromJson(
Managers.configManager.get("genesisBlock"),
);
const { transactions }: Interfaces.IBlock = genesisBlock;
for (const transaction of transactions) {
if (transaction.type === Enums.TransactionTypes.Transfer) {
const recipient: State.IWallet = this.walletManager.findByAddress(transaction.data.recipientId);
recipient.balance = new Utils.BigNumber(transaction.data.amount);
}
}
for (const transaction of transactions) {
const sender: State.IWallet = this.walletManager.findByPublicKey(transaction.data.senderPublicKey);
sender.balance = sender.balance.minus(transaction.data.amount).minus(transaction.data.fee);
if (transaction.type === Enums.TransactionTypes.DelegateRegistration) {
exports['fromData (0)'] = () => {
return Blocks.BlockFactory.fromData(dataEmpty);
};
fee: Utils.BigNumber.ZERO,
};
const payloadBuffers: Buffer[] = [];
const sortedTransactions = Utils.sortTransactions(transactions);
for (const transaction of sortedTransactions) {
transactionData.amount = transactionData.amount.plus(transaction.amount);
transactionData.fee = transactionData.fee.plus(transaction.fee);
payloadBuffers.push(Buffer.from(transaction.id, "hex"));
}
if (this.bip38) {
this.decryptKeysWithOtp();
}
const block: Interfaces.IBlock = Blocks.BlockFactory.make(
{
version: 0,
generatorPublicKey: this.publicKey,
timestamp: options.timestamp,
previousBlock: options.previousBlock.id,
previousBlockHex: options.previousBlock.idHex,
height: options.previousBlock.height + 1,
numberOfTransactions: sortedTransactions.length,
totalAmount: transactionData.amount,
totalFee: transactionData.fee,
reward: options.reward,
payloadLength: 32 * sortedTransactions.length,
payloadHash: Crypto.HashAlgorithms.sha256(payloadBuffers).toString("hex"),
transactions: sortedTransactions,
},
this.keys,