@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1
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 +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- 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.js +33 -119
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +75 -154
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +108 -916
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +89 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +132 -500
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +4 -23
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +292 -1018
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +203 -451
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +319 -491
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +129 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +102 -247
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +2 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +49 -89
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +205 -303
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +585 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -135
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +49 -75
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +85 -218
- package/es/utils/swagger.js.map +1 -1
- package/package.json +52 -43
- package/src/account/base.js +8 -9
- package/src/account/multiple.js +20 -16
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +65 -246
- package/src/ae/index.js +31 -7
- package/src/ae/oracle.js +21 -17
- package/src/chain/index.js +2 -12
- package/src/chain/node.js +26 -29
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -106
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +2 -12
- package/src/contract/ga/index.js +22 -26
- package/src/index.js +2 -4
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/helpers.js +12 -24
- package/src/tx/builder/index.js +18 -15
- package/src/tx/builder/schema.js +43 -108
- package/src/tx/tx-object.js +0 -2
- package/src/tx/tx.js +157 -144
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -17
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +24 -7
- package/CHANGELOG.md +0 -1716
- package/src/contract/aci/helpers.js +0 -140
package/es/contract/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contract/index.js"],"names":["stampit","required","ContractBase","methods","contractEncodeCallDataAPI","compileContractAPI","contractGetACI","setCompilerUrl","getCompilerVersion","contractDecodeCallResultAPI","validateByteCodeAPI","getFateAssembler","getBytecodeCompilerVersion"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,
|
|
1
|
+
{"version":3,"sources":["../../src/contract/index.js"],"names":["stampit","required","ContractBase","methods","contractEncodeCallDataAPI","compileContractAPI","contractGetACI","setCompilerUrl","getCompilerVersion","contractDecodeCallResultAPI","validateByteCodeAPI","getFateAssembler","getBytecodeCompilerVersion"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,OAAO,CAACC,QAAQ,CAAC;AACpCE,EAAAA,OAAO,EAAE;AACPC,IAAAA,yBAAyB,EAAEH,QADpB;AAEPI,IAAAA,kBAAkB,EAAEJ,QAFb;AAGPK,IAAAA,cAAc,EAAEL,QAHT;AAIPM,IAAAA,cAAc,EAAEN,QAJT;AAKPO,IAAAA,kBAAkB,EAAEP,QALb;AAMPQ,IAAAA,2BAA2B,EAAER,QANtB;AAOPS,IAAAA,mBAAmB,EAAET,QAPd;AAQPU,IAAAA,gBAAgB,EAAEV,QARX;AASPW,IAAAA,0BAA0B,EAAEX;AATrB;AAD2B,CAAD,CAAT,CAA5B;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAeC,YAAf","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 * Contract Base module\n * @module @aeternity/aepp-sdk/es/contract\n * @export Contract\n * @example import ContractBase from '@aeternity/aepp-sdk/es/contract'\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\n\n/**\n * Basic Contract Stamp\n *\n * This stamp include api call's related to contract functionality.\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/contract\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} Contract instance\n */\nconst ContractBase = stampit(required({\n methods: {\n contractEncodeCallDataAPI: required,\n compileContractAPI: required,\n contractGetACI: required,\n setCompilerUrl: required,\n getCompilerVersion: required,\n contractDecodeCallResultAPI: required,\n validateByteCodeAPI: required,\n getFateAssembler: required,\n getBytecodeCompilerVersion: required\n }\n}))\n\n/**\n * Get contract ACI\n * @function contractGetACI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, options: Array) => aciObject: Promise[Object]\n * @param {String} source - Contract source code\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {Object} - Contract aci object\n */\n\n/**\n * Encode contract data\n * @function contractEncodeCallDataAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, name: String, args: Array, options: Array) => callData: Promise[String]\n * @param {String} source - Contract source code\n * @param {String} name - Function name\n * @param {Array} args - Function argument's\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Contract encoded data\n */\n\n/**\n * Decode contract call result data\n * @function contractDecodeCallResultAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, fn: String, callValue: String, callResult: String, options: Array) => decodedResult: Promise[String]\n * @param {String} source - Contract source\n * @param {String} fn - Fn name\n * @param {String} callValue - result data (cb_das...)\n * @param {String} callResult - contract call result status('ok', 'revert', ...)\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Decoded contract call result\n */\n\n/**\n * Decode call data by source\n * @function contractDecodeCallDataBySourceAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (source: String, function: String, callData: String, options: Array) => decodedResult: Promise[String]\n * @param {String} source - contract source\n * @param {String} function - function name\n * @param {String} callData - Encoded contract call data\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {String} - Decoded contract call data\n */\n\n/**\n * Decode call data by bytecode\n * @function contractDecodeCallDataByCodeAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (code: String, callData: String) => decodedResult: Promise[String]\n * @param {String} code - contract byte code\n * @param {String} callData - Encoded contract call data\n * @return {String} - Decoded contract call data\n */\n\n/**\n * Compile contract\n * @function compileContractAPI\n * @instance\n * @abstract\n * @category async\n * @rtype (code: String, options?: Object) => compiledContract: Object\n * @param {String} code - Contract source code\n * @param {Object} [options={}] Options\n * @param {Object} [options.filesystem] Contract external namespaces map\n * @return {Object} Object which contain bytecode of contract\n */\n\n/**\n * Set compiler url\n * @function setCompilerUrl\n * @instance\n * @abstract\n * @category async\n * @rtype (url: String) => void\n * @param {String} url - Compiler url\n * @return {void}\n */\n\n/**\n * Get Compiler Version\n * @function getCompilerVersion\n * @instance\n * @abstract\n * @category async\n * @rtype () => String\n * @return {String} Compiler version\n */\n\nexport default ContractBase\n"],"file":"index.js"}
|
package/es/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import * as Bytes from './utils/bytes';
|
|
|
20
20
|
import * as TxBuilder from './tx/builder';
|
|
21
21
|
import * as TxBuilderHelper from './tx/builder/helpers';
|
|
22
22
|
import * as SCHEMA from './tx/builder/schema';
|
|
23
|
-
import * as ACIHelpers from './contract/aci/helpers';
|
|
24
23
|
import * as ACITransformation from './contract/aci/transformation';
|
|
25
24
|
import * as AmountFormatter from './utils/amount-formatter';
|
|
26
25
|
import HdWallet from './utils/hd-wallet';
|
|
@@ -31,7 +30,7 @@ import Node from './node';
|
|
|
31
30
|
import NodePool from './node-pool';
|
|
32
31
|
import Tx from './tx';
|
|
33
32
|
import Transaction from './tx/tx';
|
|
34
|
-
import
|
|
33
|
+
import verifyTransaction from './tx/validator';
|
|
35
34
|
import AccountBase from './account/base';
|
|
36
35
|
import AccountMultiple from './account/multiple';
|
|
37
36
|
import MemoryAccount from './account/memory';
|
|
@@ -53,5 +52,5 @@ export { _AeppWalletSchema as AeppWalletSchema };
|
|
|
53
52
|
export { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector';
|
|
54
53
|
export { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime';
|
|
55
54
|
export { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message';
|
|
56
|
-
export { AmountFormatter, AccountBase, AccountMultiple, Ae, Aens, Bytes, Contract, ContractCompilerAPI,
|
|
55
|
+
export { AmountFormatter, AccountBase, AccountMultiple, Ae, Aens, Bytes, Contract, ContractCompilerAPI, ACITransformation, ChainNode, RpcAepp, RpcWallet, Channel, Crypto, Keystore, Chain, GeneralizeAccount, HdWallet, MemoryAccount, Node, NodePool, Oracle, genSwaggerClient, Transaction, verifyTransaction, Tx, TxBuilder, TxBuilderHelper, Universal, SCHEMA };
|
|
57
56
|
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["Crypto","Keystore","Bytes","TxBuilder","TxBuilderHelper","SCHEMA","
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["Crypto","Keystore","Bytes","TxBuilder","TxBuilderHelper","SCHEMA","ACITransformation","AmountFormatter","HdWallet","Ae","Chain","ChainNode","Node","NodePool","Tx","Transaction","verifyTransaction","AccountBase","AccountMultiple","MemoryAccount","Aens","Contract","GeneralizeAccount","ContractCompilerAPI","RpcAepp","RpcWallet","Oracle","genSwaggerClient","Channel","Universal","default","ContentScriptBridge","AeppWalletHelpers","AeppWalletSchema","WalletDetector","BrowserRuntimeConnection","BrowserWindowMessageConnection"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,MAAZ,MAAwB,gBAAxB;AACA,OAAO,KAAKC,QAAZ,MAA0B,kBAA1B;AACA,OAAO,KAAKC,KAAZ,MAAuB,eAAvB;AACA,OAAO,KAAKC,SAAZ,MAA2B,cAA3B;AACA,OAAO,KAAKC,eAAZ,MAAiC,sBAAjC;AACA,OAAO,KAAKC,MAAZ,MAAwB,qBAAxB;AACA,OAAO,KAAKC,iBAAZ,MAAmC,+BAAnC;AACA,OAAO,KAAKC,eAAZ,MAAiC,0BAAjC;AACA,OAAOC,QAAP,MAAqB,mBAArB;AAEA,OAAOC,EAAP,MAAe,MAAf;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,IAAP,MAAiB,QAAjB;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,OAAOC,EAAP,MAAe,MAAf;AACA,OAAOC,WAAP,MAAwB,SAAxB;AACA,OAAOC,iBAAP,MAA8B,gBAA9B;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,OAAOC,IAAP,MAAiB,WAAjB;AACA,OAAOC,QAAP,MAAqB,eAArB;AACA,OAAOC,iBAAP,MAA8B,eAA9B;AACA,OAAOC,mBAAP,MAAgC,qBAAhC;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,SAAP,MAAsB,aAAtB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,OAAOC,gBAAP,MAA6B,iBAA7B;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,SAAP,MAAsB,gBAAtB;AAEA,SAASC,OAAO,IAAIC,mBAApB,QAA+C,yDAA/C;oCACmC,2C;+BAAvBC,iB;mCACsB,0C;8BAAtBC,gB;AACZ,SAASH,OAAO,IAAII,cAApB,QAA0C,mDAA1C;AACA,SAASJ,OAAO,IAAIK,wBAApB,QAAoD,8DAApD;AACA,SAASL,OAAO,IAAIM,8BAApB,QAA0D,qEAA1D;AAEA,SACE7B,eADF,EAEEU,WAFF,EAGEC,eAHF,EAIET,EAJF,EAKEW,IALF,EAMElB,KANF,EAOEmB,QAPF,EAQEE,mBARF,EASEjB,iBATF,EAUEK,SAVF,EAWEa,OAXF,EAYEC,SAZF,EAaEG,OAbF,EAcE5B,MAdF,EAeEC,QAfF,EAgBES,KAhBF,EAiBEY,iBAjBF,EAkBEd,QAlBF,EAmBEW,aAnBF,EAoBEP,IApBF,EAqBEC,QArBF,EAsBEa,MAtBF,EAuBEC,gBAvBF,EAwBEZ,WAxBF,EAyBEC,iBAzBF,EA0BEF,EA1BF,EA2BEX,SA3BF,EA4BEC,eA5BF,EA6BEyB,SA7BF,EA8BExB,MA9BF","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\nimport * as Crypto from './utils/crypto'\nimport * as Keystore from './utils/keystore'\nimport * as Bytes from './utils/bytes'\nimport * as TxBuilder from './tx/builder'\nimport * as TxBuilderHelper from './tx/builder/helpers'\nimport * as SCHEMA from './tx/builder/schema'\nimport * as ACITransformation from './contract/aci/transformation'\nimport * as AmountFormatter from './utils/amount-formatter'\nimport HdWallet from './utils/hd-wallet'\n\nimport Ae from './ae'\nimport Chain from './chain'\nimport ChainNode from './chain/node'\nimport Node from './node'\nimport NodePool from './node-pool'\nimport Tx from './tx'\nimport Transaction from './tx/tx'\nimport verifyTransaction from './tx/validator'\nimport AccountBase from './account/base'\nimport AccountMultiple from './account/multiple'\nimport MemoryAccount from './account/memory'\nimport Aens from './ae/aens'\nimport Contract from './ae/contract'\nimport GeneralizeAccount from './contract/ga'\nimport ContractCompilerAPI from './contract/compiler'\nimport RpcAepp from './ae/aepp'\nimport RpcWallet from './ae/wallet'\nimport Oracle from './ae/oracle'\nimport genSwaggerClient from './utils/swagger'\nimport Channel from './channel'\nimport Universal from './ae/universal'\n\nexport { default as ContentScriptBridge } from './utils/aepp-wallet-communication/content-script-bridge'\nexport * as AeppWalletHelpers from './utils/aepp-wallet-communication/helpers'\nexport * as AeppWalletSchema from './utils/aepp-wallet-communication/schema'\nexport { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector'\nexport { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime'\nexport { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message'\n\nexport {\n AmountFormatter,\n AccountBase,\n AccountMultiple,\n Ae,\n Aens,\n Bytes,\n Contract,\n ContractCompilerAPI,\n ACITransformation,\n ChainNode,\n RpcAepp,\n RpcWallet,\n Channel,\n Crypto,\n Keystore,\n Chain,\n GeneralizeAccount,\n HdWallet,\n MemoryAccount,\n Node,\n NodePool,\n Oracle,\n genSwaggerClient,\n Transaction,\n verifyTransaction,\n Tx,\n TxBuilder,\n TxBuilderHelper,\n Universal,\n SCHEMA\n}\n"],"file":"index.js"}
|
package/es/node-pool/index.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
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 _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
7
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
8
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
14
|
-
|
|
15
|
-
import _Map from "@babel/runtime-corejs3/core-js-stable/map";
|
|
16
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
17
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
18
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
19
|
-
import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/entries";
|
|
20
|
-
|
|
21
1
|
/**
|
|
22
2
|
* NodePool module
|
|
23
3
|
* @module @aeternity/aepp-sdk/es/node-pool
|
|
@@ -25,7 +5,6 @@ import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
|
25
5
|
* @example import { NodePool } from '@aeternity/aepp-sdk'
|
|
26
6
|
*/
|
|
27
7
|
import stampit from '@stamp/it';
|
|
28
|
-
import Joi from 'joi-browser';
|
|
29
8
|
import { getNetworkId } from '../node';
|
|
30
9
|
/**
|
|
31
10
|
* Node Pool Stamp
|
|
@@ -39,36 +18,35 @@ import { getNetworkId } from '../node';
|
|
|
39
18
|
*/
|
|
40
19
|
|
|
41
20
|
export default stampit({
|
|
42
|
-
init
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
nodes = _ref$nodes === void 0 ? [] : _ref$nodes;
|
|
48
|
-
|
|
49
|
-
this.pool = new _Map();
|
|
21
|
+
init() {
|
|
22
|
+
let {
|
|
23
|
+
nodes = []
|
|
24
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
|
+
this.pool = new Map();
|
|
50
26
|
this.validateNodes(nodes);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
27
|
+
nodes.forEach((node, i) => {
|
|
28
|
+
const {
|
|
29
|
+
name,
|
|
30
|
+
instance
|
|
31
|
+
} = node;
|
|
32
|
+
this.addNode(name, instance, i === 0);
|
|
57
33
|
});
|
|
58
|
-
|
|
59
34
|
if (nodes.length) this.selectNode(nodes[0].name);
|
|
60
35
|
},
|
|
36
|
+
|
|
61
37
|
propertyDescriptors: {
|
|
62
38
|
api: {
|
|
63
39
|
enumerable: true,
|
|
64
40
|
configurable: false,
|
|
65
|
-
|
|
41
|
+
|
|
42
|
+
get() {
|
|
66
43
|
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
67
44
|
throw new Error('You can\'t use Node API. Node is not connected or not defined!');
|
|
68
45
|
}
|
|
69
46
|
|
|
70
47
|
return this.selectedNode.instance.api;
|
|
71
48
|
}
|
|
49
|
+
|
|
72
50
|
}
|
|
73
51
|
},
|
|
74
52
|
methods: {
|
|
@@ -84,15 +62,15 @@ export default stampit({
|
|
|
84
62
|
* @example
|
|
85
63
|
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'
|
|
86
64
|
*/
|
|
87
|
-
addNode
|
|
88
|
-
|
|
89
|
-
if (this.pool.has(name)) throw new Error(
|
|
65
|
+
addNode(name, node) {
|
|
66
|
+
let select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
67
|
+
if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`);
|
|
90
68
|
this.validateNodes([{
|
|
91
|
-
name
|
|
69
|
+
name,
|
|
92
70
|
instance: node
|
|
93
71
|
}]);
|
|
94
72
|
this.pool.set(name, {
|
|
95
|
-
name
|
|
73
|
+
name,
|
|
96
74
|
instance: node,
|
|
97
75
|
url: node.url,
|
|
98
76
|
internalUrl: node.internalUrl,
|
|
@@ -116,8 +94,8 @@ export default stampit({
|
|
|
116
94
|
* @example
|
|
117
95
|
* nodePool.selectNode('testNode')
|
|
118
96
|
*/
|
|
119
|
-
selectNode
|
|
120
|
-
if (!this.pool.has(name)) throw new Error(
|
|
97
|
+
selectNode(name) {
|
|
98
|
+
if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`);
|
|
121
99
|
this.selectedNode = this.pool.get(name);
|
|
122
100
|
},
|
|
123
101
|
|
|
@@ -130,7 +108,7 @@ export default stampit({
|
|
|
130
108
|
* @example
|
|
131
109
|
* nodePool.getNetworkId()
|
|
132
110
|
*/
|
|
133
|
-
getNetworkId
|
|
111
|
+
getNetworkId,
|
|
134
112
|
|
|
135
113
|
/**
|
|
136
114
|
* Check if you have selected node
|
|
@@ -141,7 +119,7 @@ export default stampit({
|
|
|
141
119
|
* @example
|
|
142
120
|
* nodePool.isNodeConnected()
|
|
143
121
|
*/
|
|
144
|
-
isNodeConnected
|
|
122
|
+
isNodeConnected() {
|
|
145
123
|
return !!this.selectedNode.instance;
|
|
146
124
|
},
|
|
147
125
|
|
|
@@ -154,11 +132,12 @@ export default stampit({
|
|
|
154
132
|
* @example
|
|
155
133
|
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
156
134
|
*/
|
|
157
|
-
getNodeInfo
|
|
135
|
+
getNodeInfo() {
|
|
158
136
|
if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected');
|
|
159
|
-
return
|
|
160
|
-
name: this.selectedNode.name
|
|
161
|
-
|
|
137
|
+
return {
|
|
138
|
+
name: this.selectedNode.name,
|
|
139
|
+
...this.selectedNode.instance.getNodeInfo()
|
|
140
|
+
};
|
|
162
141
|
},
|
|
163
142
|
|
|
164
143
|
/**
|
|
@@ -170,32 +149,34 @@ export default stampit({
|
|
|
170
149
|
* @example
|
|
171
150
|
* nodePool.getNodesInPool()
|
|
172
151
|
*/
|
|
173
|
-
getNodesInPool
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return _objectSpread({
|
|
182
|
-
name: name
|
|
183
|
-
}, node.instance.getNodeInfo());
|
|
152
|
+
getNodesInPool() {
|
|
153
|
+
return Array.from(this.pool.entries()).map(_ref => {
|
|
154
|
+
let [name, node] = _ref;
|
|
155
|
+
return {
|
|
156
|
+
name,
|
|
157
|
+
...node.instance.getNodeInfo()
|
|
158
|
+
};
|
|
184
159
|
});
|
|
185
160
|
},
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
161
|
+
|
|
162
|
+
validateNodes(nodes) {
|
|
163
|
+
// TODO: validate it on TypeScript level instead (to speedup development, save runtime resources)
|
|
164
|
+
if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array');
|
|
165
|
+
const notObject = nodes.map(n => typeof n).find(t => t !== 'object');
|
|
166
|
+
if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`);
|
|
167
|
+
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object');
|
|
168
|
+
|
|
169
|
+
if (notObject) {
|
|
170
|
+
throw new Error('Each node should have name (string), instance (object) ' + `fields, got ${JSON.stringify(wrongFields)} instead`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const wrongInstanceFields = nodes.map(n => n.instance).find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' || typeof i.consensusProtocolVersion !== 'number');
|
|
174
|
+
|
|
175
|
+
if (wrongInstanceFields) {
|
|
176
|
+
throw new Error('Each node instance should have api (object), consensusProtocolVersion (number), ' + `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`);
|
|
177
|
+
}
|
|
198
178
|
}
|
|
179
|
+
|
|
199
180
|
},
|
|
200
181
|
props: {
|
|
201
182
|
selectedNode: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","
|
|
1
|
+
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","getNetworkId","init","nodes","pool","Map","validateNodes","forEach","node","i","name","instance","addNode","length","selectNode","propertyDescriptors","api","enumerable","configurable","get","selectedNode","Error","methods","select","has","set","url","internalUrl","networkId","nodeNetworkId","version","consensusProtocolVersion","isNodeConnected","getNodeInfo","getNodesInPool","Array","from","entries","map","isArray","notObject","n","find","t","wrongFields","JSON","stringify","wrongInstanceFields","genesisHash","props"],"mappings":"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","sourcesContent":["/**\n * NodePool module\n * @module @aeternity/aepp-sdk/es/node-pool\n * @export NodePool\n * @example import { NodePool } from '@aeternity/aepp-sdk'\n */\nimport stampit from '@stamp/it'\nimport { getNetworkId } from '../node'\n\n/**\n * Node Pool Stamp\n * This stamp allow you to make basic manipulation(add, remove, select) on list of nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Array} [options.nodes] - Array with Node instances\n * @return {Object} NodePool instance\n */\nexport default stampit({\n init ({ nodes = [] } = {}) {\n this.pool = new Map()\n this.validateNodes(nodes)\n\n nodes.forEach((node, i) => {\n const { name, instance } = node\n this.addNode(name, instance, i === 0)\n })\n if (nodes.length) this.selectNode(nodes[0].name)\n },\n propertyDescriptors: {\n api: {\n enumerable: true,\n configurable: false,\n get () {\n if (!this.selectedNode || !this.selectedNode.instance) {\n throw new Error('You can\\'t use Node API. Node is not connected or not defined!')\n }\n return this.selectedNode.instance.api\n }\n }\n },\n methods: {\n /**\n * Add Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String, nodeInstance: Object, select: Boolean) => void\n * @param {String} name - Node name\n * @param {Object} node - Node instance\n * @param {Boolean} select - Select this node as current\n * @return {void}\n * @example\n * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'\n */\n addNode (name, node, select = false) {\n if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)\n\n this.validateNodes([{ name, instance: node }])\n\n this.pool.set(name, {\n name,\n instance: node,\n url: node.url,\n internalUrl: node.internalUrl,\n networkId: node.nodeNetworkId,\n version: node.version,\n consensusProtocolVersion: node.consensusProtocolVersion\n })\n if (select || !this.selectedNode) {\n this.selectNode(name)\n }\n },\n /**\n * Select Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String) => void\n * @param {String} name - Node name\n * @return {void}\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode (name) {\n if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`)\n\n this.selectedNode = this.pool.get(name)\n },\n /**\n * Get NetworkId of current Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => String\n * @return {String}\n * @example\n * nodePool.getNetworkId()\n */\n getNetworkId,\n /**\n * Check if you have selected node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Boolean\n * @return {Boolean}\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected () {\n return !!this.selectedNode.instance\n },\n /**\n * Get information about node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object\n * @return {Object}\n * @example\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n */\n getNodeInfo () {\n if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected')\n return {\n name: this.selectedNode.name,\n ...this.selectedNode.instance.getNodeInfo()\n }\n },\n /**\n * Get array of available nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object[]\n * @return {Object[]}\n * @example\n * nodePool.getNodesInPool()\n */\n getNodesInPool () {\n return Array.from(this.pool.entries()).map(([name, node]) => ({\n name,\n ...node.instance.getNodeInfo()\n }))\n },\n validateNodes (nodes) {\n // TODO: validate it on TypeScript level instead (to speedup development, save runtime resources)\n if (!Array.isArray(nodes)) throw new Error('\"nodes\" should be an array')\n const notObject = nodes.map(n => typeof n).find(t => t !== 'object')\n if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`)\n const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')\n if (notObject) {\n throw new Error(\n 'Each node should have name (string), instance (object) ' +\n `fields, got ${JSON.stringify(wrongFields)} instead`\n )\n }\n const wrongInstanceFields = nodes\n .map(n => n.instance)\n .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||\n typeof i.consensusProtocolVersion !== 'number')\n if (wrongInstanceFields) {\n throw new Error(\n 'Each node instance should have api (object), consensusProtocolVersion (number), ' +\n `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`\n )\n }\n }\n },\n props: {\n selectedNode: {}\n }\n})\n"],"file":"index.js"}
|
package/es/node.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
6
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
7
|
-
|
|
8
1
|
/*
|
|
9
2
|
* ISC License (ISC)
|
|
10
3
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -40,25 +33,14 @@ import semverSatisfies from './utils/semver-satisfies';
|
|
|
40
33
|
*/
|
|
41
34
|
|
|
42
35
|
export function getNetworkId() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
let {
|
|
37
|
+
networkId,
|
|
38
|
+
force = false
|
|
39
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
48
40
|
if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided');
|
|
49
41
|
if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null;
|
|
50
42
|
return networkId || this.networkId || this.selectedNode.networkId;
|
|
51
43
|
}
|
|
52
|
-
/**
|
|
53
|
-
* get consensus protocol version
|
|
54
|
-
* @param {Array} protocols Array of protocols
|
|
55
|
-
* @param {Number} height Height
|
|
56
|
-
* @return {Number} version Protocol version
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function getConsensusProtocolVersion() {
|
|
60
|
-
return _getConsensusProtocolVersion.apply(this, arguments);
|
|
61
|
-
}
|
|
62
44
|
/**
|
|
63
45
|
* {@link genSwaggerClient} based Node remote API Stamp
|
|
64
46
|
* @function
|
|
@@ -72,140 +54,57 @@ function getConsensusProtocolVersion() {
|
|
|
72
54
|
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
73
55
|
*/
|
|
74
56
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
throw new Error('Protocols must be an array');
|
|
96
|
-
|
|
97
|
-
case 4:
|
|
98
|
-
if (height) {
|
|
99
|
-
_context4.next = 8;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_context4.next = 7;
|
|
104
|
-
return this.api.getCurrentKeyBlock();
|
|
105
|
-
|
|
106
|
-
case 7:
|
|
107
|
-
height = _context4.sent.height;
|
|
108
|
-
|
|
109
|
-
case 8:
|
|
110
|
-
if (!(height < 0)) {
|
|
111
|
-
_context4.next = 10;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
throw new Error('height must be a number >= 0');
|
|
116
|
-
|
|
117
|
-
case 10:
|
|
118
|
-
return _context4.abrupt("return", _reduceInstanceProperty(_context3 = _filterInstanceProperty(protocols).call(protocols, function (_ref3) {
|
|
119
|
-
var effectiveAtHeight = _ref3.effectiveAtHeight;
|
|
120
|
-
return height >= effectiveAtHeight;
|
|
121
|
-
})).call(_context3, function (acc, p) {
|
|
122
|
-
return p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc;
|
|
123
|
-
}, {
|
|
124
|
-
effectiveAtHeight: -1,
|
|
125
|
-
version: 0
|
|
126
|
-
}).version);
|
|
127
|
-
|
|
128
|
-
case 11:
|
|
129
|
-
case "end":
|
|
130
|
-
return _context4.stop();
|
|
131
|
-
}
|
|
57
|
+
const Node = AsyncInit.compose({
|
|
58
|
+
async init(_ref) {
|
|
59
|
+
let {
|
|
60
|
+
url,
|
|
61
|
+
internalUrl,
|
|
62
|
+
ignoreVersion
|
|
63
|
+
} = _ref;
|
|
64
|
+
if (!url) throw new Error('"url" required');
|
|
65
|
+
this.url = url.replace(/\/$/, '');
|
|
66
|
+
this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url;
|
|
67
|
+
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
68
|
+
internalUrl: this.internalUrl,
|
|
69
|
+
responseInterceptor: response => {
|
|
70
|
+
if (response.ok) return;
|
|
71
|
+
return Object.assign(response, {
|
|
72
|
+
statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
|
|
73
|
+
});
|
|
132
74
|
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return genSwaggerClient("".concat(_this.url, "/api?oas3"), {
|
|
163
|
-
internalUrl: _this.internalUrl
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
case 7:
|
|
167
|
-
client = _context2.sent;
|
|
168
|
-
_this.version = client.spec.info.version;
|
|
169
|
-
|
|
170
|
-
if (!(!semverSatisfies(_this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion)) {
|
|
171
|
-
_context2.next = 11;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
throw new Error("Unsupported node version ".concat(_this.version, ". ") + _concatInstanceProperty(_context = "Supported: >= ".concat(NODE_GE_VERSION, " < ")).call(_context, NODE_LT_VERSION));
|
|
176
|
-
|
|
177
|
-
case 11:
|
|
178
|
-
_this.api = client.api;
|
|
179
|
-
_context2.next = 14;
|
|
180
|
-
return _this.api.getStatus();
|
|
181
|
-
|
|
182
|
-
case 14:
|
|
183
|
-
_yield$_this$api$getS = _context2.sent;
|
|
184
|
-
revision = _yield$_this$api$getS.nodeRevision;
|
|
185
|
-
genesisHash = _yield$_this$api$getS.genesisKeyBlockHash;
|
|
186
|
-
networkId = _yield$_this$api$getS.networkId;
|
|
187
|
-
protocols = _yield$_this$api$getS.protocols;
|
|
188
|
-
_context2.next = 21;
|
|
189
|
-
return _this.getConsensusProtocolVersion(protocols);
|
|
190
|
-
|
|
191
|
-
case 21:
|
|
192
|
-
_this.consensusProtocolVersion = _context2.sent;
|
|
193
|
-
_this.nodeNetworkId = networkId;
|
|
194
|
-
return _context2.abrupt("return", _Object$assign(_this, {
|
|
195
|
-
revision: revision,
|
|
196
|
-
genesisHash: genesisHash
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
|
-
case 24:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context2.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee);
|
|
205
|
-
}))();
|
|
75
|
+
});
|
|
76
|
+
this.version = client.spec.info.version;
|
|
77
|
+
|
|
78
|
+
if (!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion) {
|
|
79
|
+
throw new Error(`Unsupported node version ${this.version}. ` + `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.api = client.api;
|
|
83
|
+
const {
|
|
84
|
+
nodeRevision: revision,
|
|
85
|
+
genesisKeyBlockHash: genesisHash,
|
|
86
|
+
networkId,
|
|
87
|
+
protocols,
|
|
88
|
+
topBlockHeight
|
|
89
|
+
} = await this.api.getStatus();
|
|
90
|
+
this.consensusProtocolVersion = protocols.filter(_ref2 => {
|
|
91
|
+
let {
|
|
92
|
+
effectiveAtHeight
|
|
93
|
+
} = _ref2;
|
|
94
|
+
return topBlockHeight >= effectiveAtHeight;
|
|
95
|
+
}).reduce((acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc, {
|
|
96
|
+
effectiveAtHeight: -1,
|
|
97
|
+
version: 0
|
|
98
|
+
}).version;
|
|
99
|
+
this.nodeNetworkId = networkId;
|
|
100
|
+
return Object.assign(this, {
|
|
101
|
+
revision,
|
|
102
|
+
genesisHash
|
|
103
|
+
});
|
|
206
104
|
},
|
|
105
|
+
|
|
207
106
|
methods: {
|
|
208
|
-
getNodeInfo
|
|
107
|
+
getNodeInfo() {
|
|
209
108
|
return {
|
|
210
109
|
url: this.url,
|
|
211
110
|
internalUrl: this.internalUrl,
|
|
@@ -213,8 +112,8 @@ var Node = AsyncInit.compose({
|
|
|
213
112
|
version: this.version,
|
|
214
113
|
consensusProtocolVersion: this.consensusProtocolVersion
|
|
215
114
|
};
|
|
216
|
-
}
|
|
217
|
-
|
|
115
|
+
}
|
|
116
|
+
|
|
218
117
|
},
|
|
219
118
|
props: {
|
|
220
119
|
version: null,
|
|
@@ -222,7 +121,7 @@ var Node = AsyncInit.compose({
|
|
|
222
121
|
nodeNetworkId: null
|
|
223
122
|
}
|
|
224
123
|
});
|
|
225
|
-
|
|
226
|
-
|
|
124
|
+
const NODE_GE_VERSION = '6.2.0';
|
|
125
|
+
const NODE_LT_VERSION = '7.0.0';
|
|
227
126
|
export default Node;
|
|
228
127
|
//# sourceMappingURL=node.js.map
|