@aeternity/aepp-sdk 13.0.0-alpha.0 → 13.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aesophia_cli +0 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- 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 +4206 -1127
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkBase.d.ts +3 -3
- package/es/AeSdkBase.mjs +4 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.d.ts +3 -4
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/Node.d.ts +4 -3
- package/es/Node.mjs +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +2 -2
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.mjs +5 -3
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.mjs +2 -1
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/Memory.mjs +2 -1
- package/es/account/Memory.mjs.map +1 -1
- package/es/aens.d.ts +1 -1
- package/es/aens.mjs +5 -1
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +19 -4
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/chain.d.ts +9 -1
- package/es/chain.mjs +4 -1
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.d.ts +6 -1
- package/es/channel/Base.mjs +9 -6
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.d.ts +8 -7
- package/es/channel/Contract.mjs +1 -1
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.d.ts +3 -1
- package/es/channel/Spend.mjs +4 -2
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +11 -9
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.mjs +3 -1
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.d.ts +21 -46
- package/es/contract/Contract.mjs +69 -52
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Base.d.ts +81 -0
- package/es/contract/compiler/Base.mjs +5 -0
- package/es/contract/compiler/Base.mjs.map +1 -0
- package/es/contract/compiler/Cli.d.ts +23 -0
- package/es/contract/compiler/Cli.mjs +155 -0
- package/es/contract/compiler/Cli.mjs.map +1 -0
- package/es/contract/compiler/Http.d.ts +32 -0
- package/es/contract/{CompilerHttp.mjs → compiler/Http.mjs} +64 -9
- package/es/contract/compiler/Http.mjs.map +1 -0
- package/es/contract/compiler/HttpNode.d.ts +17 -0
- package/es/contract/compiler/HttpNode.mjs +26 -0
- package/es/contract/compiler/HttpNode.mjs.map +1 -0
- package/es/contract/compiler/getFileSystem.d.ts +6 -0
- package/es/contract/compiler/getFileSystem.mjs +40 -0
- package/es/contract/compiler/getFileSystem.mjs.map +1 -0
- package/es/contract/ga.d.ts +5 -4
- package/es/contract/ga.mjs +11 -2
- package/es/contract/ga.mjs.map +1 -1
- package/es/index-browser.d.ts +39 -0
- package/es/index-browser.mjs +55 -0
- package/es/index-browser.mjs.map +1 -0
- package/es/index.d.ts +4 -38
- package/es/index.mjs +4 -53
- package/es/index.mjs.map +1 -1
- package/es/oracle.mjs +1 -1
- package/es/oracle.mjs.map +1 -1
- package/es/spend.mjs +1 -3
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.d.ts +28 -1
- package/es/tx/builder/constants.mjs +32 -3
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.d.ts +10 -0
- package/es/tx/builder/field-types/abi-version.mjs +20 -0
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -0
- package/es/tx/builder/field-types/address.d.ts +5 -6
- package/es/tx/builder/field-types/address.mjs +17 -8
- package/es/tx/builder/field-types/address.mjs.map +1 -1
- package/es/tx/builder/field-types/array.d.ts +7 -0
- package/es/tx/builder/field-types/array.mjs +11 -0
- package/es/tx/builder/field-types/array.mjs.map +1 -0
- package/es/tx/builder/field-types/boolean.d.ts +6 -0
- package/es/tx/builder/field-types/boolean.mjs +13 -0
- package/es/tx/builder/field-types/boolean.mjs.map +1 -0
- package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +30 -0
- package/es/tx/builder/field-types/ct-version.mjs +48 -0
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/encoded.d.ts +6 -0
- package/es/tx/builder/field-types/encoded.mjs +21 -0
- package/es/tx/builder/field-types/encoded.mjs.map +1 -0
- package/es/tx/builder/field-types/entry.d.ts +11 -0
- package/es/tx/builder/field-types/entry.mjs +31 -0
- package/es/tx/builder/field-types/entry.mjs.map +1 -0
- package/es/tx/builder/field-types/enumeration.d.ts +5 -3
- package/es/tx/builder/field-types/enumeration.mjs +11 -2
- package/es/tx/builder/field-types/enumeration.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.d.ts +10 -7
- package/es/tx/builder/field-types/fee.mjs +24 -20
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/es/tx/builder/field-types/gas-limit.mjs +9 -6
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.d.ts +1 -1
- package/es/tx/builder/field-types/index.d.ts +66 -28
- package/es/tx/builder/field-types/index.mjs +30 -12
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.d.ts +37 -0
- package/es/tx/builder/field-types/mptree.mjs +268 -0
- package/es/tx/builder/field-types/mptree.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +1 -2
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/name-id.mjs +2 -1
- package/es/tx/builder/field-types/name-id.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs +2 -2
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/raw.d.ts +6 -0
- package/es/tx/builder/field-types/raw.mjs +13 -0
- package/es/tx/builder/field-types/raw.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs +16 -0
- package/es/tx/builder/field-types/short-u-int-const.mjs.map +1 -0
- package/es/tx/builder/field-types/string.d.ts +6 -0
- package/es/tx/builder/field-types/string.mjs +10 -0
- package/es/tx/builder/field-types/string.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +1 -2
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +11 -29
- package/es/tx/builder/index.mjs +50 -211
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +2111 -571
- package/es/tx/builder/schema.mjs +57 -125
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +5 -20
- package/es/tx/index.mjs +31 -88
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +3 -5
- package/es/tx/validator.mjs +82 -95
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/errors.d.ts +3 -8
- package/es/utils/errors.mjs +1 -11
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/other.d.ts +1 -1
- package/package.json +35 -27
- package/src/AeSdkBase.ts +6 -3
- package/src/AeSdkMethods.ts +3 -4
- package/src/Node.ts +6 -3
- package/src/account/Base.ts +2 -2
- package/src/account/Generalized.ts +2 -2
- package/src/account/Ledger.ts +1 -1
- package/src/account/Memory.ts +1 -1
- package/src/aens.ts +3 -2
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +18 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +2 -2
- package/src/chain.ts +5 -3
- package/src/channel/Base.ts +13 -5
- package/src/channel/Contract.ts +11 -10
- package/src/channel/Spend.ts +7 -2
- package/src/channel/handlers.ts +10 -9
- package/src/channel/internal.ts +1 -1
- package/src/contract/Contract.ts +69 -79
- package/src/contract/compiler/Base.ts +94 -0
- package/src/contract/compiler/Cli.ts +134 -0
- package/src/contract/compiler/Http.ts +124 -0
- package/src/contract/compiler/HttpNode.ts +26 -0
- package/src/contract/compiler/getFileSystem.ts +42 -0
- package/src/contract/ga.ts +9 -6
- package/src/index-browser.ts +58 -0
- package/src/index.ts +4 -56
- package/src/oracle.ts +1 -1
- package/src/spend.ts +1 -1
- package/src/tx/builder/constants.ts +32 -3
- package/src/tx/builder/field-types/abi-version.ts +21 -0
- package/src/tx/builder/field-types/address.ts +23 -13
- package/src/tx/builder/field-types/array.ts +19 -0
- package/src/tx/builder/field-types/boolean.ts +9 -0
- package/src/tx/builder/field-types/coin-amount.ts +2 -1
- package/src/tx/builder/field-types/ct-version.ts +50 -0
- package/src/tx/builder/field-types/deposit.ts +1 -1
- package/src/tx/builder/field-types/encoded.ts +27 -0
- package/src/tx/builder/field-types/entry.ts +31 -0
- package/src/tx/builder/field-types/enumeration.ts +15 -4
- package/src/tx/builder/field-types/fee.ts +38 -18
- package/src/tx/builder/field-types/gas-limit.ts +12 -7
- package/src/tx/builder/field-types/index.ts +46 -17
- package/src/tx/builder/field-types/mptree.ts +242 -0
- package/src/tx/builder/field-types/name-fee.ts +1 -2
- package/src/tx/builder/field-types/name-id.ts +1 -1
- package/src/tx/builder/field-types/pointers.ts +2 -2
- package/src/tx/builder/field-types/raw.ts +9 -0
- package/src/tx/builder/field-types/short-u-int-const.ts +20 -0
- package/src/tx/builder/field-types/string.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +1 -3
- package/src/tx/builder/index.ts +63 -247
- package/src/tx/builder/schema.ts +273 -323
- package/src/tx/index.ts +37 -104
- package/src/tx/validator.ts +72 -95
- package/src/utils/bytes.ts +1 -1
- package/src/utils/errors.ts +4 -13
- package/types-legacy/ts4.2/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.2/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.2/Node.d.ts +3 -3
- package/types-legacy/ts4.2/account/Base.d.ts +2 -2
- package/types-legacy/ts4.2/aens.d.ts +1 -1
- package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.2/chain.d.ts +9 -1
- package/types-legacy/ts4.2/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.2/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.2/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.2/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.2/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.2/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.2/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.2/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.2/index-browser.d.ts +39 -0
- package/types-legacy/ts4.2/index.d.ts +4 -38
- package/types-legacy/ts4.2/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.2/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.2/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.2/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.2/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.2/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.2/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.2/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.2/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.2/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.2/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.2/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.2/tx/index.d.ts +5 -20
- package/types-legacy/ts4.2/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.2/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.2/utils/other.d.ts +1 -1
- package/types-legacy/ts4.5/AeSdkBase.d.ts +3 -3
- package/types-legacy/ts4.5/AeSdkMethods.d.ts +3 -4
- package/types-legacy/ts4.5/Node.d.ts +3 -3
- package/types-legacy/ts4.5/account/Base.d.ts +2 -2
- package/types-legacy/ts4.5/aens.d.ts +1 -1
- package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/types-legacy/ts4.5/chain.d.ts +9 -1
- package/types-legacy/ts4.5/channel/Base.d.ts +6 -1
- package/types-legacy/ts4.5/channel/Contract.d.ts +8 -7
- package/types-legacy/ts4.5/channel/Spend.d.ts +3 -1
- package/types-legacy/ts4.5/contract/Contract.d.ts +21 -46
- package/types-legacy/ts4.5/contract/compiler/Base.d.ts +81 -0
- package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +23 -0
- package/types-legacy/ts4.5/contract/compiler/Http.d.ts +32 -0
- package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +17 -0
- package/types-legacy/ts4.5/contract/compiler/getFileSystem.d.ts +6 -0
- package/types-legacy/ts4.5/contract/ga.d.ts +5 -4
- package/types-legacy/ts4.5/index-browser.d.ts +39 -0
- package/types-legacy/ts4.5/index.d.ts +4 -38
- package/types-legacy/ts4.5/tx/builder/constants.d.ts +28 -1
- package/types-legacy/ts4.5/tx/builder/field-types/abi-version.d.ts +10 -0
- package/types-legacy/ts4.5/tx/builder/field-types/address.d.ts +11 -12
- package/types-legacy/ts4.5/tx/builder/field-types/array.d.ts +7 -0
- package/types-legacy/ts4.5/tx/builder/field-types/boolean.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +42 -0
- package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/encoded.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/entry.d.ts +11 -0
- package/types-legacy/ts4.5/tx/builder/field-types/enumeration.d.ts +5 -3
- package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +10 -7
- package/types-legacy/ts4.5/tx/builder/field-types/gas-limit.d.ts +5 -2
- package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +1 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +72 -28
- package/types-legacy/ts4.5/tx/builder/field-types/mptree.d.ts +43 -0
- package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/field-types/raw.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/short-u-int-const.d.ts +5 -0
- package/types-legacy/ts4.5/tx/builder/field-types/string.d.ts +6 -0
- package/types-legacy/ts4.5/tx/builder/field-types/u-int.d.ts +1 -2
- package/types-legacy/ts4.5/tx/builder/index.d.ts +11 -29
- package/types-legacy/ts4.5/tx/builder/schema.d.ts +2380 -668
- package/types-legacy/ts4.5/tx/index.d.ts +5 -20
- package/types-legacy/ts4.5/tx/validator.d.ts +3 -5
- package/types-legacy/ts4.5/utils/errors.d.ts +3 -8
- package/types-legacy/ts4.5/utils/other.d.ts +1 -1
- package/es/contract/CompilerHttp.d.ts +0 -18
- package/es/contract/CompilerHttp.mjs.map +0 -1
- package/es/tx/builder/field-types/addresses.d.ts +0 -6
- package/es/tx/builder/field-types/addresses.mjs +0 -13
- package/es/tx/builder/field-types/addresses.mjs.map +0 -1
- package/es/utils/mptree.d.ts +0 -26
- package/es/utils/mptree.mjs +0 -143
- package/es/utils/mptree.mjs.map +0 -1
- package/src/contract/CompilerHttp.ts +0 -67
- package/src/tx/builder/field-types/addresses.ts +0 -18
- package/src/utils/mptree.ts +0 -145
- package/types-legacy/ts4.2/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.2/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.2/utils/mptree.d.ts +0 -32
- package/types-legacy/ts4.5/contract/CompilerHttp.d.ts +0 -18
- package/types-legacy/ts4.5/tx/builder/field-types/addresses.d.ts +0 -6
- package/types-legacy/ts4.5/utils/mptree.d.ts +0 -32
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { resolve, dirname, basename } from 'path';
|
|
4
|
+
import { mkdir, writeFile, rm } from 'fs/promises';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import CompilerBase, { Aci } from './Base';
|
|
7
|
+
import { Encoded } from '../../utils/encoder';
|
|
8
|
+
import { CompilerError, InternalError, UnsupportedVersionError } from '../../utils/errors';
|
|
9
|
+
import semverSatisfies from '../../utils/semver-satisfies';
|
|
10
|
+
|
|
11
|
+
const getPackagePath = (): string => {
|
|
12
|
+
const path = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
if (basename(path) === 'dist') return resolve(path, '..');
|
|
14
|
+
if (basename(path) === 'compiler') return resolve(path, '../../..');
|
|
15
|
+
throw new InternalError('Can\'t get package path');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A wrapper around aesophia_cli, available only in Node.js
|
|
20
|
+
* Assumes that `escript` is available in PATH.
|
|
21
|
+
*/
|
|
22
|
+
export default class CompilerCli extends CompilerBase {
|
|
23
|
+
#path: string;
|
|
24
|
+
|
|
25
|
+
#ensureCompatibleVersion: Promise<void>;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
compilerPath = resolve(getPackagePath(), './bin/aesophia_cli'),
|
|
29
|
+
{ ignoreVersion }: { ignoreVersion?: boolean } = {},
|
|
30
|
+
) {
|
|
31
|
+
super();
|
|
32
|
+
this.#path = compilerPath;
|
|
33
|
+
if (ignoreVersion !== true) {
|
|
34
|
+
this.#ensureCompatibleVersion = this.version().then((version) => {
|
|
35
|
+
const versions = [version, '7.0.1', '8.0.0'] as const;
|
|
36
|
+
if (!semverSatisfies(...versions)) throw new UnsupportedVersionError('compiler', ...versions);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async #run(...parameters: string[]): Promise<string> {
|
|
42
|
+
return new Promise((pResolve, pReject) => {
|
|
43
|
+
execFile('escript', [this.#path, ...parameters], (error, stdout, stderr) => {
|
|
44
|
+
if (error != null) pReject(error);
|
|
45
|
+
else if (stderr !== '') pReject(new CompilerError(stderr));
|
|
46
|
+
else pResolve(stdout);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static async #saveContractToTmpDir(
|
|
52
|
+
sourceCode: string,
|
|
53
|
+
fileSystem: Record<string, string> = {},
|
|
54
|
+
): Promise<string> {
|
|
55
|
+
const randomName = (): string => Math.random().toString(36).slice(2);
|
|
56
|
+
const path = resolve(tmpdir(), `aepp-sdk-js-${randomName()}`);
|
|
57
|
+
await mkdir(path);
|
|
58
|
+
const sourceCodePath = resolve(path, `${randomName()}.aes`);
|
|
59
|
+
await writeFile(sourceCodePath, sourceCode);
|
|
60
|
+
await Promise.all(Object.entries(fileSystem)
|
|
61
|
+
.map(async ([name, src]) => {
|
|
62
|
+
const p = resolve(path, name);
|
|
63
|
+
await mkdir(dirname(p), { recursive: true });
|
|
64
|
+
return writeFile(p, src);
|
|
65
|
+
}));
|
|
66
|
+
return sourceCodePath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async compile(path: string): Promise<{
|
|
70
|
+
bytecode: Encoded.ContractBytearray;
|
|
71
|
+
aci: Aci;
|
|
72
|
+
}> {
|
|
73
|
+
await this.#ensureCompatibleVersion;
|
|
74
|
+
let bytecode;
|
|
75
|
+
let aciCli;
|
|
76
|
+
try {
|
|
77
|
+
[bytecode, aciCli] = await Promise.all([
|
|
78
|
+
this.#run(path),
|
|
79
|
+
this.#run('--create_json_aci', path).then((res) => JSON.parse(res)),
|
|
80
|
+
]);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new CompilerError(error.message);
|
|
83
|
+
}
|
|
84
|
+
const aci = {
|
|
85
|
+
encodedAci: aciCli[0],
|
|
86
|
+
externalEncodedAci: aciCli.slice(1),
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
bytecode: bytecode.trimEnd() as Encoded.ContractBytearray,
|
|
90
|
+
aci: aci as Aci,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async compileBySourceCode(sourceCode: string, fileSystem?: Record<string, string>): Promise<{
|
|
95
|
+
bytecode: Encoded.ContractBytearray;
|
|
96
|
+
aci: Aci;
|
|
97
|
+
}> {
|
|
98
|
+
const tmp = await CompilerCli.#saveContractToTmpDir(sourceCode, fileSystem);
|
|
99
|
+
try {
|
|
100
|
+
return await this.compile(tmp);
|
|
101
|
+
} finally {
|
|
102
|
+
await rm(dirname(tmp), { recursive: true });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean> {
|
|
107
|
+
await this.#ensureCompatibleVersion;
|
|
108
|
+
try {
|
|
109
|
+
return (await this.#run(path, '--validate', bytecode)).includes('Validation successful.');
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async validateBySourceCode(
|
|
116
|
+
bytecode: Encoded.ContractBytearray,
|
|
117
|
+
sourceCode: string,
|
|
118
|
+
fileSystem?: Record<string, string>,
|
|
119
|
+
): Promise<boolean> {
|
|
120
|
+
const tmp = await CompilerCli.#saveContractToTmpDir(sourceCode, fileSystem);
|
|
121
|
+
try {
|
|
122
|
+
return await this.validate(bytecode, tmp);
|
|
123
|
+
} finally {
|
|
124
|
+
await rm(dirname(tmp), { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async version(): Promise<string> {
|
|
129
|
+
const verMessage = await this.#run('--version');
|
|
130
|
+
const ver = verMessage.match(/Sophia compiler version ([\d.]+)\n/)?.[1];
|
|
131
|
+
if (ver == null) throw new CompilerError('Can\'t get compiler version');
|
|
132
|
+
return ver;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 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
|
+
import { RestError } from '@azure/core-rest-pipeline';
|
|
18
|
+
import {
|
|
19
|
+
Compiler as CompilerApi,
|
|
20
|
+
ErrorModel,
|
|
21
|
+
CompilerError as CompilerErrorApi,
|
|
22
|
+
} from '../../apis/compiler';
|
|
23
|
+
import { genErrorFormatterPolicy, genVersionCheckPolicy } from '../../utils/autorest';
|
|
24
|
+
import CompilerBase, { Aci } from './Base';
|
|
25
|
+
import { Encoded } from '../../utils/encoder';
|
|
26
|
+
import { CompilerError, NotImplementedError } from '../../utils/errors';
|
|
27
|
+
|
|
28
|
+
type GeneralCompilerError = ErrorModel & {
|
|
29
|
+
info?: object;
|
|
30
|
+
parameter?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Contract Compiler over HTTP
|
|
35
|
+
*
|
|
36
|
+
* This class include api call's related to contract compiler functionality.
|
|
37
|
+
* @category contract
|
|
38
|
+
* @example CompilerHttp('COMPILER_URL')
|
|
39
|
+
*/
|
|
40
|
+
export default class CompilerHttp extends CompilerBase {
|
|
41
|
+
readonly api: CompilerApi;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param compilerUrl - Url for compiler API
|
|
45
|
+
* @param options - Options
|
|
46
|
+
* @param options.ignoreVersion - Don't check compiler version
|
|
47
|
+
*/
|
|
48
|
+
constructor(compilerUrl: string, { ignoreVersion }: { ignoreVersion?: boolean } = {}) {
|
|
49
|
+
super();
|
|
50
|
+
this.api = new CompilerApi(compilerUrl, {
|
|
51
|
+
allowInsecureConnection: true,
|
|
52
|
+
additionalPolicies: [
|
|
53
|
+
genErrorFormatterPolicy((body: GeneralCompilerError | CompilerErrorApi[]) => {
|
|
54
|
+
let message = '';
|
|
55
|
+
if ('reason' in body) {
|
|
56
|
+
message += ` ${body.reason
|
|
57
|
+
}${body.parameter != null ? ` in ${body.parameter}` : ''
|
|
58
|
+
// TODO: revising after improving documentation https://github.com/aeternity/aesophia_http/issues/78
|
|
59
|
+
}${body.info != null ? ` (${JSON.stringify(body.info)})` : ''}`;
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(body)) {
|
|
62
|
+
message += `\n${body
|
|
63
|
+
.map((e) => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context != null ? `(${e.context})` : ''}`)
|
|
64
|
+
.join('\n')}`;
|
|
65
|
+
}
|
|
66
|
+
return message;
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
if (ignoreVersion !== true) {
|
|
71
|
+
const versionPromise = this.api.apiVersion().then(({ apiVersion }) => apiVersion);
|
|
72
|
+
this.api.pipeline.addPolicy(
|
|
73
|
+
genVersionCheckPolicy('compiler', '/api-version', versionPromise, '7.0.1', '8.0.0'),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async compileBySourceCode(
|
|
79
|
+
sourceCode: string,
|
|
80
|
+
fileSystem?: Record<string, string>,
|
|
81
|
+
): Promise<{ bytecode: Encoded.ContractBytearray; aci: Aci }> {
|
|
82
|
+
try {
|
|
83
|
+
const [bytecode, aci] = await Promise.all([
|
|
84
|
+
this.api.compileContract({ code: sourceCode, options: { fileSystem } })
|
|
85
|
+
.then((res) => res.bytecode as Encoded.ContractBytearray),
|
|
86
|
+
this.api.generateACI({ code: sourceCode, options: { fileSystem } }),
|
|
87
|
+
]);
|
|
88
|
+
// TODO: should be fixed when the compiledAci interface gets updated
|
|
89
|
+
return { bytecode, aci: aci as Aci };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof RestError && error.statusCode === 400) {
|
|
92
|
+
throw new CompilerError(error.message.replace(/^aci error:/, 'compile error:'));
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
99
|
+
async compile(path: string): Promise<{ bytecode: Encoded.ContractBytearray; aci: Aci }> {
|
|
100
|
+
throw new NotImplementedError('File system access, use CompilerHttpNode instead');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async validateBySourceCode(
|
|
104
|
+
bytecode: Encoded.ContractBytearray,
|
|
105
|
+
sourceCode: string,
|
|
106
|
+
fileSystem?: Record<string, string>,
|
|
107
|
+
): Promise<boolean> {
|
|
108
|
+
try {
|
|
109
|
+
await this.api.validateByteCode({ bytecode, source: sourceCode, options: { fileSystem } });
|
|
110
|
+
return true;
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
117
|
+
async validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean> {
|
|
118
|
+
throw new NotImplementedError('File system access, use CompilerHttpNode instead');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async version(): Promise<string> {
|
|
122
|
+
return (await this.api.version()).version;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import HttpBrowser from './Http';
|
|
3
|
+
import { Aci } from './Base';
|
|
4
|
+
import { Encoded } from '../../utils/encoder';
|
|
5
|
+
import getFileSystem from './getFileSystem';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Contract Compiler over HTTP for Nodejs
|
|
9
|
+
*
|
|
10
|
+
* Inherits CompilerHttp and implements `compile`, `validate` methods
|
|
11
|
+
* @category contract
|
|
12
|
+
* @example CompilerHttpNode('COMPILER_URL')
|
|
13
|
+
*/
|
|
14
|
+
export default class CompilerHttpNode extends HttpBrowser {
|
|
15
|
+
override async compile(path: string): Promise<{ bytecode: Encoded.ContractBytearray; aci: Aci }> {
|
|
16
|
+
const fileSystem = await getFileSystem(path);
|
|
17
|
+
const sourceCode = await readFile(path, 'utf8');
|
|
18
|
+
return this.compileBySourceCode(sourceCode, fileSystem);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override async validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean> {
|
|
22
|
+
const fileSystem = await getFileSystem(path);
|
|
23
|
+
const sourceCode = await readFile(path, 'utf8');
|
|
24
|
+
return this.validateBySourceCode(bytecode, sourceCode, fileSystem);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { dirname, resolve, basename } from 'path';
|
|
3
|
+
import { InternalError } from '../../utils/errors';
|
|
4
|
+
|
|
5
|
+
const defaultIncludes = [
|
|
6
|
+
'List.aes', 'Option.aes', 'String.aes',
|
|
7
|
+
'Func.aes', 'Pair.aes', 'Triple.aes',
|
|
8
|
+
'BLS12_381.aes', 'Frac.aes', 'Set.aes',
|
|
9
|
+
'Bitwise.aes',
|
|
10
|
+
];
|
|
11
|
+
const includeRegExp = /^include\s*"([\w/.-]+)"/mi;
|
|
12
|
+
const includesRegExp = new RegExp(includeRegExp.source, `${includeRegExp.flags}g`);
|
|
13
|
+
|
|
14
|
+
async function getFileSystemRec(
|
|
15
|
+
root: string,
|
|
16
|
+
relative: string,
|
|
17
|
+
): Promise<Record<string, string>> {
|
|
18
|
+
const sourceCode = await readFile(resolve(root, relative), 'utf8');
|
|
19
|
+
const filesystem: Record<string, string> = {};
|
|
20
|
+
await Promise.all((sourceCode.match(includesRegExp) ?? [])
|
|
21
|
+
.map((include) => {
|
|
22
|
+
const m = include.match(includeRegExp);
|
|
23
|
+
if (m?.length !== 2) throw new InternalError('Unexpected match length');
|
|
24
|
+
return m[1];
|
|
25
|
+
})
|
|
26
|
+
.filter((include) => !defaultIncludes.includes(include))
|
|
27
|
+
.map(async (include) => {
|
|
28
|
+
const includePath = resolve(root, include);
|
|
29
|
+
filesystem[include] = await readFile(includePath, 'utf8');
|
|
30
|
+
Object.assign(filesystem, await getFileSystemRec(root, include));
|
|
31
|
+
}));
|
|
32
|
+
return filesystem;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reads all files included in the provided contract
|
|
37
|
+
* Available only in Node.js
|
|
38
|
+
* @param path - a path to the main contract source code
|
|
39
|
+
*/
|
|
40
|
+
export default async function getFileSystem(path: string): Promise<Record<string, string>> {
|
|
41
|
+
return getFileSystemRec(dirname(path), basename(path));
|
|
42
|
+
}
|
package/src/contract/ga.ts
CHANGED
|
@@ -31,7 +31,7 @@ import Contract from './Contract';
|
|
|
31
31
|
import { send, SendOptions } from '../spend';
|
|
32
32
|
import Node from '../Node';
|
|
33
33
|
import { getAccount } from '../chain';
|
|
34
|
-
import
|
|
34
|
+
import CompilerBase from './compiler/Base';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Convert current account to GA
|
|
@@ -44,10 +44,9 @@ import CompilerHttp from './CompilerHttp';
|
|
|
44
44
|
*/
|
|
45
45
|
export async function createGeneralizedAccount(
|
|
46
46
|
authFnName: string,
|
|
47
|
-
sourceCode: string,
|
|
48
47
|
args: any[],
|
|
49
48
|
{
|
|
50
|
-
onAccount, onCompiler, onNode, ...options
|
|
49
|
+
onAccount, onCompiler, onNode, bytecode, aci, sourceCodePath, sourceCode, fileSystem, ...options
|
|
51
50
|
}: CreateGeneralizedAccountOptions,
|
|
52
51
|
): Promise<Readonly<{
|
|
53
52
|
owner: Encoded.AccountAddress;
|
|
@@ -61,7 +60,7 @@ export async function createGeneralizedAccount(
|
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
const contract = await Contract.initialize<{ init: (...a: any[]) => void }>({
|
|
64
|
-
onAccount, onCompiler, onNode, sourceCode,
|
|
63
|
+
onAccount, onCompiler, onNode, bytecode, aci, sourceCodePath, sourceCode, fileSystem,
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
const tx = await _buildTx(Tag.GaAttachTx, {
|
|
@@ -88,9 +87,13 @@ export async function createGeneralizedAccount(
|
|
|
88
87
|
|
|
89
88
|
interface CreateGeneralizedAccountOptions extends
|
|
90
89
|
BuildTxOptions<Tag.GaAttachTx, 'authFun' | 'callData' | 'code' | 'ownerId' | 'gasLimit'>,
|
|
91
|
-
SendOptions
|
|
90
|
+
SendOptions,
|
|
91
|
+
Pick<
|
|
92
|
+
Parameters<typeof Contract.initialize>[0],
|
|
93
|
+
'bytecode' | 'aci' | 'sourceCodePath' | 'sourceCode' | 'fileSystem'
|
|
94
|
+
> {
|
|
92
95
|
onAccount: AccountBase;
|
|
93
|
-
onCompiler:
|
|
96
|
+
onCompiler: CompilerBase;
|
|
94
97
|
onNode: Node;
|
|
95
98
|
gasLimit?: number;
|
|
96
99
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2022 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
|
+
export * from './chain';
|
|
19
|
+
export * from './utils/crypto';
|
|
20
|
+
export * from './utils/keystore';
|
|
21
|
+
export * from './utils/bytes';
|
|
22
|
+
export * from './tx';
|
|
23
|
+
export * from './tx/builder';
|
|
24
|
+
export * from './tx/builder/helpers';
|
|
25
|
+
export * from './tx/builder/constants';
|
|
26
|
+
export * from './tx/builder/schema';
|
|
27
|
+
export * from './utils/amount-formatter';
|
|
28
|
+
export * from './utils/hd-wallet';
|
|
29
|
+
export { encode, decode, Encoding } from './utils/encoder';
|
|
30
|
+
export * from './aens';
|
|
31
|
+
export { default as Contract } from './contract/Contract';
|
|
32
|
+
export type { ContractMethodsBase } from './contract/Contract';
|
|
33
|
+
export * from './oracle';
|
|
34
|
+
export * from './spend';
|
|
35
|
+
export * from './contract/ga';
|
|
36
|
+
|
|
37
|
+
export { default as AeSdkMethods } from './AeSdkMethods';
|
|
38
|
+
export { default as AeSdkBase } from './AeSdkBase';
|
|
39
|
+
export { default as AeSdk } from './AeSdk';
|
|
40
|
+
export { default as AeSdkAepp } from './AeSdkAepp';
|
|
41
|
+
export { default as AeSdkWallet } from './AeSdkWallet';
|
|
42
|
+
export { default as Node } from './Node';
|
|
43
|
+
export { default as verifyTransaction } from './tx/validator';
|
|
44
|
+
export { default as AccountBase } from './account/Base';
|
|
45
|
+
export { default as MemoryAccount } from './account/Memory';
|
|
46
|
+
export { default as AccountGeneralized } from './account/Generalized';
|
|
47
|
+
export { default as AccountLedger } from './account/Ledger';
|
|
48
|
+
export { default as AccountLedgerFactory } from './account/LedgerFactory';
|
|
49
|
+
export { default as CompilerBase } from './contract/compiler/Base';
|
|
50
|
+
export { default as CompilerHttp } from './contract/compiler/Http';
|
|
51
|
+
export { default as Channel } from './channel/Contract';
|
|
52
|
+
|
|
53
|
+
export { default as connectionProxy } from './aepp-wallet-communication/connection-proxy';
|
|
54
|
+
export * from './aepp-wallet-communication/schema';
|
|
55
|
+
export { default as walletDetector } from './aepp-wallet-communication/wallet-detector';
|
|
56
|
+
export { default as BrowserRuntimeConnection } from './aepp-wallet-communication/connection/BrowserRuntime';
|
|
57
|
+
export { default as BrowserWindowMessageConnection } from './aepp-wallet-communication/connection/BrowserWindowMessage';
|
|
58
|
+
export * from './utils/errors';
|
package/src/index.ts
CHANGED
|
@@ -1,57 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
* ISC License (ISC)
|
|
3
|
-
* Copyright (c) 2022 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
|
-
*/
|
|
1
|
+
export * from './index-browser';
|
|
17
2
|
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export * from './utils/bytes';
|
|
22
|
-
export * from './tx';
|
|
23
|
-
export * from './tx/builder';
|
|
24
|
-
export * from './tx/builder/helpers';
|
|
25
|
-
export * from './tx/builder/constants';
|
|
26
|
-
export * from './tx/builder/schema';
|
|
27
|
-
export * from './utils/amount-formatter';
|
|
28
|
-
export * from './utils/hd-wallet';
|
|
29
|
-
export { encode, decode, Encoding } from './utils/encoder';
|
|
30
|
-
export * from './aens';
|
|
31
|
-
export { default as Contract } from './contract/Contract';
|
|
32
|
-
export type { ContractMethodsBase } from './contract/Contract';
|
|
33
|
-
export * from './oracle';
|
|
34
|
-
export * from './spend';
|
|
35
|
-
export * from './contract/ga';
|
|
36
|
-
|
|
37
|
-
export { default as AeSdkMethods } from './AeSdkMethods';
|
|
38
|
-
export { default as AeSdkBase } from './AeSdkBase';
|
|
39
|
-
export { default as AeSdk } from './AeSdk';
|
|
40
|
-
export { default as AeSdkAepp } from './AeSdkAepp';
|
|
41
|
-
export { default as AeSdkWallet } from './AeSdkWallet';
|
|
42
|
-
export { default as Node } from './Node';
|
|
43
|
-
export { default as verifyTransaction } from './tx/validator';
|
|
44
|
-
export { default as AccountBase } from './account/Base';
|
|
45
|
-
export { default as MemoryAccount } from './account/Memory';
|
|
46
|
-
export { default as AccountGeneralized } from './account/Generalized';
|
|
47
|
-
export { default as AccountLedger } from './account/Ledger';
|
|
48
|
-
export { default as AccountLedgerFactory } from './account/LedgerFactory';
|
|
49
|
-
export { default as CompilerHttp } from './contract/CompilerHttp';
|
|
50
|
-
export { default as Channel } from './channel/Contract';
|
|
51
|
-
|
|
52
|
-
export { default as connectionProxy } from './aepp-wallet-communication/connection-proxy';
|
|
53
|
-
export * from './aepp-wallet-communication/schema';
|
|
54
|
-
export { default as walletDetector } from './aepp-wallet-communication/wallet-detector';
|
|
55
|
-
export { default as BrowserRuntimeConnection } from './aepp-wallet-communication/connection/BrowserRuntime';
|
|
56
|
-
export { default as BrowserWindowMessageConnection } from './aepp-wallet-communication/connection/BrowserWindowMessage';
|
|
57
|
-
export * from './utils/errors';
|
|
3
|
+
export { default as CompilerCli } from './contract/compiler/Cli';
|
|
4
|
+
export { default as getFileSystem } from './contract/compiler/getFileSystem';
|
|
5
|
+
export { default as CompilerHttpNode } from './contract/compiler/HttpNode';
|
package/src/oracle.ts
CHANGED
|
@@ -181,7 +181,7 @@ export async function postQueryToOracle(
|
|
|
181
181
|
senderId,
|
|
182
182
|
query,
|
|
183
183
|
});
|
|
184
|
-
const { nonce } = unpackTx(oracleQueryTx, Tag.OracleQueryTx)
|
|
184
|
+
const { nonce } = unpackTx(oracleQueryTx, Tag.OracleQueryTx);
|
|
185
185
|
const queryId = oracleQueryId(senderId, nonce, oracleId);
|
|
186
186
|
return {
|
|
187
187
|
...await send(oracleQueryTx, options),
|
package/src/spend.ts
CHANGED
|
@@ -110,7 +110,7 @@ export async function transferFunds(
|
|
|
110
110
|
await getBalance.bind(options.onAccount)(senderId, options),
|
|
111
111
|
);
|
|
112
112
|
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);
|
|
113
|
-
const {
|
|
113
|
+
const { fee } = unpackTx(
|
|
114
114
|
await _buildTx(Tag.SpendTx, {
|
|
115
115
|
...options, senderId, recipientId, amount: desiredAmount,
|
|
116
116
|
}),
|
|
@@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js';
|
|
|
2
2
|
import { mapObject } from '../../utils/other';
|
|
3
3
|
|
|
4
4
|
export const MAX_AUTH_FUN_GAS = 50000;
|
|
5
|
+
export type Int = number | string | BigNumber;
|
|
5
6
|
// # AENS
|
|
6
7
|
export type AensName = `${string}.chain`;
|
|
7
8
|
export const NAME_TTL = 180000;
|
|
@@ -57,6 +58,34 @@ export const NAME_BID_RANGES = mapObject({
|
|
|
57
58
|
1: 5702887,
|
|
58
59
|
}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)]);
|
|
59
60
|
|
|
61
|
+
export enum ConsensusProtocolVersion {
|
|
62
|
+
Iris = 5,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @category transaction builder
|
|
67
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
68
|
+
*/
|
|
69
|
+
export enum VmVersion {
|
|
70
|
+
NoVm = 0,
|
|
71
|
+
Sophia = 1,
|
|
72
|
+
SophiaImprovementsMinerva = 3,
|
|
73
|
+
SophiaImprovementsFortuna = 4,
|
|
74
|
+
Fate = 5,
|
|
75
|
+
SophiaImprovementsLima = 6,
|
|
76
|
+
Fate2 = 7,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @category transaction builder
|
|
81
|
+
* @see {@link https://github.com/aeternity/protocol/blob/0f6dee3d9d1e8e2469816798f5c7587a6c918f94/contracts/contract_vms.md#virtual-machines-on-the-%C3%A6ternity-blockchain}
|
|
82
|
+
*/
|
|
83
|
+
export enum AbiVersion {
|
|
84
|
+
NoAbi = 0,
|
|
85
|
+
Sophia = 1,
|
|
86
|
+
Fate = 3,
|
|
87
|
+
}
|
|
88
|
+
|
|
60
89
|
/**
|
|
61
90
|
* Enum with tag types
|
|
62
91
|
* @category transaction builder
|
|
@@ -68,13 +97,13 @@ export enum Tag {
|
|
|
68
97
|
Account = 10,
|
|
69
98
|
SignedTx = 11,
|
|
70
99
|
SpendTx = 12,
|
|
71
|
-
|
|
100
|
+
Oracle = 20,
|
|
72
101
|
// OracleQuery = 21,
|
|
73
102
|
OracleRegisterTx = 22,
|
|
74
103
|
OracleQueryTx = 23,
|
|
75
104
|
OracleResponseTx = 24,
|
|
76
105
|
OracleExtendTx = 25,
|
|
77
|
-
|
|
106
|
+
Name = 30,
|
|
78
107
|
// NameCommitment = 31,
|
|
79
108
|
NameClaimTx = 32,
|
|
80
109
|
NamePreclaimTx = 33,
|
|
@@ -116,7 +145,7 @@ export enum Tag {
|
|
|
116
145
|
NameserviceMtree = 624,
|
|
117
146
|
OraclesMtree = 625,
|
|
118
147
|
AccountsMtree = 626,
|
|
119
|
-
CompilerSophia = 70,
|
|
148
|
+
// CompilerSophia = 70,
|
|
120
149
|
GaAttachTx = 80,
|
|
121
150
|
GaMetaTx = 81,
|
|
122
151
|
PayingForTx = 82,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Tag, ConsensusProtocolVersion, AbiVersion } from '../constants';
|
|
2
|
+
import { getProtocolDetails } from './ct-version';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
serialize(
|
|
6
|
+
value: AbiVersion | undefined,
|
|
7
|
+
{ tag, consensusProtocolVersion = ConsensusProtocolVersion.Iris }:
|
|
8
|
+
{ tag: Tag; consensusProtocolVersion: ConsensusProtocolVersion },
|
|
9
|
+
): Buffer {
|
|
10
|
+
const result = value ?? getProtocolDetails(
|
|
11
|
+
consensusProtocolVersion,
|
|
12
|
+
Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call',
|
|
13
|
+
).abiVersion;
|
|
14
|
+
|
|
15
|
+
return Buffer.from([result]);
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
deserialize(buffer: Buffer): AbiVersion {
|
|
19
|
+
return buffer[0];
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PrefixNotFoundError, TagNotFoundError } from '../../../utils/errors';
|
|
1
|
+
import { ArgumentError, PrefixNotFoundError, TagNotFoundError } from '../../../utils/errors';
|
|
2
2
|
import { toBytes } from '../../../utils/bytes';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
decode, encode, Encoded, Encoding,
|
|
5
|
+
} from '../../../utils/encoder';
|
|
4
6
|
import { isItemOfArray } from '../../../utils/other';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -9,7 +11,7 @@ import { isItemOfArray } from '../../../utils/other';
|
|
|
9
11
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_id.erl#L97-L102}
|
|
10
12
|
* @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L163-L168}
|
|
11
13
|
*/
|
|
12
|
-
const idTagToEncoding = [
|
|
14
|
+
export const idTagToEncoding = [
|
|
13
15
|
Encoding.AccountAddress,
|
|
14
16
|
Encoding.Name,
|
|
15
17
|
Encoding.Commitment,
|
|
@@ -20,10 +22,12 @@ const idTagToEncoding = [
|
|
|
20
22
|
|
|
21
23
|
export type AddressEncodings = typeof idTagToEncoding[number];
|
|
22
24
|
|
|
23
|
-
export default function genAddressField<Encoding extends AddressEncodings>(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
export default function genAddressField<Encoding extends AddressEncodings>(
|
|
26
|
+
...encodings: Encoding[]
|
|
27
|
+
): {
|
|
28
|
+
serialize: (value: Encoded.Generic<Encoding>) => Buffer;
|
|
29
|
+
deserialize: (value: Buffer) => Encoded.Generic<Encoding>;
|
|
30
|
+
} {
|
|
27
31
|
return {
|
|
28
32
|
/**
|
|
29
33
|
* Utility function to create and _id type
|
|
@@ -31,9 +35,12 @@ export default function genAddressField<Encoding extends AddressEncodings>(): {
|
|
|
31
35
|
* @returns Buffer Buffer with ID tag and decoded HASh
|
|
32
36
|
*/
|
|
33
37
|
serialize(hashId) {
|
|
34
|
-
const
|
|
35
|
-
if (!isItemOfArray(
|
|
36
|
-
|
|
38
|
+
const enc = hashId.slice(0, 2);
|
|
39
|
+
if (!isItemOfArray(enc, idTagToEncoding)) throw new TagNotFoundError(enc);
|
|
40
|
+
if (!isItemOfArray(enc, encodings)) {
|
|
41
|
+
throw new ArgumentError('Address encoding', encodings.join(', '), enc);
|
|
42
|
+
}
|
|
43
|
+
const idTag = idTagToEncoding.indexOf(enc) + 1;
|
|
37
44
|
return Buffer.from([...toBytes(idTag), ...decode(hashId)]);
|
|
38
45
|
},
|
|
39
46
|
|
|
@@ -44,9 +51,12 @@ export default function genAddressField<Encoding extends AddressEncodings>(): {
|
|
|
44
51
|
*/
|
|
45
52
|
deserialize(buf) {
|
|
46
53
|
const idTag = Buffer.from(buf).readUIntBE(0, 1);
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
54
|
+
const enc = idTagToEncoding[idTag - 1];
|
|
55
|
+
if (enc == null) throw new PrefixNotFoundError(idTag);
|
|
56
|
+
if (!isItemOfArray(enc, encodings)) {
|
|
57
|
+
throw new ArgumentError('Address encoding', encodings.join(', '), enc);
|
|
58
|
+
}
|
|
59
|
+
return encode(buf.subarray(1), enc) as Encoded.Generic<Encoding>;
|
|
50
60
|
},
|
|
51
61
|
};
|
|
52
62
|
}
|