How to use the @arkecosystem/crypto.Blocks.BlockFactory function in @arkecosystem/crypto

To help you get started, we’ve selected a few @arkecosystem/crypto 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 ArkEcosystem / core / __tests__ / unit / core-blockchain / stubs / state-storage.ts View on Github external
public getLastBlock(): Interfaces.IBlock | undefined {
        return Blocks.BlockFactory.fromData(this.lastDownloadedBlock) || undefined;
    }
github ArkEcosystem / core / __tests__ / utils / fixtures / unitnet / block-model.ts View on Github external
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);
github ArkEcosystem / core / __tests__ / utils / fixtures / testnet / block-model.ts View on Github external
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);
github ArkEcosystem / core / packages / core-blockchain / src / blockchain.ts View on Github external
                return this.processBlocks(blockList.blocks.map(b => Blocks.BlockFactory.fromData(b)), cb);
            } catch (error) {
github ArkEcosystem / core / packages / core-p2p / src / peer-verifier.ts View on Github external
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;
github ArkEcosystem / core / packages / core-blockchain / src / replay / replay-blockchain.ts View on Github external
        return blocks.map((block: Interfaces.IBlockData) => Blocks.BlockFactory.fromData(block));
    }
github ArkEcosystem / core / packages / core-database / src / database-service.ts View on Github external
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);
    }
github ArkEcosystem / core / packages / core-blockchain / src / replay / replay-blockchain.ts View on Github external
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) {
github ArkEcosystem / core / benchmark / block / create.js View on Github external
exports['fromData (0)'] = () => {
    return Blocks.BlockFactory.fromData(dataEmpty);
};
github ArkEcosystem / core / packages / core-forger / src / delegate.ts View on Github external
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,