How to use the @liskhq/lisk-transactions.TransactionError function in @liskhq/lisk-transactions

To help you get started, we’ve selected a few @liskhq/lisk-transactions 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 LiskHQ / lisk-sdk-examples / invoice / transactions / payment_transaction.js View on Github external
applyAsset(store) {
		const errors = [];

        const invoiceTransaction = store.account.find(
            account => account.id === this.asset.data
        ); // Find related invoice in transactions for invoiceID

		if (!transaction) {
            errors.push( new TransactionError(
					'Invoice does not exist for ID',
					this.id,
					'.asset.invoiceID',
					this.asset.data,
					'Existing invoiceID registered as invoice transaction',
				));
		}
        if (this.amount.lt(invoiceTransaction.asset.requestedAmount)) {
            errors.push( new TransactionError(
                'Paid amount is lower than amount stated on invoice',
                this.id,
                '.amount',
                transaction.requestedAmount,
                'Expected amount to be equal or greated than `requestedAmount`',
            ));
        }
github LiskHQ / lisk-sdk-examples / workshop / transactions / invoice_transaction.js View on Github external
undoAsset(store) {
		const errors = [];
		const sender = {}; // Step 4.1 retrieve sender from store (replace code)
		const invoiceId = sender.asset.invoicesSent.find(id => id === this.id);

		if (invoiceId === undefined || sender.asset.invoiceCount === 0) {
			errors.push(
				new TransactionError(
					'Invoice ID does not exist in sender.asset.invoicesSent',
					this.id,
					'sender.asset.invoicesSent',
					sender.asset.invoicesSent,
					'A string value',
				),
			);
		} else {
			// Step 4.2 and 4.3: Undo logic comes here
			// Step 4.4: Save updated sender account
		}

		return errors;
	}
}
github LiskHQ / lisk-sdk-examples / transport / transactions / solutions / light-alarm.js View on Github external
validateAsset() {
        // Static checks for presence of `timestamp` which holds the timestamp of when the alarm was triggered
        const errors = [];
        if (!this.timestamp || typeof this.timestamp !== 'number') {
            errors.push(
                new TransactionError(
                    'Invalid ".timestamp" defined on transaction',
                    this.id,
                    '.timestamp',
                    this.timestamp
                )
            );
        }
        return errors;
    }
github LiskHQ / lisk-sdk / framework / src / modules / chain / transaction_pool / transaction_pool.js View on Github external
async getTransactionAndProcessSignature(signature) {
		if (!signature) {
			const message = 'Unable to process signature, signature not provided';
			this.logger.error(message);
			throw [new TransactionError(message, '', '.signature')];
		}
		// Grab transaction with corresponding ID from transaction pool
		const transaction = this.getMultisignatureTransaction(
			signature.transactionId
		);

		if (!transaction) {
			const message =
				'Unable to process signature, corresponding transaction not found';
			this.logger.error(message, { signature });
			throw [new TransactionError(message, '', '.signature')];
		}

		const transactionResponse = await transactionsModule.processSignature(
			this.storage
		)(transaction, signature);
		if (
			transactionResponse.status === TransactionStatus.FAIL &&
			transactionResponse.errors.length > 0
		) {
			const message = transactionResponse.errors[0].message;
			this.logger.error(message, { signature });
			throw transactionResponse.errors;
		}
		return transactionResponse;
	}
