xrpl
Version:
A TypeScript/JavaScript API for interacting with the XRP Ledger in Node.js and the browser
64 lines • 3.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateBatch = exports.BatchFlags = void 0;
const errors_1 = require("../../errors");
const utils_1 = require("../utils");
const common_1 = require("./common");
var BatchFlags;
(function (BatchFlags) {
BatchFlags[BatchFlags["tfAllOrNothing"] = 65536] = "tfAllOrNothing";
BatchFlags[BatchFlags["tfOnlyOne"] = 131072] = "tfOnlyOne";
BatchFlags[BatchFlags["tfUntilFailure"] = 262144] = "tfUntilFailure";
BatchFlags[BatchFlags["tfIndependent"] = 524288] = "tfIndependent";
})(BatchFlags || (exports.BatchFlags = BatchFlags = {}));
function validateBatch(tx) {
var _a;
(0, common_1.validateBaseTransaction)(tx);
(0, common_1.validateRequiredField)(tx, 'RawTransactions', common_1.isArray);
tx.RawTransactions.forEach((rawTxObj, index) => {
if (!(0, common_1.isRecord)(rawTxObj)) {
throw new errors_1.ValidationError(`Batch: RawTransactions[${index}] is not object.`);
}
(0, common_1.validateRequiredField)(rawTxObj, 'RawTransaction', common_1.isRecord, {
paramName: `RawTransactions[${index}].RawTransaction`,
txType: 'Batch',
});
const rawTx = rawTxObj.RawTransaction;
if (rawTx.TransactionType === 'Batch') {
throw new errors_1.ValidationError(`Batch: RawTransactions[${index}] is a Batch transaction. Cannot nest Batch transactions.`);
}
if (!(0, utils_1.hasFlag)(rawTx, common_1.GlobalFlags.tfInnerBatchTxn, 'tfInnerBatchTxn')) {
throw new errors_1.ValidationError(`Batch: RawTransactions[${index}] must contain the \`tfInnerBatchTxn\` flag.`);
}
});
(0, common_1.validateOptionalField)(tx, 'BatchSigners', common_1.isArray);
(_a = tx.BatchSigners) === null || _a === void 0 ? void 0 : _a.forEach((signerObj, index) => {
if (!(0, common_1.isRecord)(signerObj)) {
throw new errors_1.ValidationError(`Batch: BatchSigners[${index}] is not object.`);
}
const signerRecord = signerObj;
(0, common_1.validateRequiredField)(signerRecord, 'BatchSigner', common_1.isRecord, {
paramName: `BatchSigners[${index}].BatchSigner`,
txType: 'Batch',
});
const signer = signerRecord.BatchSigner;
(0, common_1.validateRequiredField)(signer, 'Account', common_1.isString, {
paramName: `BatchSigners[${index}].Account`,
txType: 'Batch',
});
(0, common_1.validateOptionalField)(signer, 'SigningPubKey', common_1.isString, {
paramName: `BatchSigners[${index}].SigningPubKey`,
txType: 'Batch',
});
(0, common_1.validateOptionalField)(signer, 'TxnSignature', common_1.isString, {
paramName: `BatchSigners[${index}].TxnSignature`,
txType: 'Batch',
});
(0, common_1.validateOptionalField)(signer, 'Signers', common_1.isArray, {
paramName: `BatchSigners[${index}].Signers`,
txType: 'Batch',
});
});
}
exports.validateBatch = validateBatch;
//# sourceMappingURL=batch.js.map