@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
46 lines (45 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Abi = void 0;
const parse_cosmwasm_schema_1 = require("parse-cosmwasm-schema");
class Abi {
constructor(abiJson) {
this.json = abiJson;
this.messages = [];
}
async parseSchema() {
const parseExecuteMsg = async (schema) => {
const tree = await (0, parse_cosmwasm_schema_1.parseSchema)(schema);
const messages = [];
if (tree.value.variants === undefined) {
return messages;
}
tree.value.variants.forEach((variant) => {
Object.entries(variant.value.members).forEach(([fnName, fnBody]) => {
const msgArgs = [];
Object.entries(fnBody.value.members).forEach(([argName, argBody]) => {
const msgArg = {
name: argName,
type: rustReprAlt(argBody)
};
msgArgs.push(msgArg);
});
const message = {
args: msgArgs,
identifier: fnName
};
messages.push(message);
});
});
return messages;
};
const rustReprAlt = (node) => {
if (node.ref === undefined) {
return (0, parse_cosmwasm_schema_1.rustRepr)({ ...node, ref: undefined });
}
return (0, parse_cosmwasm_schema_1.rustRepr)(node);
};
this.messages = await parseExecuteMsg(this.json);
}
}
exports.Abi = Abi;