@aeternity/aepp-sdk 10.0.0 → 12.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/LICENSE +1 -1
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
- 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/AeSdk.d.ts +37 -0
- package/es/AeSdk.mjs +81 -0
- package/es/AeSdk.mjs.map +1 -0
- package/es/AeSdkAepp.d.ts +69 -0
- package/es/AeSdkAepp.mjs +175 -0
- package/es/AeSdkAepp.mjs.map +1 -0
- package/es/AeSdkBase.d.ts +212 -0
- package/es/AeSdkBase.mjs +310 -0
- package/es/AeSdkBase.mjs.map +1 -0
- package/es/AeSdkWallet.d.ts +103 -0
- package/es/AeSdkWallet.mjs +322 -0
- package/es/AeSdkWallet.mjs.map +1 -0
- package/es/Node.d.ts +44 -0
- package/es/Node.mjs +141 -0
- package/es/Node.mjs.map +1 -0
- package/es/account/Base.d.ts +65 -0
- package/es/account/Base.mjs +123 -0
- package/es/account/Base.mjs.map +1 -0
- package/es/account/Memory.d.ts +25 -0
- package/es/account/Memory.mjs +81 -0
- package/es/account/Memory.mjs.map +1 -0
- package/es/account/Rpc.d.ts +27 -0
- package/es/account/Rpc.mjs +79 -0
- package/es/account/Rpc.mjs.map +1 -0
- package/es/aens.d.ts +209 -0
- package/es/aens.mjs +332 -0
- package/es/aens.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
- package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
- package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
- package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
- package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +118 -0
- package/es/aepp-wallet-communication/schema.mjs +214 -0
- package/es/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/apis/compiler/compiler.d.ts +92 -0
- package/es/apis/compiler/compiler.mjs +576 -0
- package/es/apis/compiler/compiler.mjs.map +1 -0
- package/es/apis/compiler/index.d.ts +2 -0
- package/es/apis/compiler/index.mjs +3 -0
- package/es/apis/compiler/index.mjs.map +1 -0
- package/es/apis/compiler/models/index.d.ts +248 -0
- package/es/apis/compiler/models/index.mjs +48 -0
- package/es/apis/compiler/models/index.mjs.map +1 -0
- package/es/apis/compiler/models/mappers.d.ts +23 -0
- package/es/apis/compiler/models/mappers.mjs +585 -0
- package/es/apis/compiler/models/mappers.mjs.map +1 -0
- package/es/apis/compiler/models/parameters.d.ts +13 -0
- package/es/apis/compiler/models/parameters.mjs +71 -0
- package/es/apis/compiler/models/parameters.mjs.map +1 -0
- package/es/apis/node/index.d.ts +2 -0
- package/es/apis/node/index.mjs +3 -0
- package/es/apis/node/index.mjs.map +1 -0
- package/es/apis/node/models/index.d.ts +1061 -0
- package/es/apis/node/models/index.mjs +2 -0
- package/es/apis/node/models/index.mjs.map +1 -0
- package/es/apis/node/models/mappers.d.ts +95 -0
- package/es/apis/node/models/mappers.mjs +4164 -0
- package/es/apis/node/models/mappers.mjs.map +1 -0
- package/es/apis/node/models/parameters.d.ts +17 -0
- package/es/apis/node/models/parameters.mjs +165 -0
- package/es/apis/node/models/parameters.mjs.map +1 -0
- package/es/apis/node/node.d.ts +215 -0
- package/es/apis/node/node.mjs +1165 -0
- package/es/apis/node/node.mjs.map +1 -0
- package/es/chain.d.ts +220 -0
- package/es/chain.mjs +524 -0
- package/es/chain.mjs.map +1 -0
- package/es/channel/handlers.d.ts +34 -0
- package/es/channel/{handlers.js → handlers.mjs} +163 -130
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/index.d.ts +634 -0
- package/es/channel/index.mjs +978 -0
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.d.ts +100 -0
- package/es/channel/internal.mjs +328 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/Compiler.d.ts +17 -0
- package/es/contract/Compiler.mjs +67 -0
- package/es/contract/Compiler.mjs.map +1 -0
- package/es/contract/aci.d.ts +125 -0
- package/es/contract/aci.mjs +496 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/ga.d.ts +68 -0
- package/es/contract/ga.mjs +190 -0
- package/es/contract/ga.mjs.map +1 -0
- package/es/contract/methods.d.ts +68 -0
- package/es/contract/methods.mjs +101 -0
- package/es/contract/methods.mjs.map +1 -0
- package/es/index.d.ts +32 -0
- package/es/index.mjs +49 -0
- package/es/index.mjs.map +1 -0
- package/es/oracle.d.ts +154 -0
- package/es/oracle.mjs +288 -0
- package/es/oracle.mjs.map +1 -0
- package/es/spend.d.ts +61 -0
- package/es/spend.mjs +122 -0
- package/es/spend.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +41 -0
- package/es/tx/builder/constants.mjs +100 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.d.ts +62 -0
- package/es/tx/builder/field-types.mjs +126 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +131 -0
- package/es/tx/builder/helpers.mjs +223 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.d.ts +75 -0
- package/es/tx/builder/index.mjs +424 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.d.ts +350 -0
- package/es/tx/builder/schema.mjs +320 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/index.d.ts +63 -0
- package/es/tx/index.mjs +209 -0
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/min-fee.d.ts +20 -0
- package/es/tx/min-fee.mjs +148 -0
- package/es/tx/min-fee.mjs.map +1 -0
- package/es/tx/validator.d.ts +19 -0
- package/es/tx/validator.mjs +240 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
- package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
- package/es/typings/bip32-path/index.d.mjs +2 -0
- package/es/typings/bip32-path/index.d.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
- package/es/utils/amount-formatter.d.ts +42 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/autorest.d.ts +6 -0
- package/es/utils/autorest.mjs +97 -0
- package/es/utils/autorest.mjs.map +1 -0
- package/es/utils/bignumber.d.ts +13 -0
- package/es/utils/bignumber.mjs +23 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
- package/es/utils/{bytes.js → bytes.mjs} +26 -22
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/crypto.d.ts +103 -0
- package/es/utils/crypto.mjs +221 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.d.ts +26 -0
- package/es/utils/encoder.mjs +102 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.d.ts +481 -0
- package/es/utils/errors.mjs +882 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.d.ts +34 -0
- package/es/utils/hd-wallet.mjs +122 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.d.ts +5 -0
- package/es/utils/json-big.mjs +41 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.d.ts +51 -0
- package/es/utils/keystore.mjs +145 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
- package/es/utils/{mptree.js → mptree.mjs} +33 -25
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.d.ts +14 -0
- package/es/utils/other.mjs +28 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/string.d.ts +24 -0
- package/es/utils/{string.js → string.mjs} +9 -11
- package/es/utils/string.mjs.map +1 -0
- package/package.json +67 -64
- package/src/AeSdk.ts +65 -0
- package/src/AeSdkAepp.ts +167 -0
- package/src/AeSdkBase.ts +320 -0
- package/src/AeSdkWallet.ts +332 -0
- package/src/Node.ts +167 -0
- package/src/account/Base.ts +114 -0
- package/src/account/Memory.ts +83 -0
- package/src/account/Rpc.ts +67 -0
- package/src/aens.ts +391 -0
- package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
- package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
- package/src/aepp-wallet-communication/rpc/types.ts +66 -0
- package/src/aepp-wallet-communication/schema.ts +181 -0
- package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
- package/src/apis/compiler/code-model-v4.yaml +2649 -0
- package/src/apis/compiler/compiler.ts +585 -0
- package/src/apis/compiler/index.ts +2 -0
- package/src/apis/compiler/models/index.ts +301 -0
- package/src/apis/compiler/models/mappers.ts +583 -0
- package/src/apis/compiler/models/parameters.ts +93 -0
- package/src/apis/node/code-model-v4.yaml +10046 -0
- package/src/apis/node/index.ts +2 -0
- package/src/apis/node/models/index.ts +1253 -0
- package/src/apis/node/models/mappers.ts +4278 -0
- package/src/apis/node/models/parameters.ts +188 -0
- package/src/apis/node/node.ts +1299 -0
- package/src/chain.ts +444 -0
- package/src/channel/{handlers.js → handlers.ts} +238 -143
- package/src/channel/index.ts +991 -0
- package/src/channel/internal.ts +345 -0
- package/src/contract/Compiler.ts +66 -0
- package/src/contract/aci.ts +529 -0
- package/src/contract/ga.ts +178 -0
- package/src/contract/methods.ts +118 -0
- package/src/index.ts +51 -0
- package/src/oracle.ts +342 -0
- package/src/spend.ts +152 -0
- package/src/tx/builder/constants.ts +96 -0
- package/src/tx/builder/field-types.ts +111 -0
- package/src/tx/builder/helpers.ts +253 -0
- package/src/tx/builder/index.ts +394 -0
- package/src/tx/builder/schema.ts +771 -0
- package/src/tx/index.ts +199 -0
- package/src/tx/min-fee.ts +136 -0
- package/src/tx/validator.ts +226 -0
- package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
- package/src/typings/@aeternity__uuid/index.d.ts +3 -0
- package/src/typings/bip32-path/index.d.ts +33 -0
- package/src/typings/tweetnacl-auth/index.d.ts +14 -0
- package/src/utils/amount-formatter.ts +29 -41
- package/src/utils/autorest.ts +90 -0
- package/src/utils/bignumber.ts +9 -19
- package/src/utils/bytes.ts +15 -16
- package/src/utils/crypto.ts +217 -0
- package/src/utils/encoder.ts +98 -0
- package/src/utils/errors.ts +817 -0
- package/src/utils/hd-wallet.ts +134 -0
- package/src/utils/json-big.ts +26 -0
- package/src/utils/keystore.ts +179 -0
- package/src/utils/mptree.ts +26 -20
- package/src/utils/other.ts +28 -43
- package/src/utils/string.ts +8 -10
- package/CHANGELOG.md +0 -1603
- package/es/account/base.js +0 -169
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -84
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -178
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -408
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js +0 -45
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -312
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -206
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -322
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js +0 -45
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js +0 -50
- package/es/ae/wallet.js.map +0 -1
- package/es/amount-formatter.d.ts +0 -58
- package/es/bignumber.d.ts +0 -24
- package/es/chain/index.js +0 -256
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -394
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js +0 -980
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -266
- 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 -361
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -244
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -170
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -162
- package/es/contract/index.js.map +0 -1
- package/es/crypto-ts.d.ts +0 -9
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -187
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -132
- package/es/node.js.map +0 -1
- package/es/other.d.ts +0 -31
- package/es/string.d.ts +0 -26
- package/es/tx/builder/helpers.js +0 -305
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -595
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -814
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js +0 -300
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -276
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -937
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -208
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/typings/blakejs/index.d.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
- 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 -184
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -103
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -67
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -28
- 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 -304
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -112
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -45
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -228
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -43
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -132
- package/es/utils/swagger.js.map +0 -1
- package/src/account/base.js +0 -153
- package/src/account/memory.js +0 -78
- package/src/account/multiple.js +0 -154
- package/src/ae/aens.js +0 -366
- package/src/ae/aepp.js +0 -45
- package/src/ae/contract.js +0 -285
- package/src/ae/index.js +0 -167
- package/src/ae/oracle.js +0 -296
- package/src/ae/universal.js +0 -47
- package/src/ae/wallet.js +0 -50
- package/src/chain/index.js +0 -250
- package/src/chain/node.js +0 -293
- package/src/channel/index.js +0 -898
- package/src/channel/internal.js +0 -231
- package/src/contract/aci/index.js +0 -317
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/compiler.js +0 -195
- package/src/contract/ga/helpers.js +0 -17
- package/src/contract/ga/index.js +0 -147
- package/src/contract/index.js +0 -163
- package/src/index.js +0 -90
- package/src/node-pool/index.js +0 -171
- package/src/node.js +0 -118
- package/src/tx/builder/helpers.js +0 -325
- package/src/tx/builder/index.js +0 -460
- package/src/tx/builder/schema.js +0 -1211
- package/src/tx/index.js +0 -301
- package/src/tx/tx-object.js +0 -186
- package/src/tx/tx.js +0 -622
- package/src/tx/validator.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
- package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
- package/src/utils/aepp-wallet-communication/helpers.js +0 -70
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
- package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
- package/src/utils/async-init.js +0 -41
- package/src/utils/crypto.js +0 -312
- package/src/utils/hd-wallet.js +0 -115
- package/src/utils/json-big.js +0 -26
- package/src/utils/keystore.js +0 -223
- package/src/utils/swagger.js +0 -133
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
2
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
3
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
4
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
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 _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
9
|
-
import _last from "ramda/src/last";
|
|
10
|
-
import _pick from "ramda/src/pick";
|
|
11
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
12
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
13
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context14; _forEachInstanceProperty(_context14 = ownKeys(Object(source), true)).call(_context14, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context15; _forEachInstanceProperty(_context15 = ownKeys(Object(source))).call(_context15, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
20
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
21
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
22
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
23
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
24
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
25
|
-
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
|
26
|
-
import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
|
|
27
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
28
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
29
|
-
import { unpackTx } from '../../tx/builder';
|
|
30
|
-
import { decodeEvents as unpackEvents, transform, transformDecodedData, validateArguments } from './transformation';
|
|
31
|
-
/**
|
|
32
|
-
* Get function schema from contract ACI object
|
|
33
|
-
* @param {Object} aci Contract ACI object
|
|
34
|
-
* @param {String} name Function name
|
|
35
|
-
* @param external
|
|
36
|
-
* @return {Object} function ACI
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export function getFunctionACI(aci, name, _ref) {
|
|
40
|
-
var _context, _context2;
|
|
41
|
-
|
|
42
|
-
var external = _ref.external;
|
|
43
|
-
if (!aci) throw new Error('ACI required');
|
|
44
|
-
|
|
45
|
-
var fn = _findInstanceProperty(_context = aci.functions).call(_context, function (f) {
|
|
46
|
-
return f.name === name;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (!fn && name !== 'init') throw new Error("Function ".concat(name, " doesn't exist in contract"));
|
|
50
|
-
return _objectSpread(_objectSpread({}, fn), {}, {
|
|
51
|
-
bindings: _concatInstanceProperty(_context2 = [{
|
|
52
|
-
state: aci.state,
|
|
53
|
-
type_defs: aci.type_defs,
|
|
54
|
-
name: aci.name
|
|
55
|
-
}]).call(_context2, _toConsumableArray(_mapInstanceProperty(external).call(external, _pick(['state', 'type_defs', 'name'])))),
|
|
56
|
-
event: aci.event ? aci.event.variant : []
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build contract methods base on ACI
|
|
61
|
-
* @return {Object} Contract instance methods
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
export var buildContractMethods = function buildContractMethods(instance) {
|
|
65
|
-
return function () {
|
|
66
|
-
var _context3;
|
|
67
|
-
|
|
68
|
-
return _objectSpread(_objectSpread({}, instance.aci ? _reduceInstanceProperty(_context3 = instance.aci.functions).call(_context3, function (acc, _ref2) {
|
|
69
|
-
var name = _ref2.name,
|
|
70
|
-
aciArgs = _ref2.arguments,
|
|
71
|
-
stateful = _ref2.stateful;
|
|
72
|
-
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, name, _Object$assign(function () {
|
|
73
|
-
var _parseArguments = parseArguments(aciArgs)(arguments),
|
|
74
|
-
opt = _parseArguments.opt,
|
|
75
|
-
args = _parseArguments.args;
|
|
76
|
-
|
|
77
|
-
if (name === 'init') return instance.deploy(args, opt);
|
|
78
|
-
return instance.call(name, args, _objectSpread({
|
|
79
|
-
callStatic: !stateful
|
|
80
|
-
}, opt));
|
|
81
|
-
}, {
|
|
82
|
-
get: function get() {
|
|
83
|
-
var _parseArguments2 = parseArguments(aciArgs)(arguments),
|
|
84
|
-
opt = _parseArguments2.opt,
|
|
85
|
-
args = _parseArguments2.args;
|
|
86
|
-
|
|
87
|
-
return instance.call(name, args, _objectSpread(_objectSpread({}, opt), {}, {
|
|
88
|
-
callStatic: true
|
|
89
|
-
}));
|
|
90
|
-
},
|
|
91
|
-
send: function send() {
|
|
92
|
-
var _parseArguments3 = parseArguments(aciArgs)(arguments),
|
|
93
|
-
opt = _parseArguments3.opt,
|
|
94
|
-
args = _parseArguments3.args;
|
|
95
|
-
|
|
96
|
-
if (name === 'init') return instance.deploy(args, opt);
|
|
97
|
-
return instance.call(name, args, _objectSpread(_objectSpread({}, opt), {}, {
|
|
98
|
-
callStatic: false
|
|
99
|
-
}));
|
|
100
|
-
},
|
|
101
|
-
decodeEvents: function decodeEvents(events) {
|
|
102
|
-
return instance.decodeEvents(name, events);
|
|
103
|
-
}
|
|
104
|
-
})));
|
|
105
|
-
}, {}) : {}), instance.aci ? {
|
|
106
|
-
init: _Object$assign(function () {
|
|
107
|
-
var _getFunctionACI = getFunctionACI(instance.aci, 'init', {
|
|
108
|
-
external: instance.externalAci
|
|
109
|
-
}),
|
|
110
|
-
aciArgs = _getFunctionACI.arguments;
|
|
111
|
-
|
|
112
|
-
var _parseArguments4 = parseArguments(aciArgs)(arguments),
|
|
113
|
-
opt = _parseArguments4.opt,
|
|
114
|
-
args = _parseArguments4.args;
|
|
115
|
-
|
|
116
|
-
return instance.deploy(args, opt);
|
|
117
|
-
}, {
|
|
118
|
-
get: function get() {
|
|
119
|
-
var _getFunctionACI2 = getFunctionACI(instance.aci, 'init', {
|
|
120
|
-
external: instance.externalAci
|
|
121
|
-
}),
|
|
122
|
-
aciArgs = _getFunctionACI2.arguments;
|
|
123
|
-
|
|
124
|
-
var _parseArguments5 = parseArguments(aciArgs)(arguments),
|
|
125
|
-
opt = _parseArguments5.opt,
|
|
126
|
-
args = _parseArguments5.args;
|
|
127
|
-
|
|
128
|
-
return instance.deploy(args, _objectSpread(_objectSpread({}, opt), {}, {
|
|
129
|
-
callStatic: true
|
|
130
|
-
}));
|
|
131
|
-
},
|
|
132
|
-
send: function send() {
|
|
133
|
-
var _getFunctionACI3 = getFunctionACI(instance.aci, 'init', {
|
|
134
|
-
external: instance.externalAci
|
|
135
|
-
}),
|
|
136
|
-
aciArgs = _getFunctionACI3.arguments;
|
|
137
|
-
|
|
138
|
-
var _parseArguments6 = parseArguments(aciArgs)(arguments),
|
|
139
|
-
opt = _parseArguments6.opt,
|
|
140
|
-
args = _parseArguments6.args;
|
|
141
|
-
|
|
142
|
-
return instance.deploy(args, _objectSpread(_objectSpread({}, opt), {}, {
|
|
143
|
-
callStatic: false
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
} : {});
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
export var parseArguments = function parseArguments() {
|
|
151
|
-
var aciArgs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
152
|
-
return function (args) {
|
|
153
|
-
var _context4;
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
opt: args.length > aciArgs.length ? _last(args) : {},
|
|
157
|
-
args: _sliceInstanceProperty(_context4 = _Object$values(args)).call(_context4, 0, aciArgs.length)
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
export var unpackByteCode = function unpackByteCode(bytecode) {
|
|
162
|
-
return unpackTx(bytecode, false, 'cb').tx;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* Validated contract call arguments using contract ACI
|
|
166
|
-
* @function validateCallParams
|
|
167
|
-
* @rtype (aci: Object, params: Array) => Object
|
|
168
|
-
* @param {Object} aci Contract ACI
|
|
169
|
-
* @param {Array} params Contract call arguments
|
|
170
|
-
* @return Promise{Array} Object with validation errors
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
export var prepareArgsForEncode = /*#__PURE__*/function () {
|
|
174
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(aci, params) {
|
|
175
|
-
var _context9;
|
|
176
|
-
|
|
177
|
-
var _context5, _context6, _context7, _context8, bindings;
|
|
178
|
-
|
|
179
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context11) {
|
|
180
|
-
while (1) {
|
|
181
|
-
switch (_context11.prev = _context11.next) {
|
|
182
|
-
case 0:
|
|
183
|
-
if (!(!aci || !aci.arguments)) {
|
|
184
|
-
_context11.next = 2;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return _context11.abrupt("return", params);
|
|
189
|
-
|
|
190
|
-
case 2:
|
|
191
|
-
if (!(aci.arguments.length > params.length)) {
|
|
192
|
-
_context11.next = 4;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
throw new Error(_concatInstanceProperty(_context5 = _concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = "Function \"".concat(aci.name, "\" require ")).call(_context7, aci.arguments.length, " arguments of types [")).call(_context6, _mapInstanceProperty(_context8 = aci.arguments).call(_context8, function (a) {
|
|
197
|
-
return _JSON$stringify(a.type);
|
|
198
|
-
}), "] but get [")).call(_context5, _mapInstanceProperty(params).call(params, _JSON$stringify), "]"));
|
|
199
|
-
|
|
200
|
-
case 4:
|
|
201
|
-
validateArguments(aci, params);
|
|
202
|
-
bindings = aci.bindings; // Cast argument from JS to Sophia type
|
|
203
|
-
|
|
204
|
-
return _context11.abrupt("return", _Promise.all(_mapInstanceProperty(_context9 = aci.arguments).call(_context9, /*#__PURE__*/function () {
|
|
205
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref4, i) {
|
|
206
|
-
var type;
|
|
207
|
-
return _regeneratorRuntime.wrap(function _callee$(_context10) {
|
|
208
|
-
while (1) {
|
|
209
|
-
switch (_context10.prev = _context10.next) {
|
|
210
|
-
case 0:
|
|
211
|
-
type = _ref4.type;
|
|
212
|
-
return _context10.abrupt("return", transform(type, params[i], {
|
|
213
|
-
bindings: bindings
|
|
214
|
-
}));
|
|
215
|
-
|
|
216
|
-
case 2:
|
|
217
|
-
case "end":
|
|
218
|
-
return _context10.stop();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}, _callee);
|
|
222
|
-
}));
|
|
223
|
-
|
|
224
|
-
return function (_x3, _x4) {
|
|
225
|
-
return _ref5.apply(this, arguments);
|
|
226
|
-
};
|
|
227
|
-
}())));
|
|
228
|
-
|
|
229
|
-
case 7:
|
|
230
|
-
case "end":
|
|
231
|
-
return _context11.stop();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}, _callee2);
|
|
235
|
-
}));
|
|
236
|
-
|
|
237
|
-
return function prepareArgsForEncode(_x, _x2) {
|
|
238
|
-
return _ref3.apply(this, arguments);
|
|
239
|
-
};
|
|
240
|
-
}();
|
|
241
|
-
export var decodeEvents = function decodeEvents(events, fnACI) {
|
|
242
|
-
var _context12;
|
|
243
|
-
|
|
244
|
-
if (!fnACI || !fnACI.event || !fnACI.event.length) return [];
|
|
245
|
-
|
|
246
|
-
var eventsSchema = _mapInstanceProperty(_context12 = fnACI.event).call(_context12, function (e) {
|
|
247
|
-
var name = _Object$keys(e)[0];
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
name: name,
|
|
251
|
-
types: e[name]
|
|
252
|
-
};
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
return unpackEvents(events, {
|
|
256
|
-
schema: eventsSchema
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
export var decodeCallResult = /*#__PURE__*/function () {
|
|
260
|
-
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(result, fnACI, opt) {
|
|
261
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context13) {
|
|
262
|
-
while (1) {
|
|
263
|
-
switch (_context13.prev = _context13.next) {
|
|
264
|
-
case 0:
|
|
265
|
-
_context13.t0 = transformDecodedData;
|
|
266
|
-
_context13.t1 = fnACI.returns;
|
|
267
|
-
_context13.next = 4;
|
|
268
|
-
return result.decode();
|
|
269
|
-
|
|
270
|
-
case 4:
|
|
271
|
-
_context13.t2 = _context13.sent;
|
|
272
|
-
_context13.t3 = _objectSpread(_objectSpread({}, opt), {}, {
|
|
273
|
-
bindings: fnACI.bindings
|
|
274
|
-
});
|
|
275
|
-
_context13.next = 8;
|
|
276
|
-
return (0, _context13.t0)(_context13.t1, _context13.t2, _context13.t3);
|
|
277
|
-
|
|
278
|
-
case 8:
|
|
279
|
-
_context13.t4 = _context13.sent;
|
|
280
|
-
_context13.t5 = decodeEvents(result.result.log, fnACI);
|
|
281
|
-
return _context13.abrupt("return", {
|
|
282
|
-
decodedResult: _context13.t4,
|
|
283
|
-
decodedEvents: _context13.t5
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
case 11:
|
|
287
|
-
case "end":
|
|
288
|
-
return _context13.stop();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}, _callee3);
|
|
292
|
-
}));
|
|
293
|
-
|
|
294
|
-
return function decodeCallResult(_x5, _x6, _x7) {
|
|
295
|
-
return _ref6.apply(this, arguments);
|
|
296
|
-
};
|
|
297
|
-
}();
|
|
298
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contract/aci/helpers.js"],"names":["unpackTx","decodeEvents","unpackEvents","transform","transformDecodedData","validateArguments","getFunctionACI","aci","name","external","Error","fn","functions","f","bindings","state","type_defs","event","variant","buildContractMethods","instance","acc","aciArgs","arguments","stateful","parseArguments","opt","args","deploy","call","callStatic","get","send","events","init","externalAci","length","unpackByteCode","bytecode","tx","prepareArgsForEncode","params","a","type","all","i","fnACI","eventsSchema","e","types","schema","decodeCallResult","result","returns","decode","log","decodedResult","decodedEvents"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,QAAT,QAAyB,kBAAzB;AACA,SAASC,YAAY,IAAIC,YAAzB,EAAuCC,SAAvC,EAAkDC,oBAAlD,EAAwEC,iBAAxE,QAAiG,kBAAjG;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,QAAkD;AAAA;;AAAA,MAAZC,QAAY,QAAZA,QAAY;AACvD,MAAI,CAACF,GAAL,EAAU,MAAM,IAAIG,KAAJ,CAAU,cAAV,CAAN;;AACV,MAAM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P,EAJoB;;AAAA;AAAA;AAAA,4DAKrB5B,GALqB;AAKhBZ,cAAAA,QAAQ,EAAEgC,KAAK,CAAChC;AALA;AAAA;AAAA;;AAAA;AAAA;AAAA,4BAObb,YAAY,CAACmD,MAAM,CAACA,MAAP,CAAcG,GAAf,EAAoBT,KAApB,CAPC;AAAA;AAE5BU,cAAAA,aAF4B;AAO5BC,cAAAA,aAP4B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAH;;AAAA,kBAAhBN,gBAAgB;AAAA;AAAA;AAAA,GAAtB","sourcesContent":["import * as R from 'ramda'\nimport { unpackTx } from '../../tx/builder'\nimport { decodeEvents as unpackEvents, transform, transformDecodedData, validateArguments } from './transformation'\n\n/**\n * Get function schema from contract ACI object\n * @param {Object} aci Contract ACI object\n * @param {String} name Function name\n * @param external\n * @return {Object} function ACI\n */\nexport function getFunctionACI (aci, name, { external }) {\n if (!aci) throw new Error('ACI required')\n const fn = aci.functions.find(f => f.name === name)\n if (!fn && name !== 'init') throw new Error(`Function ${name} doesn't exist in contract`)\n\n return {\n ...fn,\n bindings: [\n {\n state: aci.state,\n type_defs: aci.type_defs,\n name: aci.name\n },\n ...external.map(R.pick(['state', 'type_defs', 'name']))\n ],\n event: aci.event ? aci.event.variant : []\n }\n}\n\n/**\n * Build contract methods base on ACI\n * @return {Object} Contract instance methods\n */\nexport const buildContractMethods = (instance) => () => ({\n ...instance.aci\n ? instance\n .aci\n .functions\n .reduce(\n (acc, { name, arguments: aciArgs, stateful }) => ({\n ...acc,\n [name]: Object.assign(\n function () {\n const { opt, args } = parseArguments(aciArgs)(arguments)\n if (name === 'init') return instance.deploy(args, opt)\n return instance.call(name, args, { callStatic: !stateful, ...opt })\n },\n {\n get () {\n const { opt, args } = parseArguments(aciArgs)(arguments)\n return instance.call(name, args, { ...opt, callStatic: true })\n },\n send () {\n const { opt, args } = parseArguments(aciArgs)(arguments)\n if (name === 'init') return instance.deploy(args, opt)\n return instance.call(name, args, { ...opt, callStatic: false })\n },\n decodeEvents (events) {\n return instance.decodeEvents(name, events)\n }\n }\n )\n }),\n {}\n )\n : {},\n ...instance.aci ? {\n init: Object.assign(\n function () {\n const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })\n const { opt, args } = parseArguments(aciArgs)(arguments)\n return instance.deploy(args, opt)\n },\n {\n get () {\n const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })\n const { opt, args } = parseArguments(aciArgs)(arguments)\n return instance.deploy(args, { ...opt, callStatic: true })\n },\n send () {\n const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })\n const { opt, args } = parseArguments(aciArgs)(arguments)\n return instance.deploy(args, { ...opt, callStatic: false })\n }\n }\n )\n } : {}\n})\n\nexport const parseArguments = (aciArgs = []) => (args) => ({\n opt: args.length > aciArgs.length ? R.last(args) : {},\n args: Object.values(args).slice(0, aciArgs.length)\n})\n\nexport const unpackByteCode = (bytecode) => unpackTx(bytecode, false, 'cb').tx\n\n/**\n * Validated contract call arguments using contract ACI\n * @function validateCallParams\n * @rtype (aci: Object, params: Array) => Object\n * @param {Object} aci Contract ACI\n * @param {Array} params Contract call arguments\n * @return Promise{Array} Object with validation errors\n */\nexport const prepareArgsForEncode = async (aci, params) => {\n if (!aci || !aci.arguments) return params\n // Validation\n if (aci.arguments.length > params.length) {\n throw new Error(`Function \"${aci.name}\" require ${aci.arguments.length} arguments of types [${aci.arguments.map(a => JSON.stringify(a.type))}] but get [${params.map(JSON.stringify)}]`)\n }\n\n validateArguments(aci, params)\n const bindings = aci.bindings\n // Cast argument from JS to Sophia type\n return Promise.all(aci.arguments.map(async ({ type }, i) => transform(type, params[i], {\n bindings\n })))\n}\n\nexport const decodeEvents = (events, fnACI) => {\n if (!fnACI || !fnACI.event || !fnACI.event.length) return []\n\n const eventsSchema = fnACI.event.map(e => {\n const name = Object.keys(e)[0]\n return { name, types: e[name] }\n })\n return unpackEvents(events, { schema: eventsSchema })\n}\n\nexport const decodeCallResult = async (result, fnACI, opt) => {\n return {\n decodedResult: await transformDecodedData(\n fnACI.returns,\n await result.decode(),\n { ...opt, bindings: fnACI.bindings }\n ),\n decodedEvents: decodeEvents(result.result.log, fnACI)\n }\n}\n"],"file":"helpers.js"}
|
package/es/contract/aci/index.js
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import _path from "ramda/src/path";
|
|
2
|
-
import _prop from "ramda/src/prop";
|
|
3
|
-
import _defaultTo from "ramda/src/defaultTo";
|
|
4
|
-
import _pick from "ramda/src/pick";
|
|
5
|
-
import BigNumber from 'bignumber.js';
|
|
6
|
-
import { Encoder as Calldata } from '@aeternity/aepp-calldata';
|
|
7
|
-
import { decodeEvents } from './transformation';
|
|
8
|
-
import { DRY_RUN_ACCOUNT, DEPOSIT } from '../../tx/builder/schema';
|
|
9
|
-
import TxObject from '../../tx/tx-object';
|
|
10
|
-
import { decode } from '../../tx/builder/helpers';
|
|
11
|
-
/**
|
|
12
|
-
* Get function schema from contract ACI object
|
|
13
|
-
* @param {Object} aci Contract ACI object
|
|
14
|
-
* @param {String} name Function name
|
|
15
|
-
* @param external
|
|
16
|
-
* @return {Object} function ACI
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
function getFunctionACI(aci, name, external) {
|
|
20
|
-
const fn = aci.functions.find(f => f.name === name);
|
|
21
|
-
if (!fn && name !== 'init') throw new Error(`Function ${name} doesn't exist in contract`);
|
|
22
|
-
return { ...fn,
|
|
23
|
-
bindings: [{
|
|
24
|
-
state: aci.state,
|
|
25
|
-
type_defs: aci.type_defs,
|
|
26
|
-
name: aci.name
|
|
27
|
-
}, ...external.map(_pick(['state', 'type_defs', 'name']))],
|
|
28
|
-
event: aci.event ? aci.event.variant : []
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Generate contract ACI object with predefined js methods for contract usage - can be used for
|
|
33
|
-
* creating a reference to already deployed contracts
|
|
34
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
35
|
-
* @param {Object} [options={}] Options object
|
|
36
|
-
* @param {String} [options.source] Contract source code
|
|
37
|
-
* @param {String} [options.bytecode] Contract bytecode
|
|
38
|
-
* @param {Object} [options.aci] Contract ACI
|
|
39
|
-
* @param {String} [options.contractAddress] Contract address
|
|
40
|
-
* @param {Object} [options.filesystem] Contact source external namespaces map
|
|
41
|
-
* @param {Boolean} [options.validateBytecode] Compare source code with on-chain version
|
|
42
|
-
* @return {ContractInstance} JS Contract API
|
|
43
|
-
* @example
|
|
44
|
-
* const contractIns = await client.getContractInstance({ source })
|
|
45
|
-
* await contractIns.deploy([321]) or await contractIns.methods.init(321)
|
|
46
|
-
* const callResult = await contractIns.call('setState', [123]) or
|
|
47
|
-
* await contractIns.methods.setState.send(123, options)
|
|
48
|
-
* const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or
|
|
49
|
-
* await contractIns.methods.setState.get(123, options)
|
|
50
|
-
* Also you can call contract like: await contractIns.methods.setState(123, options)
|
|
51
|
-
* Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
|
|
52
|
-
* stateful or not
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export default async function getContractInstance() {
|
|
57
|
-
var _this = this;
|
|
58
|
-
|
|
59
|
-
let {
|
|
60
|
-
source,
|
|
61
|
-
bytecode,
|
|
62
|
-
aci,
|
|
63
|
-
contractAddress,
|
|
64
|
-
filesystem = {},
|
|
65
|
-
validateBytecode,
|
|
66
|
-
...otherOptions
|
|
67
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
68
|
-
aci = aci || source && (await this.contractGetACI(source, {
|
|
69
|
-
filesystem
|
|
70
|
-
}));
|
|
71
|
-
if (!aci) throw new Error('Either ACI or source code is required');
|
|
72
|
-
contractAddress = contractAddress && (await this.resolveName(contractAddress, 'contract_pubkey', {
|
|
73
|
-
resolveByNode: true
|
|
74
|
-
}));
|
|
75
|
-
if (!contractAddress && !source && !bytecode) throw new Error('Can\'t create instance by ACI without address');
|
|
76
|
-
|
|
77
|
-
if (contractAddress) {
|
|
78
|
-
const contract = await this.getContract(contractAddress).catch(() => null);
|
|
79
|
-
if (!contract) throw new Error(`Contract with address ${contractAddress} not found on-chain`);
|
|
80
|
-
if (!contract.active) throw new Error(`Contract with address ${contractAddress} not active`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const instance = {
|
|
84
|
-
interface: _defaultTo(null, _prop('interface', aci)),
|
|
85
|
-
aci: _defaultTo(null, _path(['encoded_aci', 'contract'], aci)),
|
|
86
|
-
calldata: new Calldata([aci.encoded_aci, ...aci.external_encoded_aci]),
|
|
87
|
-
externalAci: (aci.external_encoded_aci ?? []).map(a => a.contract || a.namespace),
|
|
88
|
-
source,
|
|
89
|
-
bytecode,
|
|
90
|
-
deployInfo: {
|
|
91
|
-
address: contractAddress
|
|
92
|
-
},
|
|
93
|
-
options: { ...this.Ae.defaults,
|
|
94
|
-
callStatic: false,
|
|
95
|
-
filesystem,
|
|
96
|
-
...otherOptions
|
|
97
|
-
},
|
|
98
|
-
compilerVersion: this.compilerVersion
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
if (validateBytecode) {
|
|
102
|
-
if (!contractAddress) throw new Error('Can\'t validate bytecode without contract address');
|
|
103
|
-
const onChanBytecode = (await this.getContractByteCode(contractAddress)).bytecode;
|
|
104
|
-
const isValid = source && (await this.validateByteCodeAPI(onChanBytecode, source, instance.options).catch(() => false)) || bytecode === onChanBytecode;
|
|
105
|
-
if (!isValid) throw new Error(`Contract ${source ? 'source' : 'bytecode'} do not correspond to the bytecode deployed on the chain`);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Compile contract
|
|
109
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
110
|
-
* @rtype () => ContractInstance: Object
|
|
111
|
-
* @return {String} bytecode bytecode
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
instance.compile = async function () {
|
|
116
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
117
|
-
if (instance.bytecode) throw new Error('Contract already compiled');
|
|
118
|
-
if (!instance.source) throw new Error('Can\'t compile without source code');
|
|
119
|
-
const {
|
|
120
|
-
bytecode
|
|
121
|
-
} = await _this.contractCompile(instance.source, { ...instance.options,
|
|
122
|
-
...options
|
|
123
|
-
});
|
|
124
|
-
instance.bytecode = bytecode;
|
|
125
|
-
return instance.bytecode;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const sendAndProcess = async (tx, options) => {
|
|
129
|
-
const txData = await this.send(tx, options);
|
|
130
|
-
const result = {
|
|
131
|
-
hash: txData.hash,
|
|
132
|
-
tx: TxObject({
|
|
133
|
-
tx: txData.rawTx
|
|
134
|
-
}),
|
|
135
|
-
txData,
|
|
136
|
-
rawTx: txData.rawTx
|
|
137
|
-
};
|
|
138
|
-
if (options.waitMined === false) return result;
|
|
139
|
-
const txInfo = await this.getTxInfo(txData.hash);
|
|
140
|
-
await handleCallError(txInfo);
|
|
141
|
-
return { ...result,
|
|
142
|
-
result: txInfo
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const handleCallError = _ref => {
|
|
147
|
-
let {
|
|
148
|
-
returnType,
|
|
149
|
-
returnValue
|
|
150
|
-
} = _ref;
|
|
151
|
-
let message; // TODO: ensure that it works correctly https://github.com/aeternity/aepp-calldata-js/issues/88
|
|
152
|
-
|
|
153
|
-
switch (returnType) {
|
|
154
|
-
case 'ok':
|
|
155
|
-
return;
|
|
156
|
-
|
|
157
|
-
case 'revert':
|
|
158
|
-
message = instance.calldata.decodeFateString(returnValue);
|
|
159
|
-
break;
|
|
160
|
-
|
|
161
|
-
case 'error':
|
|
162
|
-
message = decode(returnValue).toString();
|
|
163
|
-
break;
|
|
164
|
-
|
|
165
|
-
default:
|
|
166
|
-
throw new Error(`Unknown returnType: ${returnType}`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
throw new Error(`Invocation failed${message ? `: "${message}"` : ''}`);
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Deploy contract
|
|
173
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
174
|
-
* @rtype (init: Array, options: Object) => ContractInstance: Object
|
|
175
|
-
* @param {Array} params Contract init function arguments array
|
|
176
|
-
* @param {Object} [options] options
|
|
177
|
-
* @return {Object} deploy info
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
instance.deploy = async function () {
|
|
182
|
-
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
183
|
-
let options = arguments.length > 1 ? arguments[1] : undefined;
|
|
184
|
-
const opt = { ...instance.options,
|
|
185
|
-
...options,
|
|
186
|
-
deposit: DEPOSIT
|
|
187
|
-
};
|
|
188
|
-
if (!instance.bytecode) await instance.compile(opt);
|
|
189
|
-
if (opt.callStatic) return instance.call('init', params, opt);
|
|
190
|
-
if (instance.deployInfo.address) throw new Error('Contract already deployed');
|
|
191
|
-
const ownerId = await _this.address(opt);
|
|
192
|
-
const {
|
|
193
|
-
tx,
|
|
194
|
-
contractId
|
|
195
|
-
} = await _this.contractCreateTx({ ...opt,
|
|
196
|
-
callData: instance.calldata.encode(instance.aci.name, 'init', params),
|
|
197
|
-
code: instance.bytecode,
|
|
198
|
-
ownerId
|
|
199
|
-
});
|
|
200
|
-
const {
|
|
201
|
-
hash,
|
|
202
|
-
rawTx,
|
|
203
|
-
result,
|
|
204
|
-
txData
|
|
205
|
-
} = await sendAndProcess(tx, opt);
|
|
206
|
-
instance.deployInfo = Object.freeze({
|
|
207
|
-
result,
|
|
208
|
-
owner: ownerId,
|
|
209
|
-
transaction: hash,
|
|
210
|
-
rawTx,
|
|
211
|
-
txData,
|
|
212
|
-
address: contractId,
|
|
213
|
-
call: (name, args, options) => _this.contractCall(instance.source, contractId, name, args, { ...opt,
|
|
214
|
-
...options
|
|
215
|
-
}),
|
|
216
|
-
callStatic: (name, args, options) => _this.contractCallStatic(instance.source, contractId, name, args, { ...opt,
|
|
217
|
-
...options
|
|
218
|
-
}),
|
|
219
|
-
createdAt: new Date()
|
|
220
|
-
});
|
|
221
|
-
return instance.deployInfo;
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* Call contract function
|
|
225
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
226
|
-
* @rtype (init: Array, options: Object = { callStatic: false }) => CallResult: Object
|
|
227
|
-
* @param {String} fn Function name
|
|
228
|
-
* @param {Array} params Array of function arguments
|
|
229
|
-
* @param {Object} [options={}] Array of function arguments
|
|
230
|
-
* @param {Boolean} [options.callStatic=false] Static function call
|
|
231
|
-
* @return {Object} CallResult
|
|
232
|
-
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
instance.call = async function (fn) {
|
|
236
|
-
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
237
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
238
|
-
const opt = { ...instance.options,
|
|
239
|
-
...options
|
|
240
|
-
};
|
|
241
|
-
const fnACI = getFunctionACI(instance.aci, fn, instance.externalAci);
|
|
242
|
-
const contractId = instance.deployInfo.address;
|
|
243
|
-
if (!fn) throw new Error('Function name is required');
|
|
244
|
-
if (fn === 'init' && !opt.callStatic) throw new Error('"init" can be called only via dryRun');
|
|
245
|
-
if (!contractId && fn !== 'init') throw new Error('You need to deploy contract before calling!');
|
|
246
|
-
if (BigNumber(opt.amount).gt(0) && Object.prototype.hasOwnProperty.call(fnACI, 'payable') && !fnACI.payable) throw new Error(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept tokens`);
|
|
247
|
-
const callerId = await _this.address(opt).catch(error => {
|
|
248
|
-
if (opt.callStatic) return DRY_RUN_ACCOUNT.pub;else throw error;
|
|
249
|
-
});
|
|
250
|
-
const callData = instance.calldata.encode(instance.aci.name, fn, params);
|
|
251
|
-
let res;
|
|
252
|
-
|
|
253
|
-
if (opt.callStatic) {
|
|
254
|
-
if (typeof opt.top === 'number') {
|
|
255
|
-
opt.top = (await _this.getKeyBlock(opt.top)).hash;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const txOpt = { ...opt,
|
|
259
|
-
callData,
|
|
260
|
-
nonce: opt.top && (await _this.getAccount(callerId, {
|
|
261
|
-
hash: opt.top
|
|
262
|
-
})).nonce + 1
|
|
263
|
-
};
|
|
264
|
-
const tx = fn === 'init' ? (await _this.contractCreateTx({ ...txOpt,
|
|
265
|
-
code: instance.bytecode,
|
|
266
|
-
ownerId: callerId
|
|
267
|
-
})).tx : await _this.contractCallTx({ ...txOpt,
|
|
268
|
-
callerId,
|
|
269
|
-
contractId
|
|
270
|
-
});
|
|
271
|
-
const {
|
|
272
|
-
callObj,
|
|
273
|
-
...dryRunOther
|
|
274
|
-
} = await _this.txDryRun(tx, callerId, opt);
|
|
275
|
-
await handleCallError(callObj);
|
|
276
|
-
res = { ...dryRunOther,
|
|
277
|
-
tx: TxObject({
|
|
278
|
-
tx
|
|
279
|
-
}),
|
|
280
|
-
result: callObj
|
|
281
|
-
};
|
|
282
|
-
} else {
|
|
283
|
-
const tx = await _this.contractCallTx({ ...opt,
|
|
284
|
-
callerId,
|
|
285
|
-
contractId,
|
|
286
|
-
callData
|
|
287
|
-
});
|
|
288
|
-
res = await sendAndProcess(tx, opt);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (opt.waitMined || opt.callStatic) {
|
|
292
|
-
res.decodedResult = fnACI.returns && fnACI.returns !== 'unit' && fn !== 'init' && instance.calldata.decode(instance.aci.name, fn, res.result.returnValue);
|
|
293
|
-
res.decodedEvents = instance.decodeEvents(res.result.log);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return res;
|
|
297
|
-
};
|
|
298
|
-
/**
|
|
299
|
-
* Decode Events
|
|
300
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
301
|
-
* @rtype (events: Array) => DecodedEvents: Array
|
|
302
|
-
* @param {Array} events Array of encoded events(callRes.result.log)
|
|
303
|
-
* @return {Object} DecodedEvents
|
|
304
|
-
*/
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
instance.decodeEvents = events => {
|
|
308
|
-
const eventsACI = instance.aci.event ? instance.aci.event.variant : [];
|
|
309
|
-
const eventsSchema = eventsACI.map(e => {
|
|
310
|
-
const name = Object.keys(e)[0];
|
|
311
|
-
return {
|
|
312
|
-
name,
|
|
313
|
-
types: e[name]
|
|
314
|
-
};
|
|
315
|
-
});
|
|
316
|
-
return decodeEvents(events, eventsSchema);
|
|
317
|
-
};
|
|
318
|
-
/**
|
|
319
|
-
* Generate proto function based on contract function using Contract ACI schema
|
|
320
|
-
* All function can be called like:
|
|
321
|
-
* 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx
|
|
322
|
-
* on-chain base on if function stateful or not.
|
|
323
|
-
* Also you can manually do that:
|
|
324
|
-
* `await contract.methods.testFunction.get()` -> use call-static(dry-run)
|
|
325
|
-
* `await contract.methods.testFunction.send()` -> send tx on-chain
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
instance.methods = Object.fromEntries(instance.aci.functions.map(_ref2 => {
|
|
330
|
-
let {
|
|
331
|
-
name,
|
|
332
|
-
arguments: aciArgs,
|
|
333
|
-
stateful
|
|
334
|
-
} = _ref2;
|
|
335
|
-
|
|
336
|
-
const genHandler = callStatic => function () {
|
|
337
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
338
|
-
args[_key] = arguments[_key];
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const options = args.length === aciArgs.length + 1 ? args.pop() : {};
|
|
342
|
-
if (typeof options !== 'object') throw new Error(`Options should be an object: ${options}`);
|
|
343
|
-
if (name === 'init') return instance.deploy(args, {
|
|
344
|
-
callStatic,
|
|
345
|
-
...options
|
|
346
|
-
});
|
|
347
|
-
return instance.call(name, args, {
|
|
348
|
-
callStatic,
|
|
349
|
-
...options
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
return [name, Object.assign(genHandler(name === 'init' ? false : !stateful), {
|
|
354
|
-
get: genHandler(true),
|
|
355
|
-
send: genHandler(false),
|
|
356
|
-
decodeEvents: events => instance.decodeEvents(events)
|
|
357
|
-
})];
|
|
358
|
-
}));
|
|
359
|
-
return instance;
|
|
360
|
-
}
|
|
361
|
-
//# sourceMappingURL=index.js.map
|