UNPKG

@aeternity/aepp-sdk

Version:
1,115 lines (987 loc) 39.1 kB
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys"; import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"; import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter"; import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"; import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each"; import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"; import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties"; import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property"; import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray"; import _merge from "ramda/src/merge"; import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator"; import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array"; import _Object$freeze from "@babel/runtime-corejs3/core-js-stable/object/freeze"; import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat"; import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map"; import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator"; function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context18; _forEachInstanceProperty(_context18 = ownKeys(Object(source), true)).call(_context18, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context19; _forEachInstanceProperty(_context19 = ownKeys(Object(source))).call(_context19, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; } /* * ISC License (ISC) * Copyright (c) 2018 aeternity developers * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /** * Contract module - routines to interact with the æternity contract * * High level documentation of the contracts are available at * https://github.com/aeternity/protocol/tree/master/contracts and * * @module @aeternity/aepp-sdk/es/ae/contract * @export Contract * @example import { Contract } from '@aeternity/aepp-sdk' */ import Ae from './'; import ContractCompilerAPI from '../contract/compiler'; import ContractBase from '../contract'; import getContractInstance from '../contract/aci'; import NodePool from '../node-pool'; import { AMOUNT, DEPOSIT, DRY_RUN_ACCOUNT, GAS, MIN_GAS_PRICE } from '../tx/builder/schema'; import { decode, produceNameId } from '../tx/builder/helpers'; import TxObject from '../tx/tx-object'; function _sendAndProcess(_x, _x2, _x3, _x4) { return _sendAndProcess2.apply(this, arguments); } /** * Handle contract call error * @function * @private * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source contract source code * @param {String} name name of called method * @param {Object} result call result object * @throws Error Decoded error * @return {Promise<void>} */ function _sendAndProcess2() { _sendAndProcess2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tx, source, name, options) { var txData, result, txInfo; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return this.send(tx, options); case 2: txData = _context.sent; result = { hash: txData.hash, tx: TxObject({ tx: txData.rawTx }), txData: txData, rawTx: txData.rawTx }; if (!(options.waitMined === false)) { _context.next = 6; break; } return _context.abrupt("return", result); case 6: _context.next = 8; return this.getTxInfo(txData.hash); case 8: txInfo = _context.sent; _context.next = 11; return this._handleCallError(source, name, txInfo); case 11: return _context.abrupt("return", _objectSpread(_objectSpread({}, result), {}, { result: txInfo })); case 12: case "end": return _context.stop(); } } }, _callee, this); })); return _sendAndProcess2.apply(this, arguments); } function _handleCallError(_x5, _x6, _x7) { return _handleCallError2.apply(this, arguments); } /** * Encode call data for contract call * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source Contract source code * @param {String} name Name of function to call * @param {Array} args Argument's for call * @param {Object} [options={}] Options * @param {Object} [options.filesystem={}] Contract external namespaces map * @return {Promise<String>} */ function _handleCallError2() { _handleCallError2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(source, name, result) { var error, message; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: if (!(result.returnType === 'ok')) { _context2.next = 2; break; } return _context2.abrupt("return"); case 2: _context2.next = 4; return this.contractDecodeCallResultAPI(source, name, result.returnValue, result.returnType); case 4: error = _context2.sent; message = error[{ revert: 'abort' }[result.returnType] || result.returnType][0]; throw new Error("Invocation failed".concat(message ? ": \"".concat(message, "\"") : '')); case 7: case "end": return _context2.stop(); } } }, _callee2, this); })); return _handleCallError2.apply(this, arguments); } function contractEncodeCall(_x8, _x9, _x10, _x11) { return _contractEncodeCall.apply(this, arguments); } /** * Decode contract call result data * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source - source code * @param {String } fn - function name * @param {String} callValue - result call data * @param {String} callResult - result status * @param {Object} [options={}] Options * @param {Object} [options.filesystem={}] Contract external namespaces map * @return {Promise<String>} Result object * @example * const decodedData = await client.contractDecodeData(SourceCode ,'functionName', 'cb_asdasdasd...', 'ok|revert')lt */ function _contractEncodeCall() { _contractEncodeCall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(source, name, args, options) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: return _context3.abrupt("return", this.contractEncodeCallDataAPI(source, name, args, options)); case 1: case "end": return _context3.stop(); } } }, _callee3, this); })); return _contractEncodeCall.apply(this, arguments); } function contractDecodeData(_x12, _x13, _x14, _x15, _x16) { return _contractDecodeData.apply(this, arguments); } /** * Static contract call(using dry-run) * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source Contract source code * @param {String} address Contract address * @param {String} name Name of function to call * @param {Array|String} args Argument's or callData for call/deploy transaction * @param {Object} [options] * @param {Number|String} [options.top] Block height or hash on which you want to call contract * @param {String} [options.bytecode] Block hash on which you want to call contract * @param {Object} [options.filesystem] Contract external namespaces map * @return {Promise<Object>} Result object * @example * const callResult = await client.contractCallStatic(source, address, fnName, args) * { * result: TX_DATA, * decode: (type) => Decode call result * } */ function _contractDecodeData() { _contractDecodeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(source, fn, callValue, callResult, options) { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: return _context4.abrupt("return", this.contractDecodeCallResultAPI(source, fn, callValue, callResult, options)); case 1: case "end": return _context4.stop(); } } }, _callee4, this); })); return _contractDecodeData.apply(this, arguments); } function contractCallStatic(_x17, _x18, _x19) { return _contractCallStatic.apply(this, arguments); } /** * Call contract function * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source Contract source code * @param {String} address Contract address or AENS name * @param {String} name Name of function to call * @param {Array|String} argsOrCallData Argument's array or callData for call function * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit) * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object * @example * const callResult = await client.contractCall(source, address, fnName, args = [], options) * { * hash: TX_HASH, * result: TX_DATA, * decode: (type) => Decode call result * } */ function _contractCallStatic() { _contractCallStatic = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(source, address, name) { var _this = this; var args, options, callerId, txOpt, tx, _yield$this$txDryRun, callObj, dryRunOther, returnType, returnValue, _args5 = arguments; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: args = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : []; options = _args5.length > 4 && _args5[4] !== undefined ? _args5[4] : {}; _context5.next = 4; return this.address(options)["catch"](function () { return DRY_RUN_ACCOUNT.pub; }); case 4: callerId = _context5.sent; if (!(typeof options.top === 'number')) { _context5.next = 9; break; } _context5.next = 8; return this.getKeyBlock(options.top); case 8: options.top = _context5.sent.hash; case 9: _context5.t0 = _objectSpread; _context5.t1 = _objectSpread(_objectSpread({}, this.Ae.defaults), options); _context5.t2 = {}; if (!_Array$isArray(args)) { _context5.next = 18; break; } _context5.next = 15; return this.contractEncodeCall(source, name, args, options); case 15: _context5.t3 = _context5.sent; _context5.next = 19; break; case 18: _context5.t3 = args; case 19: _context5.t4 = _context5.t3; _context5.t5 = options.top; if (!_context5.t5) { _context5.next = 26; break; } _context5.next = 24; return this.getAccount(callerId, { hash: options.top }); case 24: _context5.t6 = _context5.sent.nonce; _context5.t5 = _context5.t6 + 1; case 26: _context5.t7 = _context5.t5; _context5.t8 = { callData: _context5.t4, nonce: _context5.t7 }; txOpt = (0, _context5.t0)(_context5.t1, _context5.t2, _context5.t8); if (!(name === 'init')) { _context5.next = 35; break; } _context5.next = 32; return this.contractCreateTx(_objectSpread(_objectSpread({}, txOpt), {}, { code: options.bytecode, ownerId: callerId })); case 32: _context5.t9 = _context5.sent.tx; _context5.next = 48; break; case 35: _context5.t10 = this; _context5.t11 = _objectSpread; _context5.t12 = _objectSpread({}, txOpt); _context5.t13 = {}; _context5.t14 = callerId; _context5.next = 42; return this.resolveName(address, 'ct', { resolveByNode: true }); case 42: _context5.t15 = _context5.sent; _context5.t16 = { callerId: _context5.t14, contractId: _context5.t15 }; _context5.t17 = (0, _context5.t11)(_context5.t12, _context5.t13, _context5.t16); _context5.next = 47; return _context5.t10.contractCallTx.call(_context5.t10, _context5.t17); case 47: _context5.t9 = _context5.sent; case 48: tx = _context5.t9; _context5.next = 51; return this.txDryRun(tx, callerId, options); case 51: _yield$this$txDryRun = _context5.sent; callObj = _yield$this$txDryRun.callObj; dryRunOther = _objectWithoutProperties(_yield$this$txDryRun, ["callObj"]); _context5.next = 56; return this._handleCallError(source, name, callObj); case 56: returnType = callObj.returnType, returnValue = callObj.returnValue; return _context5.abrupt("return", _objectSpread(_objectSpread({}, dryRunOther), {}, { tx: TxObject({ tx: tx }), result: callObj, decode: function decode() { return _this.contractDecodeData(source, name, returnValue, returnType, options); } })); case 58: case "end": return _context5.stop(); } } }, _callee5, this); })); return _contractCallStatic.apply(this, arguments); } function contractCall(_x20, _x21, _x22) { return _contractCall.apply(this, arguments); } /** * Deploy contract to the node * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} code Compiled contract * @param {String} source Contract source code * @param {Array|String} initState Arguments of contract constructor(init) function. Can be array of arguments or callData string * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit) * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object * @return {Promise<Object>} Result object * @example * const deployed = await client.contractDeploy(bytecode, source, init = [], options) * { * owner: OWNER_PUB_KEY, * transaction: TX_HASH, * address: CONTRACT_ADDRESS, * createdAt: Date, * result: DEPLOY_TX_DATA, * call: (fnName, args = [], options) => Call contract function, * callStatic: (fnName, args = [], options) => Static all contract function * } */ function _contractCall() { _contractCall = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, address, name) { var _this2 = this; var argsOrCallData, options, opt, tx, _yield$this$_sendAndP, hash, rawTx, result, txData, _args6 = arguments; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: argsOrCallData = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : []; options = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : {}; opt = _merge(this.Ae.defaults, options); _context6.t0 = this; _context6.t1 = _merge; _context6.t2 = opt; _context6.next = 8; return this.address(opt); case 8: _context6.t3 = _context6.sent; _context6.next = 11; return this.resolveName(address, 'ct', { resolveByNode: true }); case 11: _context6.t4 = _context6.sent; if (!_Array$isArray(argsOrCallData)) { _context6.next = 18; break; } _context6.next = 15; return this.contractEncodeCall(source, name, argsOrCallData, opt); case 15: _context6.t5 = _context6.sent; _context6.next = 19; break; case 18: _context6.t5 = argsOrCallData; case 19: _context6.t6 = _context6.t5; _context6.t7 = { callerId: _context6.t3, contractId: _context6.t4, callData: _context6.t6 }; _context6.t8 = (0, _context6.t1)(_context6.t2, _context6.t7); _context6.next = 24; return _context6.t0.contractCallTx.call(_context6.t0, _context6.t8); case 24: tx = _context6.sent; _context6.next = 27; return this._sendAndProcess(tx, source, name, opt); case 27: _yield$this$_sendAndP = _context6.sent; hash = _yield$this$_sendAndP.hash; rawTx = _yield$this$_sendAndP.rawTx; result = _yield$this$_sendAndP.result; txData = _yield$this$_sendAndP.txData; return _context6.abrupt("return", { hash: hash, rawTx: rawTx, result: result, txData: txData, decode: function decode() { return result ? _this2.contractDecodeData(source, name, result.returnValue, result.returnType, opt) : {}; } }); case 33: case "end": return _context6.stop(); } } }, _callee6, this); })); return _contractCall.apply(this, arguments); } function contractDeploy(_x23, _x24) { return _contractDeploy.apply(this, arguments); } /** * Compile contract source code * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} source Contract sourece code * @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit) * @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object * @return {Promise<Object>} Result object * @example * const compiled = await client.contractCompile(SOURCE_CODE) * { * bytecode: CONTRACT_BYTE_CODE, * deploy: (init = [], options = {}) => Deploy Contract, * encodeCall: (fnName, args = []) => Prepare callData * } */ function _contractDeploy() { _contractDeploy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(code, source) { var _this3 = this; var initState, options, opt, callData, ownerId, _yield$this$contractC, tx, contractId, _yield$this$_sendAndP2, hash, rawTx, result, txData, _args7 = arguments; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: initState = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : []; options = _args7.length > 3 && _args7[3] !== undefined ? _args7[3] : {}; opt = _objectSpread(_objectSpread({}, this.Ae.defaults), options); if (!_Array$isArray(initState)) { _context7.next = 9; break; } _context7.next = 6; return this.contractEncodeCall(source, 'init', initState, opt); case 6: _context7.t0 = _context7.sent; _context7.next = 10; break; case 9: _context7.t0 = initState; case 10: callData = _context7.t0; _context7.next = 13; return this.address(opt); case 13: ownerId = _context7.sent; _context7.next = 16; return this.contractCreateTx(_merge(opt, { callData: callData, code: code, ownerId: ownerId })); case 16: _yield$this$contractC = _context7.sent; tx = _yield$this$contractC.tx; contractId = _yield$this$contractC.contractId; _context7.next = 21; return this._sendAndProcess(tx, source, 'init', opt); case 21: _yield$this$_sendAndP2 = _context7.sent; hash = _yield$this$_sendAndP2.hash; rawTx = _yield$this$_sendAndP2.rawTx; result = _yield$this$_sendAndP2.result; txData = _yield$this$_sendAndP2.txData; return _context7.abrupt("return", _Object$freeze({ result: result, owner: ownerId, transaction: hash, rawTx: rawTx, txData: txData, address: contractId, call: function call(name, args, options) { return _this3.contractCall(source, contractId, name, args, _objectSpread(_objectSpread({}, opt), options)); }, callStatic: function callStatic(name, args, options) { return _this3.contractCallStatic(source, contractId, name, args, _objectSpread(_objectSpread({}, opt), options)); }, createdAt: new Date() })); case 27: case "end": return _context7.stop(); } } }, _callee7, this); })); return _contractDeploy.apply(this, arguments); } function contractCompile(_x25) { return _contractCompile.apply(this, arguments); } /** * Utility method to create a delegate signature for a contract * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String[]} ids The list of id's to prepend * @param {Object} [opt={}] options * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature in hex representation */ function _contractCompile() { _contractCompile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(source) { var _this4 = this; var options, opt, bytecode, _args8 = arguments; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: options = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {}; opt = _objectSpread(_objectSpread({}, this.Ae.defaults), options); _context8.next = 4; return this.compileContractAPI(source, options); case 4: bytecode = _context8.sent; return _context8.abrupt("return", _Object$freeze({ encodeCall: function encodeCall(name, args) { return _this4.contractEncodeCall(source, name, args, opt); }, deploy: function deploy(init, options) { return _this4.contractDeploy(bytecode, source, init, _objectSpread(_objectSpread({}, opt), options)); }, deployStatic: function deployStatic(init, options) { return _this4.contractCallStatic(source, null, 'init', init, _objectSpread(_objectSpread(_objectSpread({}, opt), options), {}, { bytecode: bytecode })); }, bytecode: bytecode })); case 6: case "end": return _context8.stop(); } } }, _callee8, this); })); return _contractCompile.apply(this, arguments); } function delegateSignatureCommon() { return _delegateSignatureCommon.apply(this, arguments); } /** * Helper to generate a signature to delegate a name pre-claim to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} contractId Contract Id * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateSignatureCommon() { _delegateSignatureCommon = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { var _context9; var ids, opt, _args9 = arguments; return _regeneratorRuntime.wrap(function _callee9$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: ids = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : []; opt = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {}; _context10.t0 = this; _context10.t1 = _concatInstanceProperty(Buffer); _context10.t2 = Buffer; _context10.t3 = _concatInstanceProperty; _context10.t4 = Buffer.from(this.getNetworkId(opt)); _context10.t5 = decode; _context10.next = 10; return this.address(opt); case 10: _context10.t6 = _context10.sent; _context10.t7 = (0, _context10.t5)(_context10.t6); _context10.t8 = _context9 = [_context10.t4, _context10.t7]; _context10.t9 = (0, _context10.t3)(_context10.t8).call(_context9, _toConsumableArray(_mapInstanceProperty(ids).call(ids, function (e) { return decode(e); }))); _context10.t10 = _context10.t1.call.call(_context10.t1, _context10.t2, _context10.t9); _context10.t11 = opt; return _context10.abrupt("return", _context10.t0.sign.call(_context10.t0, _context10.t10, _context10.t11).then(function (s) { return Buffer.from(s).toString('hex'); })); case 17: case "end": return _context10.stop(); } } }, _callee9, this); })); return _delegateSignatureCommon.apply(this, arguments); } function delegateNamePreclaimSignature(_x26) { return _delegateNamePreclaimSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a name claim to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} name The name being claimed * @param {String} contractId Contract Id * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateNamePreclaimSignature() { _delegateNamePreclaimSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(contractId) { var opt, _args10 = arguments; return _regeneratorRuntime.wrap(function _callee10$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: opt = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}; return _context11.abrupt("return", this.delegateSignatureCommon([contractId], opt)); case 2: case "end": return _context11.stop(); } } }, _callee10, this); })); return _delegateNamePreclaimSignature.apply(this, arguments); } function delegateNameClaimSignature(_x27, _x28) { return _delegateNameClaimSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a name transfer to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} contractId Contract Id * @param {String} name The name being transferred * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateNameClaimSignature() { _delegateNameClaimSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(contractId, name) { var opt, _args11 = arguments; return _regeneratorRuntime.wrap(function _callee11$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: opt = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : {}; return _context12.abrupt("return", this.delegateSignatureCommon([produceNameId(name), contractId], opt)); case 2: case "end": return _context12.stop(); } } }, _callee11, this); })); return _delegateNameClaimSignature.apply(this, arguments); } function delegateNameTransferSignature(_x29, _x30) { return _delegateNameTransferSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a name revoke to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} contractId Contract Id * @param {String} name The name being revoked * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateNameTransferSignature() { _delegateNameTransferSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(contractId, name) { var opt, _args12 = arguments; return _regeneratorRuntime.wrap(function _callee12$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: opt = _args12.length > 2 && _args12[2] !== undefined ? _args12[2] : {}; return _context13.abrupt("return", this.delegateSignatureCommon([produceNameId(name), contractId], opt)); case 2: case "end": return _context13.stop(); } } }, _callee12, this); })); return _delegateNameTransferSignature.apply(this, arguments); } function delegateNameRevokeSignature(_x31, _x32) { return _delegateNameRevokeSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a Oracle register to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} contractId Contract Id * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateNameRevokeSignature() { _delegateNameRevokeSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(contractId, name) { var opt, _args13 = arguments; return _regeneratorRuntime.wrap(function _callee13$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: opt = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : {}; return _context14.abrupt("return", this.delegateSignatureCommon([produceNameId(name), contractId], opt)); case 2: case "end": return _context14.stop(); } } }, _callee13, this); })); return _delegateNameRevokeSignature.apply(this, arguments); } function delegateOracleRegisterSignature(_x33) { return _delegateOracleRegisterSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a Oracle extend to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} contractId Contract Id * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateOracleRegisterSignature() { _delegateOracleRegisterSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(contractId) { var opt, _args14 = arguments; return _regeneratorRuntime.wrap(function _callee14$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: opt = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {}; return _context15.abrupt("return", this.delegateSignatureCommon([contractId], opt)); case 2: case "end": return _context15.stop(); } } }, _callee14, this); })); return _delegateOracleRegisterSignature.apply(this, arguments); } function delegateOracleExtendSignature(_x34) { return _delegateOracleExtendSignature.apply(this, arguments); } /** * Helper to generate a signature to delegate a Oracle respond to a contract. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @category async * @param {String} queryId Oracle Query Id * @param {String} contractId Contract Id * @param {{ onAccount: String | Object }} [opt={}] opt Options * @return {Promise<String>} Signature for delegation */ function _delegateOracleExtendSignature() { _delegateOracleExtendSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(contractId) { var opt, _args15 = arguments; return _regeneratorRuntime.wrap(function _callee15$(_context16) { while (1) { switch (_context16.prev = _context16.next) { case 0: opt = _args15.length > 1 && _args15[1] !== undefined ? _args15[1] : {}; return _context16.abrupt("return", this.delegateSignatureCommon([contractId], opt)); case 2: case "end": return _context16.stop(); } } }, _callee15, this); })); return _delegateOracleExtendSignature.apply(this, arguments); } function delegateOracleRespondSignature(_x35, _x36) { return _delegateOracleRespondSignature.apply(this, arguments); } /** * Contract Stamp * * Provide contract implementation * {@link module:@aeternity/aepp-sdk/es/ae--Ae} clients. * @function * @alias module:@aeternity/aepp-sdk/es/ae/contract * @rtype Stamp * @param {Object} [options={}] - Initializer object * @return {Object} Contract instance * @example * import Transaction from '@aeternity/aepp-sdk/es/tx/tx * import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory * import ChainNode from '@aeternity/aepp-sdk/es/chain/node * import ContractCompilerAPI from '@aeternity/aepp-sdk/es/contract/compiler * // or using bundle * import { * Transaction, * MemoryAccount, * ChainNode, * ContractCompilerAPI * } from '@aeternity/aepp-sdk * * const ContractWithAE = await Contract * .compose(Transaction, MemoryAccount, ChainNode) // AE implementation * .compose(ContractCompilerAPI) // ContractBase implementation * const client = await ContractWithAe({ url, internalUrl, compilerUrl, keypair, ... }) * */ function _delegateOracleRespondSignature() { _delegateOracleRespondSignature = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(queryId, contractId) { var opt, _args16 = arguments; return _regeneratorRuntime.wrap(function _callee16$(_context17) { while (1) { switch (_context17.prev = _context17.next) { case 0: opt = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : {}; return _context17.abrupt("return", this.delegateSignatureCommon([queryId, contractId], opt)); case 2: case "end": return _context17.stop(); } } }, _callee16, this); })); return _delegateOracleRespondSignature.apply(this, arguments); } export var ContractAPI = Ae.compose(ContractBase, { methods: { getContractInstance: getContractInstance, contractCompile: contractCompile, contractCallStatic: contractCallStatic, contractDeploy: contractDeploy, contractCall: contractCall, contractEncodeCall: contractEncodeCall, contractDecodeData: contractDecodeData, _handleCallError: _handleCallError, _sendAndProcess: _sendAndProcess, // Delegation for contract // AENS delegateSignatureCommon: delegateSignatureCommon, delegateNamePreclaimSignature: delegateNamePreclaimSignature, delegateNameClaimSignature: delegateNameClaimSignature, delegateNameTransferSignature: delegateNameTransferSignature, delegateNameRevokeSignature: delegateNameRevokeSignature, // Oracle delegateOracleRegisterSignature: delegateOracleRegisterSignature, delegateOracleExtendSignature: delegateOracleExtendSignature, delegateOracleRespondSignature: delegateOracleRespondSignature }, deepProps: { Ae: { defaults: { deposit: DEPOSIT, gasPrice: MIN_GAS_PRICE, amount: AMOUNT, gas: GAS } } } }); export var Contract = ContractAPI.compose(NodePool); export var ContractWithCompiler = Contract.compose(ContractCompilerAPI); export default ContractWithCompiler; //# sourceMappingURL=contract.js.map