@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
package/src/chain.ts
CHANGED
|
@@ -353,7 +353,7 @@ export async function getMicroBlockHeader(
|
|
|
353
353
|
interface TxDryRunArguments {
|
|
354
354
|
tx: Encoded.Transaction;
|
|
355
355
|
accountAddress: Encoded.AccountAddress;
|
|
356
|
-
top?: number;
|
|
356
|
+
top?: number | Encoded.KeyBlockHash | Encoded.MicroBlockHash;
|
|
357
357
|
txEvents?: any;
|
|
358
358
|
resolve: Function;
|
|
359
359
|
reject: Function;
|
|
@@ -367,8 +367,10 @@ async function txDryRunHandler(key: string, onNode: Node): Promise<void> {
|
|
|
367
367
|
|
|
368
368
|
let dryRunRes;
|
|
369
369
|
try {
|
|
370
|
+
const top = typeof rs[0].top === 'number'
|
|
371
|
+
? (await getKeyBlock(rs[0].top, { onNode })).hash : rs[0].top;
|
|
370
372
|
dryRunRes = await onNode.protectedDryRunTxs({
|
|
371
|
-
top
|
|
373
|
+
top,
|
|
372
374
|
txEvents: rs[0].txEvents,
|
|
373
375
|
txs: rs.map((req) => ({ tx: req.tx })),
|
|
374
376
|
accounts: Array.from(new Set(rs.map((req) => req.accountAddress)))
|
|
@@ -406,7 +408,7 @@ export async function txDryRun(
|
|
|
406
408
|
{
|
|
407
409
|
top, txEvents, combine, onNode,
|
|
408
410
|
}:
|
|
409
|
-
{ top?:
|
|
411
|
+
{ top?: TxDryRunArguments['top']; txEvents?: boolean; combine?: boolean; onNode: Node },
|
|
410
412
|
): Promise<{
|
|
411
413
|
txEvents?: TransformNodeType<DryRunResults['txEvents']>;
|
|
412
414
|
} & TransformNodeType<DryRunResult>> {
|
package/src/channel/Base.ts
CHANGED
|
@@ -210,7 +210,12 @@ export default class Channel {
|
|
|
210
210
|
/**
|
|
211
211
|
* Get current state
|
|
212
212
|
*/
|
|
213
|
-
async state(): Promise<
|
|
213
|
+
async state(): Promise<{
|
|
214
|
+
calls: Encoded.CallStateTree;
|
|
215
|
+
halfSignedTx: Encoded.Transaction | '';
|
|
216
|
+
signedTx: Encoded.Transaction;
|
|
217
|
+
trees: Encoded.StateTrees;
|
|
218
|
+
}> {
|
|
214
219
|
return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
|
|
215
220
|
}
|
|
216
221
|
|
|
@@ -224,14 +229,14 @@ export default class Channel {
|
|
|
224
229
|
if (this._state == null) {
|
|
225
230
|
return null;
|
|
226
231
|
}
|
|
227
|
-
const {
|
|
228
|
-
switch (
|
|
232
|
+
const { tag, round } = unpackTx(this._state, Tag.SignedTx).encodedTx;
|
|
233
|
+
switch (tag) {
|
|
229
234
|
case Tag.ChannelCreateTx:
|
|
230
235
|
return 1;
|
|
231
236
|
case Tag.ChannelOffChainTx:
|
|
232
237
|
case Tag.ChannelWithdrawTx:
|
|
233
238
|
case Tag.ChannelDepositTx:
|
|
234
|
-
return
|
|
239
|
+
return round;
|
|
235
240
|
default:
|
|
236
241
|
return null;
|
|
237
242
|
}
|
|
@@ -321,7 +326,10 @@ export default class Channel {
|
|
|
321
326
|
|
|
322
327
|
return Channel.initialize({
|
|
323
328
|
...options,
|
|
324
|
-
reconnectTx: await sign(
|
|
329
|
+
reconnectTx: await sign(
|
|
330
|
+
'reconnect',
|
|
331
|
+
buildTx({ ...txParams, tag: Tag.ChannelClientReconnectTx }),
|
|
332
|
+
),
|
|
325
333
|
});
|
|
326
334
|
}
|
|
327
335
|
}
|
package/src/channel/Contract.ts
CHANGED
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import BigNumber from 'bignumber.js';
|
|
18
18
|
import { snakeToPascal } from '../utils/string';
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
MIN_GAS_PRICE, Tag, AbiVersion, VmVersion,
|
|
21
|
+
} from '../tx/builder/constants';
|
|
20
22
|
import {
|
|
21
23
|
signAndNotify,
|
|
22
24
|
awaitingCompletion,
|
|
@@ -46,7 +48,7 @@ function snakeToPascalObjKeys<Type>(obj: object): Type {
|
|
|
46
48
|
interface CallContractOptions {
|
|
47
49
|
amount?: number | BigNumber;
|
|
48
50
|
callData?: Encoded.ContractBytearray;
|
|
49
|
-
abiVersion?:
|
|
51
|
+
abiVersion?: AbiVersion;
|
|
50
52
|
contract?: Encoded.ContractAddress;
|
|
51
53
|
returnValue?: any;
|
|
52
54
|
gasUsed?: number | BigNumber;
|
|
@@ -58,13 +60,13 @@ interface CallContractOptions {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
interface Contract {
|
|
61
|
-
abiVersion:
|
|
63
|
+
abiVersion: AbiVersion;
|
|
62
64
|
active: boolean;
|
|
63
65
|
deposit: number | BigNumber;
|
|
64
66
|
id: string;
|
|
65
67
|
ownerId: string;
|
|
66
68
|
referrerIds: string[];
|
|
67
|
-
vmVersion:
|
|
69
|
+
vmVersion: VmVersion;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export default class ChannelContract extends ChannelSpend {
|
|
@@ -113,8 +115,8 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
113
115
|
code: Encoded.ContractBytearray;
|
|
114
116
|
callData: Encoded.ContractBytearray;
|
|
115
117
|
deposit: number | BigNumber;
|
|
116
|
-
vmVersion:
|
|
117
|
-
abiVersion:
|
|
118
|
+
vmVersion: VmVersion;
|
|
119
|
+
abiVersion: AbiVersion;
|
|
118
120
|
},
|
|
119
121
|
sign: SignTx,
|
|
120
122
|
): Promise<{
|
|
@@ -150,8 +152,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
150
152
|
state2: ChannelState,
|
|
151
153
|
): ChannelFsm => (
|
|
152
154
|
awaitingCompletion(this, message2, state2, () => {
|
|
153
|
-
const { round } = unpackTx(message2.params.data.state, Tag.SignedTx)
|
|
154
|
-
.tx.encodedTx.tx;
|
|
155
|
+
const { round } = unpackTx(message2.params.data.state, Tag.SignedTx).encodedTx;
|
|
155
156
|
const addressKey = this._options.role === 'initiator'
|
|
156
157
|
? 'initiatorId' : 'responderId';
|
|
157
158
|
const owner = this._options[addressKey];
|
|
@@ -294,7 +295,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
294
295
|
amount: number;
|
|
295
296
|
callData: Encoded.ContractBytearray;
|
|
296
297
|
contract: Encoded.ContractAddress;
|
|
297
|
-
abiVersion:
|
|
298
|
+
abiVersion: AbiVersion;
|
|
298
299
|
gasLimit?: number;
|
|
299
300
|
gasPrice?: number;
|
|
300
301
|
},
|
|
@@ -390,7 +391,7 @@ export default class ChannelContract extends ChannelSpend {
|
|
|
390
391
|
amount: number;
|
|
391
392
|
callData: Encoded.ContractBytearray;
|
|
392
393
|
contract: Encoded.ContractAddress;
|
|
393
|
-
abiVersion:
|
|
394
|
+
abiVersion: AbiVersion;
|
|
394
395
|
},
|
|
395
396
|
): Promise<CallContractOptions> {
|
|
396
397
|
return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
|
package/src/channel/Spend.ts
CHANGED
|
@@ -25,6 +25,8 @@ import { ChannelConnectionError } from '../utils/errors';
|
|
|
25
25
|
import {
|
|
26
26
|
awaitingCompletion, channelOpen, handleUnexpectedMessage, signAndNotify,
|
|
27
27
|
} from './handlers';
|
|
28
|
+
import { unpackTx } from '../tx/builder';
|
|
29
|
+
import { Tag } from '../tx/builder/constants';
|
|
28
30
|
|
|
29
31
|
export default class ChannelSpend extends Channel {
|
|
30
32
|
/**
|
|
@@ -133,8 +135,11 @@ export default class ChannelSpend extends Channel {
|
|
|
133
135
|
accounts: Encoded.AccountAddress[];
|
|
134
136
|
contracts?: Encoded.ContractAddress[];
|
|
135
137
|
},
|
|
136
|
-
): Promise<
|
|
137
|
-
return (
|
|
138
|
+
): Promise<ReturnType<typeof unpackTx<Tag.TreesPoi>>> {
|
|
139
|
+
return unpackTx(
|
|
140
|
+
(await call(this, 'channels.get.poi', { accounts, contracts })).poi,
|
|
141
|
+
Tag.TreesPoi,
|
|
142
|
+
);
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
/**
|
package/src/channel/handlers.ts
CHANGED
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
ChannelState,
|
|
22
22
|
changeStatus,
|
|
23
23
|
changeState,
|
|
24
|
-
call,
|
|
25
24
|
notify,
|
|
26
25
|
emit,
|
|
27
26
|
disconnect,
|
|
@@ -31,7 +30,7 @@ import {
|
|
|
31
30
|
ChannelStatus,
|
|
32
31
|
} from './internal';
|
|
33
32
|
import { unpackTx, buildTx } from '../tx/builder';
|
|
34
|
-
import {
|
|
33
|
+
import { decode, Encoded } from '../utils/encoder';
|
|
35
34
|
import {
|
|
36
35
|
IllegalArgumentError,
|
|
37
36
|
InsufficientBalanceError,
|
|
@@ -46,14 +45,16 @@ export async function appendSignature(
|
|
|
46
45
|
tx: Encoded.Transaction,
|
|
47
46
|
signFn: SignTx,
|
|
48
47
|
): Promise<Encoded.Transaction | number | null> {
|
|
49
|
-
const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx)
|
|
50
|
-
const
|
|
48
|
+
const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx);
|
|
49
|
+
const payloadTx = buildTx(encodedTx);
|
|
50
|
+
const result = await signFn(payloadTx);
|
|
51
51
|
if (typeof result === 'string') {
|
|
52
|
-
const {
|
|
52
|
+
const { signatures: signatures2 } = unpackTx(result, Tag.SignedTx);
|
|
53
53
|
return buildTx({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
tag: Tag.SignedTx,
|
|
55
|
+
signatures: signatures.concat(signatures2),
|
|
56
|
+
encodedTx: decode(payloadTx),
|
|
57
|
+
});
|
|
57
58
|
}
|
|
58
59
|
return result;
|
|
59
60
|
}
|
|
@@ -164,7 +165,7 @@ export async function awaitingReconnection(
|
|
|
164
165
|
if (message.method === 'channels.info') {
|
|
165
166
|
if (message.params.data.event === 'fsm_up') {
|
|
166
167
|
channel._fsmId = message.params.data.fsm_id;
|
|
167
|
-
changeState(channel, (await
|
|
168
|
+
changeState(channel, (await channel.state()).signedTx);
|
|
168
169
|
return { handler: channelOpen };
|
|
169
170
|
}
|
|
170
171
|
}
|
package/src/channel/internal.ts
CHANGED
|
@@ -317,7 +317,7 @@ export async function initialize(
|
|
|
317
317
|
changeStatus(channel, 'connected');
|
|
318
318
|
if (channelOptions.reconnectTx != null) {
|
|
319
319
|
enterState(channel, { handler: openHandler });
|
|
320
|
-
const signedTx =
|
|
320
|
+
const { signedTx } = await channel.state();
|
|
321
321
|
changeState(channel, signedTx);
|
|
322
322
|
}
|
|
323
323
|
ping(channel);
|
package/src/contract/Contract.ts
CHANGED
|
@@ -26,8 +26,8 @@ import { Encoder as Calldata } from '@aeternity/aepp-calldata';
|
|
|
26
26
|
import { DRY_RUN_ACCOUNT } from '../tx/builder/schema';
|
|
27
27
|
import { Tag, AensName } from '../tx/builder/constants';
|
|
28
28
|
import { buildContractIdByContractTx, unpackTx } from '../tx/builder';
|
|
29
|
-
import { _buildTx } from '../tx';
|
|
30
|
-
import { send } from '../spend';
|
|
29
|
+
import { _buildTx, BuildTxOptions } from '../tx';
|
|
30
|
+
import { send, SendOptions } from '../spend';
|
|
31
31
|
import { decode, Encoded } from '../utils/encoder';
|
|
32
32
|
import {
|
|
33
33
|
MissingContractDefError,
|
|
@@ -49,40 +49,19 @@ import {
|
|
|
49
49
|
NoWalletConnectedError,
|
|
50
50
|
} from '../utils/errors';
|
|
51
51
|
import { hash as calcHash } from '../utils/crypto';
|
|
52
|
-
import { Aci as BaseAci } from '../apis/compiler';
|
|
53
52
|
import {
|
|
54
53
|
ContractCallObject as NodeContractCallObject, ContractCallReturnType, Event as NodeEvent,
|
|
55
54
|
} from '../apis/node';
|
|
56
|
-
import
|
|
55
|
+
import CompilerBase, { Aci } from './compiler/Base';
|
|
57
56
|
import Node, { TransformNodeType } from '../Node';
|
|
58
57
|
import {
|
|
59
|
-
getAccount, getContract, getContractByteCode,
|
|
58
|
+
getAccount, getContract, getContractByteCode, resolveName, txDryRun,
|
|
60
59
|
} from '../chain';
|
|
61
60
|
import AccountBase from '../account/Base';
|
|
62
61
|
import { concatBuffers } from '../utils/other';
|
|
63
62
|
import { isNameValid, produceNameId } from '../tx/builder/helpers';
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
arguments: any[];
|
|
67
|
-
name: string;
|
|
68
|
-
payable: boolean;
|
|
69
|
-
returns: string;
|
|
70
|
-
stateful: boolean;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
interface Aci extends BaseAci {
|
|
74
|
-
encodedAci: {
|
|
75
|
-
contract: {
|
|
76
|
-
name: string;
|
|
77
|
-
event: any;
|
|
78
|
-
kind: string;
|
|
79
|
-
state: any;
|
|
80
|
-
type_defs: any[];
|
|
81
|
-
functions: FunctionACI[];
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
externalEncodedAci: any[];
|
|
85
|
-
}
|
|
64
|
+
type FunctionAci = Aci['encodedAci']['contract']['functions'][0];
|
|
86
65
|
|
|
87
66
|
interface Event extends NodeEvent {
|
|
88
67
|
address: Encoded.ContractAddress;
|
|
@@ -217,9 +196,10 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
217
196
|
async $compile(): Promise<Encoded.ContractBytearray> {
|
|
218
197
|
if (this.$options.bytecode != null) return this.$options.bytecode;
|
|
219
198
|
if (this.$options.sourceCode == null) throw new IllegalArgumentError('Can\'t compile without source code');
|
|
220
|
-
this.$options.
|
|
221
|
-
|
|
222
|
-
|
|
199
|
+
if (this.$options.onCompiler == null) throw new IllegalArgumentError('Can\'t compile without compiler');
|
|
200
|
+
this.$options.bytecode = (await this.$options.onCompiler
|
|
201
|
+
.compileBySourceCode(this.$options.sourceCode, this.$options.fileSystem)
|
|
202
|
+
).bytecode;
|
|
223
203
|
return this.$options.bytecode;
|
|
224
204
|
}
|
|
225
205
|
|
|
@@ -247,10 +227,9 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
247
227
|
|
|
248
228
|
protected async _sendAndProcess(
|
|
249
229
|
tx: Encoded.Transaction,
|
|
250
|
-
options:
|
|
230
|
+
options: SendOptions,
|
|
251
231
|
): Promise<SendAndProcessReturnType> {
|
|
252
|
-
|
|
253
|
-
const txData = await send(tx, options);
|
|
232
|
+
const txData = await send(tx, { ...this.$options, ...options });
|
|
254
233
|
const result = {
|
|
255
234
|
hash: txData.hash,
|
|
256
235
|
tx: unpackTx<Tag.ContractCallTx | Tag.ContractCreateTx>(txData.rawTx),
|
|
@@ -285,18 +264,22 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
285
264
|
*/
|
|
286
265
|
async $deploy(
|
|
287
266
|
params: MethodParameters<M, 'init'>,
|
|
288
|
-
options?: Parameters<Contract<M>['$call']>[2]
|
|
267
|
+
options?: Parameters<Contract<M>['$call']>[2]
|
|
268
|
+
& Partial<BuildTxOptions<Tag.ContractCreateTx, 'ownerId' | 'code' | 'callData'>>,
|
|
289
269
|
): Promise<Omit<SendAndProcessReturnType, 'hash'> & {
|
|
290
270
|
transaction?: Encoded.TxHash;
|
|
291
271
|
owner?: Encoded.AccountAddress;
|
|
292
272
|
address?: Encoded.ContractAddress;
|
|
273
|
+
decodedEvents?: ReturnType<Contract<M>['$decodeEvents']>;
|
|
293
274
|
}> {
|
|
294
|
-
const opt = { ...this.$options, ...options };
|
|
275
|
+
const { callStatic, ...opt } = { ...this.$options, ...options };
|
|
295
276
|
if (this.$options.bytecode == null) await this.$compile();
|
|
296
|
-
if (
|
|
277
|
+
if (callStatic === true) return this.$call('init', params, { ...opt, callStatic });
|
|
297
278
|
if (this.$options.address != null) throw new DuplicateContractError();
|
|
298
279
|
|
|
280
|
+
if (opt.onAccount == null) throw new IllegalArgumentError('Can\'t deploy without account');
|
|
299
281
|
const ownerId = opt.onAccount.address;
|
|
282
|
+
if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t deploy without bytecode');
|
|
300
283
|
const tx = await _buildTx(Tag.ContractCreateTx, {
|
|
301
284
|
...opt,
|
|
302
285
|
gasLimit: opt.gasLimit ?? await this._estimateGas('init', params, opt),
|
|
@@ -305,9 +288,12 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
305
288
|
ownerId,
|
|
306
289
|
});
|
|
307
290
|
this.$options.address = buildContractIdByContractTx(tx);
|
|
308
|
-
const { hash, ...other } = await this._sendAndProcess(tx, opt);
|
|
291
|
+
const { hash, ...other } = await this._sendAndProcess(tx, { ...opt, onAccount: opt.onAccount });
|
|
309
292
|
return {
|
|
310
293
|
...other,
|
|
294
|
+
...other.result?.log != null && {
|
|
295
|
+
decodedEvents: this.$decodeEvents(other.result.log, opt),
|
|
296
|
+
},
|
|
311
297
|
owner: ownerId,
|
|
312
298
|
transaction: hash,
|
|
313
299
|
address: this.$options.address,
|
|
@@ -319,7 +305,7 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
319
305
|
* @param name - Function name
|
|
320
306
|
* @returns function ACI
|
|
321
307
|
*/
|
|
322
|
-
protected _getFunctionACI(name: string): Partial<
|
|
308
|
+
protected _getFunctionACI(name: string): Partial<FunctionAci> {
|
|
323
309
|
const fn = this._aci.encodedAci.contract.functions.find(
|
|
324
310
|
(f: { name: string }) => f.name === name,
|
|
325
311
|
);
|
|
@@ -340,25 +326,32 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
340
326
|
async $call<Fn extends MethodNames<M>>(
|
|
341
327
|
fn: Fn,
|
|
342
328
|
params: MethodParameters<M, Fn>,
|
|
343
|
-
options:
|
|
329
|
+
options: Partial<BuildTxOptions<Tag.ContractCallTx, 'callerId' | 'contractId' | 'callData'>>
|
|
330
|
+
& Parameters<Contract<M>['$decodeEvents']>[1]
|
|
331
|
+
& Omit<Parameters<Contract<M>['_sendAndProcess']>[1], 'onAccount' | 'onNode'>
|
|
332
|
+
& Omit<Parameters<typeof txDryRun>[2], 'onNode'>
|
|
333
|
+
& { onAccount?: AccountBase; onNode?: Node; callStatic?: boolean } = {},
|
|
344
334
|
): Promise<{
|
|
345
335
|
decodedResult?: any;
|
|
346
336
|
decodedEvents?: ReturnType<Contract<M>['$decodeEvents']>;
|
|
347
337
|
} & SendAndProcessReturnType> {
|
|
348
|
-
const opt = { ...this.$options, ...options };
|
|
338
|
+
const { callStatic, top, ...opt } = { ...this.$options, ...options };
|
|
349
339
|
const fnACI = this._getFunctionACI(fn);
|
|
350
340
|
const contractId = this.$options.address;
|
|
351
341
|
const { onNode } = opt;
|
|
352
342
|
|
|
353
343
|
if (fn == null) throw new MissingFunctionNameError();
|
|
354
|
-
if (fn === 'init' &&
|
|
355
|
-
if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false)
|
|
344
|
+
if (fn === 'init' && callStatic !== true) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
|
|
345
|
+
if (fn !== 'init' && opt.amount != null && opt.amount > 0 && fnACI.payable === false) {
|
|
346
|
+
throw new NotPayableFunctionError(opt.amount, fn);
|
|
347
|
+
}
|
|
356
348
|
|
|
357
349
|
let callerId;
|
|
358
350
|
try {
|
|
351
|
+
if (opt.onAccount == null) throw new InternalError('Use fallback account');
|
|
359
352
|
callerId = opt.onAccount.address;
|
|
360
353
|
} catch (error) {
|
|
361
|
-
const useFallbackAccount =
|
|
354
|
+
const useFallbackAccount = callStatic === true && (
|
|
362
355
|
(error instanceof TypeError && error.message === 'Account should be an address (ak-prefixed string), or instance of AccountBase, got undefined instead')
|
|
363
356
|
|| (error instanceof NoWalletConnectedError)
|
|
364
357
|
);
|
|
@@ -368,14 +361,12 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
368
361
|
const callData = this._calldata.encode(this._name, fn, params);
|
|
369
362
|
|
|
370
363
|
let res: any;
|
|
371
|
-
if (
|
|
372
|
-
if (
|
|
373
|
-
|
|
364
|
+
if (callStatic === true) {
|
|
365
|
+
if (opt.nonce == null && top != null) {
|
|
366
|
+
const topKey = typeof top === 'number' ? 'height' : 'hash';
|
|
367
|
+
opt.nonce = (await getAccount(callerId, { [topKey]: top, onNode })).nonce + 1;
|
|
374
368
|
}
|
|
375
369
|
const txOpt = { ...opt, onNode, callData };
|
|
376
|
-
if (opt.nonce == null && opt.top != null) {
|
|
377
|
-
opt.nonce = (await getAccount(callerId, { hash: opt.top, onNode })).nonce + 1;
|
|
378
|
-
}
|
|
379
370
|
let tx;
|
|
380
371
|
if (fn === 'init') {
|
|
381
372
|
if (this.$options.bytecode == null) throw new IllegalArgumentError('Can\'t dry-run "init" without bytecode');
|
|
@@ -388,7 +379,7 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
388
379
|
tx = await _buildTx(Tag.ContractCallTx, { ...txOpt, callerId, contractId });
|
|
389
380
|
}
|
|
390
381
|
|
|
391
|
-
const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, opt);
|
|
382
|
+
const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, { ...opt, top });
|
|
392
383
|
if (callObj == null) throw new UnexpectedTsError();
|
|
393
384
|
this._handleCallError({
|
|
394
385
|
returnType: callObj.returnType as ContractCallReturnType,
|
|
@@ -396,6 +387,7 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
396
387
|
}, tx);
|
|
397
388
|
res = { ...dryRunOther, tx: unpackTx(tx), result: callObj };
|
|
398
389
|
} else {
|
|
390
|
+
if (top != null) throw new IllegalArgumentError('Can\'t handle `top` option in on-chain contract call');
|
|
399
391
|
if (contractId == null) throw new MissingContractAddressError('Can\'t call contract without address');
|
|
400
392
|
const tx = await _buildTx(Tag.ContractCallTx, {
|
|
401
393
|
...opt,
|
|
@@ -404,9 +396,10 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
404
396
|
contractId,
|
|
405
397
|
callData,
|
|
406
398
|
});
|
|
407
|
-
|
|
399
|
+
if (opt.onAccount == null) throw new IllegalArgumentError('Can\'t call contract on chain without account');
|
|
400
|
+
res = await this._sendAndProcess(tx, { ...opt, onAccount: opt.onAccount });
|
|
408
401
|
}
|
|
409
|
-
if (
|
|
402
|
+
if (callStatic === true || res.txData.blockHeight != null) {
|
|
410
403
|
res.decodedResult = fnACI.returns != null && fnACI.returns !== 'unit' && fn !== 'init'
|
|
411
404
|
&& this._calldata.decode(this._name, fn, res.result.returnValue);
|
|
412
405
|
res.decodedEvents = this.$decodeEvents(res.result.log, opt);
|
|
@@ -489,10 +482,11 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
489
482
|
{
|
|
490
483
|
onCompiler,
|
|
491
484
|
onNode,
|
|
492
|
-
sourceCode,
|
|
493
485
|
bytecode,
|
|
494
486
|
aci,
|
|
495
487
|
address,
|
|
488
|
+
sourceCodePath,
|
|
489
|
+
sourceCode,
|
|
496
490
|
fileSystem,
|
|
497
491
|
validateBytecode,
|
|
498
492
|
...otherOptions
|
|
@@ -502,9 +496,14 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
502
496
|
address?: Encoded.ContractAddress | AensName;
|
|
503
497
|
},
|
|
504
498
|
): Promise<ContractWithMethods<M>> {
|
|
505
|
-
if (aci == null &&
|
|
506
|
-
|
|
507
|
-
|
|
499
|
+
if (aci == null && onCompiler != null) {
|
|
500
|
+
let res;
|
|
501
|
+
if (sourceCodePath != null) res = await onCompiler.compile(sourceCodePath);
|
|
502
|
+
if (sourceCode != null) res = await onCompiler.compileBySourceCode(sourceCode, fileSystem);
|
|
503
|
+
if (res != null) {
|
|
504
|
+
aci = res.aci;
|
|
505
|
+
bytecode ??= res.bytecode;
|
|
506
|
+
}
|
|
508
507
|
}
|
|
509
508
|
if (aci == null) throw new MissingContractDefError();
|
|
510
509
|
|
|
@@ -525,14 +524,15 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
525
524
|
if (contract.active == null) throw new InactiveContractError(address);
|
|
526
525
|
}
|
|
527
526
|
|
|
528
|
-
if (validateBytecode
|
|
527
|
+
if (validateBytecode === true) {
|
|
529
528
|
if (address == null) throw new MissingContractAddressError('Can\'t validate bytecode without contract address');
|
|
530
529
|
const onChanBytecode = (await getContractByteCode(address, { onNode })).bytecode;
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
530
|
+
let isValid = false;
|
|
531
|
+
if (bytecode != null) isValid = bytecode === onChanBytecode;
|
|
532
|
+
else if (sourceCode != null) {
|
|
533
|
+
if (onCompiler == null) throw new IllegalArgumentError('Can\'t validate bytecode without compiler');
|
|
534
|
+
isValid = await onCompiler.validateBySourceCode(onChanBytecode, sourceCode, fileSystem);
|
|
535
|
+
}
|
|
536
536
|
if (!isValid) throw new BytecodeMismatchError(sourceCode != null ? 'source code' : 'bytecode');
|
|
537
537
|
}
|
|
538
538
|
|
|
@@ -547,32 +547,22 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
547
547
|
|
|
548
548
|
_calldata: Calldata;
|
|
549
549
|
|
|
550
|
-
$options:
|
|
551
|
-
sourceCode?: string;
|
|
552
|
-
bytecode?: Encoded.ContractBytearray;
|
|
553
|
-
address?: Encoded.ContractAddress;
|
|
554
|
-
onCompiler: CompilerHttp;
|
|
555
|
-
onNode: Node;
|
|
556
|
-
omitUnknown?: boolean;
|
|
557
|
-
contractAddressToName?: { [key: Encoded.ContractAddress]: string };
|
|
558
|
-
[key: string]: any;
|
|
559
|
-
};
|
|
550
|
+
$options: Omit<ConstructorParameters<typeof Contract>[0], 'aci'>;
|
|
560
551
|
|
|
561
552
|
constructor({ aci, ...otherOptions }: {
|
|
562
|
-
|
|
563
|
-
onCompiler: CompilerHttp;
|
|
553
|
+
onCompiler?: CompilerBase;
|
|
564
554
|
onNode: Node;
|
|
565
|
-
sourceCode?: string;
|
|
566
555
|
bytecode?: Encoded.ContractBytearray;
|
|
567
556
|
aci: Aci;
|
|
568
557
|
address?: Encoded.ContractAddress;
|
|
569
|
-
|
|
570
|
-
[
|
|
571
|
-
|
|
558
|
+
sourceCodePath?: Parameters<CompilerBase['compile']>[0];
|
|
559
|
+
sourceCode?: Parameters<CompilerBase['compileBySourceCode']>[0];
|
|
560
|
+
fileSystem?: Parameters<CompilerBase['compileBySourceCode']>[1];
|
|
561
|
+
} & Parameters<Contract<M>['$deploy']>[1]) {
|
|
572
562
|
this._aci = aci;
|
|
573
563
|
this._name = aci.encodedAci.contract.name;
|
|
574
564
|
this._calldata = new Calldata([aci.encodedAci, ...aci.externalEncodedAci]);
|
|
575
|
-
this.$options =
|
|
565
|
+
this.$options = otherOptions;
|
|
576
566
|
|
|
577
567
|
/**
|
|
578
568
|
* Generate proto function based on contract function using Contract ACI schema
|
|
@@ -591,7 +581,7 @@ class Contract<M extends ContractMethodsBase> {
|
|
|
591
581
|
Object.assign(
|
|
592
582
|
this,
|
|
593
583
|
Object.fromEntries(this._aci.encodedAci.contract.functions
|
|
594
|
-
.map(({ name, arguments: aciArgs, stateful }:
|
|
584
|
+
.map(({ name, arguments: aciArgs, stateful }: FunctionAci) => {
|
|
595
585
|
const callStatic = name !== 'init' && !stateful;
|
|
596
586
|
return [
|
|
597
587
|
name,
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Encoded } from '../../utils/encoder';
|
|
2
|
+
import { Aci as BaseAci } from '../../apis/compiler';
|
|
3
|
+
|
|
4
|
+
interface FunctionAci {
|
|
5
|
+
arguments: any[];
|
|
6
|
+
name: string;
|
|
7
|
+
payable: boolean;
|
|
8
|
+
returns: string;
|
|
9
|
+
stateful: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Aci extends BaseAci {
|
|
13
|
+
encodedAci: {
|
|
14
|
+
contract: {
|
|
15
|
+
name: string;
|
|
16
|
+
event: any;
|
|
17
|
+
kind: string;
|
|
18
|
+
state: any;
|
|
19
|
+
type_defs: any[];
|
|
20
|
+
functions: FunctionAci[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
externalEncodedAci: any[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A base class for all compiler implementations
|
|
28
|
+
*/
|
|
29
|
+
export default abstract class CompilerBase {
|
|
30
|
+
/**
|
|
31
|
+
* Compile contract by contract's path
|
|
32
|
+
* Available only in Node.js
|
|
33
|
+
* @param path - Path to contract source code
|
|
34
|
+
* @returns ACI and bytecode
|
|
35
|
+
*/
|
|
36
|
+
abstract compile(path: string): Promise<{
|
|
37
|
+
bytecode: Encoded.ContractBytearray;
|
|
38
|
+
aci: Aci;
|
|
39
|
+
}>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Compile contract by contract's source code
|
|
43
|
+
* @param sourceCode - Contract source code as string
|
|
44
|
+
* @param fileSystem - A map of contract filename to the corresponding contract source code to
|
|
45
|
+
* include into the main contract
|
|
46
|
+
* @example
|
|
47
|
+
* ```js
|
|
48
|
+
* {
|
|
49
|
+
* 'library.aes': 'namespace TestLib =\n function sum(x: int, y: int) : int = x + y'
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
* @returns ACI and bytecode
|
|
53
|
+
*/
|
|
54
|
+
abstract compileBySourceCode(
|
|
55
|
+
sourceCode: string,
|
|
56
|
+
fileSystem?: Record<string, string>,
|
|
57
|
+
): Promise<{
|
|
58
|
+
bytecode: Encoded.ContractBytearray;
|
|
59
|
+
aci: Aci;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Verify that a contract bytecode is the result of compiling the given source code
|
|
64
|
+
* Available only in Node.js
|
|
65
|
+
* @param bytecode - Contract bytecode to verify
|
|
66
|
+
* @param path - Path to contract source code
|
|
67
|
+
* @returns ACI and bytecode
|
|
68
|
+
*/
|
|
69
|
+
abstract validate(bytecode: Encoded.ContractBytearray, path: string): Promise<boolean>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Verify that a contract bytecode is the result of compiling the given source code
|
|
73
|
+
* @param bytecode - Contract bytecode to verify
|
|
74
|
+
* @param sourceCode - Contract source code as string
|
|
75
|
+
* @param fileSystem - A map of contract filename to the corresponding contract source code to
|
|
76
|
+
* include into the main contract
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* {
|
|
80
|
+
* 'library.aes': 'namespace TestLib =\n function sum(x: int, y: int) : int = x + y'
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
abstract validateBySourceCode(
|
|
85
|
+
bytecode: Encoded.ContractBytearray,
|
|
86
|
+
sourceCode: string,
|
|
87
|
+
fileSystem?: Record<string, string>,
|
|
88
|
+
): Promise<boolean>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @returns Compiler version
|
|
92
|
+
*/
|
|
93
|
+
abstract version(): Promise<string>;
|
|
94
|
+
}
|