@aeternity/aepp-sdk 9.0.1 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.mjs +179 -0
- package/es/account/base.mjs.map +1 -0
- package/es/account/memory.mjs +99 -0
- package/es/account/memory.mjs.map +1 -0
- package/es/account/multiple.mjs +179 -0
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/aens.mjs +404 -0
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/index.mjs +207 -0
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/oracle.mjs +339 -0
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +29 -9
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/node.mjs +442 -0
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/handlers.mjs +1110 -0
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +245 -472
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.mjs +283 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/index.mjs +178 -0
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/index.mjs +188 -0
- package/es/node-pool/index.mjs.map +1 -0
- package/es/node.mjs +133 -0
- package/es/node.mjs.map +1 -0
- package/es/other.d.ts +1 -1
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +363 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.mjs +606 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +760 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +107 -15
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/tx-object.mjs +283 -0
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/tx.mjs +938 -0
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/validator.mjs +247 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +139 -0
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/async-init.mjs +64 -0
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/bignumber.mjs +21 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -12
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/crypto.mjs +239 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.mjs +111 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.mjs +45 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.mjs +240 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/mptree.mjs +161 -0
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.mjs +43 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/semver-satisfies.mjs +16 -0
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/{string.js → string.mjs} +5 -14
- package/es/utils/string.mjs.map +1 -0
- package/es/utils/swagger.mjs +164 -0
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +55 -62
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +31 -22
- package/src/ae/aens.js +75 -77
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +27 -291
- package/src/ae/index.js +9 -7
- package/src/ae/oracle.js +51 -28
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -67
- package/src/channel/handlers.js +30 -21
- package/src/channel/index.js +44 -20
- package/src/channel/internal.js +30 -24
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +41 -91
- package/src/contract/ga/helpers.js +10 -13
- package/src/contract/ga/index.js +42 -33
- package/src/index.js +9 -10
- package/src/node-pool/index.js +29 -17
- package/src/node.js +33 -36
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +126 -84
- package/src/tx/builder/index.js +83 -41
- package/src/tx/builder/schema.js +50 -40
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +232 -153
- package/src/tx/validator.js +34 -12
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +3 -10
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +10 -144
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +75 -45
- package/es/account/base.js +0 -259
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -86
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -267
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -829
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -985
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -442
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -690
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -1119
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js +0 -1601
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -438
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -517
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -742
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -316
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -120
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -307
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -204
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -228
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -355
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -686
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -695
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -297
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -1757
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -344
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -148
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -103
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js +0 -152
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -103
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -36
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -358
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -148
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -78
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -393
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js +0 -198
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -93
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js +0 -35
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -269
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/helpers.js +0 -140
- package/src/contract/aci/index.js +0 -191
- package/src/contract/aci/transformation.js +0 -464
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -110
package/es/contract/aci/index.js
DELETED
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
6
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
7
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
8
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
9
|
-
import _merge from "ramda/src/merge";
|
|
10
|
-
import _path from "ramda/src/path";
|
|
11
|
-
import _prop from "ramda/src/prop";
|
|
12
|
-
import _defaultTo from "ramda/src/defaultTo";
|
|
13
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
14
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
15
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
16
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
17
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
18
|
-
|
|
19
|
-
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; }
|
|
20
|
-
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context7; _forEachInstanceProperty(_context7 = ownKeys(Object(source), true)).call(_context7, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context8; _forEachInstanceProperty(_context8 = ownKeys(Object(source))).call(_context8, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
22
|
-
|
|
23
|
-
import BigNumber from 'bignumber.js';
|
|
24
|
-
import { buildContractMethods, decodeCallResult, decodeEvents, getFunctionACI, prepareArgsForEncode as prepareArgs } from './helpers';
|
|
25
|
-
/**
|
|
26
|
-
* Generate contract ACI object with predefined js methods for contract usage - can be used for creating a reference to already deployed contracts
|
|
27
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
28
|
-
* @param {String} source Contract source code
|
|
29
|
-
* @param {Object} [options={}] Options object
|
|
30
|
-
* @param {String} [options.aci] Contract ACI
|
|
31
|
-
* @param {String} [options.contractAddress] Contract address
|
|
32
|
-
* @param {Object} [options.filesystem] Contact source external namespaces map
|
|
33
|
-
* @param {Object} [options.forceCodeCheck=true] Don't check contract code
|
|
34
|
-
* @param {Object} [options.opt] Contract options
|
|
35
|
-
* @return {ContractInstance} JS Contract API
|
|
36
|
-
* @example
|
|
37
|
-
* const contractIns = await client.getContractInstance(sourceCode)
|
|
38
|
-
* await contractIns.deploy([321]) or await contractIns.methods.init(321)
|
|
39
|
-
* const callResult = await contractIns.call('setState', [123]) or await contractIns.methods.setState.send(123, options)
|
|
40
|
-
* const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or await contractIns.methods.setState.get(123, options)
|
|
41
|
-
* Also you can call contract like: await contractIns.methods.setState(123, options)
|
|
42
|
-
* Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is stateful or not
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
export default function getContractInstance(_x) {
|
|
46
|
-
return _getContractInstance.apply(this, arguments);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function _getContractInstance() {
|
|
50
|
-
_getContractInstance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(source) {
|
|
51
|
-
var _context5;
|
|
52
|
-
|
|
53
|
-
var _ref,
|
|
54
|
-
aci,
|
|
55
|
-
contractAddress,
|
|
56
|
-
_ref$filesystem,
|
|
57
|
-
filesystem,
|
|
58
|
-
_ref$forceCodeCheck,
|
|
59
|
-
forceCodeCheck,
|
|
60
|
-
opt,
|
|
61
|
-
defaultOptions,
|
|
62
|
-
instance,
|
|
63
|
-
contract,
|
|
64
|
-
onChanByteCode,
|
|
65
|
-
isCorrespondingBytecode,
|
|
66
|
-
_args4 = arguments;
|
|
67
|
-
|
|
68
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context6) {
|
|
69
|
-
while (1) {
|
|
70
|
-
switch (_context6.prev = _context6.next) {
|
|
71
|
-
case 0:
|
|
72
|
-
_ref = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}, aci = _ref.aci, contractAddress = _ref.contractAddress, _ref$filesystem = _ref.filesystem, filesystem = _ref$filesystem === void 0 ? {} : _ref$filesystem, _ref$forceCodeCheck = _ref.forceCodeCheck, forceCodeCheck = _ref$forceCodeCheck === void 0 ? true : _ref$forceCodeCheck, opt = _ref.opt;
|
|
73
|
-
_context6.t0 = aci;
|
|
74
|
-
|
|
75
|
-
if (_context6.t0) {
|
|
76
|
-
_context6.next = 6;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_context6.next = 5;
|
|
81
|
-
return this.contractGetACI(source, {
|
|
82
|
-
filesystem: filesystem
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
case 5:
|
|
86
|
-
_context6.t0 = _context6.sent;
|
|
87
|
-
|
|
88
|
-
case 6:
|
|
89
|
-
aci = _context6.t0;
|
|
90
|
-
|
|
91
|
-
if (!contractAddress) {
|
|
92
|
-
_context6.next = 11;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_context6.next = 10;
|
|
97
|
-
return this.resolveName(contractAddress, 'ct', {
|
|
98
|
-
resolveByNode: true
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
case 10:
|
|
102
|
-
contractAddress = _context6.sent;
|
|
103
|
-
|
|
104
|
-
case 11:
|
|
105
|
-
defaultOptions = _objectSpread(_objectSpread({}, this.Ae.defaults), {}, {
|
|
106
|
-
skipArgsConvert: false,
|
|
107
|
-
skipTransformDecoded: false,
|
|
108
|
-
callStatic: false,
|
|
109
|
-
filesystem: filesystem
|
|
110
|
-
});
|
|
111
|
-
instance = {
|
|
112
|
-
"interface": _defaultTo(null, _prop('interface', aci)),
|
|
113
|
-
aci: _defaultTo(null, _path(['encoded_aci', 'contract'], aci)),
|
|
114
|
-
externalAci: aci.external_encoded_aci ? _mapInstanceProperty(_context5 = aci.external_encoded_aci).call(_context5, function (a) {
|
|
115
|
-
return a.contract || a.namespace;
|
|
116
|
-
}) : [],
|
|
117
|
-
source: source,
|
|
118
|
-
compiled: null,
|
|
119
|
-
deployInfo: {
|
|
120
|
-
address: contractAddress
|
|
121
|
-
},
|
|
122
|
-
options: _merge(defaultOptions, opt),
|
|
123
|
-
compilerVersion: this.compilerVersion,
|
|
124
|
-
setOptions: function setOptions(opt) {
|
|
125
|
-
this.options = _merge(this.options, opt);
|
|
126
|
-
}
|
|
127
|
-
}; // Check for valid contract address and contract code
|
|
128
|
-
|
|
129
|
-
if (!contractAddress) {
|
|
130
|
-
_context6.next = 28;
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
_context6.next = 16;
|
|
135
|
-
return this.getContract(contractAddress)["catch"](function (e) {
|
|
136
|
-
return null;
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
case 16:
|
|
140
|
-
contract = _context6.sent;
|
|
141
|
-
|
|
142
|
-
if (!(!contract || !contract.active)) {
|
|
143
|
-
_context6.next = 19;
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
throw new Error("Contract with address ".concat(contractAddress, " not found on-chain or not active"));
|
|
148
|
-
|
|
149
|
-
case 19:
|
|
150
|
-
if (forceCodeCheck) {
|
|
151
|
-
_context6.next = 28;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
_context6.next = 22;
|
|
156
|
-
return this.getContractByteCode(contractAddress);
|
|
157
|
-
|
|
158
|
-
case 22:
|
|
159
|
-
onChanByteCode = _context6.sent.bytecode;
|
|
160
|
-
_context6.next = 25;
|
|
161
|
-
return this.validateByteCodeAPI(onChanByteCode, instance.source, instance.options)["catch"](function (e) {
|
|
162
|
-
return false;
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
case 25:
|
|
166
|
-
isCorrespondingBytecode = _context6.sent;
|
|
167
|
-
|
|
168
|
-
if (isCorrespondingBytecode) {
|
|
169
|
-
_context6.next = 28;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
throw new Error('Contract source do not correspond to the contract bytecode deployed on the chain');
|
|
174
|
-
|
|
175
|
-
case 28:
|
|
176
|
-
/**
|
|
177
|
-
* Compile contract
|
|
178
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
179
|
-
* @rtype () => ContractInstance: Object
|
|
180
|
-
* @return {ContractInstance} Contract ACI object with predefined js methods for contract usage
|
|
181
|
-
*/
|
|
182
|
-
instance.compile = compile({
|
|
183
|
-
client: this,
|
|
184
|
-
instance: instance
|
|
185
|
-
});
|
|
186
|
-
/**
|
|
187
|
-
* Deploy contract
|
|
188
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
189
|
-
* @rtype (init: Array, options: Object = { skipArgsConvert: false }) => ContractInstance: Object
|
|
190
|
-
* @param {Array} init Contract init function arguments array
|
|
191
|
-
* @param {Object} [options={}] options Options object
|
|
192
|
-
* @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data
|
|
193
|
-
* @return {ContractInstance} Contract ACI object with predefined js methods for contract usage
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
instance.deploy = deploy({
|
|
197
|
-
client: this,
|
|
198
|
-
instance: instance
|
|
199
|
-
});
|
|
200
|
-
/**
|
|
201
|
-
* Call contract function
|
|
202
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
203
|
-
* @rtype (init: Array, options: Object = { skipArgsConvert: false, skipTransformDecoded: false, callStatic: false }) => CallResult: Object
|
|
204
|
-
* @param {String} fn Function name
|
|
205
|
-
* @param {Array} params Array of function arguments
|
|
206
|
-
* @param {Object} [options={}] Array of function arguments
|
|
207
|
-
* @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data
|
|
208
|
-
* @param {Boolean} [options.skipTransformDecoded=false] Skip Transform decoded data to JS type
|
|
209
|
-
* @param {Boolean} [options.callStatic=false] Static function call
|
|
210
|
-
* @return {Object} CallResult
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
instance.call = call({
|
|
214
|
-
client: this,
|
|
215
|
-
instance: instance
|
|
216
|
-
});
|
|
217
|
-
/**
|
|
218
|
-
* Decode Events
|
|
219
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
220
|
-
* @rtype (fn: String, events: Array) => DecodedEvents: Array
|
|
221
|
-
* @param {String} fn Function name
|
|
222
|
-
* @param {Array} events Array of encoded events(callRes.result.log)
|
|
223
|
-
* @return {Object} DecodedEvents
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
instance.decodeEvents = eventDecode({
|
|
227
|
-
instance: instance
|
|
228
|
-
});
|
|
229
|
-
/**
|
|
230
|
-
* Generate proto function based on contract function using Contract ACI schema
|
|
231
|
-
* All function can be called like:
|
|
232
|
-
* 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx on-chain base on if function stateful or not.
|
|
233
|
-
* Also you can manually do that:
|
|
234
|
-
* `await contract.methods.testFunction.get()` -> use call-static(dry-run)
|
|
235
|
-
* `await contract.methods.testFunction.send()` -> send tx on-chain
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
instance.methods = buildContractMethods(instance)();
|
|
239
|
-
return _context6.abrupt("return", instance);
|
|
240
|
-
|
|
241
|
-
case 34:
|
|
242
|
-
case "end":
|
|
243
|
-
return _context6.stop();
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}, _callee4, this);
|
|
247
|
-
}));
|
|
248
|
-
return _getContractInstance.apply(this, arguments);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
var eventDecode = function eventDecode(_ref2) {
|
|
252
|
-
var instance = _ref2.instance;
|
|
253
|
-
return function (fn, events) {
|
|
254
|
-
return decodeEvents(events, getFunctionACI(instance.aci, fn, {
|
|
255
|
-
external: instance.externalAci
|
|
256
|
-
}));
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
var call = function call(_ref3) {
|
|
261
|
-
var client = _ref3.client,
|
|
262
|
-
instance = _ref3.instance;
|
|
263
|
-
return /*#__PURE__*/function () {
|
|
264
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fn) {
|
|
265
|
-
var _context;
|
|
266
|
-
|
|
267
|
-
var params,
|
|
268
|
-
options,
|
|
269
|
-
opt,
|
|
270
|
-
fnACI,
|
|
271
|
-
source,
|
|
272
|
-
result,
|
|
273
|
-
_args = arguments;
|
|
274
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
275
|
-
while (1) {
|
|
276
|
-
switch (_context2.prev = _context2.next) {
|
|
277
|
-
case 0:
|
|
278
|
-
params = _args.length > 1 && _args[1] !== undefined ? _args[1] : [];
|
|
279
|
-
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
280
|
-
opt = _objectSpread(_objectSpread({}, instance.options), options);
|
|
281
|
-
fnACI = getFunctionACI(instance.aci, fn, {
|
|
282
|
-
external: instance.externalAci
|
|
283
|
-
});
|
|
284
|
-
source = opt.source || instance.source;
|
|
285
|
-
|
|
286
|
-
if (fn) {
|
|
287
|
-
_context2.next = 7;
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
throw new Error('Function name is required');
|
|
292
|
-
|
|
293
|
-
case 7:
|
|
294
|
-
if (instance.deployInfo.address) {
|
|
295
|
-
_context2.next = 9;
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
throw new Error('You need to deploy contract before calling!');
|
|
300
|
-
|
|
301
|
-
case 9:
|
|
302
|
-
if (!(BigNumber(opt.amount).gt(0) && Object.prototype.hasOwnProperty.call(fnACI, 'payable') && !fnACI.payable)) {
|
|
303
|
-
_context2.next = 11;
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
throw new Error(_concatInstanceProperty(_context = "You try to pay \"".concat(opt.amount, "\" to function \"")).call(_context, fn, "\" which is not payable. Only payable function can accept tokens"));
|
|
308
|
-
|
|
309
|
-
case 11:
|
|
310
|
-
if (opt.skipArgsConvert) {
|
|
311
|
-
_context2.next = 17;
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
_context2.next = 14;
|
|
316
|
-
return prepareArgs(fnACI, params);
|
|
317
|
-
|
|
318
|
-
case 14:
|
|
319
|
-
_context2.t0 = _context2.sent;
|
|
320
|
-
_context2.next = 18;
|
|
321
|
-
break;
|
|
322
|
-
|
|
323
|
-
case 17:
|
|
324
|
-
_context2.t0 = params;
|
|
325
|
-
|
|
326
|
-
case 18:
|
|
327
|
-
params = _context2.t0;
|
|
328
|
-
|
|
329
|
-
if (!opt.callStatic) {
|
|
330
|
-
_context2.next = 25;
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
_context2.next = 22;
|
|
335
|
-
return client.contractCallStatic(source, instance.deployInfo.address, fn, params, opt);
|
|
336
|
-
|
|
337
|
-
case 22:
|
|
338
|
-
_context2.t1 = _context2.sent;
|
|
339
|
-
_context2.next = 28;
|
|
340
|
-
break;
|
|
341
|
-
|
|
342
|
-
case 25:
|
|
343
|
-
_context2.next = 27;
|
|
344
|
-
return client.contractCall(source, instance.deployInfo.address, fn, params, opt);
|
|
345
|
-
|
|
346
|
-
case 27:
|
|
347
|
-
_context2.t1 = _context2.sent;
|
|
348
|
-
|
|
349
|
-
case 28:
|
|
350
|
-
result = _context2.t1;
|
|
351
|
-
_context2.t2 = _objectSpread;
|
|
352
|
-
_context2.t3 = _objectSpread({}, result);
|
|
353
|
-
|
|
354
|
-
if (!opt.waitMined) {
|
|
355
|
-
_context2.next = 37;
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
_context2.next = 34;
|
|
360
|
-
return decodeCallResult(result, fnACI, opt);
|
|
361
|
-
|
|
362
|
-
case 34:
|
|
363
|
-
_context2.t4 = _context2.sent;
|
|
364
|
-
_context2.next = 38;
|
|
365
|
-
break;
|
|
366
|
-
|
|
367
|
-
case 37:
|
|
368
|
-
_context2.t4 = {};
|
|
369
|
-
|
|
370
|
-
case 38:
|
|
371
|
-
_context2.t5 = _context2.t4;
|
|
372
|
-
return _context2.abrupt("return", (0, _context2.t2)(_context2.t3, _context2.t5));
|
|
373
|
-
|
|
374
|
-
case 40:
|
|
375
|
-
case "end":
|
|
376
|
-
return _context2.stop();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}, _callee);
|
|
380
|
-
}));
|
|
381
|
-
|
|
382
|
-
return function (_x2) {
|
|
383
|
-
return _ref4.apply(this, arguments);
|
|
384
|
-
};
|
|
385
|
-
}();
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
var deploy = function deploy(_ref5) {
|
|
389
|
-
var client = _ref5.client,
|
|
390
|
-
instance = _ref5.instance;
|
|
391
|
-
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
392
|
-
var init,
|
|
393
|
-
options,
|
|
394
|
-
opt,
|
|
395
|
-
fnACI,
|
|
396
|
-
source,
|
|
397
|
-
_yield$client$contrac,
|
|
398
|
-
owner,
|
|
399
|
-
transaction,
|
|
400
|
-
address,
|
|
401
|
-
createdAt,
|
|
402
|
-
result,
|
|
403
|
-
rawTx,
|
|
404
|
-
_args2 = arguments;
|
|
405
|
-
|
|
406
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
407
|
-
while (1) {
|
|
408
|
-
switch (_context3.prev = _context3.next) {
|
|
409
|
-
case 0:
|
|
410
|
-
init = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : [];
|
|
411
|
-
options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
|
|
412
|
-
opt = _objectSpread(_objectSpread({}, instance.options), options);
|
|
413
|
-
fnACI = getFunctionACI(instance.aci, 'init', {
|
|
414
|
-
external: instance.externalAci
|
|
415
|
-
});
|
|
416
|
-
source = opt.source || instance.source;
|
|
417
|
-
|
|
418
|
-
if (instance.compiled) {
|
|
419
|
-
_context3.next = 8;
|
|
420
|
-
break;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
_context3.next = 8;
|
|
424
|
-
return instance.compile(opt);
|
|
425
|
-
|
|
426
|
-
case 8:
|
|
427
|
-
if (opt.skipArgsConvert) {
|
|
428
|
-
_context3.next = 14;
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
_context3.next = 11;
|
|
433
|
-
return prepareArgs(fnACI, init);
|
|
434
|
-
|
|
435
|
-
case 11:
|
|
436
|
-
_context3.t0 = _context3.sent;
|
|
437
|
-
_context3.next = 15;
|
|
438
|
-
break;
|
|
439
|
-
|
|
440
|
-
case 14:
|
|
441
|
-
_context3.t0 = init;
|
|
442
|
-
|
|
443
|
-
case 15:
|
|
444
|
-
init = _context3.t0;
|
|
445
|
-
|
|
446
|
-
if (!opt.callStatic) {
|
|
447
|
-
_context3.next = 20;
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return _context3.abrupt("return", client.contractCallStatic(source, null, 'init', init, _objectSpread(_objectSpread({}, opt), {}, {
|
|
452
|
-
bytecode: instance.compiled
|
|
453
|
-
})));
|
|
454
|
-
|
|
455
|
-
case 20:
|
|
456
|
-
_context3.next = 22;
|
|
457
|
-
return client.contractDeploy(instance.compiled, opt.source || instance.source, init, opt);
|
|
458
|
-
|
|
459
|
-
case 22:
|
|
460
|
-
_yield$client$contrac = _context3.sent;
|
|
461
|
-
owner = _yield$client$contrac.owner;
|
|
462
|
-
transaction = _yield$client$contrac.transaction;
|
|
463
|
-
address = _yield$client$contrac.address;
|
|
464
|
-
createdAt = _yield$client$contrac.createdAt;
|
|
465
|
-
result = _yield$client$contrac.result;
|
|
466
|
-
rawTx = _yield$client$contrac.rawTx;
|
|
467
|
-
instance.deployInfo = {
|
|
468
|
-
owner: owner,
|
|
469
|
-
transaction: transaction,
|
|
470
|
-
address: address,
|
|
471
|
-
createdAt: createdAt,
|
|
472
|
-
result: result,
|
|
473
|
-
rawTx: rawTx
|
|
474
|
-
};
|
|
475
|
-
return _context3.abrupt("return", instance.deployInfo);
|
|
476
|
-
|
|
477
|
-
case 31:
|
|
478
|
-
case "end":
|
|
479
|
-
return _context3.stop();
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}, _callee2);
|
|
483
|
-
}));
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
var compile = function compile(_ref7) {
|
|
487
|
-
var client = _ref7.client,
|
|
488
|
-
instance = _ref7.instance;
|
|
489
|
-
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
490
|
-
var options,
|
|
491
|
-
_yield$client$contrac2,
|
|
492
|
-
bytecode,
|
|
493
|
-
_args3 = arguments;
|
|
494
|
-
|
|
495
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
496
|
-
while (1) {
|
|
497
|
-
switch (_context4.prev = _context4.next) {
|
|
498
|
-
case 0:
|
|
499
|
-
options = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
|
|
500
|
-
_context4.next = 3;
|
|
501
|
-
return client.contractCompile(instance.source, _objectSpread(_objectSpread({}, instance.options), options));
|
|
502
|
-
|
|
503
|
-
case 3:
|
|
504
|
-
_yield$client$contrac2 = _context4.sent;
|
|
505
|
-
bytecode = _yield$client$contrac2.bytecode;
|
|
506
|
-
instance.compiled = bytecode;
|
|
507
|
-
return _context4.abrupt("return", instance.compiled);
|
|
508
|
-
|
|
509
|
-
case 7:
|
|
510
|
-
case "end":
|
|
511
|
-
return _context4.stop();
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}, _callee3);
|
|
515
|
-
}));
|
|
516
|
-
};
|
|
517
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contract/aci/index.js"],"names":["BigNumber","buildContractMethods","decodeCallResult","decodeEvents","getFunctionACI","prepareArgsForEncode","prepareArgs","getContractInstance","source","aci","contractAddress","filesystem","forceCodeCheck","opt","contractGetACI","resolveName","resolveByNode","defaultOptions","Ae","defaults","skipArgsConvert","skipTransformDecoded","callStatic","instance","externalAci","external_encoded_aci","a","contract","namespace","compiled","deployInfo","address","options","compilerVersion","setOptions","getContract","e","active","Error","getContractByteCode","onChanByteCode","bytecode","validateByteCodeAPI","isCorrespondingBytecode","compile","client","deploy","call","eventDecode","methods","fn","events","external","params","fnACI","amount","gt","Object","prototype","hasOwnProperty","payable","contractCallStatic","contractCall","result","waitMined","init","contractDeploy","owner","transaction","createdAt","rawTx","contractCompile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAOA,SAAP,MAAsB,cAAtB;AAEA,SACEC,oBADF,EAEEC,gBAFF,EAGEC,YAHF,EAIEC,cAJF,EAKEC,oBAAoB,IAAIC,WAL1B,QAMO,WANP;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,wBAA8BC,mBAA9B;AAAA;AAAA;;;kFAAe,kBAAoCC,MAApC;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,8EAAoH,EAApH,EAA8CC,GAA9C,QAA8CA,GAA9C,EAAmDC,eAAnD,QAAmDA,eAAnD,yBAAoEC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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAA1B;AAAA,CAAf;;AAoBA,IAAMc,OAAO,GAAG,SAAVA,OAAU;AAAA,MAAGC,MAAH,SAAGA,MAAH;AAAA,MAAWtB,QAAX,SAAWA,QAAX;AAAA,+EAA0B;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAOS,YAAAA,OAAP,8DAAiB,EAAjB;AAAA;AAAA,mBACba,MAAM,CAAC0B,eAAP,CAAuBhD,QAAQ,CAACf,MAAhC,kCAA6Ce,QAAQ,CAACS,OAAtD,GAAkEA,OAAlE,EADa;;AAAA;AAAA;AAChCS,YAAAA,QADgC,0BAChCA,QADgC;AAExClB,YAAAA,QAAQ,CAACM,QAAT,GAAoBY,QAApB;AAFwC,8CAGjClB,QAAQ,CAACM,QAHwB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAA1B;AAAA,CAAhB","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * ContractACI module\n *\n * @module @aeternity/aepp-sdk/es/contract/aci\n * @export getContractInstance\n */\n\nimport * as R from 'ramda'\nimport BigNumber from 'bignumber.js'\n\nimport {\n buildContractMethods,\n decodeCallResult,\n decodeEvents,\n getFunctionACI,\n prepareArgsForEncode as prepareArgs\n} from './helpers'\n\n/**\n * Generate contract ACI object with predefined js methods for contract usage - can be used for creating a reference to already deployed contracts\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @param {String} source Contract source code\n * @param {Object} [options={}] Options object\n * @param {String} [options.aci] Contract ACI\n * @param {String} [options.contractAddress] Contract address\n * @param {Object} [options.filesystem] Contact source external namespaces map\n * @param {Object} [options.forceCodeCheck=true] Don't check contract code\n * @param {Object} [options.opt] Contract options\n * @return {ContractInstance} JS Contract API\n * @example\n * const contractIns = await client.getContractInstance(sourceCode)\n * await contractIns.deploy([321]) or await contractIns.methods.init(321)\n * const callResult = await contractIns.call('setState', [123]) or await contractIns.methods.setState.send(123, options)\n * const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or await contractIns.methods.setState.get(123, options)\n * Also you can call contract like: await contractIns.methods.setState(123, options)\n * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is stateful or not\n */\nexport default async function getContractInstance (source, { aci, contractAddress, filesystem = {}, forceCodeCheck = true, opt } = {}) {\n aci = aci || await this.contractGetACI(source, { filesystem })\n if (contractAddress) contractAddress = await this.resolveName(contractAddress, 'ct', { resolveByNode: true })\n const defaultOptions = {\n ...this.Ae.defaults,\n skipArgsConvert: false,\n skipTransformDecoded: false,\n callStatic: false,\n filesystem\n }\n const instance = {\n interface: R.defaultTo(null, R.prop('interface', aci)),\n aci: R.defaultTo(null, R.path(['encoded_aci', 'contract'], aci)),\n externalAci: aci.external_encoded_aci ? aci.external_encoded_aci.map(a => a.contract || a.namespace) : [],\n source,\n compiled: null,\n deployInfo: { address: contractAddress },\n options: R.merge(defaultOptions, opt),\n compilerVersion: this.compilerVersion,\n setOptions (opt) {\n this.options = R.merge(this.options, opt)\n }\n }\n\n // Check for valid contract address and contract code\n if (contractAddress) {\n const contract = await this.getContract(contractAddress).catch(e => null)\n if (!contract || !contract.active) throw new Error(`Contract with address ${contractAddress} not found on-chain or not active`)\n if (!forceCodeCheck) {\n const onChanByteCode = (await this.getContractByteCode(contractAddress)).bytecode\n const isCorrespondingBytecode = await this.validateByteCodeAPI(onChanByteCode, instance.source, instance.options).catch(e => false)\n if (!isCorrespondingBytecode) throw new Error('Contract source do not correspond to the contract bytecode deployed on the chain')\n }\n }\n\n /**\n * Compile contract\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype () => ContractInstance: Object\n * @return {ContractInstance} Contract ACI object with predefined js methods for contract usage\n */\n instance.compile = compile({ client: this, instance })\n /**\n * Deploy contract\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (init: Array, options: Object = { skipArgsConvert: false }) => ContractInstance: Object\n * @param {Array} init Contract init function arguments array\n * @param {Object} [options={}] options Options object\n * @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data\n * @return {ContractInstance} Contract ACI object with predefined js methods for contract usage\n */\n instance.deploy = deploy({ client: this, instance })\n /**\n * Call contract function\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (init: Array, options: Object = { skipArgsConvert: false, skipTransformDecoded: false, callStatic: false }) => CallResult: Object\n * @param {String} fn Function name\n * @param {Array} params Array of function arguments\n * @param {Object} [options={}] Array of function arguments\n * @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data\n * @param {Boolean} [options.skipTransformDecoded=false] Skip Transform decoded data to JS type\n * @param {Boolean} [options.callStatic=false] Static function call\n * @return {Object} CallResult\n */\n instance.call = call({ client: this, instance })\n /**\n * Decode Events\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (fn: String, events: Array) => DecodedEvents: Array\n * @param {String} fn Function name\n * @param {Array} events Array of encoded events(callRes.result.log)\n * @return {Object} DecodedEvents\n */\n instance.decodeEvents = eventDecode({ instance })\n\n /**\n * Generate proto function based on contract function using Contract ACI schema\n * All function can be called like:\n * 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx on-chain base on if function stateful or not.\n * Also you can manually do that:\n * `await contract.methods.testFunction.get()` -> use call-static(dry-run)\n * `await contract.methods.testFunction.send()` -> send tx on-chain\n */\n instance.methods = buildContractMethods(instance)()\n return instance\n}\n\nconst eventDecode = ({ instance }) => (fn, events) => {\n return decodeEvents(events, getFunctionACI(instance.aci, fn, { external: instance.externalAci }))\n}\n\nconst call = ({ client, instance }) => async (fn, params = [], options = {}) => {\n const opt = { ...instance.options, ...options }\n const fnACI = getFunctionACI(instance.aci, fn, { external: instance.externalAci })\n const source = opt.source || instance.source\n\n if (!fn) throw new Error('Function name is required')\n if (!instance.deployInfo.address) throw new Error('You need to deploy contract before calling!')\n if (\n BigNumber(opt.amount).gt(0) &&\n (Object.prototype.hasOwnProperty.call(fnACI, 'payable') && !fnACI.payable)\n ) throw new Error(`You try to pay \"${opt.amount}\" to function \"${fn}\" which is not payable. Only payable function can accept tokens`)\n params = !opt.skipArgsConvert ? await prepareArgs(fnACI, params) : params\n const result = opt.callStatic\n ? await client.contractCallStatic(source, instance.deployInfo.address, fn, params, opt)\n : await client.contractCall(source, instance.deployInfo.address, fn, params, opt)\n return {\n ...result,\n ...opt.waitMined ? await decodeCallResult(result, fnACI, opt) : {}\n }\n}\n\nconst deploy = ({ client, instance }) => async (init = [], options = {}) => {\n const opt = { ...instance.options, ...options }\n const fnACI = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })\n const source = opt.source || instance.source\n\n if (!instance.compiled) await instance.compile(opt)\n init = !opt.skipArgsConvert ? await prepareArgs(fnACI, init) : init\n\n if (opt.callStatic) {\n return client.contractCallStatic(source, null, 'init', init, {\n ...opt,\n bytecode: instance.compiled\n })\n } else {\n const { owner, transaction, address, createdAt, result, rawTx } = await client.contractDeploy(instance.compiled, opt.source || instance.source, init, opt)\n instance.deployInfo = { owner, transaction, address, createdAt, result, rawTx }\n return instance.deployInfo\n }\n}\n\nconst compile = ({ client, instance }) => async (options = {}) => {\n const { bytecode } = await client.contractCompile(instance.source, { ...instance.options, ...options })\n instance.compiled = bytecode\n return instance.compiled\n}\n"],"file":"index.js"}
|