UNPKG

@mavrykdynamics/taquito-local-forging

Version:

Provide local forging functionality to be with taquito

57 lines (56 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateMissingProperty = exports.validateOperationKind = void 0; const operation_1 = require("./schema/operation"); const OperationKindMapping = { activate_account: operation_1.ActivationSchema, reveal: operation_1.RevealSchema, delegation: operation_1.DelegationSchema, transaction: operation_1.TransactionSchema, origination: operation_1.OriginationSchema, ballot: operation_1.BallotSchema, attestation: operation_1.AttestationSchema, attestation_with_dal: operation_1.AttestationWithDalSchema, seed_nonce_revelation: operation_1.SeedNonceRevelationSchema, proposals: operation_1.ProposalsSchema, register_global_constant: operation_1.RegisterGlobalConstantSchema, transfer_ticket: operation_1.TransferTicketSchema, increase_paid_storage: operation_1.IncreasePaidStorageSchema, update_consensus_key: operation_1.UpdateConsensusKeySchema, drain_delegate: operation_1.DrainDelegateSchema, set_deposits_limit: operation_1.SetDepositsLimitSchema, smart_rollup_originate: operation_1.SmartRollupOriginateSchema, smart_rollup_add_messages: operation_1.SmartRollupAddMessagesSchema, smart_rollup_execute_outbox_message: operation_1.SmartRollupExecuteOutboxMessageSchema, dal_publish_commitment: operation_1.DalPublishCommitmentSchema, failing_noop: operation_1.FailingNoopSchema, }; // Asymmetric difference: only account for things in arr2 that are not present in arr1, not vice versa const getArrayDifference = (arr1, arr2) => { return arr2.filter((x) => !arr1.includes(x)); }; const deleteArrayElementByValue = (array, item) => { return array.filter((e) => e !== item); }; /** * @returns A boolean value to indicate whether the operation kind is valid or not */ const validateOperationKind = (opKind) => { const opKindList = Object.keys(OperationKindMapping); return opKindList.includes(opKind); }; exports.validateOperationKind = validateOperationKind; /** * returns 0 when the two array of properties are identical or the passed property * does not have any missing parameters from the corresponding schema * * @returns array element differences if there are missing required property keys */ const validateMissingProperty = (operationContent) => { const kind = operationContent.kind; const keys = Object.keys(operationContent); const cleanKeys = deleteArrayElementByValue(keys, 'kind'); const schemaKeys = Object.keys(OperationKindMapping[kind]); return getArrayDifference(cleanKeys, schemaKeys); }; exports.validateMissingProperty = validateMissingProperty;