UNPKG

@solarity/hardhat-migrate

Version:
56 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateKeyDeploymentFields = validateKeyDeploymentFields; exports.validateKeyTxFields = validateKeyTxFields; exports.isTypechainFactoryClass = isTypechainFactoryClass; exports.isBytecodeFactory = isBytecodeFactory; exports.isEthersContractFactory = isEthersContractFactory; const errors_1 = require("../errors"); function validateKeyDeploymentFields(_target, _propertyKey, descriptor) { const originalMethod = descriptor.value; descriptor.value = function (...args) { const key = args[0]; baseTxValidation(key, "KeyDeploymentFields"); return originalMethod.apply(this, args); }; return descriptor; } function validateKeyTxFields(_target, _propertyKey, descriptor) { const originalMethod = descriptor.value; descriptor.value = function (...args) { const key = args[0]; baseTxValidation(key, "KeyTransactionFields"); if (!key.to || key.to === "") { throw new errors_1.MigrateError(`KeyTransactionFields.to is not valid`); } if (key.name === undefined) { throw new errors_1.MigrateError(`KeyTransactionFields.name is not valid`); } return originalMethod.apply(this, args); }; return descriptor; } function isTypechainFactoryClass(instance) { return instance.createInterface !== undefined; } function isBytecodeFactory(instance) { return instance.contractName !== undefined; } function isEthersContractFactory(instance) { return instance.interface !== undefined && instance.bytecode !== undefined; } function baseTxValidation(key, namespace) { if (!key.data || key.data === "") { throw new errors_1.MigrateError(`${namespace}.data is not valid`); } if (!key.from || key.from === "") { throw new errors_1.MigrateError(`${namespace}.from is not valid`); } if (!key.chainId || key.chainId === 0n) { throw new errors_1.MigrateError(`${namespace}.chainId is not valid`); } if (key.value === undefined) { throw new errors_1.MigrateError(`${namespace}.value is not valid`); } } //# sourceMappingURL=type-checks.js.map