test-triam-base-contract
Version:
Low level triam smart cotnract support library
121 lines (98 loc) • 3.36 kB
JavaScript
;
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);var value = info.value;
} catch (error) {
reject(error);return;
}if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}_next(undefined);
});
};
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.exec = exec;
var _state = require("./state");
var _storage2 = require("./storage");
var _error = require("./error");
/**
* @return {string}
*/
function exec(instance) {
//check interface contract
if (typeof new instance().main !== "function") {
throw new Error("Contract dose not have function main");
}
if (typeof new instance().fallback !== "function") {
throw new Error("Contract dose not have function fallback");
}
if (typeof new instance().initialize !== "function") {
throw new Error("Contract dose not have function initialize");
}
var state = (0, _state.State)();
_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var data, _instance, _storage, storage, _instance2, output;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
data = void 0;
if (!(state.functionName === 'constructor')) {
_context.next = 8;
break;
}
if (!(state.currentState !== 'empty')) {
_context.next = 4;
break;
}
throw new Error("Contract was initialize");
case 4:
_instance = new instance();
data = _instance.main(state.functionName, state.param);
_context.next = 14;
break;
case 8:
_storage = (0, _state.Decode)(state.currentState);
storage = new _storage2.Storage(_storage);
_instance2 = new instance(storage.show());
_context.next = 13;
return _instance2.main(state.functionName, state.param);
case 13:
data = _context.sent;
case 14:
_context.next = 16;
return data;
case 16:
output = _context.sent;
if (!(output['error'] === undefined || output['newState'] === undefined || output['ContrOps'] === undefined || output['contract'] === undefined)) {
_context.next = 19;
break;
}
throw new Error('Json format invalid');
case 19:
(0, _state.ReturnData)(output);
case 20:
case "end":
return _context.stop();
}
}
}, _callee);
}))().catch(function (err) {
var output = (0, _state.OutputFormat)(_error.ResultCode.ERR_ENV, "", "", state.contractKey, err.message);
(0, _state.ReturnData)(output);
});
}