near-typechain
Version:
24 lines (23 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFullDefinitionFromAbi = exports._getTypesSection = void 0;
const contract_1 = require("./contract");
const imports_1 = require("./imports");
const _getTypeFromFunctions = (functions) => {
return functions.filter((f) => f.hasArgs && f.argsType).map((f) => { var _a; return (_a = f.argsType) === null || _a === void 0 ? void 0 : _a.type; });
};
const _getTypesSection = (contractDef) => {
const typesCall = _getTypeFromFunctions(contractDef.callFunctions);
const typesView = _getTypeFromFunctions(contractDef.viewFunctions);
// TODO: add return types from view fn`s
const fnTypes = [...typesCall, ...typesView];
return fnTypes.map((t) => `export ${t}`).join('\n');
};
exports._getTypesSection = _getTypesSection;
const getFullDefinitionFromAbi = (abi) => {
const contractDef = (0, contract_1.getContractTypeDefinition)(abi);
const typesSection = (0, exports._getTypesSection)(contractDef);
const importsSection = (0, imports_1.getImportsForDefinition)();
return [importsSection, typesSection, contractDef.contract].join('\n\n');
};
exports.getFullDefinitionFromAbi = getFullDefinitionFromAbi;