@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
127 lines (108 loc) • 4.09 kB
JavaScript
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
import BigNumber from 'bignumber.js';
import { MAX_AUTH_FUN_GAS, TX_TYPE } from '../../tx/builder/schema';
import { buildTx } from '../../tx/builder';
import { hash } from '../../utils/crypto';
export var prepareGaParams = function prepareGaParams(ins) {
return /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(authData, authFnName) {
var _context;
var gas;
return _regeneratorRuntime.wrap(function _callee$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!(_typeof(authData) !== 'object')) {
_context2.next = 2;
break;
}
throw new Error('AuthData must be an object');
case 2:
if (!(authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS))) {
_context2.next = 4;
break;
}
throw new Error(_concatInstanceProperty(_context = "the maximum gas value for ga authFun is ".concat(MAX_AUTH_FUN_GAS, ", got ")).call(_context, authData.gas));
case 4:
gas = authData.gas || MAX_AUTH_FUN_GAS;
if (!authData.callData) {
_context2.next = 11;
break;
}
if (!(authData.callData.split('_')[0] !== 'cb')) {
_context2.next = 8;
break;
}
throw new Error('Auth data must be a string with "cb" prefix.');
case 8:
return _context2.abrupt("return", {
authCallData: authData.callData,
gas: gas
});
case 11:
if (!(!authData.source || !authData.args)) {
_context2.next = 13;
break;
}
throw new Error('Auth data must contain source code and arguments.');
case 13:
_context2.next = 15;
return ins.contractEncodeCall(authData.source, authFnName, authData.args);
case 15:
_context2.t0 = _context2.sent;
_context2.t1 = gas;
return _context2.abrupt("return", {
authCallData: _context2.t0,
gas: _context2.t1
});
case 18:
case "end":
return _context2.stop();
}
}
}, _callee);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
};
export var getContractAuthFan = function getContractAuthFan(ins) {
return /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(source, fnName) {
var _yield$ins$contractCo, bytecode;
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return ins.contractCompile(source);
case 2:
_yield$ins$contractCo = _context3.sent;
bytecode = _yield$ins$contractCo.bytecode;
return _context3.abrupt("return", {
bytecode: bytecode,
authFun: hash(fnName)
});
case 5:
case "end":
return _context3.stop();
}
}
}, _callee2);
}));
return function (_x3, _x4) {
return _ref2.apply(this, arguments);
};
}();
};
export var wrapInEmptySignedTx = function wrapInEmptySignedTx(rlp) {
return buildTx({
encodedTx: rlp,
signatures: []
}, TX_TYPE.signed);
};
//# sourceMappingURL=helpers.js.map