@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/contract/aci.ts
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
// @ts-expect-error TODO remove
|
|
18
|
-
import { Encoder as Calldata } from '@aeternity/aepp-calldata'
|
|
19
|
-
import { DRY_RUN_ACCOUNT,
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
18
|
+
import { Encoder as Calldata } from '@aeternity/aepp-calldata';
|
|
19
|
+
import { DRY_RUN_ACCOUNT, AMOUNT } from '../tx/builder/schema';
|
|
20
|
+
import { Tag, AensName } from '../tx/builder/constants';
|
|
21
|
+
import { buildContractIdByContractTx, unpackTx } from '../tx/builder';
|
|
22
|
+
import { _buildTx } from '../tx';
|
|
23
|
+
import { send } from '../spend';
|
|
24
|
+
import { decode, Encoded } from '../utils/encoder';
|
|
24
25
|
import {
|
|
25
26
|
MissingContractDefError,
|
|
26
27
|
MissingContractAddressError,
|
|
@@ -36,114 +37,115 @@ import {
|
|
|
36
37
|
NoSuchContractFunctionError,
|
|
37
38
|
MissingEventDefinitionError,
|
|
38
39
|
AmbiguousEventDefinitionError,
|
|
39
|
-
UnexpectedTsError
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import {
|
|
43
|
-
import
|
|
44
|
-
import
|
|
40
|
+
UnexpectedTsError,
|
|
41
|
+
InternalError,
|
|
42
|
+
} from '../utils/errors';
|
|
43
|
+
import { hash as calcHash } from '../utils/crypto';
|
|
44
|
+
import { Aci as BaseAci } from '../apis/compiler';
|
|
45
|
+
import { ContractCallReturnType } from '../apis/node';
|
|
46
|
+
import Compiler from './Compiler';
|
|
47
|
+
import Node from '../Node';
|
|
45
48
|
import {
|
|
46
|
-
getAccount, getContract, getContractByteCode, getKeyBlock, resolveName, txDryRun
|
|
47
|
-
} from '../chain'
|
|
48
|
-
import AccountBase from '../account/Base'
|
|
49
|
+
getAccount, getContract, getContractByteCode, getKeyBlock, resolveName, txDryRun,
|
|
50
|
+
} from '../chain';
|
|
51
|
+
import AccountBase from '../account/Base';
|
|
49
52
|
|
|
50
53
|
interface FunctionACI {
|
|
51
|
-
arguments: any[]
|
|
52
|
-
name: string
|
|
53
|
-
payable: boolean
|
|
54
|
-
returns: string
|
|
55
|
-
stateful: boolean
|
|
54
|
+
arguments: any[];
|
|
55
|
+
name: string;
|
|
56
|
+
payable: boolean;
|
|
57
|
+
returns: string;
|
|
58
|
+
stateful: boolean;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
interface Aci extends BaseAci {
|
|
59
62
|
encodedAci: {
|
|
60
63
|
contract: {
|
|
61
|
-
name: string
|
|
62
|
-
event: any
|
|
63
|
-
kind: string
|
|
64
|
-
state: any
|
|
65
|
-
type_defs: any[]
|
|
66
|
-
functions: FunctionACI[]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
externalEncodedAci: any[]
|
|
64
|
+
name: string;
|
|
65
|
+
event: any;
|
|
66
|
+
kind: string;
|
|
67
|
+
state: any;
|
|
68
|
+
type_defs: any[];
|
|
69
|
+
functions: FunctionACI[];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
externalEncodedAci: any[];
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
interface Event {
|
|
73
|
-
address:
|
|
74
|
-
data: string
|
|
75
|
-
topics: Array<string | number
|
|
76
|
+
address: Encoded.ContractAddress;
|
|
77
|
+
data: string;
|
|
78
|
+
topics: Array<string | number>;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
interface DecodedEvent {
|
|
79
|
-
name: string
|
|
80
|
-
args: unknown
|
|
82
|
+
name: string;
|
|
83
|
+
args: unknown;
|
|
81
84
|
contract: {
|
|
82
|
-
name: string
|
|
83
|
-
address:
|
|
84
|
-
}
|
|
85
|
+
name: string;
|
|
86
|
+
address: Encoded.ContractAddress;
|
|
87
|
+
};
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
type TxData = Awaited<ReturnType<typeof send
|
|
90
|
+
type TxData = Awaited<ReturnType<typeof send>>;
|
|
88
91
|
|
|
89
92
|
export interface ContractInstance {
|
|
90
|
-
_aci: Aci
|
|
91
|
-
_name: string
|
|
92
|
-
calldata: any
|
|
93
|
-
source?: string
|
|
94
|
-
bytecode?:
|
|
93
|
+
_aci: Aci;
|
|
94
|
+
_name: string;
|
|
95
|
+
calldata: any;
|
|
96
|
+
source?: string;
|
|
97
|
+
bytecode?: Encoded.ContractBytearray;
|
|
95
98
|
deployInfo: {
|
|
96
|
-
address?:
|
|
99
|
+
address?: Encoded.ContractAddress;
|
|
97
100
|
result?: {
|
|
98
|
-
callerId: string
|
|
99
|
-
callerNonce: string
|
|
100
|
-
contractId: string
|
|
101
|
-
gasPrice: bigint
|
|
102
|
-
gasUsed: number
|
|
103
|
-
height: number
|
|
104
|
-
log: any[]
|
|
105
|
-
returnType:
|
|
106
|
-
returnValue: string
|
|
107
|
-
}
|
|
108
|
-
owner?:
|
|
109
|
-
transaction?: string
|
|
110
|
-
rawTx?: string
|
|
111
|
-
txData?: TxData
|
|
112
|
-
}
|
|
113
|
-
options: any
|
|
114
|
-
compile: (options?: {}) => Promise<
|
|
115
|
-
_estimateGas: (name: string, params: any[], options: object) => Promise<number
|
|
116
|
-
deploy: (params?: any[], options?: object) => Promise<any
|
|
101
|
+
callerId: string;
|
|
102
|
+
callerNonce: string;
|
|
103
|
+
contractId: string;
|
|
104
|
+
gasPrice: bigint;
|
|
105
|
+
gasUsed: number;
|
|
106
|
+
height: number;
|
|
107
|
+
log: any[];
|
|
108
|
+
returnType: ContractCallReturnType;
|
|
109
|
+
returnValue: string;
|
|
110
|
+
};
|
|
111
|
+
owner?: Encoded.AccountAddress;
|
|
112
|
+
transaction?: string;
|
|
113
|
+
rawTx?: string;
|
|
114
|
+
txData?: TxData;
|
|
115
|
+
};
|
|
116
|
+
options: any;
|
|
117
|
+
compile: (options?: {}) => Promise<Encoded.ContractBytearray>;
|
|
118
|
+
_estimateGas: (name: string, params: any[], options: object) => Promise<number>;
|
|
119
|
+
deploy: (params?: any[], options?: object) => Promise<any>;
|
|
117
120
|
call: (fn: string, params?: any[], options?: {}) => Promise<{
|
|
118
|
-
hash: string
|
|
119
|
-
tx: any
|
|
120
|
-
txData: TxData
|
|
121
|
-
rawTx: string
|
|
121
|
+
hash: string;
|
|
122
|
+
tx: any;
|
|
123
|
+
txData: TxData;
|
|
124
|
+
rawTx: string;
|
|
122
125
|
result: {
|
|
123
|
-
callerId:
|
|
124
|
-
callerNonce: number
|
|
125
|
-
contractId:
|
|
126
|
-
gasPrice: number
|
|
127
|
-
gasUsed: number
|
|
128
|
-
height: number
|
|
129
|
-
log: any[]
|
|
130
|
-
returnType:
|
|
131
|
-
returnValue: string
|
|
132
|
-
}
|
|
133
|
-
decodedResult: any
|
|
134
|
-
decodedEvents: DecodedEvent[]
|
|
135
|
-
}
|
|
126
|
+
callerId: Encoded.AccountAddress;
|
|
127
|
+
callerNonce: number;
|
|
128
|
+
contractId: Encoded.ContractAddress;
|
|
129
|
+
gasPrice: number;
|
|
130
|
+
gasUsed: number;
|
|
131
|
+
height: number;
|
|
132
|
+
log: any[];
|
|
133
|
+
returnType: ContractCallReturnType;
|
|
134
|
+
returnValue: string;
|
|
135
|
+
};
|
|
136
|
+
decodedResult: any;
|
|
137
|
+
decodedEvents: DecodedEvent[];
|
|
138
|
+
}>;
|
|
136
139
|
decodeEvents: (
|
|
137
|
-
events: Event[], options?: { omitUnknown?: boolean
|
|
138
|
-
) => DecodedEvent[]
|
|
139
|
-
methods: any
|
|
140
|
+
events: Event[], options?: { omitUnknown?: boolean; contractAddressToName?: any }
|
|
141
|
+
) => DecodedEvent[];
|
|
142
|
+
methods: any;
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
type ContractCallReturnType = 'ok' | 'error' | 'revert'
|
|
143
|
-
|
|
144
145
|
/**
|
|
145
146
|
* Generate contract ACI object with predefined js methods for contract usage - can be used for
|
|
146
147
|
* creating a reference to already deployed contracts
|
|
148
|
+
* @category contract
|
|
147
149
|
* @param options - Options object
|
|
148
150
|
* @returns JS Contract API
|
|
149
151
|
* @example
|
|
@@ -159,7 +161,7 @@ type ContractCallReturnType = 'ok' | 'error' | 'revert'
|
|
|
159
161
|
* Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
|
|
160
162
|
* stateful or not
|
|
161
163
|
*/
|
|
162
|
-
export default async function getContractInstance
|
|
164
|
+
export default async function getContractInstance({
|
|
163
165
|
onAccount,
|
|
164
166
|
onCompiler,
|
|
165
167
|
onNode,
|
|
@@ -171,36 +173,38 @@ export default async function getContractInstance ({
|
|
|
171
173
|
validateBytecode,
|
|
172
174
|
...otherOptions
|
|
173
175
|
}: {
|
|
174
|
-
onAccount
|
|
175
|
-
onCompiler: Compiler
|
|
176
|
-
onNode: Node
|
|
177
|
-
source?: string
|
|
178
|
-
bytecode?:
|
|
179
|
-
aci?: Aci
|
|
180
|
-
contractAddress?:
|
|
181
|
-
fileSystem?: Record<string, string
|
|
182
|
-
validateBytecode?: boolean
|
|
183
|
-
[key: string]: any
|
|
176
|
+
onAccount?: AccountBase;
|
|
177
|
+
onCompiler: Compiler;
|
|
178
|
+
onNode: Node;
|
|
179
|
+
source?: string;
|
|
180
|
+
bytecode?: Encoded.ContractBytearray;
|
|
181
|
+
aci?: Aci;
|
|
182
|
+
contractAddress?: Encoded.ContractAddress | AensName;
|
|
183
|
+
fileSystem?: Record<string, string>;
|
|
184
|
+
validateBytecode?: boolean;
|
|
185
|
+
[key: string]: any;
|
|
184
186
|
}): Promise<ContractInstance> {
|
|
185
187
|
if (_aci == null && source != null) {
|
|
186
188
|
// TODO: should be fixed when the compiledAci interface gets updated
|
|
187
|
-
_aci = await onCompiler.generateACI({ code: source, options: { fileSystem } }) as Aci
|
|
189
|
+
_aci = await onCompiler.generateACI({ code: source, options: { fileSystem } }) as Aci;
|
|
188
190
|
}
|
|
189
|
-
if (_aci == null) throw new MissingContractDefError()
|
|
191
|
+
if (_aci == null) throw new MissingContractDefError();
|
|
190
192
|
|
|
191
193
|
if (contractAddress != null) {
|
|
192
194
|
contractAddress = await resolveName(
|
|
193
|
-
contractAddress,
|
|
194
|
-
|
|
195
|
+
contractAddress,
|
|
196
|
+
'contract_pubkey',
|
|
197
|
+
{ resolveByNode: true, onNode },
|
|
198
|
+
) as Encoded.ContractAddress;
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
if (contractAddress == null && source == null && bytecode == null) {
|
|
198
|
-
throw new MissingContractAddressError('Can\'t create instance by ACI without address')
|
|
202
|
+
throw new MissingContractAddressError('Can\'t create instance by ACI without address');
|
|
199
203
|
}
|
|
200
204
|
|
|
201
205
|
if (contractAddress != null) {
|
|
202
|
-
const contract = await getContract(contractAddress, { onNode })
|
|
203
|
-
if (contract.active == null) throw new InactiveContractError(contractAddress)
|
|
206
|
+
const contract = await getContract(contractAddress, { onNode });
|
|
207
|
+
if (contract.active == null) throw new InactiveContractError(contractAddress);
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
const instance: ContractInstance = {
|
|
@@ -217,90 +221,95 @@ export default async function getContractInstance ({
|
|
|
217
221
|
amount: AMOUNT,
|
|
218
222
|
callStatic: false,
|
|
219
223
|
fileSystem,
|
|
220
|
-
...otherOptions
|
|
224
|
+
...otherOptions,
|
|
221
225
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
): Promise<any> {},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
decodeEvents
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
227
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
228
|
+
async compile(_options?: {}): Promise<any> {},
|
|
229
|
+
async _estimateGas(_name: string, _params: any[], _options: object): Promise<any> {},
|
|
230
|
+
async deploy(_params?: any[], _options?: any): Promise<any> {},
|
|
231
|
+
async call(_fn: string, _params?: any[], _options?: {}): Promise<any> {},
|
|
232
|
+
decodeEvents(_events: Event[], options?: { omitUnknown?: boolean }): any {},
|
|
233
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
234
|
+
/* eslint-enable @typescript-eslint/no-empty-function */
|
|
235
|
+
methods: undefined,
|
|
236
|
+
};
|
|
231
237
|
|
|
232
238
|
if (validateBytecode != null) {
|
|
233
|
-
if (contractAddress == null) throw new MissingContractAddressError('Can\'t validate bytecode without contract address')
|
|
234
|
-
const onChanBytecode = (await getContractByteCode(contractAddress, { onNode })).bytecode
|
|
239
|
+
if (contractAddress == null) throw new MissingContractAddressError('Can\'t validate bytecode without contract address');
|
|
240
|
+
const onChanBytecode = (await getContractByteCode(contractAddress, { onNode })).bytecode;
|
|
235
241
|
const isValid: boolean = source != null
|
|
236
242
|
? await onCompiler.validateByteCode(
|
|
237
|
-
{ bytecode: onChanBytecode, source, options: instance.options }
|
|
243
|
+
{ bytecode: onChanBytecode, source, options: instance.options },
|
|
238
244
|
).then(() => true, () => false)
|
|
239
|
-
: bytecode === onChanBytecode
|
|
240
|
-
if (!isValid) throw new BytecodeMismatchError(source != null ? 'source' : 'bytecode')
|
|
245
|
+
: bytecode === onChanBytecode;
|
|
246
|
+
if (!isValid) throw new BytecodeMismatchError(source != null ? 'source' : 'bytecode');
|
|
241
247
|
}
|
|
242
248
|
|
|
243
249
|
/**
|
|
244
250
|
* Compile contract
|
|
245
251
|
* @returns bytecode
|
|
246
252
|
*/
|
|
247
|
-
instance.compile = async (options = {}): Promise<
|
|
248
|
-
if (instance.bytecode != null) throw new IllegalArgumentError('Contract already compiled')
|
|
249
|
-
if (instance.source == null) throw new IllegalArgumentError('Can\'t compile without source code')
|
|
253
|
+
instance.compile = async (options = {}): Promise<Encoded.ContractBytearray> => {
|
|
254
|
+
if (instance.bytecode != null) throw new IllegalArgumentError('Contract already compiled');
|
|
255
|
+
if (instance.source == null) throw new IllegalArgumentError('Can\'t compile without source code');
|
|
250
256
|
instance.bytecode = (await onCompiler.compileContract({
|
|
251
|
-
code: instance.source, options: { ...instance.options, ...options }
|
|
252
|
-
})).bytecode as
|
|
253
|
-
return instance.bytecode
|
|
254
|
-
}
|
|
257
|
+
code: instance.source, options: { ...instance.options, ...options },
|
|
258
|
+
})).bytecode as Encoded.ContractBytearray;
|
|
259
|
+
return instance.bytecode;
|
|
260
|
+
};
|
|
255
261
|
|
|
256
|
-
const sendAndProcess = async (tx: EncodedData<'tx'>, options: any): Promise<{
|
|
257
|
-
result?: ContractInstance['deployInfo']['result']
|
|
258
|
-
hash: TxData['hash']
|
|
259
|
-
tx: Awaited<ReturnType<typeof unpackTx<TX_TYPE.contractCall | TX_TYPE.contractCreate>>>
|
|
260
|
-
txData: TxData
|
|
261
|
-
rawTx: EncodedData<'tx'>
|
|
262
|
-
}> => {
|
|
263
|
-
options = { ...instance.options, ...options }
|
|
264
|
-
const txData = await send(tx, options)
|
|
265
|
-
const result = {
|
|
266
|
-
hash: txData.hash,
|
|
267
|
-
tx: unpackTx<TX_TYPE.contractCall | TX_TYPE.contractCreate>(txData.rawTx),
|
|
268
|
-
txData,
|
|
269
|
-
rawTx: txData.rawTx
|
|
270
|
-
}
|
|
271
|
-
if (txData.blockHeight == null) return result
|
|
272
|
-
const { callInfo } = await onNode.getTransactionInfoByHash(txData.hash)
|
|
273
|
-
Object.assign(result.txData, callInfo) // TODO: don't duplicate data in result
|
|
274
|
-
// @ts-expect-error TODO api should be updated to match types
|
|
275
|
-
handleCallError(callInfo, tx)
|
|
276
|
-
return { ...result, result: callInfo }
|
|
277
|
-
}
|
|
278
262
|
const handleCallError = (
|
|
279
263
|
{ returnType, returnValue }: {
|
|
280
|
-
returnType: ContractCallReturnType
|
|
281
|
-
returnValue:
|
|
264
|
+
returnType: ContractCallReturnType;
|
|
265
|
+
returnValue: Encoded.ContractBytearray;
|
|
282
266
|
},
|
|
283
|
-
transaction: string
|
|
284
|
-
|
|
267
|
+
transaction: string,
|
|
268
|
+
): void => {
|
|
269
|
+
let message: string;
|
|
285
270
|
switch (returnType) {
|
|
286
|
-
case 'ok': return
|
|
271
|
+
case 'ok': return;
|
|
287
272
|
case 'revert':
|
|
288
|
-
message = instance.calldata.decodeFateString(returnValue)
|
|
289
|
-
break
|
|
273
|
+
message = instance.calldata.decodeFateString(returnValue);
|
|
274
|
+
break;
|
|
290
275
|
case 'error':
|
|
291
|
-
message = decode(returnValue).toString()
|
|
292
|
-
break
|
|
276
|
+
message = decode(returnValue).toString();
|
|
277
|
+
break;
|
|
278
|
+
default:
|
|
279
|
+
throw new InternalError(`Unknown return type: ${returnType}`);
|
|
293
280
|
}
|
|
294
|
-
throw new NodeInvocationError(message, transaction)
|
|
295
|
-
}
|
|
281
|
+
throw new NodeInvocationError(message, transaction);
|
|
282
|
+
};
|
|
296
283
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
284
|
+
const sendAndProcess = async (tx: Encoded.Transaction, options: any): Promise<{
|
|
285
|
+
result?: ContractInstance['deployInfo']['result'];
|
|
286
|
+
hash: TxData['hash'];
|
|
287
|
+
tx: Awaited<ReturnType<typeof unpackTx<Tag.ContractCallTx | Tag.ContractCreateTx>>>;
|
|
288
|
+
txData: TxData;
|
|
289
|
+
rawTx: Encoded.Transaction;
|
|
290
|
+
}> => {
|
|
291
|
+
options = { ...instance.options, ...options };
|
|
292
|
+
const txData = await send(tx, options);
|
|
293
|
+
const result = {
|
|
294
|
+
hash: txData.hash,
|
|
295
|
+
tx: unpackTx<Tag.ContractCallTx | Tag.ContractCreateTx>(txData.rawTx),
|
|
296
|
+
txData,
|
|
297
|
+
rawTx: txData.rawTx,
|
|
298
|
+
};
|
|
299
|
+
if (txData.blockHeight == null) return result;
|
|
300
|
+
const { callInfo } = await onNode.getTransactionInfoByHash(txData.hash);
|
|
301
|
+
Object.assign(result.txData, callInfo); // TODO: don't duplicate data in result
|
|
302
|
+
// @ts-expect-error TODO api should be updated to match types
|
|
303
|
+
handleCallError(callInfo, tx);
|
|
304
|
+
return { ...result, result: callInfo };
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
instance._estimateGas = async (name: string, params: any[], options: object): Promise<number> => {
|
|
308
|
+
const { result: { gasUsed } } = await instance
|
|
309
|
+
.call(name, params, { ...options, callStatic: true });
|
|
301
310
|
// taken from https://github.com/aeternity/aepp-sdk-js/issues/1286#issuecomment-977814771
|
|
302
|
-
return Math.floor(gasUsed * 1.25)
|
|
303
|
-
}
|
|
311
|
+
return Math.floor(gasUsed * 1.25);
|
|
312
|
+
};
|
|
304
313
|
|
|
305
314
|
/**
|
|
306
315
|
* Deploy contract
|
|
@@ -308,54 +317,58 @@ export default async function getContractInstance ({
|
|
|
308
317
|
* @param options - Options
|
|
309
318
|
* @returns deploy info
|
|
310
319
|
*/
|
|
311
|
-
instance.deploy = async (
|
|
312
|
-
|
|
320
|
+
instance.deploy = async (
|
|
321
|
+
params = [],
|
|
322
|
+
options?:
|
|
313
323
|
Parameters<typeof instance.compile>[0] &
|
|
314
324
|
Parameters<typeof instance.call>[2] &
|
|
315
325
|
Parameters<AccountBase['address']>[0] &
|
|
316
|
-
Parameters<typeof sendAndProcess>[1]
|
|
326
|
+
Parameters<typeof sendAndProcess>[1],
|
|
317
327
|
): Promise<ContractInstance['deployInfo']> => {
|
|
318
|
-
const opt = { ...instance.options, ...options }
|
|
319
|
-
if (instance.bytecode == null) await instance.compile(opt)
|
|
320
|
-
// @ts-expect-error
|
|
321
|
-
if (opt.callStatic === true) return
|
|
322
|
-
if (instance.deployInfo.address != null) throw new DuplicateContractError()
|
|
328
|
+
const opt = { ...instance.options, ...options };
|
|
329
|
+
if (instance.bytecode == null) await instance.compile(opt);
|
|
330
|
+
// @ts-expect-error TODO: need to fix compatibility between return types of `deploy` and `call`
|
|
331
|
+
if (opt.callStatic === true) return instance.call('init', params, opt);
|
|
332
|
+
if (instance.deployInfo.address != null) throw new DuplicateContractError();
|
|
323
333
|
|
|
324
|
-
const ownerId = await opt.onAccount.address(options)
|
|
325
|
-
const tx = await _buildTx(
|
|
334
|
+
const ownerId = await opt.onAccount.address(options);
|
|
335
|
+
const tx = await _buildTx(Tag.ContractCreateTx, {
|
|
326
336
|
...opt,
|
|
327
337
|
gasLimit: opt.gasLimit ?? await instance._estimateGas('init', params, opt),
|
|
328
338
|
callData: instance.calldata.encode(instance._name, 'init', params),
|
|
329
339
|
code: instance.bytecode,
|
|
330
340
|
ownerId,
|
|
331
|
-
onNode
|
|
332
|
-
})
|
|
333
|
-
const contractId = buildContractIdByContractTx(tx)
|
|
334
|
-
const {
|
|
341
|
+
onNode,
|
|
342
|
+
});
|
|
343
|
+
const contractId = buildContractIdByContractTx(tx);
|
|
344
|
+
const {
|
|
345
|
+
hash, rawTx, result, txData,
|
|
346
|
+
} = await sendAndProcess(tx, opt);
|
|
335
347
|
instance.deployInfo = Object.freeze({
|
|
336
348
|
result,
|
|
337
349
|
owner: ownerId,
|
|
338
350
|
transaction: hash,
|
|
339
351
|
rawTx,
|
|
340
352
|
txData,
|
|
341
|
-
address: contractId
|
|
342
|
-
})
|
|
343
|
-
return instance.deployInfo
|
|
344
|
-
}
|
|
353
|
+
address: contractId,
|
|
354
|
+
});
|
|
355
|
+
return instance.deployInfo;
|
|
356
|
+
};
|
|
345
357
|
|
|
346
358
|
/**
|
|
347
359
|
* Get function schema from contract ACI object
|
|
348
360
|
* @param name - Function name
|
|
349
361
|
* @returns function ACI
|
|
350
362
|
*/
|
|
351
|
-
function getFunctionACI
|
|
363
|
+
function getFunctionACI(name: string): Partial<FunctionACI> {
|
|
352
364
|
const fn = instance._aci.encodedAci.contract.functions.find(
|
|
353
|
-
(f: { name: string }) => f.name === name
|
|
365
|
+
(f: { name: string }) => f.name === name,
|
|
366
|
+
);
|
|
354
367
|
if (fn != null) {
|
|
355
|
-
return fn
|
|
368
|
+
return fn;
|
|
356
369
|
}
|
|
357
|
-
if (name === 'init') return { payable: false }
|
|
358
|
-
throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`)
|
|
370
|
+
if (name === 'init') return { payable: false };
|
|
371
|
+
throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`);
|
|
359
372
|
}
|
|
360
373
|
|
|
361
374
|
/**
|
|
@@ -366,66 +379,61 @@ export default async function getContractInstance ({
|
|
|
366
379
|
* @returns CallResult
|
|
367
380
|
*/
|
|
368
381
|
instance.call = async (fn: string, params: any[] = [], options: object = {}) => {
|
|
369
|
-
const opt = { ...instance.options, ...options }
|
|
370
|
-
const fnACI = getFunctionACI(fn)
|
|
371
|
-
const contractId = instance.deployInfo.address
|
|
382
|
+
const opt = { ...instance.options, ...options };
|
|
383
|
+
const fnACI = getFunctionACI(fn);
|
|
384
|
+
const contractId = instance.deployInfo.address;
|
|
372
385
|
|
|
373
|
-
if (fn == null) throw new MissingFunctionNameError()
|
|
374
|
-
if (fn === 'init' && opt.callStatic === false) throw new InvalidMethodInvocationError('"init" can be called only via dryRun')
|
|
375
|
-
if (contractId == null && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!')
|
|
376
|
-
if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(opt.amount, fn)
|
|
386
|
+
if (fn == null) throw new MissingFunctionNameError();
|
|
387
|
+
if (fn === 'init' && opt.callStatic === false) throw new InvalidMethodInvocationError('"init" can be called only via dryRun');
|
|
388
|
+
if (contractId == null && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!');
|
|
389
|
+
if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(opt.amount, fn);
|
|
377
390
|
|
|
378
391
|
const callerId = await Promise.resolve()
|
|
379
392
|
.then(() => opt.onAccount.address(opt))
|
|
380
393
|
.catch((error: any) => {
|
|
381
|
-
if (opt.callStatic === true) return DRY_RUN_ACCOUNT.pub
|
|
382
|
-
|
|
383
|
-
}) as
|
|
384
|
-
const callData = instance.calldata.encode(instance._name, fn, params)
|
|
394
|
+
if (opt.callStatic === true) return DRY_RUN_ACCOUNT.pub;
|
|
395
|
+
throw error;
|
|
396
|
+
}) as Encoded.AccountAddress;
|
|
397
|
+
const callData = instance.calldata.encode(instance._name, fn, params);
|
|
385
398
|
|
|
386
|
-
let res: any
|
|
399
|
+
let res: any;
|
|
387
400
|
if (opt.callStatic === true) {
|
|
388
401
|
if (typeof opt.top === 'number') {
|
|
389
|
-
opt.top = (await getKeyBlock(opt.top, { onNode })).hash
|
|
390
|
-
}
|
|
391
|
-
const txOpt = {
|
|
392
|
-
...opt,
|
|
393
|
-
onNode,
|
|
394
|
-
gasLimit: opt.gasLimit ?? GAS_MAX,
|
|
395
|
-
callData
|
|
402
|
+
opt.top = (await getKeyBlock(opt.top, { onNode })).hash;
|
|
396
403
|
}
|
|
404
|
+
const txOpt = { ...opt, onNode, callData };
|
|
397
405
|
if (opt.nonce == null && opt.top != null) {
|
|
398
|
-
opt.nonce = (await getAccount(callerId, { hash: opt.top, onNode })).nonce + 1
|
|
406
|
+
opt.nonce = (await getAccount(callerId, { hash: opt.top, onNode })).nonce + 1;
|
|
399
407
|
}
|
|
400
408
|
const tx = await (fn === 'init'
|
|
401
|
-
? _buildTx(
|
|
402
|
-
: _buildTx(
|
|
409
|
+
? _buildTx(Tag.ContractCreateTx, { ...txOpt, code: instance.bytecode, ownerId: callerId })
|
|
410
|
+
: _buildTx(Tag.ContractCallTx, { ...txOpt, callerId, contractId }));
|
|
403
411
|
|
|
404
|
-
const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, { onNode, ...opt })
|
|
405
|
-
if (callObj == null) throw new UnexpectedTsError()
|
|
412
|
+
const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, { onNode, ...opt });
|
|
413
|
+
if (callObj == null) throw new UnexpectedTsError();
|
|
406
414
|
handleCallError({
|
|
407
415
|
returnType: callObj.returnType as ContractCallReturnType,
|
|
408
|
-
returnValue: callObj.returnValue as
|
|
409
|
-
}, tx)
|
|
410
|
-
res = { ...dryRunOther, tx: unpackTx(tx), result: callObj }
|
|
416
|
+
returnValue: callObj.returnValue as Encoded.ContractBytearray,
|
|
417
|
+
}, tx);
|
|
418
|
+
res = { ...dryRunOther, tx: unpackTx(tx), result: callObj };
|
|
411
419
|
} else {
|
|
412
|
-
const tx = await _buildTx(
|
|
420
|
+
const tx = await _buildTx(Tag.ContractCallTx, {
|
|
413
421
|
...opt,
|
|
414
422
|
onNode,
|
|
415
423
|
gasLimit: opt.gasLimit ?? await instance._estimateGas(fn, params, opt),
|
|
416
424
|
callerId,
|
|
417
425
|
contractId,
|
|
418
|
-
callData
|
|
419
|
-
})
|
|
420
|
-
res = await sendAndProcess(tx, opt)
|
|
426
|
+
callData,
|
|
427
|
+
});
|
|
428
|
+
res = await sendAndProcess(tx, opt);
|
|
421
429
|
}
|
|
422
430
|
if (opt.callStatic === true || res.txData.blockHeight != null) {
|
|
423
|
-
res.decodedResult = fnACI.returns != null && fnACI.returns !== 'unit' && fn !== 'init'
|
|
424
|
-
instance.calldata.decode(instance._name, fn, res.result.returnValue)
|
|
425
|
-
res.decodedEvents = instance.decodeEvents(res.result.log, opt)
|
|
431
|
+
res.decodedResult = fnACI.returns != null && fnACI.returns !== 'unit' && fn !== 'init'
|
|
432
|
+
&& instance.calldata.decode(instance._name, fn, res.result.returnValue);
|
|
433
|
+
res.decodedEvents = instance.decodeEvents(res.result.log, opt);
|
|
426
434
|
}
|
|
427
|
-
return res
|
|
428
|
-
}
|
|
435
|
+
return res;
|
|
436
|
+
};
|
|
429
437
|
|
|
430
438
|
/**
|
|
431
439
|
* @param address - Contract address that emitted event
|
|
@@ -435,27 +443,29 @@ export default async function getContractInstance ({
|
|
|
435
443
|
* @throws {@link MissingEventDefinitionError}
|
|
436
444
|
* @throws {@link AmbiguousEventDefinitionError}
|
|
437
445
|
*/
|
|
438
|
-
function getContractNameByEvent
|
|
439
|
-
address:
|
|
446
|
+
function getContractNameByEvent(
|
|
447
|
+
address: Encoded.ContractAddress,
|
|
440
448
|
nameHash: BigInt,
|
|
441
|
-
{ contractAddressToName }: {
|
|
449
|
+
{ contractAddressToName }: {
|
|
450
|
+
contractAddressToName?: { [key: Encoded.ContractAddress]: string };
|
|
451
|
+
},
|
|
442
452
|
): string {
|
|
443
|
-
const addressToName = { ...instance.options.contractAddressToName, ...contractAddressToName }
|
|
444
|
-
if (addressToName[address] != null) return addressToName[address]
|
|
453
|
+
const addressToName = { ...instance.options.contractAddressToName, ...contractAddressToName };
|
|
454
|
+
if (addressToName[address] != null) return addressToName[address];
|
|
445
455
|
|
|
446
456
|
const matchedEvents = [
|
|
447
457
|
instance._aci.encodedAci,
|
|
448
|
-
...instance._aci.externalEncodedAci
|
|
458
|
+
...instance._aci.externalEncodedAci,
|
|
449
459
|
]
|
|
450
460
|
.filter(({ contract }) => contract?.event)
|
|
451
461
|
.map(({ contract }) => [contract.name, contract.event.variant])
|
|
452
462
|
.map(([name, events]) => events.map((event: {}) => [name, Object.keys(event)[0]]))
|
|
453
463
|
.flat()
|
|
454
|
-
.filter(([, eventName]) => BigInt(
|
|
464
|
+
.filter(([, eventName]) => BigInt(`0x${calcHash(eventName).toString('hex')}`) === nameHash);
|
|
455
465
|
switch (matchedEvents.length) {
|
|
456
|
-
case 0: throw new MissingEventDefinitionError(nameHash.toString(), address)
|
|
457
|
-
case 1: return matchedEvents[0][0]
|
|
458
|
-
default: throw new AmbiguousEventDefinitionError(address, matchedEvents)
|
|
466
|
+
case 0: throw new MissingEventDefinitionError(nameHash.toString(), address);
|
|
467
|
+
case 1: return matchedEvents[0][0];
|
|
468
|
+
default: throw new AmbiguousEventDefinitionError(address, matchedEvents);
|
|
459
469
|
}
|
|
460
470
|
}
|
|
461
471
|
|
|
@@ -467,28 +477,28 @@ export default async function getContractInstance ({
|
|
|
467
477
|
*/
|
|
468
478
|
instance.decodeEvents = (
|
|
469
479
|
events: Event[],
|
|
470
|
-
{ omitUnknown, ...opt }: { omitUnknown?: boolean } = {}
|
|
480
|
+
{ omitUnknown, ...opt }: { omitUnknown?: boolean } = {},
|
|
471
481
|
): DecodedEvent[] => events
|
|
472
|
-
.map(event => {
|
|
473
|
-
const topics = event.topics.map((t: string | number) => BigInt(t))
|
|
474
|
-
let contractName
|
|
482
|
+
.map((event) => {
|
|
483
|
+
const topics = event.topics.map((t: string | number) => BigInt(t));
|
|
484
|
+
let contractName;
|
|
475
485
|
try {
|
|
476
|
-
contractName = getContractNameByEvent(event.address, topics[0], opt)
|
|
486
|
+
contractName = getContractNameByEvent(event.address, topics[0], opt);
|
|
477
487
|
} catch (error) {
|
|
478
|
-
if ((omitUnknown ?? false) && error instanceof MissingEventDefinitionError) return null
|
|
479
|
-
throw error
|
|
488
|
+
if ((omitUnknown ?? false) && error instanceof MissingEventDefinitionError) return null;
|
|
489
|
+
throw error;
|
|
480
490
|
}
|
|
481
|
-
const decoded = instance.calldata.decodeEvent(contractName, event.data, topics)
|
|
482
|
-
const [name, args] = Object.entries(decoded)[0]
|
|
491
|
+
const decoded = instance.calldata.decodeEvent(contractName, event.data, topics);
|
|
492
|
+
const [name, args] = Object.entries(decoded)[0];
|
|
483
493
|
return {
|
|
484
494
|
name,
|
|
485
495
|
args,
|
|
486
496
|
contract: {
|
|
487
497
|
name: contractName,
|
|
488
|
-
address: event.address
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}).filter((e: DecodedEvent | null): e is DecodedEvent => e != null)
|
|
498
|
+
address: event.address,
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
}).filter((e: DecodedEvent | null): e is DecodedEvent => e != null);
|
|
492
502
|
|
|
493
503
|
/**
|
|
494
504
|
* Generate proto function based on contract function using Contract ACI schema
|
|
@@ -507,23 +517,22 @@ export default async function getContractInstance ({
|
|
|
507
517
|
instance.methods = Object.fromEntries(instance._aci.encodedAci.contract.functions
|
|
508
518
|
.map(({ name, arguments: aciArgs, stateful }: FunctionACI) => {
|
|
509
519
|
const genHandler = (callStatic: boolean) => async (...args: any[]) => {
|
|
510
|
-
const options = args.length === aciArgs.length + 1 ? args.pop() : {}
|
|
511
|
-
if (typeof options !== 'object') throw new TypeError(`Options should be an object: ${options as string}`)
|
|
512
|
-
if (name === 'init') return
|
|
513
|
-
return
|
|
514
|
-
}
|
|
520
|
+
const options = args.length === aciArgs.length + 1 ? args.pop() : {};
|
|
521
|
+
if (typeof options !== 'object') throw new TypeError(`Options should be an object: ${options as string}`);
|
|
522
|
+
if (name === 'init') return instance.deploy(args, { callStatic, ...options });
|
|
523
|
+
return instance.call(name, args, { callStatic, ...options });
|
|
524
|
+
};
|
|
515
525
|
return [
|
|
516
526
|
name,
|
|
517
527
|
Object.assign(
|
|
518
528
|
genHandler(name === 'init' ? false : !stateful),
|
|
519
529
|
{
|
|
520
530
|
get: genHandler(true),
|
|
521
|
-
send: genHandler(false)
|
|
522
|
-
}
|
|
523
|
-
)
|
|
524
|
-
]
|
|
525
|
-
})
|
|
526
|
-
)
|
|
531
|
+
send: genHandler(false),
|
|
532
|
+
},
|
|
533
|
+
),
|
|
534
|
+
];
|
|
535
|
+
}));
|
|
527
536
|
|
|
528
|
-
return instance
|
|
537
|
+
return instance;
|
|
529
538
|
}
|