Skip to content

Commit

Permalink
refactor(constructionPayloads): replace Number conversion with regex …
Browse files Browse the repository at this point in the history
…in op validation

Refs cardano-foundation#199
  • Loading branch information
tomasBustamante committed Nov 19, 2020
1 parent b1cfc77 commit 01233e3
Showing 1 changed file with 5 additions and 4 deletions.
@@ -1,4 +1,5 @@
/* eslint-disable camelcase */
/* eslint-disable wrap-regex */
import CardanoWasm, {
BigNum,
Ed25519Signature,
Expand Down Expand Up @@ -333,12 +334,12 @@ const validateAndParseTransactionOutputs = (
logger.error('[validateAndParseTransactionOutputs] Output has missing address field');
throw ErrorFactory.transactionOutputsParametersMissingError('Output has missing address field');
}
const value = Number(output.amount?.value);
const value = output.amount?.value;
if (!value) {
logger.error('[validateAndParseTransactionOutputs] Output has missing amount value field');
throw ErrorFactory.transactionOutputsParametersMissingError('Output has missing amount value field');
}
if (value <= 0) {
if (/^-\d+/.test(value)) {
logger.error('[validateAndParseTransactionOutputs] Output has negative value');
throw ErrorFactory.transactionOutputsParametersMissingError('Output has negative amount value');
}
Expand Down Expand Up @@ -366,12 +367,12 @@ const validateAndParseTransactionInputs = (
logger.error('[validateAndParseTransactionInputs] Input has missing transactionId and index');
throw ErrorFactory.transactionInputsParametersMissingError('Input has invalid coin_identifier field');
}
const value = Number(input.amount?.value);
const value = input.amount?.value;
if (!value) {
logger.error('[validateAndParseTransactionInputs] Input has missing amount value field');
throw ErrorFactory.transactionInputsParametersMissingError('Input has missing amount value field');
}
if (value >= 0) {
if (/^\+?\d+/.test(value)) {
logger.error('[validateAndParseTransactionInputs] Input has positive value');
throw ErrorFactory.transactionInputsParametersMissingError('Input has positive amount value');
}
Expand Down

0 comments on commit 01233e3

Please sign in to comment.