UNPKG

@aeternity/aepp-sdk

Version:
1,147 lines (964 loc) 36 kB
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 _objectWithoutProperties from "@babel/runtime-corejs3/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray"; import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty"; import _merge from "ramda/src/merge"; import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator"; 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 _context30; _forEachInstanceProperty(_context30 = ownKeys(Object(source), true)).call(_context30, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context31; _forEachInstanceProperty(_context31 = ownKeys(Object(source))).call(_context31, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; } import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign"; import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify"; import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes"; import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat"; import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values"; import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys"; import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find"; import Chain from './'; import { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter'; import TransactionValidator from '../tx/validator'; import NodePool from '../node-pool'; import { assertedType } from '../utils/crypto'; import { pause } from '../utils/other'; import { isNameValid, produceNameId } from '../tx/builder/helpers'; import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'; /** * ChainNode module * * This is the complement to {@link module:@aeternity/aepp-sdk/es/chain}. * @module @aeternity/aepp-sdk/es/chain/node * @export ChainNode * @example import { ChainNode } from '@aeternity/aepp-sdk' */ function sendTransaction(_x) { return _sendTransaction.apply(this, arguments); } function _sendTransaction() { _sendTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tx) { var _this = this; var options, _R$merge, waitMined, verify, _yield$this$unpackAnd, validation, txObject, txType, _yield$this$api$postT, txHash, txData, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}; _R$merge = _merge(this.Ae.defaults, options), waitMined = _R$merge.waitMined, verify = _R$merge.verify; // Verify transaction before broadcast if (!(verify || typeof verify !== 'boolean' && this.verifyTxBeforeSend)) { _context.next = 11; break; } _context.next = 5; return this.unpackAndVerify(tx); case 5: _yield$this$unpackAnd = _context.sent; validation = _yield$this$unpackAnd.validation; txObject = _yield$this$unpackAnd.tx; txType = _yield$this$unpackAnd.txType; if (!validation.length) { _context.next = 11; break; } throw _Object$assign(new Error('Transaction verification error: ' + _JSON$stringify(validation)), { code: 'TX_VERIFICATION_ERROR', errorData: { validation: validation, tx: txObject, txType: txType }, txHash: tx }); case 11: _context.prev = 11; _context.next = 14; return this.api.postTransaction({ tx: tx }); case 14: _yield$this$api$postT = _context.sent; txHash = _yield$this$api$postT.txHash; if (!waitMined) { _context.next = 37; break; } _context.t0 = _objectSpread; _context.t1 = _objectSpread; _context.t2 = {}; _context.next = 22; return this.poll(txHash, options); case 22: _context.t3 = _context.sent; _context.t4 = (0, _context.t1)(_context.t2, _context.t3); _context.t5 = {}; _context.t6 = { rawTx: tx }; txData = (0, _context.t0)(_context.t4, _context.t5, _context.t6); if (!options.confirm) { _context.next = 36; break; } _context.t7 = _objectSpread; _context.t8 = _objectSpread({}, txData); _context.t9 = {}; _context.next = 33; return this.waitForTxConfirm(txHash, options); case 33: _context.t10 = _context.sent; _context.t11 = { confirmationHeight: _context.t10 }; return _context.abrupt("return", (0, _context.t7)(_context.t8, _context.t9, _context.t11)); case 36: return _context.abrupt("return", txData); case 37: return _context.abrupt("return", { hash: txHash, rawTx: tx }); case 40: _context.prev = 40; _context.t12 = _context["catch"](11); throw _Object$assign(_context.t12, { rawTx: tx, verifyTx: function verifyTx() { return _this.unpackAndVerify(tx); } }); case 43: case "end": return _context.stop(); } } }, _callee, this, [[11, 40]]); })); return _sendTransaction.apply(this, arguments); } function waitForTxConfirm(_x2) { return _waitForTxConfirm.apply(this, arguments); } function _waitForTxConfirm() { _waitForTxConfirm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(txHash) { var options, _yield$this$tx, blockHeight, height, _yield$this$tx2, newBlockHeight, _args2 = arguments; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : { confirm: 3 }; options.confirm = options.confirm === true ? 3 : options.confirm; _context2.next = 4; return this.tx(txHash); case 4: _yield$this$tx = _context2.sent; blockHeight = _yield$this$tx.blockHeight; _context2.next = 8; return this.awaitHeight(blockHeight + options.confirm, options); case 8: height = _context2.sent; _context2.next = 11; return this.tx(txHash); case 11: _yield$this$tx2 = _context2.sent; newBlockHeight = _yield$this$tx2.blockHeight; _context2.t0 = newBlockHeight; _context2.next = _context2.t0 === -1 ? 16 : _context2.t0 === blockHeight ? 17 : 18; break; case 16: throw new Error("Transaction ".concat(txHash, " is removed from chain")); case 17: return _context2.abrupt("return", height); case 18: return _context2.abrupt("return", waitForTxConfirm(txHash, options)); case 19: case "end": return _context2.stop(); } } }, _callee2, this); })); return _waitForTxConfirm.apply(this, arguments); } function getAccount(_x3) { return _getAccount.apply(this, arguments); } /** * @function * @deprecated */ function _getAccount() { _getAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(address) { var _ref2, height, hash, _args3 = arguments; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _ref2 = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}, height = _ref2.height, hash = _ref2.hash; if (!height) { _context3.next = 3; break; } return _context3.abrupt("return", this.api.getAccountByPubkeyAndHeight(address, height)); case 3: if (!hash) { _context3.next = 5; break; } return _context3.abrupt("return", this.api.getAccountByPubkeyAndHash(address, hash)); case 5: return _context3.abrupt("return", this.api.getAccountByPubkey(address)); case 6: case "end": return _context3.stop(); } } }, _callee3, this); })); return _getAccount.apply(this, arguments); } function balance(_x4) { return _balance.apply(this, arguments); } function _balance() { _balance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(address) { var _ref3, height, hash, _ref3$format, format, _yield$this$getAccoun, balance, _args4 = arguments; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _ref3 = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}, height = _ref3.height, hash = _ref3.hash, _ref3$format = _ref3.format, format = _ref3$format === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref3$format; _context4.next = 3; return this.getAccount(address, { hash: hash, height: height }); case 3: _yield$this$getAccoun = _context4.sent; balance = _yield$this$getAccoun.balance; return _context4.abrupt("return", formatAmount(balance, { targetDenomination: format }).toString()); case 6: case "end": return _context4.stop(); } } }, _callee4, this); })); return _balance.apply(this, arguments); } function getBalance(_x5) { return _getBalance.apply(this, arguments); } function _getBalance() { _getBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(address) { var _ref4, height, hash, _ref4$format, format, _yield$this$getAccoun2, balance, _args5 = arguments; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _ref4 = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {}, height = _ref4.height, hash = _ref4.hash, _ref4$format = _ref4.format, format = _ref4$format === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref4$format; _context5.next = 3; return this.getAccount(address, { hash: hash, height: height })["catch"](function (_) { return { balance: 0 }; }); case 3: _yield$this$getAccoun2 = _context5.sent; balance = _yield$this$getAccoun2.balance; return _context5.abrupt("return", formatAmount(balance, { targetDenomination: format }).toString()); case 6: case "end": return _context5.stop(); } } }, _callee5, this); })); return _getBalance.apply(this, arguments); } function tx(_x6) { return _tx.apply(this, arguments); } function _tx() { _tx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(hash) { var _context6; var info, tx, _args6 = arguments; return _regeneratorRuntime.wrap(function _callee6$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: info = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : true; _context7.next = 3; return this.api.getTransactionByHash(hash); case 3: tx = _context7.sent; if (!(_includesInstanceProperty(_context6 = ['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx']).call(_context6, tx.tx.type) && info && tx.blockHeight !== -1)) { _context7.next = 16; break; } _context7.prev = 5; _context7.t0 = _objectSpread; _context7.t1 = _objectSpread({}, tx); _context7.next = 10; return this.getTxInfo(hash); case 10: _context7.t2 = _context7.sent; return _context7.abrupt("return", (0, _context7.t0)(_context7.t1, _context7.t2)); case 14: _context7.prev = 14; _context7.t3 = _context7["catch"](5); case 16: return _context7.abrupt("return", tx); case 17: case "end": return _context7.stop(); } } }, _callee6, this, [[5, 14]]); })); return _tx.apply(this, arguments); } function height() { return _height.apply(this, arguments); } function _height() { _height = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { return _regeneratorRuntime.wrap(function _callee7$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.prev = 0; if (!this._heightPromise) { this._heightPromise = this.api.getCurrentKeyBlockHeight(); } _context8.next = 4; return this._heightPromise; case 4: return _context8.abrupt("return", _context8.sent.height); case 5: _context8.prev = 5; delete this._heightPromise; return _context8.finish(5); case 8: case "end": return _context8.stop(); } } }, _callee7, this, [[0,, 5, 8]]); })); return _height.apply(this, arguments); } function awaitHeight(_x7) { return _awaitHeight.apply(this, arguments); } /** * @deprecated */ function _awaitHeight() { _awaitHeight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(height) { var _context9, _context10; var _ref5, _ref5$interval, interval, _ref5$attempts, attempts, currentHeight, i, _args8 = arguments; return _regeneratorRuntime.wrap(function _callee8$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _ref5 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {}, _ref5$interval = _ref5.interval, interval = _ref5$interval === void 0 ? 5000 : _ref5$interval, _ref5$attempts = _ref5.attempts, attempts = _ref5$attempts === void 0 ? 20 : _ref5$attempts; i = 0; case 2: if (!(i < attempts)) { _context11.next = 14; break; } if (!i) { _context11.next = 6; break; } _context11.next = 6; return pause(interval); case 6: _context11.next = 8; return this.height(); case 8: currentHeight = _context11.sent; if (!(currentHeight >= height)) { _context11.next = 11; break; } return _context11.abrupt("return", currentHeight); case 11: i++; _context11.next = 2; break; case 14: throw new Error(_concatInstanceProperty(_context9 = _concatInstanceProperty(_context10 = "Giving up after ".concat((attempts - 1) * interval, "ms, current height: ")).call(_context10, currentHeight, ", desired height: ")).call(_context9, height)); case 15: case "end": return _context11.stop(); } } }, _callee8, this); })); return _awaitHeight.apply(this, arguments); } function topBlock() { return _topBlock.apply(this, arguments); } function _topBlock() { _topBlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { return _regeneratorRuntime.wrap(function _callee9$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: if (!this._isIrisNode) { _context12.next = 6; break; } _context12.next = 3; return this.api.getTopHeader(); case 3: _context12.t0 = _context12.sent; _context12.next = 11; break; case 6: _context12.t1 = _Object$values; _context12.next = 9; return this.api.getTopBlock(); case 9: _context12.t2 = _context12.sent; _context12.t0 = (0, _context12.t1)(_context12.t2)[0]; case 11: return _context12.abrupt("return", _context12.t0); case 12: case "end": return _context12.stop(); } } }, _callee9, this); })); return _topBlock.apply(this, arguments); } function poll(_x8) { return _poll.apply(this, arguments); } function _poll() { _poll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(th) { var _context13; var _ref6, _ref6$blocks, blocks, _ref6$interval, interval, _ref6$allowUnsynced, allowUnsynced, max, _tx2, _args10 = arguments; return _regeneratorRuntime.wrap(function _callee10$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _ref6 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {}, _ref6$blocks = _ref6.blocks, blocks = _ref6$blocks === void 0 ? 10 : _ref6$blocks, _ref6$interval = _ref6.interval, interval = _ref6$interval === void 0 ? 5000 : _ref6$interval, _ref6$allowUnsynced = _ref6.allowUnsynced, allowUnsynced = _ref6$allowUnsynced === void 0 ? false : _ref6$allowUnsynced; _context14.next = 3; return this.height(); case 3: _context14.t0 = _context14.sent; _context14.t1 = blocks; max = _context14.t0 + _context14.t1; case 6: _context14.next = 8; return this.tx(th)["catch"](function (_) { return null; }); case 8: _tx2 = _context14.sent; if (!(_tx2 && (_tx2.blockHeight !== -1 || allowUnsynced && _tx2.height))) { _context14.next = 11; break; } return _context14.abrupt("return", _tx2); case 11: _context14.next = 13; return pause(interval); case 13: _context14.next = 15; return this.height(); case 15: _context14.t2 = _context14.sent; _context14.t3 = max; if (_context14.t2 < _context14.t3) { _context14.next = 6; break; } case 18: throw new Error(_concatInstanceProperty(_context13 = "Giving up after ".concat(blocks, " blocks mined, transaction hash: ")).call(_context13, th)); case 19: case "end": return _context14.stop(); } } }, _callee10, this); })); return _poll.apply(this, arguments); } function getTxInfo(_x9) { return _getTxInfo.apply(this, arguments); } function _getTxInfo() { _getTxInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(hash) { var result; return _regeneratorRuntime.wrap(function _callee11$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: _context15.next = 2; return this.api.getTransactionInfoByHash(hash); case 2: result = _context15.sent; return _context15.abrupt("return", result.callInfo || result); case 4: case "end": return _context15.stop(); } } }, _callee11, this); })); return _getTxInfo.apply(this, arguments); } function mempool() { return _mempool.apply(this, arguments); } function _mempool() { _mempool = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() { return _regeneratorRuntime.wrap(function _callee12$(_context16) { while (1) { switch (_context16.prev = _context16.next) { case 0: return _context16.abrupt("return", this.api.getPendingTransactions()); case 1: case "end": return _context16.stop(); } } }, _callee12, this); })); return _mempool.apply(this, arguments); } function getCurrentGeneration() { return _getCurrentGeneration.apply(this, arguments); } function _getCurrentGeneration() { _getCurrentGeneration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() { return _regeneratorRuntime.wrap(function _callee13$(_context17) { while (1) { switch (_context17.prev = _context17.next) { case 0: return _context17.abrupt("return", this.api.getCurrentGeneration()); case 1: case "end": return _context17.stop(); } } }, _callee13, this); })); return _getCurrentGeneration.apply(this, arguments); } function getGeneration(_x10) { return _getGeneration.apply(this, arguments); } function _getGeneration() { _getGeneration = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(hashOrHeight) { return _regeneratorRuntime.wrap(function _callee14$(_context18) { while (1) { switch (_context18.prev = _context18.next) { case 0: if (!(typeof hashOrHeight === 'string')) { _context18.next = 2; break; } return _context18.abrupt("return", this.api.getGenerationByHash(hashOrHeight)); case 2: if (!(typeof hashOrHeight === 'number')) { _context18.next = 4; break; } return _context18.abrupt("return", this.api.getGenerationByHeight(hashOrHeight)); case 4: throw new Error('Invalid param, param must be hash or height'); case 5: case "end": return _context18.stop(); } } }, _callee14, this); })); return _getGeneration.apply(this, arguments); } function getMicroBlockTransactions(_x11) { return _getMicroBlockTransactions.apply(this, arguments); } function _getMicroBlockTransactions() { _getMicroBlockTransactions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(hash) { return _regeneratorRuntime.wrap(function _callee15$(_context19) { while (1) { switch (_context19.prev = _context19.next) { case 0: _context19.next = 2; return this.api.getMicroBlockTransactionsByHash(hash); case 2: return _context19.abrupt("return", _context19.sent.transactions); case 3: case "end": return _context19.stop(); } } }, _callee15, this); })); return _getMicroBlockTransactions.apply(this, arguments); } function getKeyBlock(_x12) { return _getKeyBlock.apply(this, arguments); } function _getKeyBlock() { _getKeyBlock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(hashOrHeight) { return _regeneratorRuntime.wrap(function _callee16$(_context20) { while (1) { switch (_context20.prev = _context20.next) { case 0: if (!(typeof hashOrHeight === 'string')) { _context20.next = 2; break; } return _context20.abrupt("return", this.api.getKeyBlockByHash(hashOrHeight)); case 2: if (!(typeof hashOrHeight === 'number')) { _context20.next = 4; break; } return _context20.abrupt("return", this.api.getKeyBlockByHeight(hashOrHeight)); case 4: throw new Error('Invalid param, param must be hash or height'); case 5: case "end": return _context20.stop(); } } }, _callee16, this); })); return _getKeyBlock.apply(this, arguments); } function getMicroBlockHeader(_x13) { return _getMicroBlockHeader.apply(this, arguments); } function _getMicroBlockHeader() { _getMicroBlockHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(hash) { return _regeneratorRuntime.wrap(function _callee17$(_context21) { while (1) { switch (_context21.prev = _context21.next) { case 0: return _context21.abrupt("return", this.api.getMicroBlockHeaderByHash(hash)); case 1: case "end": return _context21.stop(); } } }, _callee17, this); })); return _getMicroBlockHeader.apply(this, arguments); } function txDryRun(_x14, _x15, _x16) { return _txDryRun.apply(this, arguments); } function _txDryRun() { _txDryRun = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(tx, accountAddress, options) { var _yield$this$api, _yield$this$api$resul, _yield$this$api$resul2, result, reason, resultPayload, other; return _regeneratorRuntime.wrap(function _callee18$(_context22) { while (1) { switch (_context22.prev = _context22.next) { case 0: _context22.next = 2; return this.api[this._isIrisNode ? 'protectedDryRunTxs' : 'dryRunTxs'](_objectSpread(_objectSpread({}, options), {}, { txs: [{ tx: tx }], accounts: [{ pubKey: accountAddress, amount: DRY_RUN_ACCOUNT.amount }] })); case 2: _yield$this$api = _context22.sent; _yield$this$api$resul = _slicedToArray(_yield$this$api.results, 1); _yield$this$api$resul2 = _yield$this$api$resul[0]; result = _yield$this$api$resul2.result; reason = _yield$this$api$resul2.reason; resultPayload = _objectWithoutProperties(_yield$this$api$resul2, ["result", "reason"]); other = _objectWithoutProperties(_yield$this$api, ["results"]); if (!(result === 'ok')) { _context22.next = 11; break; } return _context22.abrupt("return", _objectSpread(_objectSpread({}, resultPayload), other)); case 11: throw _Object$assign(new Error('Dry run error, ' + reason), { tx: tx, accountAddress: accountAddress, options: options }); case 12: case "end": return _context22.stop(); } } }, _callee18, this); })); return _txDryRun.apply(this, arguments); } function getContractByteCode(_x17) { return _getContractByteCode.apply(this, arguments); } function _getContractByteCode() { _getContractByteCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(contractId) { return _regeneratorRuntime.wrap(function _callee19$(_context23) { while (1) { switch (_context23.prev = _context23.next) { case 0: return _context23.abrupt("return", this.api.getContractCode(contractId)); case 1: case "end": return _context23.stop(); } } }, _callee19, this); })); return _getContractByteCode.apply(this, arguments); } function getContract(_x18) { return _getContract.apply(this, arguments); } function _getContract() { _getContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(contractId) { return _regeneratorRuntime.wrap(function _callee20$(_context24) { while (1) { switch (_context24.prev = _context24.next) { case 0: return _context24.abrupt("return", this.api.getContract(contractId)); case 1: case "end": return _context24.stop(); } } }, _callee20, this); })); return _getContract.apply(this, arguments); } function getName(_x19) { return _getName.apply(this, arguments); } /** * Resolve AENS name and return name hash * @param {String} nameOrId * @param {String} prefix * @param {Object} [options] * @param {Boolean} [options.verify] Enables resolving by node, needed for compatibility with `verify` option of other methods * @param {Boolean} [options.resolveByNode] Enables pointer resolving using node (isn't more durable to resolve it on the node side?) * @return {String} Address or AENS name hash */ function _getName() { _getName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(name) { return _regeneratorRuntime.wrap(function _callee21$(_context25) { while (1) { switch (_context25.prev = _context25.next) { case 0: return _context25.abrupt("return", this.api.getNameEntryByName(name)); case 1: case "end": return _context25.stop(); } } }, _callee21, this); })); return _getName.apply(this, arguments); } function resolveName(_x20, _x21) { return _resolveName.apply(this, arguments); } /** * ChainNode Stamp * * This is implementation of {@link module:@aeternity/aepp-sdk/es/chain--Chain} * composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and {@link module:@aeternity/aepp-sdk/es/oracle/node--OracleNodeAPI} * @function * @alias module:@aeternity/aepp-sdk/es/chain/node * @rtype Stamp * @param {Object} [options={}] - Initializer object * @return {Object} ChainNode instance * @example ChainNode({url: 'https://testnet.aeternity.io/'}) */ function _resolveName() { _resolveName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(nameOrId, prefix) { var _ref7, verify, resolveByNode, prefixes, _context26, _context27, _context28, name, pointer, _args22 = arguments; return _regeneratorRuntime.wrap(function _callee22$(_context29) { while (1) { switch (_context29.prev = _context29.next) { case 0: _ref7 = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {}, verify = _ref7.verify, resolveByNode = _ref7.resolveByNode; if (!(!nameOrId || typeof nameOrId !== 'string')) { _context29.next = 3; break; } throw new Error('Invalid name or address. Should be a string'); case 3: prefixes = _Object$keys(NAME_ID_KEY); if (_includesInstanceProperty(prefixes).call(prefixes, prefix)) { _context29.next = 6; break; } throw new Error(_concatInstanceProperty(_context26 = "Invalid prefix ".concat(prefix, ". Should be one of [")).call(_context26, prefixes, "]")); case 6: if (!assertedType(nameOrId, prefix, true)) { _context29.next = 8; break; } return _context29.abrupt("return", nameOrId); case 8: if (!isNameValid(nameOrId)) { _context29.next = 20; break; } if (!(resolveByNode || verify)) { _context29.next = 19; break; } _context29.next = 12; return this.getName(nameOrId)["catch"](function (_) { return null; }); case 12: name = _context29.sent; if (name) { _context29.next = 15; break; } throw new Error('Name not found'); case 15: pointer = _findInstanceProperty(_context27 = name.pointers).call(_context27, function (_ref8) { var id = _ref8.id; return id.split('_')[0] === prefix; }); if (pointer) { _context29.next = 18; break; } throw new Error(_concatInstanceProperty(_context28 = "Name ".concat(nameOrId, " do not have pointers for ")).call(_context28, prefix)); case 18: return _context29.abrupt("return", pointer.id); case 19: return _context29.abrupt("return", produceNameId(nameOrId)); case 20: throw new Error('Invalid name or address'); case 21: case "end": return _context29.stop(); } } }, _callee22, this); })); return _resolveName.apply(this, arguments); } var ChainNode = Chain.compose(TransactionValidator, NodePool, { init: function init(_ref) { var _ref$verifyTx = _ref.verifyTx, verifyTx = _ref$verifyTx === void 0 ? true : _ref$verifyTx; this.verifyTxBeforeSend = verifyTx; }, methods: { sendTransaction: sendTransaction, balance: balance, getBalance: getBalance, getAccount: getAccount, topBlock: topBlock, tx: tx, height: height, awaitHeight: awaitHeight, poll: poll, getTxInfo: getTxInfo, mempool: mempool, getCurrentGeneration: getCurrentGeneration, getGeneration: getGeneration, getMicroBlockHeader: getMicroBlockHeader, getMicroBlockTransactions: getMicroBlockTransactions, getKeyBlock: getKeyBlock, txDryRun: txDryRun, getContractByteCode: getContractByteCode, getContract: getContract, getName: getName, waitForTxConfirm: waitForTxConfirm, resolveName: resolveName } }); export default ChainNode; //# sourceMappingURL=node.js.map