github LiskHQ / lisk-sdk / lisk / src / transactions / 6_in_transfer_transaction.ts View on Github external
protected validateAsset(): ReadonlyArray {
		validator.validate(inTransferAssetFormatSchema, this.asset);
		const errors = convertToAssetError(
			this.id,
			validator.errors
		) as TransactionError[];

		if (this.type !== TRANSACTION_INTRANSFER_TYPE) {
			errors.push(
				new TransactionError(
					'Invalid type',
					this.id,
					'.type',
					this.type,
					TRANSACTION_INTRANSFER_TYPE
				)
			);
		}

		// Per current protocol, this recipientId and recipientPublicKey must be empty
		if (this.recipientId) {
			errors.push(
				new TransactionError(
					'RecipientId is expected to be undefined.',
					this.id,
					'.recipientId',
github LiskHQ / lisk-sdk / lisk / src / transactions / 7_out_transfer_transaction.ts View on Github external
if (this.type !== TRANSACTION_OUTTRANSFER_TYPE) {
			errors.push(
				new TransactionError(
					'Invalid type',
					this.id,
					'.type',
					this.type,
					TRANSACTION_OUTTRANSFER_TYPE
				)
			);
		}

		// Amount has to be greater than 0
		if (this.amount.lte(0)) {
			errors.push(
				new TransactionError(
					'Amount must be greater than zero for outTransfer transaction',
					this.id,
					'.amount',
					this.amount.toString()
				)
			);
		}

		if (!this.fee.eq(OUT_TRANSFER_FEE)) {
			errors.push(
				new TransactionError(
					`Fee must be equal to ${OUT_TRANSFER_FEE}`,
					this.id,
					'.fee',
					this.fee.toString(),
					OUT_TRANSFER_FEE
github LiskHQ / lisk-sdk / framework / src / modules / chain / transaction_pool / transaction_pool.js View on Github external
if (this.transactionInPool(transaction.id)) {
			throw [
				new TransactionError(
					`Transaction is already processed: ${transaction.id}`,
					transaction.id,
					'.id',
				),
			];
		}

		if (
			this.slots.getSlotNumber(transaction.timestamp) >
			this.slots.getSlotNumber()
		) {
			throw [
				new TransactionError(
					'Invalid transaction timestamp. Timestamp is in the future',
					transaction.id,
					'.timestamp',
				),
			];
		}

		if (transaction.bundled) {
			return this.addBundledTransaction(transaction);
		}
		const { transactionsResponses } = await this.verifyTransactions([
			transaction,
		]);
		if (transactionsResponses[0].status === TransactionStatus.OK) {
			return this.addVerifiedTransaction(transaction);
		}
github LiskHQ / lisk-sdk / framework / src / modules / chain / transaction_pool / transaction_pool.js View on Github external
async processUnconfirmedTransaction(transaction) {
		if (this.transactionInPool(transaction.id)) {
			throw [
				new TransactionError(
					`Transaction is already processed: ${transaction.id}`,
					transaction.id,
					'.id'
				),
			];
		}

		if (
			this.slots.getSlotNumber(transaction.timestamp) >
			this.slots.getSlotNumber()
		) {
			throw [
				new TransactionError(
					'Invalid transaction timestamp. Timestamp is in the future',
					transaction.id,
					'.timestamp'
github LiskHQ / lisk-sdk-examples / transport / transactions / register-packet.js View on Github external
balance: packetBalanceWithPostage.toString(),
                    asset: {
                        recipient: this.recipientId,
                        sender: this.senderId,
                        security: this.asset.security,
                        postage: this.asset.postage,
                        minTrust: this.asset.minTrust,
                        status: 'pending',
                        carrier: null
                    }
                }
            };
            store.account.set(packet.address, updatedPacketAccount);
        } else {
            errors.push(
                new TransactionError(
                    'packet has already been registered',
                    packet.asset.status
                )
            );
        }
        return errors;
    }
github LiskHQ / lisk-sdk-examples / workshop / transactions / invoice_transaction.js View on Github external
!this.asset.requestedAmount ||
			typeof this.asset.requestedAmount !== 'string'
		) {
			errors.push(
				new TransactionError(
					'Invalid "asset.requestedAmount" defined on transaction',
					this.id,
					'.asset.requestedAmount',
					this.asset.requestedAmount,
					'A string value',
				),
			);
		}
		if (!this.asset.description || typeof this.asset.description !== 'string') {
			errors.push(
				new TransactionError(
					'Invalid "asset.description" defined on transaction',
					this.id,
					'.asset.description',
					this.asset.description,
					'A string value',
				),
			);
		}
		return errors;
	}