@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/tx/builder/index.js
DELETED
|
@@ -1,686 +0,0 @@
|
|
|
1
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
2
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
3
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
4
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
5
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
6
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
7
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
8
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source), true)).call(_context11, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context12; _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
15
|
-
|
|
16
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
17
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
18
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
19
|
-
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
|
20
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
21
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
22
|
-
import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
|
|
23
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
24
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
25
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
26
|
-
import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
|
|
27
|
-
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
|
28
|
-
import BigNumber from 'bignumber.js';
|
|
29
|
-
import { decode as rlpDecode, encode as rlpEncode } from 'rlp';
|
|
30
|
-
import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter';
|
|
31
|
-
import { hash } from '../../utils/crypto';
|
|
32
|
-
import { DEFAULT_FEE, FIELD_TYPES, OBJECT_ID_TX_TYPE, PREFIX_ID_TAG, TX_DESERIALIZATION_SCHEMA, TX_FEE_BASE_GAS, TX_FEE_OTHER_GAS, TX_SERIALIZATION_SCHEMA, TX_TYPE, VALIDATION_MESSAGE, VSN } from './schema';
|
|
33
|
-
import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode } from './helpers';
|
|
34
|
-
import { toBytes } from '../../utils/bytes';
|
|
35
|
-
import MPTree from '../../utils/mptree';
|
|
36
|
-
/**
|
|
37
|
-
* JavaScript-based Transaction builder
|
|
38
|
-
* @module @aeternity/aepp-sdk/es/tx/builder
|
|
39
|
-
* @export TxBuilder
|
|
40
|
-
* @example import { TxBuilder } from '@aeternity/aepp-sdk'
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
var ORACLE_TTL_TYPES = {
|
|
44
|
-
delta: 'delta',
|
|
45
|
-
block: 'block'
|
|
46
|
-
}; // SERIALIZE AND DESERIALIZE PART
|
|
47
|
-
|
|
48
|
-
function deserializeField(value, type, prefix) {
|
|
49
|
-
if (!value) return '';
|
|
50
|
-
|
|
51
|
-
switch (type) {
|
|
52
|
-
case FIELD_TYPES.ctVersion:
|
|
53
|
-
{
|
|
54
|
-
var _value = _slicedToArray(value, 3),
|
|
55
|
-
vm = _value[0],
|
|
56
|
-
abi = _value[2];
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
vmVersion: readInt(Buffer.from([vm])),
|
|
60
|
-
abiVersion: readInt(Buffer.from([abi]))
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
case FIELD_TYPES.amount:
|
|
65
|
-
return readInt(value);
|
|
66
|
-
|
|
67
|
-
case FIELD_TYPES["int"]:
|
|
68
|
-
return readInt(value);
|
|
69
|
-
|
|
70
|
-
case FIELD_TYPES.id:
|
|
71
|
-
return readId(value);
|
|
72
|
-
|
|
73
|
-
case FIELD_TYPES.ids:
|
|
74
|
-
return _mapInstanceProperty(value).call(value, readId);
|
|
75
|
-
|
|
76
|
-
case FIELD_TYPES.bool:
|
|
77
|
-
return value[0] === 1;
|
|
78
|
-
|
|
79
|
-
case FIELD_TYPES.binary:
|
|
80
|
-
return encode(value, prefix);
|
|
81
|
-
|
|
82
|
-
case FIELD_TYPES.stateTree:
|
|
83
|
-
return encode(value, 'ss');
|
|
84
|
-
|
|
85
|
-
case FIELD_TYPES.string:
|
|
86
|
-
return value.toString();
|
|
87
|
-
|
|
88
|
-
case FIELD_TYPES.payload:
|
|
89
|
-
return encode(value, 'ba');
|
|
90
|
-
|
|
91
|
-
case FIELD_TYPES.pointers:
|
|
92
|
-
return readPointers(value);
|
|
93
|
-
|
|
94
|
-
case FIELD_TYPES.rlpBinary:
|
|
95
|
-
return unpackTx(value, true);
|
|
96
|
-
|
|
97
|
-
case FIELD_TYPES.rlpBinaries:
|
|
98
|
-
return _mapInstanceProperty(value).call(value, function (v) {
|
|
99
|
-
return unpackTx(v, true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
case FIELD_TYPES.rawBinary:
|
|
103
|
-
return value;
|
|
104
|
-
|
|
105
|
-
case FIELD_TYPES.hex:
|
|
106
|
-
return value.toString('hex');
|
|
107
|
-
|
|
108
|
-
case FIELD_TYPES.offChainUpdates:
|
|
109
|
-
return _mapInstanceProperty(value).call(value, function (v) {
|
|
110
|
-
return unpackTx(v, true);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
case FIELD_TYPES.callStack:
|
|
114
|
-
// TODO: fix this
|
|
115
|
-
return [readInt(value)];
|
|
116
|
-
|
|
117
|
-
case FIELD_TYPES.mptrees:
|
|
118
|
-
return _mapInstanceProperty(value).call(value, function (t) {
|
|
119
|
-
return new MPTree(t);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
case FIELD_TYPES.callReturnType:
|
|
123
|
-
switch (readInt(value)) {
|
|
124
|
-
case '0':
|
|
125
|
-
return 'ok';
|
|
126
|
-
|
|
127
|
-
case '1':
|
|
128
|
-
return 'error';
|
|
129
|
-
|
|
130
|
-
case '2':
|
|
131
|
-
return 'revert';
|
|
132
|
-
|
|
133
|
-
default:
|
|
134
|
-
return value;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
case FIELD_TYPES.sophiaCodeTypeInfo:
|
|
138
|
-
return _reduceInstanceProperty(value).call(value, function (acc, _ref) {
|
|
139
|
-
var _ref2 = _slicedToArray(_ref, 4),
|
|
140
|
-
funHash = _ref2[0],
|
|
141
|
-
fnName = _ref2[1],
|
|
142
|
-
argType = _ref2[2],
|
|
143
|
-
outType = _ref2[3];
|
|
144
|
-
|
|
145
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, fnName.toString(), {
|
|
146
|
-
funHash: funHash,
|
|
147
|
-
argType: argType,
|
|
148
|
-
outType: outType
|
|
149
|
-
}));
|
|
150
|
-
}, {});
|
|
151
|
-
|
|
152
|
-
default:
|
|
153
|
-
return value;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function serializeField(value, type, prefix) {
|
|
158
|
-
var _value$rlpEncoded, _context;
|
|
159
|
-
|
|
160
|
-
switch (type) {
|
|
161
|
-
case FIELD_TYPES.amount:
|
|
162
|
-
case FIELD_TYPES["int"]:
|
|
163
|
-
return writeInt(value);
|
|
164
|
-
|
|
165
|
-
case FIELD_TYPES.id:
|
|
166
|
-
return writeId(value);
|
|
167
|
-
|
|
168
|
-
case FIELD_TYPES.ids:
|
|
169
|
-
return _mapInstanceProperty(value).call(value, writeId);
|
|
170
|
-
|
|
171
|
-
case FIELD_TYPES.bool:
|
|
172
|
-
return Buffer.from([value ? 1 : 0]);
|
|
173
|
-
|
|
174
|
-
case FIELD_TYPES.binary:
|
|
175
|
-
return decode(value, prefix);
|
|
176
|
-
|
|
177
|
-
case FIELD_TYPES.stateTree:
|
|
178
|
-
return decode(value, 'ss');
|
|
179
|
-
|
|
180
|
-
case FIELD_TYPES.hex:
|
|
181
|
-
return Buffer.from(value, 'hex');
|
|
182
|
-
|
|
183
|
-
case FIELD_TYPES.signatures:
|
|
184
|
-
return _mapInstanceProperty(value).call(value, Buffer.from);
|
|
185
|
-
|
|
186
|
-
case FIELD_TYPES.payload:
|
|
187
|
-
return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value, 'ba') : toBytes(value);
|
|
188
|
-
|
|
189
|
-
case FIELD_TYPES.string:
|
|
190
|
-
return toBytes(value);
|
|
191
|
-
|
|
192
|
-
case FIELD_TYPES.pointers:
|
|
193
|
-
return buildPointers(value);
|
|
194
|
-
|
|
195
|
-
case FIELD_TYPES.rlpBinary:
|
|
196
|
-
return (_value$rlpEncoded = value.rlpEncoded) !== null && _value$rlpEncoded !== void 0 ? _value$rlpEncoded : value;
|
|
197
|
-
|
|
198
|
-
case FIELD_TYPES.mptrees:
|
|
199
|
-
return _mapInstanceProperty(value).call(value, function (t) {
|
|
200
|
-
return t.serialize();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
case FIELD_TYPES.ctVersion:
|
|
204
|
-
return Buffer.from(_concatInstanceProperty(_context = []).call(_context, _toConsumableArray(toBytes(value.vmVersion)), [0], _toConsumableArray(toBytes(value.abiVersion))));
|
|
205
|
-
|
|
206
|
-
case FIELD_TYPES.callReturnType:
|
|
207
|
-
switch (value) {
|
|
208
|
-
case 'ok':
|
|
209
|
-
return writeInt(0);
|
|
210
|
-
|
|
211
|
-
case 'error':
|
|
212
|
-
return writeInt(1);
|
|
213
|
-
|
|
214
|
-
case 'revert':
|
|
215
|
-
return writeInt(2);
|
|
216
|
-
|
|
217
|
-
default:
|
|
218
|
-
return value;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
default:
|
|
222
|
-
return value;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function validateField(value, key, type, prefix) {
|
|
227
|
-
var assert = function assert(valid, params) {
|
|
228
|
-
return valid ? {} : _defineProperty({}, key, VALIDATION_MESSAGE[type](params));
|
|
229
|
-
}; // All fields are required
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (value === undefined || value === null) return _defineProperty({}, key, 'Field is required'); // Validate type of value
|
|
233
|
-
|
|
234
|
-
switch (type) {
|
|
235
|
-
case FIELD_TYPES.amount:
|
|
236
|
-
case FIELD_TYPES["int"]:
|
|
237
|
-
{
|
|
238
|
-
var isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0);
|
|
239
|
-
return assert((!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0), {
|
|
240
|
-
value: value,
|
|
241
|
-
isMinusValue: isMinusValue
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
case FIELD_TYPES.id:
|
|
246
|
-
{
|
|
247
|
-
var prefixes = _Array$isArray(prefix) ? prefix : [prefix];
|
|
248
|
-
|
|
249
|
-
var p = _findInstanceProperty(prefixes).call(prefixes, function (p) {
|
|
250
|
-
return p === value.split('_')[0];
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
return assert(p && PREFIX_ID_TAG[value.split('_')[0]], {
|
|
254
|
-
value: value,
|
|
255
|
-
prefix: prefix
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
case FIELD_TYPES.binary:
|
|
260
|
-
return assert(value.split('_')[0] === prefix, {
|
|
261
|
-
prefix: prefix,
|
|
262
|
-
value: value
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
case FIELD_TYPES.string:
|
|
266
|
-
return assert(true);
|
|
267
|
-
|
|
268
|
-
case FIELD_TYPES.ctVersion:
|
|
269
|
-
return assert(_typeof(value) === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'));
|
|
270
|
-
|
|
271
|
-
case FIELD_TYPES.pointers:
|
|
272
|
-
return assert(_Array$isArray(value) && !_findInstanceProperty(value).call(value, function (e) {
|
|
273
|
-
return e !== Object(e);
|
|
274
|
-
}), {
|
|
275
|
-
value: value
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
default:
|
|
279
|
-
return {};
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function transformParams(params, schema) {
|
|
284
|
-
var _context2, _context3;
|
|
285
|
-
|
|
286
|
-
var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
287
|
-
denomination = _ref5.denomination;
|
|
288
|
-
|
|
289
|
-
params = _reduceInstanceProperty(_context2 = _filterInstanceProperty(schema).call(schema, function (_ref6) {
|
|
290
|
-
var _ref7 = _slicedToArray(_ref6, 2),
|
|
291
|
-
_ = _ref7[0],
|
|
292
|
-
t = _ref7[1];
|
|
293
|
-
|
|
294
|
-
return t === FIELD_TYPES.amount;
|
|
295
|
-
})).call(_context2, function (acc, _ref8) {
|
|
296
|
-
var _ref9 = _slicedToArray(_ref8, 1),
|
|
297
|
-
key = _ref9[0];
|
|
298
|
-
|
|
299
|
-
return _objectSpread(_objectSpread({}, params), {}, _defineProperty({}, key, formatAmount(params[key], {
|
|
300
|
-
denomination: denomination
|
|
301
|
-
})));
|
|
302
|
-
}, params);
|
|
303
|
-
|
|
304
|
-
var schemaKeys = _mapInstanceProperty(schema).call(schema, function (_ref10) {
|
|
305
|
-
var _ref11 = _slicedToArray(_ref10, 1),
|
|
306
|
-
k = _ref11[0];
|
|
307
|
-
|
|
308
|
-
return k;
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
return _reduceInstanceProperty(_context3 = _Object$entries(params)).call(_context3, function (acc, _ref12) {
|
|
312
|
-
var _context4;
|
|
313
|
-
|
|
314
|
-
var _ref13 = _slicedToArray(_ref12, 2),
|
|
315
|
-
key = _ref13[0],
|
|
316
|
-
value = _ref13[1];
|
|
317
|
-
|
|
318
|
-
if (_includesInstanceProperty(schemaKeys).call(schemaKeys, key)) acc[key] = value;
|
|
319
|
-
|
|
320
|
-
if (_includesInstanceProperty(_context4 = ['oracleTtl', 'queryTtl', 'responseTtl']).call(_context4, key)) {
|
|
321
|
-
acc["".concat(key, "Type")] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
|
|
322
|
-
acc["".concat(key, "Value")] = value.value;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return acc;
|
|
326
|
-
}, {});
|
|
327
|
-
} // INTERFACE
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
function getOracleRelativeTtl(params, txType) {
|
|
331
|
-
var _TX_TYPE$oracleRegist;
|
|
332
|
-
|
|
333
|
-
var ttlKey = (_TX_TYPE$oracleRegist = {}, _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleRegister, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleExtend, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleQuery, 'queryTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleResponse, 'responseTtl'), _TX_TYPE$oracleRegist)[txType];
|
|
334
|
-
|
|
335
|
-
if (params[ttlKey] || params["".concat(ttlKey, "Value")]) {
|
|
336
|
-
return params["".concat(ttlKey, "Value")] || params[ttlKey].value;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return 1;
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Calculate min fee
|
|
343
|
-
* @function
|
|
344
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/index
|
|
345
|
-
* @rtype (txType, { gas = 0, params }) => String
|
|
346
|
-
* @param {String} txType - Transaction type
|
|
347
|
-
* @param {Options} options - Options object
|
|
348
|
-
* @param {String|Number} options.gas - Gas amount
|
|
349
|
-
* @param {Object} options.params - Tx params
|
|
350
|
-
* @return {String|Number}
|
|
351
|
-
* @example calculateMinFee('spendTx', { gas, params })
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
export function calculateMinFee(txType, _ref14) {
|
|
356
|
-
var _ref14$gas = _ref14.gas,
|
|
357
|
-
gas = _ref14$gas === void 0 ? 0 : _ref14$gas,
|
|
358
|
-
params = _ref14.params,
|
|
359
|
-
vsn = _ref14.vsn;
|
|
360
|
-
var multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
|
|
361
|
-
|
|
362
|
-
if (!params) return BigNumber(DEFAULT_FEE).times(multiplier).toString(10);
|
|
363
|
-
var actualFee = buildFee(txType, {
|
|
364
|
-
params: _objectSpread(_objectSpread({}, params), {}, {
|
|
365
|
-
fee: 0
|
|
366
|
-
}),
|
|
367
|
-
multiplier: multiplier,
|
|
368
|
-
gas: gas,
|
|
369
|
-
vsn: vsn
|
|
370
|
-
});
|
|
371
|
-
var expected = BigNumber(0);
|
|
372
|
-
|
|
373
|
-
while (!actualFee.eq(expected)) {
|
|
374
|
-
actualFee = buildFee(txType, {
|
|
375
|
-
params: _objectSpread(_objectSpread({}, params), {}, {
|
|
376
|
-
fee: actualFee
|
|
377
|
-
}),
|
|
378
|
-
multiplier: multiplier,
|
|
379
|
-
gas: gas,
|
|
380
|
-
vsn: vsn
|
|
381
|
-
});
|
|
382
|
-
expected = actualFee;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return expected.toString(10);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Calculate fee based on tx type and params
|
|
389
|
-
* @param txType
|
|
390
|
-
* @param params
|
|
391
|
-
* @param gas
|
|
392
|
-
* @param multiplier
|
|
393
|
-
* @param vsn
|
|
394
|
-
* @return {BigNumber}
|
|
395
|
-
*/
|
|
396
|
-
|
|
397
|
-
function buildFee(txType, _ref15) {
|
|
398
|
-
var _context5;
|
|
399
|
-
|
|
400
|
-
var params = _ref15.params,
|
|
401
|
-
_ref15$gas = _ref15.gas,
|
|
402
|
-
gas = _ref15$gas === void 0 ? 0 : _ref15$gas,
|
|
403
|
-
multiplier = _ref15.multiplier,
|
|
404
|
-
vsn = _ref15.vsn;
|
|
405
|
-
|
|
406
|
-
var _buildTx = buildTx(_objectSpread({}, params), txType, {
|
|
407
|
-
vsn: vsn
|
|
408
|
-
}),
|
|
409
|
-
txWithOutFee = _buildTx.rlpEncoded;
|
|
410
|
-
|
|
411
|
-
var txSize = txWithOutFee.length;
|
|
412
|
-
return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, txSize, {
|
|
413
|
-
relativeTtl: getOracleRelativeTtl(params, txType),
|
|
414
|
-
innerTxSize: _includesInstanceProperty(_context5 = [TX_TYPE.gaMeta, TX_TYPE.payingFor]).call(_context5, txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
|
|
415
|
-
})).times(multiplier);
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Calculate fee
|
|
419
|
-
* @function
|
|
420
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
421
|
-
* @rtype (fee, txType, gas = 0) => String
|
|
422
|
-
* @param {String|Number} fee - fee
|
|
423
|
-
* @param {String} txType - Transaction type
|
|
424
|
-
* @param {Options} options - Options object
|
|
425
|
-
* @param {String|Number} options.gas - Gas amount
|
|
426
|
-
* @param {Object} options.params - Tx params
|
|
427
|
-
* @return {String|Number}
|
|
428
|
-
* @example calculateFee(null, 'spendTx', { gas, params })
|
|
429
|
-
*/
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
export function calculateFee() {
|
|
433
|
-
var fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
434
|
-
var txType = arguments.length > 1 ? arguments[1] : undefined;
|
|
435
|
-
|
|
436
|
-
var _ref16 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
437
|
-
_ref16$gas = _ref16.gas,
|
|
438
|
-
gas = _ref16$gas === void 0 ? 0 : _ref16$gas,
|
|
439
|
-
params = _ref16.params,
|
|
440
|
-
_ref16$showWarning = _ref16.showWarning,
|
|
441
|
-
showWarning = _ref16$showWarning === void 0 ? true : _ref16$showWarning,
|
|
442
|
-
vsn = _ref16.vsn;
|
|
443
|
-
|
|
444
|
-
if (!params && showWarning) console.warn("Can't build transaction fee, we will use DEFAULT_FEE(".concat(DEFAULT_FEE, ")"));
|
|
445
|
-
return fee || calculateMinFee(txType, {
|
|
446
|
-
params: params,
|
|
447
|
-
gas: gas,
|
|
448
|
-
vsn: vsn
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Validate transaction params
|
|
453
|
-
* @function
|
|
454
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
455
|
-
* @param {Object} params Object with tx params
|
|
456
|
-
* @param {Array} schema Transaction schema
|
|
457
|
-
* @param {Array} excludeKeys Array of keys to exclude for validation
|
|
458
|
-
* @return {Object} Object with validation errors
|
|
459
|
-
*/
|
|
460
|
-
|
|
461
|
-
export function validateParams(params, schema, _ref17) {
|
|
462
|
-
var _context6;
|
|
463
|
-
|
|
464
|
-
var _ref17$excludeKeys = _ref17.excludeKeys,
|
|
465
|
-
excludeKeys = _ref17$excludeKeys === void 0 ? [] : _ref17$excludeKeys;
|
|
466
|
-
return _reduceInstanceProperty(_context6 = _filterInstanceProperty(schema).call(schema, function (_ref18) {
|
|
467
|
-
var _ref19 = _slicedToArray(_ref18, 1),
|
|
468
|
-
key = _ref19[0];
|
|
469
|
-
|
|
470
|
-
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && key !== 'payload';
|
|
471
|
-
})).call(_context6, function (acc, _ref20) {
|
|
472
|
-
var _ref21 = _slicedToArray(_ref20, 3),
|
|
473
|
-
key = _ref21[0],
|
|
474
|
-
type = _ref21[1],
|
|
475
|
-
prefix = _ref21[2];
|
|
476
|
-
|
|
477
|
-
return _Object$assign(acc, validateField(params[key], key, type, prefix));
|
|
478
|
-
}, {});
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Build binary transaction
|
|
482
|
-
* @function
|
|
483
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
484
|
-
* @param {Object} params Object with tx params
|
|
485
|
-
* @param {Array} schema Transaction schema
|
|
486
|
-
* @param {Object} [options={}] options
|
|
487
|
-
* @param {Array} [options.excludeKeys=[]] excludeKeys Array of keys to exclude for validation and build
|
|
488
|
-
* @param {String} [options.denomination='aettos'] denomination Denomination of amounts (default: aettos)
|
|
489
|
-
* @throws {Error} Validation error
|
|
490
|
-
* @return {Array} Array with binary fields of transaction
|
|
491
|
-
*/
|
|
492
|
-
|
|
493
|
-
export function buildRawTx(params, schema) {
|
|
494
|
-
var _ref22 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
495
|
-
_ref22$excludeKeys = _ref22.excludeKeys,
|
|
496
|
-
excludeKeys = _ref22$excludeKeys === void 0 ? [] : _ref22$excludeKeys,
|
|
497
|
-
_ref22$denomination = _ref22.denomination,
|
|
498
|
-
denomination = _ref22$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref22$denomination;
|
|
499
|
-
|
|
500
|
-
var filteredSchema = _filterInstanceProperty(schema).call(schema, function (_ref23) {
|
|
501
|
-
var _ref24 = _slicedToArray(_ref23, 1),
|
|
502
|
-
key = _ref24[0];
|
|
503
|
-
|
|
504
|
-
return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
|
|
505
|
-
}); // Transform `amount` type fields to `aettos`
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
params = transformParams(params, filteredSchema, {
|
|
509
|
-
denomination: denomination
|
|
510
|
-
}); // Validation
|
|
511
|
-
|
|
512
|
-
var valid = validateParams(params, schema, {
|
|
513
|
-
excludeKeys: excludeKeys
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
if (_Object$keys(valid).length) {
|
|
517
|
-
throw new Error('Transaction build error. ' + _JSON$stringify(valid));
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return _mapInstanceProperty(filteredSchema).call(filteredSchema, function (_ref25) {
|
|
521
|
-
var _ref26 = _slicedToArray(_ref25, 3),
|
|
522
|
-
key = _ref26[0],
|
|
523
|
-
fieldType = _ref26[1],
|
|
524
|
-
prefix = _ref26[2];
|
|
525
|
-
|
|
526
|
-
return serializeField(params[key], fieldType, prefix);
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Unpack binary transaction
|
|
531
|
-
* @function
|
|
532
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
533
|
-
* @param {Array} binary Array with binary transaction field's
|
|
534
|
-
* @param {Array} schema Transaction schema
|
|
535
|
-
* @return {Object} Object with transaction field's
|
|
536
|
-
*/
|
|
537
|
-
|
|
538
|
-
export function unpackRawTx(binary, schema) {
|
|
539
|
-
return _reduceInstanceProperty(schema).call(schema, function (acc, _ref27, index) {
|
|
540
|
-
var _ref28 = _slicedToArray(_ref27, 3),
|
|
541
|
-
key = _ref28[0],
|
|
542
|
-
fieldType = _ref28[1],
|
|
543
|
-
prefix = _ref28[2];
|
|
544
|
-
|
|
545
|
-
return _Object$assign(acc, _defineProperty({}, key, deserializeField(binary[index], fieldType, prefix)));
|
|
546
|
-
}, {});
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Get transaction serialization/deserialization schema
|
|
550
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
551
|
-
* @param {{ vsn: String, objId: Number, type: String }}
|
|
552
|
-
* @throws {Error} Schema not found error
|
|
553
|
-
* @return {Object} Schema
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
|
-
var getSchema = function getSchema(_ref29) {
|
|
557
|
-
var vsn = _ref29.vsn,
|
|
558
|
-
objId = _ref29.objId,
|
|
559
|
-
type = _ref29.type;
|
|
560
|
-
var isDeserialize = !!objId;
|
|
561
|
-
var firstKey = isDeserialize ? objId : type;
|
|
562
|
-
var schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
|
|
563
|
-
|
|
564
|
-
if (!schema[firstKey]) {
|
|
565
|
-
var _context7;
|
|
566
|
-
|
|
567
|
-
throw new Error(_concatInstanceProperty(_context7 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context7, isDeserialize ? 'tag ' + objId : type));
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (!schema[firstKey][vsn]) {
|
|
571
|
-
var _context8, _context9;
|
|
572
|
-
|
|
573
|
-
throw new Error(_concatInstanceProperty(_context8 = _concatInstanceProperty(_context9 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context9, isDeserialize ? 'tag ' + objId : type, " version ")).call(_context8, vsn));
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return schema[firstKey][vsn];
|
|
577
|
-
};
|
|
578
|
-
/**
|
|
579
|
-
* Build transaction hash
|
|
580
|
-
* @function
|
|
581
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
582
|
-
* @param {Object} params Object with tx params
|
|
583
|
-
* @param {String} type Transaction type
|
|
584
|
-
* @param {Object} [options={}] options
|
|
585
|
-
* @param {Object} [options.excludeKeys] excludeKeys Array of keys to exclude for validation and build
|
|
586
|
-
* @param {String} [options.prefix] Prefix of transaction
|
|
587
|
-
* @throws {Error} Validation error
|
|
588
|
-
* @return {Object} { tx, rlpEncoded, binary } Object with tx -> Base64Check transaction hash with 'tx_' prefix, rlp encoded transaction and binary transaction
|
|
589
|
-
*/
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
export function buildTx(params, type) {
|
|
593
|
-
var _context10;
|
|
594
|
-
|
|
595
|
-
var _ref30 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
596
|
-
_ref30$excludeKeys = _ref30.excludeKeys,
|
|
597
|
-
excludeKeys = _ref30$excludeKeys === void 0 ? [] : _ref30$excludeKeys,
|
|
598
|
-
_ref30$prefix = _ref30.prefix,
|
|
599
|
-
prefix = _ref30$prefix === void 0 ? 'tx' : _ref30$prefix,
|
|
600
|
-
_ref30$vsn = _ref30.vsn,
|
|
601
|
-
vsn = _ref30$vsn === void 0 ? VSN : _ref30$vsn,
|
|
602
|
-
_ref30$denomination = _ref30.denomination,
|
|
603
|
-
denomination = _ref30$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref30$denomination;
|
|
604
|
-
|
|
605
|
-
var _getSchema = getSchema({
|
|
606
|
-
type: type,
|
|
607
|
-
vsn: vsn
|
|
608
|
-
}),
|
|
609
|
-
_getSchema2 = _slicedToArray(_getSchema, 2),
|
|
610
|
-
schema = _getSchema2[0],
|
|
611
|
-
tag = _getSchema2[1];
|
|
612
|
-
|
|
613
|
-
var binary = _filterInstanceProperty(_context10 = buildRawTx(_objectSpread(_objectSpread({}, params), {}, {
|
|
614
|
-
VSN: vsn,
|
|
615
|
-
tag: tag
|
|
616
|
-
}), schema, {
|
|
617
|
-
excludeKeys: excludeKeys,
|
|
618
|
-
denomination: params.denomination || denomination
|
|
619
|
-
})).call(_context10, function (e) {
|
|
620
|
-
return e !== undefined;
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
var rlpEncoded = rlpEncode(binary);
|
|
624
|
-
var tx = encode(rlpEncoded, prefix);
|
|
625
|
-
return {
|
|
626
|
-
tx: tx,
|
|
627
|
-
rlpEncoded: rlpEncoded,
|
|
628
|
-
binary: binary,
|
|
629
|
-
txObject: unpackRawTx(binary, schema)
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Unpack transaction hash
|
|
634
|
-
* @function
|
|
635
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
636
|
-
* @param {String|Buffer} encodedTx String or RLP encoded transaction array (if fromRlpBinary flag is true)
|
|
637
|
-
* @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
|
|
638
|
-
* @param {String} prefix - Prefix of data
|
|
639
|
-
* @return {Object} { tx, rlpEncoded, binary } Object with tx -> Object with transaction param's, rlp encoded transaction and binary transaction
|
|
640
|
-
*/
|
|
641
|
-
|
|
642
|
-
export function unpackTx(encodedTx) {
|
|
643
|
-
var fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
644
|
-
var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
|
|
645
|
-
var rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
|
|
646
|
-
var binary = rlpDecode(rlpEncoded);
|
|
647
|
-
var objId = readInt(binary[0]);
|
|
648
|
-
var vsn = readInt(binary[1]);
|
|
649
|
-
|
|
650
|
-
var _getSchema3 = getSchema({
|
|
651
|
-
objId: objId,
|
|
652
|
-
vsn: vsn
|
|
653
|
-
}),
|
|
654
|
-
_getSchema4 = _slicedToArray(_getSchema3, 1),
|
|
655
|
-
schema = _getSchema4[0];
|
|
656
|
-
|
|
657
|
-
return {
|
|
658
|
-
txType: OBJECT_ID_TX_TYPE[objId],
|
|
659
|
-
tx: unpackRawTx(binary, schema),
|
|
660
|
-
rlpEncoded: rlpEncoded,
|
|
661
|
-
binary: binary
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Build a transaction hash
|
|
666
|
-
* @function
|
|
667
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
668
|
-
* @param {String | Buffer} rawTx base64 or rlp encoded transaction
|
|
669
|
-
* @return {String} Transaction hash
|
|
670
|
-
*/
|
|
671
|
-
|
|
672
|
-
export function buildTxHash(rawTx) {
|
|
673
|
-
var data = typeof rawTx === 'string' && _startsWithInstanceProperty(rawTx).call(rawTx, 'tx_') ? decode(rawTx, 'tx') : rawTx;
|
|
674
|
-
return encode(hash(data), 'th');
|
|
675
|
-
}
|
|
676
|
-
export default {
|
|
677
|
-
calculateMinFee: calculateMinFee,
|
|
678
|
-
calculateFee: calculateFee,
|
|
679
|
-
unpackTx: unpackTx,
|
|
680
|
-
unpackRawTx: unpackRawTx,
|
|
681
|
-
buildTx: buildTx,
|
|
682
|
-
buildRawTx: buildRawTx,
|
|
683
|
-
validateParams: validateParams,
|
|
684
|
-
buildTxHash: buildTxHash
|
|
685
|
-
};
|
|
686
|
-
//# sourceMappingURL=index.js.map
|