@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
1,623 lines (1,427 loc) • 52.7 kB
JavaScript
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 _last from "ramda/src/last";
import _merge from "ramda/src/merge";
import _head from "ramda/src/head";
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
import _contains from "ramda/src/contains";
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 _context23; _forEachInstanceProperty(_context23 = ownKeys(Object(source), true)).call(_context23, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context24; _forEachInstanceProperty(_context24 = ownKeys(Object(source))).call(_context24, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
import ChainNode from '../chain/node';
import Tx from './';
import { buildTx, calculateFee } from './builder';
import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL } from './builder/schema';
import { buildContractId } from './builder/helpers';
import { TxObject } from './tx-object';
function spendTx(_x) {
return _spendTx.apply(this, arguments);
}
function _spendTx() {
_spendTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
var senderId,
recipientId,
amount,
_ref$payload,
payload,
_yield$this$prepareTx,
fee,
ttl,
nonce,
_ref21,
tx,
_args = arguments;
return _regeneratorRuntime.wrap(function _callee$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
senderId = _ref.senderId, recipientId = _ref.recipientId, amount = _ref.amount, _ref$payload = _ref.payload, payload = _ref$payload === void 0 ? '' : _ref$payload;
_context3.next = 3;
return this.prepareTxParams(TX_TYPE.spend, _objectSpread(_objectSpread({
senderId: senderId
}, _head(_args)), {}, {
payload: payload
}));
case 3:
_yield$this$prepareTx = _context3.sent;
fee = _yield$this$prepareTx.fee;
ttl = _yield$this$prepareTx.ttl;
nonce = _yield$this$prepareTx.nonce;
if (!this.nativeMode) {
_context3.next = 11;
break;
}
_context3.t0 = {
tx: TxObject({
params: _merge(_head(_args), {
recipientId: recipientId,
senderId: senderId,
nonce: nonce,
ttl: ttl,
payload: payload
}),
type: TX_TYPE.spend
}).encodedTx
};
_context3.next = 14;
break;
case 11:
_context3.next = 13;
return this.api.postSpend(_merge(_head(_args), {
amount: _parseInt(amount),
recipientId: recipientId,
senderId: senderId,
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee),
payload: payload
}));
case 13:
_context3.t0 = _context3.sent;
case 14:
_ref21 = _context3.t0;
tx = _ref21.tx;
return _context3.abrupt("return", tx);
case 17:
case "end":
return _context3.stop();
}
}
}, _callee, this);
}));
return _spendTx.apply(this, arguments);
}
function namePreclaimTx(_x2) {
return _namePreclaimTx.apply(this, arguments);
}
function _namePreclaimTx() {
_namePreclaimTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
var accountId,
commitmentId,
_yield$this$prepareTx2,
fee,
ttl,
nonce,
_ref22,
tx,
_args2 = arguments;
return _regeneratorRuntime.wrap(function _callee2$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
accountId = _ref2.accountId, commitmentId = _ref2.commitmentId;
_context4.next = 3;
return this.prepareTxParams(TX_TYPE.namePreClaim, _objectSpread({
senderId: accountId
}, _head(_args2)));
case 3:
_yield$this$prepareTx2 = _context4.sent;
fee = _yield$this$prepareTx2.fee;
ttl = _yield$this$prepareTx2.ttl;
nonce = _yield$this$prepareTx2.nonce;
if (!this.nativeMode) {
_context4.next = 11;
break;
}
_context4.t0 = {
tx: TxObject({
params: _merge(_head(_args2), {
nonce: nonce,
ttl: ttl,
fee: fee
}),
type: TX_TYPE.namePreClaim
}).encodedTx
};
_context4.next = 14;
break;
case 11:
_context4.next = 13;
return this.api.postNamePreclaim(_merge(_head(_args2), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee)
}));
case 13:
_context4.t0 = _context4.sent;
case 14:
_ref22 = _context4.t0;
tx = _ref22.tx;
return _context4.abrupt("return", tx);
case 17:
case "end":
return _context4.stop();
}
}
}, _callee2, this);
}));
return _namePreclaimTx.apply(this, arguments);
}
function nameClaimTx(_x3) {
return _nameClaimTx.apply(this, arguments);
}
function _nameClaimTx() {
_nameClaimTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) {
var accountId,
name,
nameSalt,
_ref3$vsn,
vsn,
_yield$this$prepareTx3,
fee,
ttl,
nonce,
_ref23,
tx,
_args3 = arguments;
return _regeneratorRuntime.wrap(function _callee3$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
accountId = _ref3.accountId, name = _ref3.name, nameSalt = _ref3.nameSalt, _ref3$vsn = _ref3.vsn, vsn = _ref3$vsn === void 0 ? 2 : _ref3$vsn;
_context5.next = 3;
return this.prepareTxParams(TX_TYPE.nameClaim, _objectSpread(_objectSpread({
senderId: accountId
}, _head(_args3)), {}, {
vsn: vsn
}));
case 3:
_yield$this$prepareTx3 = _context5.sent;
fee = _yield$this$prepareTx3.fee;
ttl = _yield$this$prepareTx3.ttl;
nonce = _yield$this$prepareTx3.nonce;
if (!this.nativeMode) {
_context5.next = 11;
break;
}
_context5.t0 = {
tx: TxObject({
params: _merge(_head(_args3), {
nonce: nonce,
ttl: ttl,
fee: fee,
vsn: vsn
}),
type: TX_TYPE.nameClaim
}).encodedTx
};
_context5.next = 14;
break;
case 11:
_context5.next = 13;
return this.api.postNameClaim(_merge(_head(_args3), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee)
}));
case 13:
_context5.t0 = _context5.sent;
case 14:
_ref23 = _context5.t0;
tx = _ref23.tx;
return _context5.abrupt("return", tx);
case 17:
case "end":
return _context5.stop();
}
}
}, _callee3, this);
}));
return _nameClaimTx.apply(this, arguments);
}
function nameTransferTx(_x4) {
return _nameTransferTx.apply(this, arguments);
}
function _nameTransferTx() {
_nameTransferTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
var accountId,
nameId,
recipientId,
_yield$this$prepareTx4,
fee,
ttl,
nonce,
_ref24,
tx,
_args4 = arguments;
return _regeneratorRuntime.wrap(function _callee4$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
accountId = _ref4.accountId, nameId = _ref4.nameId, recipientId = _ref4.recipientId;
_context6.next = 3;
return this.prepareTxParams(TX_TYPE.nameTransfer, _objectSpread({
senderId: accountId
}, _head(_args4)));
case 3:
_yield$this$prepareTx4 = _context6.sent;
fee = _yield$this$prepareTx4.fee;
ttl = _yield$this$prepareTx4.ttl;
nonce = _yield$this$prepareTx4.nonce;
if (!this.nativeMode) {
_context6.next = 11;
break;
}
_context6.t0 = {
tx: TxObject({
params: _merge(_head(_args4), {
recipientId: recipientId,
nonce: nonce,
ttl: ttl,
fee: fee
}),
type: TX_TYPE.nameTransfer
}).encodedTx
};
_context6.next = 14;
break;
case 11:
_context6.next = 13;
return this.api.postNameTransfer(_merge(_head(_args4), {
recipientId: recipientId,
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee)
}));
case 13:
_context6.t0 = _context6.sent;
case 14:
_ref24 = _context6.t0;
tx = _ref24.tx;
return _context6.abrupt("return", tx);
case 17:
case "end":
return _context6.stop();
}
}
}, _callee4, this);
}));
return _nameTransferTx.apply(this, arguments);
}
function nameUpdateTx(_x5) {
return _nameUpdateTx.apply(this, arguments);
}
function _nameUpdateTx() {
_nameUpdateTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) {
var accountId,
nameId,
nameTtl,
pointers,
clientTtl,
_yield$this$prepareTx5,
fee,
ttl,
nonce,
_ref25,
tx,
_args5 = arguments;
return _regeneratorRuntime.wrap(function _callee5$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
accountId = _ref5.accountId, nameId = _ref5.nameId, nameTtl = _ref5.nameTtl, pointers = _ref5.pointers, clientTtl = _ref5.clientTtl;
_context7.next = 3;
return this.prepareTxParams(TX_TYPE.nameUpdate, _objectSpread({
senderId: accountId
}, _head(_args5)));
case 3:
_yield$this$prepareTx5 = _context7.sent;
fee = _yield$this$prepareTx5.fee;
ttl = _yield$this$prepareTx5.ttl;
nonce = _yield$this$prepareTx5.nonce;
if (!this.nativeMode) {
_context7.next = 11;
break;
}
_context7.t0 = {
tx: TxObject({
params: _merge(_head(_args5), {
nonce: nonce,
ttl: ttl,
fee: fee
}),
type: TX_TYPE.nameUpdate
}).encodedTx
};
_context7.next = 14;
break;
case 11:
_context7.next = 13;
return this.api.postNameUpdate(_merge(_head(_args5), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee)
}));
case 13:
_context7.t0 = _context7.sent;
case 14:
_ref25 = _context7.t0;
tx = _ref25.tx;
return _context7.abrupt("return", tx);
case 17:
case "end":
return _context7.stop();
}
}
}, _callee5, this);
}));
return _nameUpdateTx.apply(this, arguments);
}
function nameRevokeTx(_x6) {
return _nameRevokeTx.apply(this, arguments);
}
function _nameRevokeTx() {
_nameRevokeTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref6) {
var accountId,
nameId,
_yield$this$prepareTx6,
fee,
ttl,
nonce,
_ref26,
tx,
_args6 = arguments;
return _regeneratorRuntime.wrap(function _callee6$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
accountId = _ref6.accountId, nameId = _ref6.nameId;
_context8.next = 3;
return this.prepareTxParams(TX_TYPE.nameRevoke, _objectSpread({
senderId: accountId
}, _head(_args6)));
case 3:
_yield$this$prepareTx6 = _context8.sent;
fee = _yield$this$prepareTx6.fee;
ttl = _yield$this$prepareTx6.ttl;
nonce = _yield$this$prepareTx6.nonce;
if (!this.nativeMode) {
_context8.next = 11;
break;
}
_context8.t0 = {
tx: TxObject({
params: _merge(_head(_args6), {
nonce: nonce,
ttl: ttl,
fee: fee
}),
type: TX_TYPE.nameRevoke
}).encodedTx
};
_context8.next = 14;
break;
case 11:
_context8.next = 13;
return this.api.postNameRevoke(_merge(_head(_args6), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee)
}));
case 13:
_context8.t0 = _context8.sent;
case 14:
_ref26 = _context8.t0;
tx = _ref26.tx;
return _context8.abrupt("return", tx);
case 17:
case "end":
return _context8.stop();
}
}
}, _callee6, this);
}));
return _nameRevokeTx.apply(this, arguments);
}
function contractCreateTx(_x7) {
return _contractCreateTx.apply(this, arguments);
}
function _contractCreateTx() {
_contractCreateTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref7) {
var ownerId,
code,
vmVersion,
abiVersion,
deposit,
amount,
gas,
_ref7$gasPrice,
gasPrice,
callData,
ctVersion,
_yield$this$prepareTx7,
fee,
ttl,
nonce,
_args7 = arguments;
return _regeneratorRuntime.wrap(function _callee7$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
ownerId = _ref7.ownerId, code = _ref7.code, vmVersion = _ref7.vmVersion, abiVersion = _ref7.abiVersion, deposit = _ref7.deposit, amount = _ref7.amount, gas = _ref7.gas, _ref7$gasPrice = _ref7.gasPrice, gasPrice = _ref7$gasPrice === void 0 ? MIN_GAS_PRICE : _ref7$gasPrice, callData = _ref7.callData;
// Get VM_ABI version
ctVersion = this.getVmVersion(TX_TYPE.contractCreate, _head(_args7)); // Calculate fee, get absolute ttl (ttl + height), get account nonce
_context9.next = 4;
return this.prepareTxParams(TX_TYPE.contractCreate, _objectSpread(_objectSpread({
senderId: ownerId
}, _head(_args7)), {}, {
ctVersion: ctVersion,
gasPrice: gasPrice
}));
case 4:
_yield$this$prepareTx7 = _context9.sent;
fee = _yield$this$prepareTx7.fee;
ttl = _yield$this$prepareTx7.ttl;
nonce = _yield$this$prepareTx7.nonce;
return _context9.abrupt("return", this.nativeMode ? {
tx: TxObject({
params: _merge(_head(_args7), {
nonce: nonce,
ttl: ttl,
fee: fee,
ctVersion: ctVersion,
gasPrice: gasPrice
}),
type: TX_TYPE.contractCreate
}).encodedTx,
contractId: buildContractId(ownerId, nonce)
} : this.api.postContractCreate(_merge(_head(_args7), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee),
gas: _parseInt(gas),
gasPrice: gasPrice,
vmVersion: ctVersion.vmVersion,
abiVersion: ctVersion.abiVersion
})));
case 9:
case "end":
return _context9.stop();
}
}
}, _callee7, this);
}));
return _contractCreateTx.apply(this, arguments);
}
function contractCallTx(_x8) {
return _contractCallTx.apply(this, arguments);
}
function _contractCallTx() {
_contractCallTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref8) {
var callerId,
contractId,
abiVersion,
amount,
gas,
_ref8$gasPrice,
gasPrice,
callData,
ctVersion,
_yield$this$prepareTx8,
fee,
ttl,
nonce,
_ref27,
tx,
_args8 = arguments;
return _regeneratorRuntime.wrap(function _callee8$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
callerId = _ref8.callerId, contractId = _ref8.contractId, abiVersion = _ref8.abiVersion, amount = _ref8.amount, gas = _ref8.gas, _ref8$gasPrice = _ref8.gasPrice, gasPrice = _ref8$gasPrice === void 0 ? MIN_GAS_PRICE : _ref8$gasPrice, callData = _ref8.callData;
ctVersion = this.getVmVersion(TX_TYPE.contractCall, _head(_args8)); // Calculate fee, get absolute ttl (ttl + height), get account nonce
_context10.next = 4;
return this.prepareTxParams(TX_TYPE.contractCall, _objectSpread(_objectSpread({
senderId: callerId
}, _head(_args8)), {}, {
gasPrice: gasPrice,
abiVersion: ctVersion.abiVersion
}));
case 4:
_yield$this$prepareTx8 = _context10.sent;
fee = _yield$this$prepareTx8.fee;
ttl = _yield$this$prepareTx8.ttl;
nonce = _yield$this$prepareTx8.nonce;
if (!this.nativeMode) {
_context10.next = 12;
break;
}
_context10.t0 = {
tx: TxObject({
params: _merge(_head(_args8), {
nonce: nonce,
ttl: ttl,
fee: fee,
abiVersion: ctVersion.abiVersion,
gasPrice: gasPrice
}),
type: TX_TYPE.contractCall
}).encodedTx
};
_context10.next = 15;
break;
case 12:
_context10.next = 14;
return this.api.postContractCall(_merge(_head(_args8), {
nonce: nonce,
ttl: ttl,
fee: _parseInt(fee),
gas: _parseInt(gas),
gasPrice: gasPrice,
abiVersion: ctVersion.abiVersion
}));
case 14:
_context10.t0 = _context10.sent;
case 15:
_ref27 = _context10.t0;
tx = _ref27.tx;
return _context10.abrupt("return", tx);
case 18:
case "end":
return _context10.stop();
}
}
}, _callee8, this);
}));
return _contractCallTx.apply(this, arguments);
}
function oracleRegisterTx(_x9) {
return _oracleRegisterTx.apply(this, arguments);
}
function _oracleRegisterTx() {
_oracleRegisterTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref9) {
var accountId,
queryFormat,
responseFormat,
queryFee,
oracleTtl,
_ref9$abiVersion,
abiVersion,
_yield$this$prepareTx9,
fee,
ttl,
nonce,
_ref28,
tx,
_args9 = arguments;
return _regeneratorRuntime.wrap(function _callee9$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
accountId = _ref9.accountId, queryFormat = _ref9.queryFormat, responseFormat = _ref9.responseFormat, queryFee = _ref9.queryFee, oracleTtl = _ref9.oracleTtl, _ref9$abiVersion = _ref9.abiVersion, abiVersion = _ref9$abiVersion === void 0 ? ABI_VERSIONS.NO_ABI : _ref9$abiVersion;
_context11.next = 3;
return this.prepareTxParams(TX_TYPE.oracleRegister, _objectSpread(_objectSpread({
senderId: accountId
}, _head(_args9)), {}, {
abiVersion: abiVersion
}));
case 3:
_yield$this$prepareTx9 = _context11.sent;
fee = _yield$this$prepareTx9.fee;
ttl = _yield$this$prepareTx9.ttl;
nonce = _yield$this$prepareTx9.nonce;
if (!this.nativeMode) {
_context11.next = 11;
break;
}
_context11.t0 = {
tx: TxObject({
params: {
accountId: accountId,
queryFee: queryFee,
abiVersion: abiVersion,
fee: fee,
oracleTtl: oracleTtl,
nonce: nonce,
ttl: ttl,
queryFormat: queryFormat,
responseFormat: responseFormat
},
type: TX_TYPE.oracleRegister
}).encodedTx
};
_context11.next = 14;
break;
case 11:
_context11.next = 13;
return this.api.postOracleRegister({
accountId: accountId,
queryFee: queryFee,
abiVersion: abiVersion,
fee: _parseInt(fee),
oracleTtl: oracleTtl,
nonce: nonce,
ttl: ttl,
queryFormat: queryFormat,
responseFormat: responseFormat
});
case 13:
_context11.t0 = _context11.sent;
case 14:
_ref28 = _context11.t0;
tx = _ref28.tx;
return _context11.abrupt("return", tx);
case 17:
case "end":
return _context11.stop();
}
}
}, _callee9, this);
}));
return _oracleRegisterTx.apply(this, arguments);
}
function oracleExtendTx(_x10) {
return _oracleExtendTx.apply(this, arguments);
}
function _oracleExtendTx() {
_oracleExtendTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref10) {
var oracleId,
callerId,
oracleTtl,
_yield$this$prepareTx10,
fee,
ttl,
nonce,
_ref29,
tx,
_args10 = arguments;
return _regeneratorRuntime.wrap(function _callee10$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
oracleId = _ref10.oracleId, callerId = _ref10.callerId, oracleTtl = _ref10.oracleTtl;
_context12.next = 3;
return this.prepareTxParams(TX_TYPE.oracleExtend, _objectSpread({
senderId: callerId
}, _head(_args10)));
case 3:
_yield$this$prepareTx10 = _context12.sent;
fee = _yield$this$prepareTx10.fee;
ttl = _yield$this$prepareTx10.ttl;
nonce = _yield$this$prepareTx10.nonce;
if (!this.nativeMode) {
_context12.next = 11;
break;
}
_context12.t0 = {
tx: TxObject({
params: {
oracleId: oracleId,
fee: fee,
oracleTtl: oracleTtl,
nonce: nonce,
ttl: ttl
},
type: TX_TYPE.oracleExtend
}).encodedTx
};
_context12.next = 14;
break;
case 11:
_context12.next = 13;
return this.api.postOracleExtend({
oracleId: oracleId,
fee: _parseInt(fee),
oracleTtl: oracleTtl,
nonce: nonce,
ttl: ttl
});
case 13:
_context12.t0 = _context12.sent;
case 14:
_ref29 = _context12.t0;
tx = _ref29.tx;
return _context12.abrupt("return", tx);
case 17:
case "end":
return _context12.stop();
}
}
}, _callee10, this);
}));
return _oracleExtendTx.apply(this, arguments);
}
function oraclePostQueryTx(_x11) {
return _oraclePostQueryTx.apply(this, arguments);
}
function _oraclePostQueryTx() {
_oraclePostQueryTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref11) {
var oracleId,
responseTtl,
query,
queryTtl,
queryFee,
senderId,
_yield$this$prepareTx11,
fee,
ttl,
nonce,
_ref30,
tx,
_args11 = arguments;
return _regeneratorRuntime.wrap(function _callee11$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
oracleId = _ref11.oracleId, responseTtl = _ref11.responseTtl, query = _ref11.query, queryTtl = _ref11.queryTtl, queryFee = _ref11.queryFee, senderId = _ref11.senderId;
_context13.next = 3;
return this.prepareTxParams(TX_TYPE.oracleQuery, _objectSpread({
senderId: senderId
}, _head(_args11)));
case 3:
_yield$this$prepareTx11 = _context13.sent;
fee = _yield$this$prepareTx11.fee;
ttl = _yield$this$prepareTx11.ttl;
nonce = _yield$this$prepareTx11.nonce;
if (!this.nativeMode) {
_context13.next = 11;
break;
}
_context13.t0 = {
tx: TxObject({
params: {
oracleId: oracleId,
responseTtl: responseTtl,
query: query,
queryTtl: queryTtl,
fee: fee,
queryFee: queryFee,
ttl: ttl,
nonce: nonce,
senderId: senderId
},
type: TX_TYPE.oracleQuery
}).encodedTx
};
_context13.next = 14;
break;
case 11:
_context13.next = 13;
return this.api.postOracleQuery({
oracleId: oracleId,
responseTtl: responseTtl,
query: query,
queryTtl: queryTtl,
fee: _parseInt(fee),
queryFee: queryFee,
ttl: ttl,
nonce: nonce,
senderId: senderId
});
case 13:
_context13.t0 = _context13.sent;
case 14:
_ref30 = _context13.t0;
tx = _ref30.tx;
return _context13.abrupt("return", tx);
case 17:
case "end":
return _context13.stop();
}
}
}, _callee11, this);
}));
return _oraclePostQueryTx.apply(this, arguments);
}
function oracleRespondTx(_x12) {
return _oracleRespondTx.apply(this, arguments);
}
function _oracleRespondTx() {
_oracleRespondTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref12) {
var oracleId,
callerId,
responseTtl,
queryId,
response,
_yield$this$prepareTx12,
fee,
ttl,
nonce,
_ref31,
tx,
_args12 = arguments;
return _regeneratorRuntime.wrap(function _callee12$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
oracleId = _ref12.oracleId, callerId = _ref12.callerId, responseTtl = _ref12.responseTtl, queryId = _ref12.queryId, response = _ref12.response;
_context14.next = 3;
return this.prepareTxParams(TX_TYPE.oracleResponse, _objectSpread({
senderId: callerId
}, _head(_args12)));
case 3:
_yield$this$prepareTx12 = _context14.sent;
fee = _yield$this$prepareTx12.fee;
ttl = _yield$this$prepareTx12.ttl;
nonce = _yield$this$prepareTx12.nonce;
if (!this.nativeMode) {
_context14.next = 11;
break;
}
_context14.t0 = {
tx: TxObject({
params: {
oracleId: oracleId,
responseTtl: responseTtl,
queryId: queryId,
response: response,
fee: fee,
ttl: ttl,
nonce: nonce
},
type: TX_TYPE.oracleResponse
}).encodedTx
};
_context14.next = 14;
break;
case 11:
_context14.next = 13;
return this.api.postOracleRespond({
oracleId: oracleId,
responseTtl: responseTtl,
queryId: queryId,
response: response,
fee: _parseInt(fee),
ttl: ttl,
nonce: nonce
});
case 13:
_context14.t0 = _context14.sent;
case 14:
_ref31 = _context14.t0;
tx = _ref31.tx;
return _context14.abrupt("return", tx);
case 17:
case "end":
return _context14.stop();
}
}
}, _callee12, this);
}));
return _oracleRespondTx.apply(this, arguments);
}
function channelCloseSoloTx(_x13) {
return _channelCloseSoloTx.apply(this, arguments);
}
function _channelCloseSoloTx() {
_channelCloseSoloTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref13) {
var channelId,
fromId,
payload,
poi,
_yield$this$prepareTx13,
fee,
ttl,
nonce,
_ref32,
tx,
_args13 = arguments;
return _regeneratorRuntime.wrap(function _callee13$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
channelId = _ref13.channelId, fromId = _ref13.fromId, payload = _ref13.payload, poi = _ref13.poi;
_context15.next = 3;
return this.prepareTxParams(TX_TYPE.channelCloseSolo, _objectSpread(_objectSpread({
senderId: fromId
}, _head(_args13)), {}, {
payload: payload
}));
case 3:
_yield$this$prepareTx13 = _context15.sent;
fee = _yield$this$prepareTx13.fee;
ttl = _yield$this$prepareTx13.ttl;
nonce = _yield$this$prepareTx13.nonce;
if (!this.nativeMode) {
_context15.next = 11;
break;
}
_context15.t0 = buildTx(_merge(_head(_args13), {
channelId: channelId,
fromId: fromId,
payload: payload,
poi: poi,
ttl: ttl,
fee: fee,
nonce: nonce
}), TX_TYPE.channelCloseSolo);
_context15.next = 14;
break;
case 11:
_context15.next = 13;
return this.api.postChannelCloseSolo(_merge(_head(_args13), {
channelId: channelId,
fromId: fromId,
payload: payload,
poi: poi,
ttl: ttl,
fee: _parseInt(fee),
nonce: nonce
}));
case 13:
_context15.t0 = _context15.sent;
case 14:
_ref32 = _context15.t0;
tx = _ref32.tx;
return _context15.abrupt("return", tx);
case 17:
case "end":
return _context15.stop();
}
}
}, _callee13, this);
}));
return _channelCloseSoloTx.apply(this, arguments);
}
function channelSlashTx(_x14) {
return _channelSlashTx.apply(this, arguments);
}
function _channelSlashTx() {
_channelSlashTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref14) {
var channelId,
fromId,
payload,
poi,
_yield$this$prepareTx14,
fee,
ttl,
nonce,
_ref33,
tx,
_args14 = arguments;
return _regeneratorRuntime.wrap(function _callee14$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
channelId = _ref14.channelId, fromId = _ref14.fromId, payload = _ref14.payload, poi = _ref14.poi;
_context16.next = 3;
return this.prepareTxParams(TX_TYPE.channelSlash, _objectSpread(_objectSpread({
senderId: fromId
}, _head(_args14)), {}, {
payload: payload
}));
case 3:
_yield$this$prepareTx14 = _context16.sent;
fee = _yield$this$prepareTx14.fee;
ttl = _yield$this$prepareTx14.ttl;
nonce = _yield$this$prepareTx14.nonce;
if (!this.nativeMode) {
_context16.next = 11;
break;
}
_context16.t0 = buildTx(_merge(_head(_args14), {
channelId: channelId,
fromId: fromId,
payload: payload,
poi: poi,
ttl: ttl,
fee: fee,
nonce: nonce
}), TX_TYPE.channelSlash);
_context16.next = 14;
break;
case 11:
_context16.next = 13;
return this.api.postChannelSlash(_merge(_head(_args14), {
channelId: channelId,
fromId: fromId,
payload: payload,
poi: poi,
ttl: ttl,
fee: _parseInt(fee),
nonce: nonce
}));
case 13:
_context16.t0 = _context16.sent;
case 14:
_ref33 = _context16.t0;
tx = _ref33.tx;
return _context16.abrupt("return", tx);
case 17:
case "end":
return _context16.stop();
}
}
}, _callee14, this);
}));
return _channelSlashTx.apply(this, arguments);
}
function channelSettleTx(_x15) {
return _channelSettleTx.apply(this, arguments);
}
function _channelSettleTx() {
_channelSettleTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref15) {
var channelId,
fromId,
initiatorAmountFinal,
responderAmountFinal,
_yield$this$prepareTx15,
fee,
ttl,
nonce,
_ref34,
tx,
_args15 = arguments;
return _regeneratorRuntime.wrap(function _callee15$(_context17) {
while (1) {
switch (_context17.prev = _context17.next) {
case 0:
channelId = _ref15.channelId, fromId = _ref15.fromId, initiatorAmountFinal = _ref15.initiatorAmountFinal, responderAmountFinal = _ref15.responderAmountFinal;
_context17.next = 3;
return this.prepareTxParams(TX_TYPE.channelSettle, _objectSpread({
senderId: fromId
}, _head(_args15)));
case 3:
_yield$this$prepareTx15 = _context17.sent;
fee = _yield$this$prepareTx15.fee;
ttl = _yield$this$prepareTx15.ttl;
nonce = _yield$this$prepareTx15.nonce;
if (!this.nativeMode) {
_context17.next = 11;
break;
}
_context17.t0 = buildTx(_merge(_head(_args15), {
channelId: channelId,
fromId: fromId,
initiatorAmountFinal: initiatorAmountFinal,
responderAmountFinal: responderAmountFinal,
ttl: ttl,
fee: fee,
nonce: nonce
}), TX_TYPE.channelSettle);
_context17.next = 14;
break;
case 11:
_context17.next = 13;
return this.api.postChannelSettle(_merge(_head(_args15), {
channelId: channelId,
fromId: fromId,
initiatorAmountFinal: _parseInt(initiatorAmountFinal),
responderAmountFinal: _parseInt(responderAmountFinal),
ttl: ttl,
fee: _parseInt(fee),
nonce: nonce
}));
case 13:
_context17.t0 = _context17.sent;
case 14:
_ref34 = _context17.t0;
tx = _ref34.tx;
return _context17.abrupt("return", tx);
case 17:
case "end":
return _context17.stop();
}
}
}, _callee15, this);
}));
return _channelSettleTx.apply(this, arguments);
}
function channelSnapshotSoloTx(_x16) {
return _channelSnapshotSoloTx.apply(this, arguments);
}
function _channelSnapshotSoloTx() {
_channelSnapshotSoloTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref16) {
var channelId,
fromId,
payload,
_yield$this$prepareTx16,
fee,
ttl,
nonce,
_ref35,
tx,
_args16 = arguments;
return _regeneratorRuntime.wrap(function _callee16$(_context18) {
while (1) {
switch (_context18.prev = _context18.next) {
case 0:
channelId = _ref16.channelId, fromId = _ref16.fromId, payload = _ref16.payload;
_context18.next = 3;
return this.prepareTxParams(TX_TYPE.channelSnapshotSolo, _objectSpread(_objectSpread({
senderId: fromId
}, _head(_args16)), {}, {
payload: payload
}));
case 3:
_yield$this$prepareTx16 = _context18.sent;
fee = _yield$this$prepareTx16.fee;
ttl = _yield$this$prepareTx16.ttl;
nonce = _yield$this$prepareTx16.nonce;
if (!this.nativeMode) {
_context18.next = 11;
break;
}
_context18.t0 = buildTx(_merge(_head(_args16), {
channelId: channelId,
fromId: fromId,
payload: payload,
ttl: ttl,
fee: fee,
nonce: nonce
}), TX_TYPE.channelSnapshotSolo);
_context18.next = 14;
break;
case 11:
_context18.next = 13;
return this.api.postChannelSnapshotSolo(_merge(_head(_args16), {
channelId: channelId,
fromId: fromId,
payload: payload,
ttl: ttl,
fee: _parseInt(fee),
nonce: nonce
}));
case 13:
_context18.t0 = _context18.sent;
case 14:
_ref35 = _context18.t0;
tx = _ref35.tx;
return _context18.abrupt("return", tx);
case 17:
case "end":
return _context18.stop();
}
}
}, _callee16, this);
}));
return _channelSnapshotSoloTx.apply(this, arguments);
}
function gaAttachTx(_x17) {
return _gaAttachTx.apply(this, arguments);
}
/**
* Validated vm/abi version or get default based on transaction type and NODE version
*
* @param {string} txType Type of transaction
* @param {object} vmAbi Object with vm and abi version fields
* @return {object} Object with vm/abi version ({ vmVersion: number, abiVersion: number })
*/
function _gaAttachTx() {
_gaAttachTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref17) {
var ownerId,
code,
vmVersion,
abiVersion,
authFun,
gas,
_ref17$gasPrice,
gasPrice,
callData,
ctVersion,
_yield$this$prepareTx17,
fee,
ttl,
nonce,
_args17 = arguments;
return _regeneratorRuntime.wrap(function _callee17$(_context19) {
while (1) {
switch (_context19.prev = _context19.next) {
case 0:
ownerId = _ref17.ownerId, code = _ref17.code, vmVersion = _ref17.vmVersion, abiVersion = _ref17.abiVersion, authFun = _ref17.authFun, gas = _ref17.gas, _ref17$gasPrice = _ref17.gasPrice, gasPrice = _ref17$gasPrice === void 0 ? MIN_GAS_PRICE : _ref17$gasPrice, callData = _ref17.callData;
// Get VM_ABI version
ctVersion = this.getVmVersion(TX_TYPE.contractCreate, _head(_args17)); // Calculate fee, get absolute ttl (ttl + height), get account nonce
_context19.next = 4;
return this.prepareTxParams(TX_TYPE.gaAttach, _objectSpread(_objectSpread({
senderId: ownerId
}, _head(_args17)), {}, {
ctVersion: ctVersion,
gasPrice: gasPrice
}));
case 4:
_yield$this$prepareTx17 = _context19.sent;
fee = _yield$this$prepareTx17.fee;
ttl = _yield$this$prepareTx17.ttl;
nonce = _yield$this$prepareTx17.nonce;
return _context19.abrupt("return", {
tx: TxObject({
params: _merge(_head(_args17), {
nonce: nonce,
ttl: ttl,
fee: fee,
ctVersion: ctVersion,
gasPrice: gasPrice
}),
type: TX_TYPE.gaAttach
}).encodedTx,
contractId: buildContractId(ownerId, nonce)
});
case 9:
case "end":
return _context19.stop();
}
}
}, _callee17, this);
}));
return _gaAttachTx.apply(this, arguments);
}
function getVmVersion(txType) {
var _context, _context2;
var _ref18 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
vmVersion = _ref18.vmVersion,
abiVersion = _ref18.abiVersion;
var _this$getNodeInfo = this.getNodeInfo(),
consensusProtocolVersion = _this$getNodeInfo.consensusProtocolVersion;
var supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
if (!supportedProtocol) throw new Error('Not supported consensus protocol version');
var protocolForTX = supportedProtocol[txType];
if (!protocolForTX) throw new Error('Not supported tx type');
var ctVersion = {
abiVersion: abiVersion || protocolForTX.abiVersion[0],
vmVersion: vmVersion || protocolForTX.vmVersion[0]
};
if (protocolForTX.vmVersion.length && !_contains(ctVersion.vmVersion, protocolForTX.vmVersion)) throw new Error(_concatInstanceProperty(_context = "VM VERSION ".concat(ctVersion.vmVersion, " do not support by this node. Supported: [")).call(_context, protocolForTX.vmVersion, "]"));
if (protocolForTX.abiVersion.length && !_contains(ctVersion.abiVersion, protocolForTX.abiVersion)) throw new Error(_concatInstanceProperty(_context2 = "ABI VERSION ".concat(ctVersion.abiVersion, " do not support by this node. Supported: [")).call(_context2, protocolForTX.abiVersion, "]"));
return ctVersion;
}
/**
* Compute the absolute ttl by adding the ttl to the current height of the chain
*
* @param {number} ttl
* @param {boolean} relative ttl is absolute or relative(default: true(relative))
* @return {number} Absolute Ttl
*/
function calculateTtl() {
return _calculateTtl.apply(this, arguments);
}
/**
* Get the next nonce to be used for a transaction for an account
*
* @param {string} accountId
* @param {number} nonce
* @return {number} Next Nonce
*/
function _calculateTtl() {
_calculateTtl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
var ttl,
relative,
_yield$this$api$getCu,
height,
_args18 = arguments;
return _regeneratorRuntime.wrap(function _callee18$(_context20) {
while (1) {
switch (_context20.prev = _context20.next) {
case 0:
ttl = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : TX_TTL;
relative = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : true;
if (!(ttl === 0)) {
_context20.next = 4;
break;
}
return _context20.abrupt("return", 0);
case 4:
if (!(ttl < 0)) {
_context20.next = 6;
break;
}
throw new Error('ttl must be greater than 0');
case 6:
if (!relative) {
_context20.next = 12;
break;
}
_context20.next = 9;
return this.api.getCurrentKeyBlock();
case 9:
_yield$this$api$getCu = _context20.sent;
height = _yield$this$api$getCu.height;
return _context20.abrupt("return", +height + ttl);
case 12:
return _context20.abrupt("return", ttl);
case 13:
case "end":
return _context20.stop();
}
}
}, _callee18, this);
}));
return _calculateTtl.apply(this, arguments);
}
function getAccountNonce(_x18, _x19) {
return _getAccountNonce.apply(this, arguments);
}
/**
* Calculate fee, get absolute ttl (ttl + height), get account nonce
*
* @param {String} txType Type of transaction
* @param {Object} params Object which contains all tx data
* @return {Object} { ttl, nonce, fee } Object with account nonce, absolute ttl and transaction fee
*/
function _getAccountNonce() {
_getAccountNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(accountId, nonce) {
var _yield$this$api$getAc, accountNonce;
return _regeneratorRuntime.wrap(function _callee19$(_context21) {
while (1) {
switch (_context21.prev = _context21.next) {
case 0:
if (!nonce) {
_context21.next = 2;
break;
}
return _context21.abrupt("return", nonce);
case 2:
_context21.next = 4;
return this.api.getAccountByPubkey(accountId)["catch"](function () {
return {
nonce: 0
};
});
case 4:
_yield$this$api$getAc = _context21.sent;
accountNonce = _yield$this$api$getAc.nonce;
return _context21.abrupt("return", accountNonce + 1);
case 7:
case "end":
return _context21.stop();
}
}
}, _callee19, this);
}));
return _getAccountNonce.apply(this, arguments);
}
function prepareTxParams(_x20, _x21) {
return _prepareTxParams.apply(this, arguments);
}
/**
* Transaction Stamp
*
* This is implementation of [Tx](api/tx.md) relays
* the creation of transactions to {@link module:@aeternity/aepp-sdk/es/Node}.
* This stamp provide ability to create native transaction's,
* or transaction's using Node API.
* As there is no built-in security between Node and client communication,
* creating transaction using {@link module:@aeternity/aepp-sdk/es/Node} API
* must never be used for production but can be very useful to verify other
* implementations.
* @function
* @alias module:@aeternity/aepp-sdk/es/tx/tx
* @rtype Stamp
* @param {Object} [options={}] - Initializer object
* @param {Boolean} [options.nativeMode=true] options.nativeMode - Use Native build of transaction's
* @param {String} options.url - Node url
* @param {String} options.internalUrl - Node internal url
* @return {Object} Transaction instance
* @example Transaction({url: 'https://testnet.aeternity.io/'})
*/
function _prepareTxParams() {
_prepareTxParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(txType, _ref19) {
var senderId,
n,
t,
f,
gas,
absoluteTtl,
vsn,
account,
ttl,
fee,
_args20 = arguments;