Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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`',
));
}
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;
}
}
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;
}
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;
}
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',
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
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);
}
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'
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;
}
!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;
}