@aeternity/aepp-sdk 9.0.1 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.mjs +179 -0
- package/es/account/base.mjs.map +1 -0
- package/es/account/memory.mjs +99 -0
- package/es/account/memory.mjs.map +1 -0
- package/es/account/multiple.mjs +179 -0
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/aens.mjs +404 -0
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/index.mjs +207 -0
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/oracle.mjs +339 -0
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +29 -9
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/node.mjs +442 -0
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/handlers.mjs +1110 -0
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +245 -472
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.mjs +283 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/index.mjs +178 -0
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/index.mjs +188 -0
- package/es/node-pool/index.mjs.map +1 -0
- package/es/node.mjs +133 -0
- package/es/node.mjs.map +1 -0
- package/es/other.d.ts +1 -1
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +363 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.mjs +606 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +760 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +107 -15
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/tx-object.mjs +283 -0
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/tx.mjs +938 -0
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/validator.mjs +247 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +139 -0
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/async-init.mjs +64 -0
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/bignumber.mjs +21 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -12
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/crypto.mjs +239 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.mjs +111 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.mjs +45 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.mjs +240 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/mptree.mjs +161 -0
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.mjs +43 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/semver-satisfies.mjs +16 -0
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/{string.js → string.mjs} +5 -14
- package/es/utils/string.mjs.map +1 -0
- package/es/utils/swagger.mjs +164 -0
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +55 -62
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +31 -22
- package/src/ae/aens.js +75 -77
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +27 -291
- package/src/ae/index.js +9 -7
- package/src/ae/oracle.js +51 -28
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -67
- package/src/channel/handlers.js +30 -21
- package/src/channel/index.js +44 -20
- package/src/channel/internal.js +30 -24
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +41 -91
- package/src/contract/ga/helpers.js +10 -13
- package/src/contract/ga/index.js +42 -33
- package/src/index.js +9 -10
- package/src/node-pool/index.js +29 -17
- package/src/node.js +33 -36
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +126 -84
- package/src/tx/builder/index.js +83 -41
- package/src/tx/builder/schema.js +50 -40
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +232 -153
- package/src/tx/validator.js +34 -12
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +3 -10
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +10 -144
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +75 -45
- package/es/account/base.js +0 -259
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -86
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -267
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -829
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -985
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -442
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -690
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -1119
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js +0 -1601
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -438
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -517
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -742
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -316
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -120
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -307
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -204
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -228
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -355
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -686
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -695
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -297
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -1757
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -344
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -148
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -103
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js +0 -152
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -103
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -36
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -358
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -148
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -78
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -393
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js +0 -198
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -93
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js +0 -35
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -269
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/helpers.js +0 -140
- package/src/contract/aci/index.js +0 -191
- package/src/contract/aci/transformation.js +0 -464
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -110
package/es/utils/swagger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/swagger.js"],"names":["SwaggerClient","fetch","JsonBig","snakizeKeys","pascalizeKeys","mapObject","filterObject","warnedAboutInternalApiUsage","specUrl","spec","internalUrl","disableBigNumbers","disableCaseConversion","json","jsonImp","JSON","origin","schemes","all","url","responseInterceptor","response","text","body","parse","external","internal","combinedApi","apis","key","handler","console","warn","acc","n","opSpecs","paths","operationId","api","opId","toLowerCase","args","opSpec","parameters","requestBody","required","schema","content","name","param","p","length","Error","values","req","idx","value","rootKeys","properties","filteredValue","stringify","__requestBody","stringified"],"mappings":";;;;;;;;;;;;;;;;;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AyBsEtC,IAzBtE;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eAFsD,GAArB;AAAA,aAAd,CAjDR;AAAA,+CAgFN,eAAcE,QAAd,EAAwB;AAAEa,cAAAA,GAAG,EAAHA;AAAF,aAAxB,CAhFM;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAf;;AAAA;AAAA;AAAA;AAAA","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 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 * Generator of Swagger client module\n * @module @aeternity/aepp-sdk/es/utils/swagger\n * @export genSwaggerClient\n */\n\nimport SwaggerClient from 'swagger-client'\nimport fetch from 'cross-fetch'\nimport JsonBig from './json-big'\nimport { snakizeKeys, pascalizeKeys, mapObject, filterObject } from './other'\n\nlet warnedAboutInternalApiUsage = false\n\n/**\n * Generator of Swagger client\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/swagger\n * @rtype Object\n * @param {String} specUrl - Swagger specification URL on external node host\n * @param {Object} options\n * @param {String} [options.spec] - Override OpenAPI definition\n * @param {String} [options.internalUrl] - Node internal URL\n * @param {Boolean} [options.disableBigNumbers]\n * @param {Boolean} [options.disableCaseConversion]\n * @return {Object} Swagger client\n * @example (await genSwaggerClient('https://mainnet.aeternity.io/api')).getAccountByPubkey('ak_jupBUgZNbcC4krDLR3tAkw1iBZoBbkNeShAq4atBtpFWmz36r')\n */\nexport default async (specUrl, { spec, internalUrl, disableBigNumbers, disableCaseConversion } = {}) => {\n spec = spec || await (await fetch(specUrl)).json()\n const jsonImp = disableBigNumbers ? JSON : JsonBig\n\n if (\n [\n 'https://compiler.aepps.com',\n 'https://latest.compiler.aepps.com'\n ].includes(new URL(specUrl).origin) ||\n new URL(specUrl).origin.includes('https://')\n ) {\n spec.schemes = ['https']\n }\n\n const [external, internal] = await Promise.all([specUrl, internalUrl].map((url) => {\n if (!url) return null\n return SwaggerClient({\n url,\n spec,\n responseInterceptor: response => {\n if (!response.text) return response\n const body = jsonImp.parse(response.text)\n return Object.assign(response, {\n body: disableCaseConversion ? body : pascalizeKeys(body)\n })\n }\n })\n }))\n\n const combinedApi = [\n ...Object.values(external.apis),\n mapObject(internal?.apis.internal || {}, ([key, handler]) => [key, (...args) => {\n if (!warnedAboutInternalApiUsage) {\n console.warn(\n 'SDK\\'s wrapper of aeternity node internal API is deprecated, please use external ' +\n 'equivalent (for example, \"sdk.api.protectedDryRunTxs\" instead of \"sdk.api.dryRunTxs\") ' +\n 'or create a wrapper of internal API by yourself (using \"genSwaggerClient\")'\n )\n warnedAboutInternalApiUsage = true\n }\n return handler(...args)\n }])\n ].reduce((acc, n) => ({ ...acc, ...n }))\n\n const opSpecs = Object.values(spec.paths)\n .map(paths => Object.values(paths))\n .flat()\n .reduce((acc, n) => ({ ...acc, [n.operationId]: n }), {})\n\n const api = mapObject(combinedApi, ([opId, handler]) => [\n opId.slice(0, 1).toLowerCase() + opId.slice(1),\n async (...args) => {\n const opSpec = opSpecs[opId]\n const parameters = [\n ...opSpec.parameters,\n ...opSpec.requestBody ? [{\n required: opSpec.requestBody.required,\n schema: Object.values(opSpec.requestBody.content)[0].schema,\n name: '__requestBody'\n }] : []\n ]\n const required = parameters.filter(param => param.required).map(p => p.name)\n if (args.length < required.length) throw new Error('swagger: Not enough arguments')\n const values = required.reduce(\n (acc, req, idx) => ({ ...acc, [req]: args[idx] }),\n args[required.length] || {}\n )\n const { __requestBody, ...stringified } = mapObject(values, ([param, value]) => {\n if (typeof value !== 'object') return [param, value]\n const rootKeys = Object.keys(parameters.find(p => p.name === param).schema.properties)\n const filteredValue = filterObject(\n disableCaseConversion ? value : snakizeKeys(value),\n ([key]) => rootKeys.includes(key)\n )\n return [param, jsonImp.stringify(filteredValue)]\n })\n return (await handler(stringified, { requestBody: __requestBody })).body\n }\n ])\n\n return Object.assign(external, { api })\n}\n"],"file":"swagger.js"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda'
|
|
2
|
-
import { unpackTx } from '../../tx/builder'
|
|
3
|
-
import { decodeEvents as unpackEvents, transform, transformDecodedData, validateArguments } from './transformation'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get function schema from contract ACI object
|
|
7
|
-
* @param {Object} aci Contract ACI object
|
|
8
|
-
* @param {String} name Function name
|
|
9
|
-
* @param external
|
|
10
|
-
* @return {Object} function ACI
|
|
11
|
-
*/
|
|
12
|
-
export function getFunctionACI (aci, name, { external }) {
|
|
13
|
-
if (!aci) throw new Error('ACI required')
|
|
14
|
-
const fn = aci.functions.find(f => f.name === name)
|
|
15
|
-
if (!fn && name !== 'init') throw new Error(`Function ${name} doesn't exist in contract`)
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
...fn,
|
|
19
|
-
bindings: [
|
|
20
|
-
{
|
|
21
|
-
state: aci.state,
|
|
22
|
-
type_defs: aci.type_defs,
|
|
23
|
-
name: aci.name
|
|
24
|
-
},
|
|
25
|
-
...external.map(R.pick(['state', 'type_defs', 'name']))
|
|
26
|
-
],
|
|
27
|
-
event: aci.event ? aci.event.variant : []
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Build contract methods base on ACI
|
|
33
|
-
* @return {Object} Contract instance methods
|
|
34
|
-
*/
|
|
35
|
-
export const buildContractMethods = (instance) => () => ({
|
|
36
|
-
...instance.aci
|
|
37
|
-
? instance
|
|
38
|
-
.aci
|
|
39
|
-
.functions
|
|
40
|
-
.reduce(
|
|
41
|
-
(acc, { name, arguments: aciArgs, stateful }) => ({
|
|
42
|
-
...acc,
|
|
43
|
-
[name]: Object.assign(
|
|
44
|
-
function () {
|
|
45
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
46
|
-
if (name === 'init') return instance.deploy(args, opt)
|
|
47
|
-
return instance.call(name, args, { callStatic: !stateful, ...opt })
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
get () {
|
|
51
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
52
|
-
return instance.call(name, args, { ...opt, callStatic: true })
|
|
53
|
-
},
|
|
54
|
-
send () {
|
|
55
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
56
|
-
if (name === 'init') return instance.deploy(args, opt)
|
|
57
|
-
return instance.call(name, args, { ...opt, callStatic: false })
|
|
58
|
-
},
|
|
59
|
-
decodeEvents (events) {
|
|
60
|
-
return instance.decodeEvents(name, events)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
}),
|
|
65
|
-
{}
|
|
66
|
-
)
|
|
67
|
-
: {},
|
|
68
|
-
...instance.aci ? {
|
|
69
|
-
init: Object.assign(
|
|
70
|
-
function () {
|
|
71
|
-
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })
|
|
72
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
73
|
-
return instance.deploy(args, opt)
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
get () {
|
|
77
|
-
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })
|
|
78
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
79
|
-
return instance.deploy(args, { ...opt, callStatic: true })
|
|
80
|
-
},
|
|
81
|
-
send () {
|
|
82
|
-
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })
|
|
83
|
-
const { opt, args } = parseArguments(aciArgs)(arguments)
|
|
84
|
-
return instance.deploy(args, { ...opt, callStatic: false })
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
)
|
|
88
|
-
} : {}
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
export const parseArguments = (aciArgs = []) => (args) => ({
|
|
92
|
-
opt: args.length > aciArgs.length ? R.last(args) : {},
|
|
93
|
-
args: Object.values(args).slice(0, aciArgs.length)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
export const unpackByteCode = (bytecode) => unpackTx(bytecode, false, 'cb').tx
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Validated contract call arguments using contract ACI
|
|
100
|
-
* @function validateCallParams
|
|
101
|
-
* @rtype (aci: Object, params: Array) => Object
|
|
102
|
-
* @param {Object} aci Contract ACI
|
|
103
|
-
* @param {Array} params Contract call arguments
|
|
104
|
-
* @return Promise{Array} Object with validation errors
|
|
105
|
-
*/
|
|
106
|
-
export const prepareArgsForEncode = async (aci, params) => {
|
|
107
|
-
if (!aci || !aci.arguments) return params
|
|
108
|
-
// Validation
|
|
109
|
-
if (aci.arguments.length > params.length) {
|
|
110
|
-
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)}]`)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
validateArguments(aci, params)
|
|
114
|
-
const bindings = aci.bindings
|
|
115
|
-
// Cast argument from JS to Sophia type
|
|
116
|
-
return Promise.all(aci.arguments.map(async ({ type }, i) => transform(type, params[i], {
|
|
117
|
-
bindings
|
|
118
|
-
})))
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export const decodeEvents = (events, fnACI) => {
|
|
122
|
-
if (!fnACI || !fnACI.event || !fnACI.event.length) return []
|
|
123
|
-
|
|
124
|
-
const eventsSchema = fnACI.event.map(e => {
|
|
125
|
-
const name = Object.keys(e)[0]
|
|
126
|
-
return { name, types: e[name] }
|
|
127
|
-
})
|
|
128
|
-
return unpackEvents(events, { schema: eventsSchema })
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export const decodeCallResult = async (result, fnACI, opt) => {
|
|
132
|
-
return {
|
|
133
|
-
decodedResult: await transformDecodedData(
|
|
134
|
-
fnACI.returns,
|
|
135
|
-
await result.decode(),
|
|
136
|
-
{ ...opt, bindings: fnACI.bindings }
|
|
137
|
-
),
|
|
138
|
-
decodedEvents: decodeEvents(result.result.log, fnACI)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2018 aeternity developers
|
|
4
|
-
*
|
|
5
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
* copyright notice and this permission notice appear in all copies.
|
|
8
|
-
*
|
|
9
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* ContractACI module
|
|
20
|
-
*
|
|
21
|
-
* @module @aeternity/aepp-sdk/es/contract/aci
|
|
22
|
-
* @export getContractInstance
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import * as R from 'ramda'
|
|
26
|
-
import BigNumber from 'bignumber.js'
|
|
27
|
-
|
|
28
|
-
import {
|
|
29
|
-
buildContractMethods,
|
|
30
|
-
decodeCallResult,
|
|
31
|
-
decodeEvents,
|
|
32
|
-
getFunctionACI,
|
|
33
|
-
prepareArgsForEncode as prepareArgs
|
|
34
|
-
} from './helpers'
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Generate contract ACI object with predefined js methods for contract usage - can be used for creating a reference to already deployed contracts
|
|
38
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
39
|
-
* @param {String} source Contract source code
|
|
40
|
-
* @param {Object} [options={}] Options object
|
|
41
|
-
* @param {String} [options.aci] Contract ACI
|
|
42
|
-
* @param {String} [options.contractAddress] Contract address
|
|
43
|
-
* @param {Object} [options.filesystem] Contact source external namespaces map
|
|
44
|
-
* @param {Object} [options.forceCodeCheck=true] Don't check contract code
|
|
45
|
-
* @param {Object} [options.opt] Contract options
|
|
46
|
-
* @return {ContractInstance} JS Contract API
|
|
47
|
-
* @example
|
|
48
|
-
* const contractIns = await client.getContractInstance(sourceCode)
|
|
49
|
-
* await contractIns.deploy([321]) or await contractIns.methods.init(321)
|
|
50
|
-
* const callResult = await contractIns.call('setState', [123]) or await contractIns.methods.setState.send(123, options)
|
|
51
|
-
* const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or await contractIns.methods.setState.get(123, options)
|
|
52
|
-
* Also you can call contract like: await contractIns.methods.setState(123, options)
|
|
53
|
-
* Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is stateful or not
|
|
54
|
-
*/
|
|
55
|
-
export default async function getContractInstance (source, { aci, contractAddress, filesystem = {}, forceCodeCheck = true, opt } = {}) {
|
|
56
|
-
aci = aci || await this.contractGetACI(source, { filesystem })
|
|
57
|
-
if (contractAddress) contractAddress = await this.resolveName(contractAddress, 'ct', { resolveByNode: true })
|
|
58
|
-
const defaultOptions = {
|
|
59
|
-
...this.Ae.defaults,
|
|
60
|
-
skipArgsConvert: false,
|
|
61
|
-
skipTransformDecoded: false,
|
|
62
|
-
callStatic: false,
|
|
63
|
-
filesystem
|
|
64
|
-
}
|
|
65
|
-
const instance = {
|
|
66
|
-
interface: R.defaultTo(null, R.prop('interface', aci)),
|
|
67
|
-
aci: R.defaultTo(null, R.path(['encoded_aci', 'contract'], aci)),
|
|
68
|
-
externalAci: aci.external_encoded_aci ? aci.external_encoded_aci.map(a => a.contract || a.namespace) : [],
|
|
69
|
-
source,
|
|
70
|
-
compiled: null,
|
|
71
|
-
deployInfo: { address: contractAddress },
|
|
72
|
-
options: R.merge(defaultOptions, opt),
|
|
73
|
-
compilerVersion: this.compilerVersion,
|
|
74
|
-
setOptions (opt) {
|
|
75
|
-
this.options = R.merge(this.options, opt)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Check for valid contract address and contract code
|
|
80
|
-
if (contractAddress) {
|
|
81
|
-
const contract = await this.getContract(contractAddress).catch(e => null)
|
|
82
|
-
if (!contract || !contract.active) throw new Error(`Contract with address ${contractAddress} not found on-chain or not active`)
|
|
83
|
-
if (!forceCodeCheck) {
|
|
84
|
-
const onChanByteCode = (await this.getContractByteCode(contractAddress)).bytecode
|
|
85
|
-
const isCorrespondingBytecode = await this.validateByteCodeAPI(onChanByteCode, instance.source, instance.options).catch(e => false)
|
|
86
|
-
if (!isCorrespondingBytecode) throw new Error('Contract source do not correspond to the contract bytecode deployed on the chain')
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Compile contract
|
|
92
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
93
|
-
* @rtype () => ContractInstance: Object
|
|
94
|
-
* @return {ContractInstance} Contract ACI object with predefined js methods for contract usage
|
|
95
|
-
*/
|
|
96
|
-
instance.compile = compile({ client: this, instance })
|
|
97
|
-
/**
|
|
98
|
-
* Deploy contract
|
|
99
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
100
|
-
* @rtype (init: Array, options: Object = { skipArgsConvert: false }) => ContractInstance: Object
|
|
101
|
-
* @param {Array} init Contract init function arguments array
|
|
102
|
-
* @param {Object} [options={}] options Options object
|
|
103
|
-
* @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data
|
|
104
|
-
* @return {ContractInstance} Contract ACI object with predefined js methods for contract usage
|
|
105
|
-
*/
|
|
106
|
-
instance.deploy = deploy({ client: this, instance })
|
|
107
|
-
/**
|
|
108
|
-
* Call contract function
|
|
109
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
110
|
-
* @rtype (init: Array, options: Object = { skipArgsConvert: false, skipTransformDecoded: false, callStatic: false }) => CallResult: Object
|
|
111
|
-
* @param {String} fn Function name
|
|
112
|
-
* @param {Array} params Array of function arguments
|
|
113
|
-
* @param {Object} [options={}] Array of function arguments
|
|
114
|
-
* @param {Boolean} [options.skipArgsConvert=false] Skip Validation and Transforming arguments before prepare call-data
|
|
115
|
-
* @param {Boolean} [options.skipTransformDecoded=false] Skip Transform decoded data to JS type
|
|
116
|
-
* @param {Boolean} [options.callStatic=false] Static function call
|
|
117
|
-
* @return {Object} CallResult
|
|
118
|
-
*/
|
|
119
|
-
instance.call = call({ client: this, instance })
|
|
120
|
-
/**
|
|
121
|
-
* Decode Events
|
|
122
|
-
* @alias module:@aeternity/aepp-sdk/es/contract/aci
|
|
123
|
-
* @rtype (fn: String, events: Array) => DecodedEvents: Array
|
|
124
|
-
* @param {String} fn Function name
|
|
125
|
-
* @param {Array} events Array of encoded events(callRes.result.log)
|
|
126
|
-
* @return {Object} DecodedEvents
|
|
127
|
-
*/
|
|
128
|
-
instance.decodeEvents = eventDecode({ instance })
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Generate proto function based on contract function using Contract ACI schema
|
|
132
|
-
* All function can be called like:
|
|
133
|
-
* 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx on-chain base on if function stateful or not.
|
|
134
|
-
* Also you can manually do that:
|
|
135
|
-
* `await contract.methods.testFunction.get()` -> use call-static(dry-run)
|
|
136
|
-
* `await contract.methods.testFunction.send()` -> send tx on-chain
|
|
137
|
-
*/
|
|
138
|
-
instance.methods = buildContractMethods(instance)()
|
|
139
|
-
return instance
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const eventDecode = ({ instance }) => (fn, events) => {
|
|
143
|
-
return decodeEvents(events, getFunctionACI(instance.aci, fn, { external: instance.externalAci }))
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const call = ({ client, instance }) => async (fn, params = [], options = {}) => {
|
|
147
|
-
const opt = { ...instance.options, ...options }
|
|
148
|
-
const fnACI = getFunctionACI(instance.aci, fn, { external: instance.externalAci })
|
|
149
|
-
const source = opt.source || instance.source
|
|
150
|
-
|
|
151
|
-
if (!fn) throw new Error('Function name is required')
|
|
152
|
-
if (!instance.deployInfo.address) throw new Error('You need to deploy contract before calling!')
|
|
153
|
-
if (
|
|
154
|
-
BigNumber(opt.amount).gt(0) &&
|
|
155
|
-
(Object.prototype.hasOwnProperty.call(fnACI, 'payable') && !fnACI.payable)
|
|
156
|
-
) throw new Error(`You try to pay "${opt.amount}" to function "${fn}" which is not payable. Only payable function can accept tokens`)
|
|
157
|
-
params = !opt.skipArgsConvert ? await prepareArgs(fnACI, params) : params
|
|
158
|
-
const result = opt.callStatic
|
|
159
|
-
? await client.contractCallStatic(source, instance.deployInfo.address, fn, params, opt)
|
|
160
|
-
: await client.contractCall(source, instance.deployInfo.address, fn, params, opt)
|
|
161
|
-
return {
|
|
162
|
-
...result,
|
|
163
|
-
...opt.waitMined ? await decodeCallResult(result, fnACI, opt) : {}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const deploy = ({ client, instance }) => async (init = [], options = {}) => {
|
|
168
|
-
const opt = { ...instance.options, ...options }
|
|
169
|
-
const fnACI = getFunctionACI(instance.aci, 'init', { external: instance.externalAci })
|
|
170
|
-
const source = opt.source || instance.source
|
|
171
|
-
|
|
172
|
-
if (!instance.compiled) await instance.compile(opt)
|
|
173
|
-
init = !opt.skipArgsConvert ? await prepareArgs(fnACI, init) : init
|
|
174
|
-
|
|
175
|
-
if (opt.callStatic) {
|
|
176
|
-
return client.contractCallStatic(source, null, 'init', init, {
|
|
177
|
-
...opt,
|
|
178
|
-
bytecode: instance.compiled
|
|
179
|
-
})
|
|
180
|
-
} else {
|
|
181
|
-
const { owner, transaction, address, createdAt, result, rawTx } = await client.contractDeploy(instance.compiled, opt.source || instance.source, init, opt)
|
|
182
|
-
instance.deployInfo = { owner, transaction, address, createdAt, result, rawTx }
|
|
183
|
-
return instance.deployInfo
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const compile = ({ client, instance }) => async (options = {}) => {
|
|
188
|
-
const { bytecode } = await client.contractCompile(instance.source, { ...instance.options, ...options })
|
|
189
|
-
instance.compiled = bytecode
|
|
190
|
-
return instance.compiled
|
|
191
|
-
}
|