How to use the @arkecosystem/crypto.Transactions.TransactionFactory 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 / packages / core-database-postgres / src / postgres-connection.ts View on Github external
await this.db.task(task => {
                const transactions = [];

                for (const tx of chunk) {
                    const transaction = Transactions.TransactionFactory.fromBytesUnsafe(tx.serialized, tx.id);
                    if (transaction.data.asset) {
                        let transactionId = transaction.id;

                        // If the transaction is a broken v1 transaction use the broken id for the query.
                        if (transactionIdFixTable && transactionIdFixTable[transactionId]) {
                            transactionId = transactionIdFixTable[transactionId];
                        }

                        const query =
                            this.pgp.helpers.update(
                                {
                                    asset: transaction.data.asset,
                                },
                                ["asset"],
                                "transactions",
                            ) + ` WHERE id = '${transactionId}'`;
github ArkEcosystem / core / packages / core-api / src / handlers / transactions / transformer.ts View on Github external
export const transformTransaction = (model, transform) => {
    const blockchain = app.resolvePlugin("blockchain");
    const databaseService = app.resolvePlugin("database");

    const transaction: Interfaces.ITransaction = Transactions.TransactionFactory.fromBytesUnsafe(
        model.serialized,
        model.id,
    );

    if (!transform) {
        return transaction.toJson();
    }

    const { data } = transaction;

    const sender: string = databaseService.walletManager.findByPublicKey(data.senderPublicKey).address;

    const lastBlock: Interfaces.IBlock = blockchain.getLastBlock();

    return {
        id: data.id,
github ArkEcosystem / core / packages / core-snapshots / src / transport / verification.ts View on Github external
`Failed to verify signature: ${JSON.stringify(data)}`,
                );
            }

            return signatureVerify;
        }

        return true;
    }

    if (context === "transactions") {
        if (!verifySignatures) {
            return true;
        }

        return Transactions.TransactionFactory.fromBytes(data.serialized).verified;
    }

    if (context === "rounds") {
        return true;
    }

    return false;
};
github ArkEcosystem / core / packages / core-p2p / src / peer-communicator.ts View on Github external
transactions = block.transactions.map(transaction => {
                    const { data } = Transactions.TransactionFactory.fromBytesUnsafe(Buffer.from(transaction, "hex"));
                    data.blockId = block.id;
                    return data;
                });
            } catch {
github ArkEcosystem / core / packages / core-transaction-pool / src / worker / worker.ts View on Github external
const result: IPendingTransactionJobResult = {
            ticketId: job.ticketId,
            validTransactions: [],
            invalid: {},
            excess: {},
            errors: {},
        };

        for (const transactionData of transactions) {
            try {
                if (!this.performBasicTransactionChecks(result, transactionData)) {
                    continue;
                }

                const transaction: Interfaces.ITransaction = Transactions.TransactionFactory.fromData(transactionData);
                const handler: Handlers.TransactionHandler = Handlers.Registry.get(
                    transaction.type,
                    transaction.typeGroup,
                );

                const walletData: State.IWallet = senderWallets[transactionData.senderPublicKey];
                const senderWallet: State.IWallet = Object.assign(new Wallets.Wallet(walletData.address), {
                    ...walletData,
                });

                if (!(await handler.verify(transaction, senderWallet))) {

                    pushError(result, transactionData.id, {
                        type: "ERR_BAD_DATA",
                        message: "Failed to verify transaction signature.",
                    });
github ArkEcosystem / core / packages / core-database / src / database-service.ts View on Github external
const transactions = dbTransactions.map(tx => {
            const { data } = Transactions.TransactionFactory.fromBytesUnsafe(tx.serialized, tx.id);
            data.blockId = tx.blockId;
            return data;
        });
github ArkEcosystem / core / packages / core-transaction-pool / src / processor.ts View on Github external
const exists: boolean = this.pool.has(transaction.id);

            if (exists) {
                this.pushError(transaction, "ERR_DUPLICATE", `Duplicate transaction ${transaction.id}`);
            } else if (JSON.stringify(transaction).length > maxTransactionBytes) {
                this.pushError(
                    transaction,
                    "ERR_TOO_LARGE",
                    `Transaction ${transaction.id} is larger than ${maxTransactionBytes} bytes.`,
                );
            } else if (this.pool.hasExceededMaxTransactions(transaction.senderPublicKey)) {
                this.excess.push(transaction.id);
            } else if (this.validateTransaction(transaction)) {
                try {
                    const receivedId: string = transaction.id;
                    const trx: Interfaces.ITransaction = Transactions.TransactionFactory.fromData(transaction);
                    const handler = Handlers.Registry.get(trx.type);
                    if (handler.verify(trx, this.pool.walletManager)) {
                        try {
                            this.walletManager.throwIfApplyingFails(trx);
                            const dynamicFee: IDynamicFeeMatch = dynamicFeeMatcher(trx);
                            if (!dynamicFee.enterPool && !dynamicFee.broadcast) {
                                this.pushError(
                                    transaction,
                                    "ERR_LOW_FEE",
                                    "The fee is too low to broadcast and accept the transaction",
                                );
                            } else {
                                if (dynamicFee.enterPool) {
                                    this.accept.set(trx.data.id, trx);
                                }
github ArkEcosystem / core / deprecated / core-json-rpc / src / server / modules.ts View on Github external
async method(params: { id: string }) {
            const transaction: Interfaces.ITransactionData = await database.get(params.id);

            if (!transaction) {
                return Boom.notFound(`Transaction ${params.id} could not be found.`);
            }

            const { data } = Transactions.TransactionFactory.fromData(transaction);

            if (!Transactions.Verifier.verifyHash(data)) {
                return Boom.badData();
            }

            await network.sendPOST({
                path: "transactions",
                body: { transactions: [transaction] },
            });

            return transaction;
        },
        schema: {
github ArkEcosystem / core / packages / core-forger / src / manager.ts View on Github external
            (hex: string) => Transactions.TransactionFactory.fromBytesUnsafe(Buffer.from(hex, "hex")).data,
        );
github ArkEcosystem / core / packages / core-transaction-pool / src / connection.ts View on Github external
private async validateTransactions(transactions: Interfaces.ITransaction[]): Promise {
        const validTransactions: string[] = [];
        const forgedIds: string[] = await this.removeForgedTransactions(transactions);

        const unforgedTransactions = transactions.filter(
            (transaction: Interfaces.ITransaction) => !forgedIds.includes(transaction.id),
        );

        const databaseWalletManager: State.IWalletManager = this.databaseService.walletManager;
        const localWalletManager: Wallets.WalletManager = new Wallets.WalletManager();

        for (const transaction of unforgedTransactions) {
            try {
                const deserialized: Interfaces.ITransaction = Transactions.TransactionFactory.fromBytes(
                    transaction.serialized,
                );

                strictEqual(transaction.id, deserialized.id);

                const { sender, recipient } = this.getSenderAndRecipient(transaction, localWalletManager);

                const handler: Handlers.TransactionHandler = Handlers.Registry.get(transaction.type);
                handler.canBeApplied(transaction, sender, databaseWalletManager);

                handler.applyToSenderInPool(transaction, localWalletManager);

                if (recipient && sender.address !== recipient.address) {
                    handler.applyToRecipientInPool(transaction, localWalletManager);
                }