@aeternity/aepp-sdk 10.0.0 → 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 -27
- 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 → base.mjs} +20 -10
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +10 -9
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +18 -22
- 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.js → index.mjs} +8 -7
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +33 -16
- 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} +20 -4
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +121 -73
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +7 -7
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +49 -32
- 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.js → index.mjs} +36 -28
- 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.js → index.mjs} +11 -10
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +9 -8
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +79 -68
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +11 -65
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +5 -2
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- 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} +7 -6
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
- 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} +5 -2
- 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} +6 -5
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
- 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.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- 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.js → crypto.mjs} +40 -105
- 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.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +46 -14
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +46 -55
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +12 -4
- package/src/ae/aens.js +12 -17
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +15 -152
- package/src/ae/index.js +2 -1
- package/src/ae/oracle.js +25 -10
- package/src/ae/universal.js +2 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +21 -2
- package/src/chain/node.js +80 -53
- package/src/channel/handlers.js +20 -17
- package/src/channel/internal.js +30 -24
- package/src/contract/{aci/index.js → aci.js} +152 -93
- package/src/contract/compiler.js +22 -117
- package/src/contract/ga/helpers.js +7 -5
- package/src/contract/ga/index.js +27 -24
- package/src/index.js +7 -8
- package/src/node-pool/index.js +9 -8
- package/src/node.js +5 -7
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +113 -58
- package/src/tx/builder/index.js +39 -34
- package/src/tx/builder/schema.js +11 -25
- package/src/tx/tx-object.js +10 -9
- package/src/tx/tx.js +17 -8
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
- package/src/utils/aepp-wallet-communication/helpers.js +2 -12
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +9 -92
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +47 -51
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +67 -44
- package/CHANGELOG.md +0 -1603
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- 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.map +0 -1
- package/es/contract/index.js +0 -162
- 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.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- 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.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.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- 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.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- 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.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -163
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
package/src/contract/compiler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* ContractCompilerHttp module
|
|
20
20
|
*
|
|
21
|
-
* This is the complement to {@link module:@aeternity/aepp-sdk/es/contract}.
|
|
22
21
|
* @module @aeternity/aepp-sdk/es/contract/compiler
|
|
23
|
-
* @export
|
|
24
|
-
* @example import {
|
|
22
|
+
* @export ContractCompilerHttp
|
|
23
|
+
* @example import { ContractCompilerHttp } from '@aeternity/aepp-sdk'
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
|
-
import ContractBase from './index'
|
|
28
26
|
import semverSatisfies from '../utils/semver-satisfies'
|
|
29
27
|
import AsyncInit from '../utils/async-init'
|
|
30
28
|
import genSwaggerClient from '../utils/swagger'
|
|
29
|
+
import { MissingParamError, UnsupportedVersionError } from '../utils/errors'
|
|
30
|
+
import { mapObject } from '../utils/other'
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Contract Compiler Stamp
|
|
@@ -39,16 +39,16 @@ import genSwaggerClient from '../utils/swagger'
|
|
|
39
39
|
* @param {Object} [options={}] - Initializer object
|
|
40
40
|
* @param {String} [options.compilerUrl] compilerUrl - Url for compiler API
|
|
41
41
|
* @return {Object} Contract compiler instance
|
|
42
|
-
* @example
|
|
42
|
+
* @example ContractCompilerHttp({ compilerUrl: 'COMPILER_URL' })
|
|
43
43
|
*/
|
|
44
|
-
export default AsyncInit.compose(
|
|
44
|
+
export default AsyncInit.compose({
|
|
45
45
|
async init ({ compilerUrl, ignoreVersion }) {
|
|
46
46
|
if (!compilerUrl) return
|
|
47
47
|
await this.setCompilerUrl(compilerUrl, { ignoreVersion })
|
|
48
48
|
},
|
|
49
49
|
methods: {
|
|
50
50
|
async setCompilerUrl (compilerUrl, { ignoreVersion = false } = {}) {
|
|
51
|
-
if (!compilerUrl) throw new
|
|
51
|
+
if (!compilerUrl) throw new MissingParamError('compilerUrl required')
|
|
52
52
|
compilerUrl = compilerUrl.replace(/\/$/, '')
|
|
53
53
|
const client = await genSwaggerClient(`${compilerUrl}/api`, {
|
|
54
54
|
disableBigNumbers: true,
|
|
@@ -73,117 +73,22 @@ export default AsyncInit.compose(ContractBase, {
|
|
|
73
73
|
}
|
|
74
74
|
})
|
|
75
75
|
this.compilerVersion = client.spec.info.version
|
|
76
|
-
this.
|
|
76
|
+
this.compilerApi = mapObject(
|
|
77
|
+
client.api,
|
|
78
|
+
([key, fn]) => [
|
|
79
|
+
key,
|
|
80
|
+
({ options: { filesystem, ...options } = {}, ...args } = {}) => fn({
|
|
81
|
+
...args, options: { ...options, file_system: filesystem }
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
)
|
|
77
85
|
|
|
78
86
|
if (ignoreVersion) return
|
|
79
87
|
if (!semverSatisfies(this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
|
|
80
|
-
throw new
|
|
81
|
-
|
|
88
|
+
throw new UnsupportedVersionError(
|
|
89
|
+
'compiler', this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION
|
|
90
|
+
)
|
|
82
91
|
}
|
|
83
|
-
},
|
|
84
|
-
_ensureCompilerReady () {
|
|
85
|
-
if (!this._compilerApi) throw new Error('Compiler is not ready')
|
|
86
|
-
},
|
|
87
|
-
_prepareCompilerOptions ({ filesystem = {} } = {}) {
|
|
88
|
-
return { file_system: filesystem }
|
|
89
|
-
},
|
|
90
|
-
getCompilerVersion () {
|
|
91
|
-
this._ensureCompilerReady()
|
|
92
|
-
return Promise.resolve(this.compilerVersion)
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* Encode call data for contract call
|
|
96
|
-
* @function
|
|
97
|
-
* @category async
|
|
98
|
-
* @param {String} source Contract source code
|
|
99
|
-
* @param {String} name Name of function to call
|
|
100
|
-
* @param {Array} args Argument's for call
|
|
101
|
-
* @param {Object} [options={}] Options
|
|
102
|
-
* @param {Object} [options.filesystem={}] Contract external namespaces map
|
|
103
|
-
* @return {Promise<String>}
|
|
104
|
-
*/
|
|
105
|
-
async contractEncodeCallDataAPI (source, name, args = [], options) {
|
|
106
|
-
this._ensureCompilerReady()
|
|
107
|
-
const { calldata } = await this._compilerApi.encodeCalldata({
|
|
108
|
-
source,
|
|
109
|
-
function: name,
|
|
110
|
-
arguments: args,
|
|
111
|
-
options: this._prepareCompilerOptions(options)
|
|
112
|
-
})
|
|
113
|
-
return calldata
|
|
114
|
-
},
|
|
115
|
-
async compileContractAPI (code, options) {
|
|
116
|
-
this._ensureCompilerReady()
|
|
117
|
-
const { bytecode } = await this._compilerApi.compileContract({
|
|
118
|
-
code,
|
|
119
|
-
options: this._prepareCompilerOptions(options)
|
|
120
|
-
})
|
|
121
|
-
return bytecode
|
|
122
|
-
},
|
|
123
|
-
contractGetACI (code, options) {
|
|
124
|
-
this._ensureCompilerReady()
|
|
125
|
-
return this._compilerApi.generateACI({ code, options: this._prepareCompilerOptions(options) })
|
|
126
|
-
},
|
|
127
|
-
contractDecodeCallDataByCodeAPI (bytecode, calldata) {
|
|
128
|
-
this._ensureCompilerReady()
|
|
129
|
-
return this._compilerApi.decodeCalldataBytecode({ bytecode, calldata })
|
|
130
|
-
},
|
|
131
|
-
contractDecodeCallDataBySourceAPI (source, fn, callData, options) {
|
|
132
|
-
this._ensureCompilerReady()
|
|
133
|
-
return this._compilerApi.decodeCalldataSource({
|
|
134
|
-
function: fn,
|
|
135
|
-
source,
|
|
136
|
-
calldata: callData,
|
|
137
|
-
options: this._prepareCompilerOptions(options)
|
|
138
|
-
})
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* Decode contract call result data
|
|
142
|
-
* @function
|
|
143
|
-
* @category async
|
|
144
|
-
* @param {String} source - source code
|
|
145
|
-
* @param {String } fn - function name
|
|
146
|
-
* @param {String} callValue - result call data
|
|
147
|
-
* @param {String} callResult - result status
|
|
148
|
-
* @param {Object} [options={}] Options
|
|
149
|
-
* @param {Object} [options.filesystem={}] Contract external namespaces map
|
|
150
|
-
* @return {Promise<String>} Result object
|
|
151
|
-
* @example
|
|
152
|
-
* const decodedData = await sdk.contractDecodeCallResultAPI(
|
|
153
|
-
* SourceCode ,'functionName', 'cb_asdasdasd...', 'ok|revert'
|
|
154
|
-
* )
|
|
155
|
-
*/
|
|
156
|
-
contractDecodeCallResultAPI (source, fn, callValue, callResult, options) {
|
|
157
|
-
this._ensureCompilerReady()
|
|
158
|
-
return this._compilerApi.decodeCallResult({
|
|
159
|
-
function: fn,
|
|
160
|
-
source,
|
|
161
|
-
'call-result': callResult,
|
|
162
|
-
'call-value': callValue,
|
|
163
|
-
options: this._prepareCompilerOptions(options)
|
|
164
|
-
})
|
|
165
|
-
},
|
|
166
|
-
async validateByteCodeAPI (bytecode, source, options) {
|
|
167
|
-
this._ensureCompilerReady()
|
|
168
|
-
const res = await this._compilerApi.validateByteCode({
|
|
169
|
-
bytecode,
|
|
170
|
-
source,
|
|
171
|
-
options: this._prepareCompilerOptions(options)
|
|
172
|
-
})
|
|
173
|
-
return typeof res === 'object' ? true : res
|
|
174
|
-
},
|
|
175
|
-
getFateAssembler (bytecode, options) {
|
|
176
|
-
this._ensureCompilerReady()
|
|
177
|
-
return this._compilerApi.getFateAssemblerCode(
|
|
178
|
-
{ bytecode, options: this._prepareCompilerOptions(options) }
|
|
179
|
-
)
|
|
180
|
-
},
|
|
181
|
-
getBytecodeCompilerVersion (bytecode, options) {
|
|
182
|
-
this._ensureCompilerReady()
|
|
183
|
-
return this._compilerApi.getCompilerVersion({
|
|
184
|
-
bytecode,
|
|
185
|
-
options: this._prepareCompilerOptions(options)
|
|
186
|
-
})
|
|
187
92
|
}
|
|
188
93
|
},
|
|
189
94
|
props: {
|
|
@@ -191,5 +96,5 @@ export default AsyncInit.compose(ContractBase, {
|
|
|
191
96
|
}
|
|
192
97
|
})
|
|
193
98
|
|
|
194
|
-
const COMPILER_GE_VERSION = '6.
|
|
99
|
+
const COMPILER_GE_VERSION = '6.1.0'
|
|
195
100
|
const COMPILER_LT_VERSION = '7.0.0'
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js'
|
|
2
2
|
import { MAX_AUTH_FUN_GAS } from '../../tx/builder/schema'
|
|
3
|
+
import { InvalidAuthDataError } from '../../utils/errors'
|
|
3
4
|
|
|
4
5
|
export const prepareGaParams = (ins) => async (authData, authFnName) => {
|
|
5
|
-
if (typeof authData !== 'object') throw new
|
|
6
|
-
if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) throw new
|
|
6
|
+
if (typeof authData !== 'object') throw new InvalidAuthDataError('AuthData must be an object')
|
|
7
|
+
if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) { throw new InvalidAuthDataError(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`) }
|
|
7
8
|
const gas = authData.gas || MAX_AUTH_FUN_GAS
|
|
8
9
|
if (authData.callData) {
|
|
9
|
-
if (authData.callData.split('_')[0] !== 'cb') throw new
|
|
10
|
+
if (authData.callData.split('_')[0] !== 'cb') throw new InvalidAuthDataError('Auth data must be a string with "cb" prefix.')
|
|
10
11
|
return { authCallData: authData.callData, gas }
|
|
11
12
|
}
|
|
12
|
-
if (!authData.source || !authData.args) throw new
|
|
13
|
+
if (!authData.source || !authData.args) throw new InvalidAuthDataError('Auth data must contain source code and arguments.')
|
|
14
|
+
const contract = await ins.getContractInstance({ source: authData.source })
|
|
13
15
|
return {
|
|
14
|
-
authCallData:
|
|
16
|
+
authCallData: contract.calldata.encode(contract._name, authFnName, authData.args),
|
|
15
17
|
gas
|
|
16
18
|
}
|
|
17
19
|
}
|
package/src/contract/ga/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,52 +16,53 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Generalized Account module - routines to use generalized account
|
|
20
20
|
*
|
|
21
21
|
* @module @aeternity/aepp-sdk/es/contract/ga
|
|
22
|
-
* @export
|
|
23
|
-
* @example import {
|
|
22
|
+
* @export GeneralizedAccount
|
|
23
|
+
* @example import { GeneralizedAccount } from '@aeternity/aepp-sdk'
|
|
24
24
|
*/
|
|
25
|
-
import
|
|
25
|
+
import Contract from '../../ae/contract'
|
|
26
26
|
import { TX_TYPE } from '../../tx/builder/schema'
|
|
27
27
|
import { buildTx, unpackTx } from '../../tx/builder'
|
|
28
28
|
import { prepareGaParams } from './helpers'
|
|
29
29
|
import { hash } from '../../utils/crypto'
|
|
30
|
+
import { IllegalArgumentError, MissingParamError } from '../../utils/errors'
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* GeneralizedAccount Stamp
|
|
33
34
|
*
|
|
34
|
-
* Provide
|
|
35
|
+
* Provide Generalized Account implementation
|
|
35
36
|
* {@link module:@aeternity/aepp-sdk/es/contract/ga} clients.
|
|
36
37
|
* @function
|
|
37
38
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
38
39
|
* @rtype Stamp
|
|
39
40
|
* @param {Object} [options={}] - Initializer object
|
|
40
|
-
* @return {Object}
|
|
41
|
+
* @return {Object} GeneralizedAccount instance
|
|
41
42
|
* @example
|
|
42
43
|
* const authContract = ``
|
|
43
|
-
* await
|
|
44
|
+
* await aeSdk.createGeneralizedAccount(authFnName, authContract, [...authFnArguments]
|
|
44
45
|
* // Make spend using GA
|
|
45
46
|
* const callData = 'cb_...' // encoded call data for auth contract
|
|
46
|
-
* await
|
|
47
|
+
* await aeSdk.spend(10000, receiverPub, { authData: { callData } })
|
|
47
48
|
* // or
|
|
48
|
-
* await
|
|
49
|
+
* await aeSdk.spend(10000, receiverPub, {
|
|
49
50
|
* authData: { source: authContract, args: [...authContractArgs] }
|
|
50
51
|
* }) // sdk will prepare callData itself
|
|
51
52
|
*/
|
|
52
|
-
export const
|
|
53
|
+
export const GeneralizedAccount = Contract.compose({
|
|
53
54
|
methods: {
|
|
54
|
-
|
|
55
|
+
createGeneralizedAccount,
|
|
55
56
|
createMetaTx,
|
|
56
57
|
isGA
|
|
57
58
|
}
|
|
58
59
|
})
|
|
59
|
-
export default
|
|
60
|
+
export default GeneralizedAccount
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
63
64
|
* @function
|
|
64
|
-
* Check if account is GA
|
|
65
|
+
* Check if account is GA
|
|
65
66
|
* @param {String} address - Account address
|
|
66
67
|
* @return {Boolean}
|
|
67
68
|
*/
|
|
@@ -71,7 +72,7 @@ async function isGA (address) {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/**
|
|
74
|
-
* Convert current account to GA
|
|
75
|
+
* Convert current account to GA
|
|
75
76
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
76
77
|
* @function
|
|
77
78
|
* @param {String} authFnName - Authorization function name
|
|
@@ -79,20 +80,22 @@ async function isGA (address) {
|
|
|
79
80
|
* @param {Array} [args] - init arguments
|
|
80
81
|
* @param {Object} [options] - Options
|
|
81
82
|
* @return {Promise<Readonly<{
|
|
82
|
-
* result: *, owner: *,
|
|
83
|
+
* result: *, owner: *, address, rawTx: *, transaction: *
|
|
83
84
|
* }>>}
|
|
84
85
|
*/
|
|
85
|
-
async function
|
|
86
|
+
async function createGeneralizedAccount (authFnName, source, args = [], options = {}) {
|
|
86
87
|
const opt = { ...this.Ae.defaults, ...options }
|
|
87
88
|
const ownerId = await this.address(opt)
|
|
89
|
+
if (await this.isGA(ownerId)) throw new IllegalArgumentError(`Account ${ownerId} is already GA`)
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
const contract = await this.getContractInstance({ source })
|
|
92
|
+
await contract.compile()
|
|
91
93
|
const { tx, contractId } = await this.gaAttachTx({
|
|
92
94
|
...opt,
|
|
95
|
+
gas: opt.gas ?? await contract._estimateGas('init', args, opt),
|
|
93
96
|
ownerId,
|
|
94
|
-
code:
|
|
95
|
-
callData:
|
|
97
|
+
code: contract.bytecode,
|
|
98
|
+
callData: contract.calldata.encode(contract._name, 'init', args),
|
|
96
99
|
authFun: hash(authFnName)
|
|
97
100
|
})
|
|
98
101
|
|
|
@@ -119,7 +122,7 @@ const wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, T
|
|
|
119
122
|
* @return {String}
|
|
120
123
|
*/
|
|
121
124
|
async function createMetaTx (rawTransaction, authData, authFnName, options = {}) {
|
|
122
|
-
if (!authData) throw new
|
|
125
|
+
if (!authData) throw new MissingParamError('authData is required')
|
|
123
126
|
// Check if authData is callData or if it's an object prepare a callData from source and args
|
|
124
127
|
const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)
|
|
125
128
|
const opt = { ...this.Ae.defaults, ...options }
|
|
@@ -132,7 +135,7 @@ async function createMetaTx (rawTransaction, authData, authFnName, options = {})
|
|
|
132
135
|
tx: wrappedTx.txObject
|
|
133
136
|
},
|
|
134
137
|
gaId: await this.address(opt),
|
|
135
|
-
abiVersion
|
|
138
|
+
abiVersion,
|
|
136
139
|
authData: authCallData,
|
|
137
140
|
gas,
|
|
138
141
|
vsn: 2
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -21,9 +21,8 @@ import * as Bytes from './utils/bytes'
|
|
|
21
21
|
import * as TxBuilder from './tx/builder'
|
|
22
22
|
import * as TxBuilderHelper from './tx/builder/helpers'
|
|
23
23
|
import * as SCHEMA from './tx/builder/schema'
|
|
24
|
-
import * as ACITransformation from './contract/aci/transformation'
|
|
25
24
|
import * as AmountFormatter from './utils/amount-formatter'
|
|
26
|
-
import HdWallet from './utils/hd-wallet'
|
|
25
|
+
import * as HdWallet from './utils/hd-wallet'
|
|
27
26
|
|
|
28
27
|
import Ae from './ae'
|
|
29
28
|
import Chain from './chain'
|
|
@@ -38,8 +37,8 @@ import AccountMultiple from './account/multiple'
|
|
|
38
37
|
import MemoryAccount from './account/memory'
|
|
39
38
|
import Aens from './ae/aens'
|
|
40
39
|
import Contract from './ae/contract'
|
|
41
|
-
import
|
|
42
|
-
import
|
|
40
|
+
import GeneralizedAccount from './contract/ga'
|
|
41
|
+
import ContractCompilerHttp from './contract/compiler'
|
|
43
42
|
import RpcAepp from './ae/aepp'
|
|
44
43
|
import RpcWallet from './ae/wallet'
|
|
45
44
|
import Oracle from './ae/oracle'
|
|
@@ -53,6 +52,7 @@ export * as AeppWalletSchema from './utils/aepp-wallet-communication/schema'
|
|
|
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'
|
|
55
|
+
export * from './utils/errors'
|
|
56
56
|
|
|
57
57
|
export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey
|
|
58
58
|
|
|
@@ -64,8 +64,7 @@ export {
|
|
|
64
64
|
Aens,
|
|
65
65
|
Bytes,
|
|
66
66
|
Contract,
|
|
67
|
-
|
|
68
|
-
ACITransformation,
|
|
67
|
+
ContractCompilerHttp,
|
|
69
68
|
ChainNode,
|
|
70
69
|
RpcAepp,
|
|
71
70
|
RpcWallet,
|
|
@@ -73,7 +72,7 @@ export {
|
|
|
73
72
|
Crypto,
|
|
74
73
|
Keystore,
|
|
75
74
|
Chain,
|
|
76
|
-
|
|
75
|
+
GeneralizedAccount,
|
|
77
76
|
HdWallet,
|
|
78
77
|
MemoryAccount,
|
|
79
78
|
Node,
|
package/src/node-pool/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import stampit from '@stamp/it'
|
|
8
8
|
import { getNetworkId } from '../node'
|
|
9
|
+
import { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from '../utils/errors'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Node Pool Stamp
|
|
@@ -34,7 +35,7 @@ export default stampit({
|
|
|
34
35
|
configurable: false,
|
|
35
36
|
get () {
|
|
36
37
|
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
37
|
-
throw new
|
|
38
|
+
throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!')
|
|
38
39
|
}
|
|
39
40
|
return this.selectedNode.instance.api
|
|
40
41
|
}
|
|
@@ -55,7 +56,7 @@ export default stampit({
|
|
|
55
56
|
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
|
|
56
57
|
*/
|
|
57
58
|
addNode (name, node, select = false) {
|
|
58
|
-
if (this.pool.has(name)) throw new
|
|
59
|
+
if (this.pool.has(name)) throw new DuplicateNodeError(name)
|
|
59
60
|
|
|
60
61
|
this.validateNodes([{ name, instance: node }])
|
|
61
62
|
|
|
@@ -83,7 +84,7 @@ export default stampit({
|
|
|
83
84
|
* nodePool.selectNode('testNode')
|
|
84
85
|
*/
|
|
85
86
|
selectNode (name) {
|
|
86
|
-
if (!this.pool.has(name)) throw new
|
|
87
|
+
if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)
|
|
87
88
|
|
|
88
89
|
this.selectedNode = this.pool.get(name)
|
|
89
90
|
},
|
|
@@ -119,7 +120,7 @@ export default stampit({
|
|
|
119
120
|
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
120
121
|
*/
|
|
121
122
|
getNodeInfo () {
|
|
122
|
-
if (!this.isNodeConnected()) throw new
|
|
123
|
+
if (!this.isNodeConnected()) throw new DisconnectedError()
|
|
123
124
|
return {
|
|
124
125
|
name: this.selectedNode.name,
|
|
125
126
|
...this.selectedNode.instance.getNodeInfo()
|
|
@@ -143,12 +144,12 @@ export default stampit({
|
|
|
143
144
|
validateNodes (nodes) {
|
|
144
145
|
// TODO: validate it on TypeScript level instead
|
|
145
146
|
// (to speedup development, save runtime resources)
|
|
146
|
-
if (!Array.isArray(nodes)) throw new
|
|
147
|
+
if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array')
|
|
147
148
|
const notObject = nodes.map(n => typeof n).find(t => t !== 'object')
|
|
148
|
-
if (notObject) throw new
|
|
149
|
+
if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`)
|
|
149
150
|
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
|
|
150
151
|
if (notObject) {
|
|
151
|
-
throw new
|
|
152
|
+
throw new TypeError(
|
|
152
153
|
'Each node should have name (string), instance (object) ' +
|
|
153
154
|
`fields, got ${JSON.stringify(wrongFields)} instead`
|
|
154
155
|
)
|
|
@@ -158,7 +159,7 @@ export default stampit({
|
|
|
158
159
|
.find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
|
|
159
160
|
typeof i.consensusProtocolVersion !== 'number')
|
|
160
161
|
if (wrongInstanceFields) {
|
|
161
|
-
throw new
|
|
162
|
+
throw new TypeError(
|
|
162
163
|
'Each node instance should have api (object), consensusProtocolVersion (number), ' +
|
|
163
164
|
`genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
|
|
164
165
|
)
|
package/src/node.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import AsyncInit from './utils/async-init'
|
|
26
26
|
import genSwaggerClient from './utils/swagger'
|
|
27
27
|
import semverSatisfies from './utils/semver-satisfies'
|
|
28
|
+
import { MissingParamError, UnsupportedVersionError } from './utils/errors'
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Obtain networkId from account or node
|
|
@@ -35,7 +36,7 @@ import semverSatisfies from './utils/semver-satisfies'
|
|
|
35
36
|
*/
|
|
36
37
|
export function getNetworkId ({ networkId, force = false } = {}) {
|
|
37
38
|
const res = networkId || this.networkId || this.selectedNode?.networkId
|
|
38
|
-
if (!force && !res) throw new
|
|
39
|
+
if (!force && !res) throw new MissingParamError('networkId is not provided')
|
|
39
40
|
if (force && !res) return null
|
|
40
41
|
return res
|
|
41
42
|
}
|
|
@@ -56,9 +57,9 @@ export function getNetworkId ({ networkId, force = false } = {}) {
|
|
|
56
57
|
*/
|
|
57
58
|
const Node = AsyncInit.compose({
|
|
58
59
|
async init ({ url, internalUrl, ignoreVersion }) {
|
|
59
|
-
if (!url) throw new
|
|
60
|
+
if (!url) throw new MissingParamError('"url" required')
|
|
60
61
|
this.url = url.replace(/\/$/, '')
|
|
61
|
-
this.internalUrl = internalUrl
|
|
62
|
+
this.internalUrl = internalUrl?.replace(/\/$/, '')
|
|
62
63
|
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
63
64
|
internalUrl: this.internalUrl,
|
|
64
65
|
responseInterceptor: response => {
|
|
@@ -73,10 +74,7 @@ const Node = AsyncInit.compose({
|
|
|
73
74
|
!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
|
|
74
75
|
!ignoreVersion
|
|
75
76
|
) {
|
|
76
|
-
throw new
|
|
77
|
-
`Unsupported node version ${this.version}. ` +
|
|
78
|
-
`Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
|
|
79
|
-
)
|
|
77
|
+
throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)
|
|
80
78
|
}
|
|
81
79
|
this.api = client.api
|
|
82
80
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt
|
|
3
|
+
} from './helpers'
|
|
4
|
+
import { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'
|
|
5
|
+
|
|
6
|
+
export class Field {
|
|
7
|
+
static serialize (value) {
|
|
8
|
+
return value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static deserialize (value) {
|
|
12
|
+
return value
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Name extends Field {
|
|
17
|
+
static serialize (value) {
|
|
18
|
+
ensureNameValid(value)
|
|
19
|
+
return Buffer.from(value)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static deserialize (value) {
|
|
23
|
+
return value.toString()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class NameId extends Field {
|
|
28
|
+
static serialize (value) {
|
|
29
|
+
return writeId(isNameValid(value) ? produceNameId(value) : value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static deserialize (value) {
|
|
33
|
+
return readId(value)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class NameFee extends Field {
|
|
38
|
+
static serialize (value, { name }) {
|
|
39
|
+
const minNameFee = getMinimumNameFee(name)
|
|
40
|
+
value ??= minNameFee
|
|
41
|
+
if (minNameFee.gt(value)) {
|
|
42
|
+
throw new InsufficientNameFeeError(value, minNameFee)
|
|
43
|
+
}
|
|
44
|
+
return writeInt(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static deserialize (value) {
|
|
48
|
+
return readInt(value)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class Deposit extends Field {
|
|
53
|
+
static serialize (value, { name }) {
|
|
54
|
+
if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`)
|
|
55
|
+
return writeInt(0)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static deserialize (value) {
|
|
59
|
+
return readInt(value)
|
|
60
|
+
}
|
|
61
|
+
}
|