@aztec/aztec.js 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8
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/dest/api/abi.d.ts +2 -2
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/block.d.ts +2 -2
- package/dest/api/block.d.ts.map +1 -1
- package/dest/api/block.js +1 -1
- package/dest/api/contract.d.ts +18 -12
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +16 -10
- package/dest/api/deployment.d.ts +1 -2
- package/dest/api/deployment.d.ts.map +1 -1
- package/dest/api/deployment.js +0 -1
- package/dest/api/events.d.ts +10 -6
- package/dest/api/events.d.ts.map +1 -1
- package/dest/api/events.js +30 -20
- package/dest/api/fields.d.ts +2 -1
- package/dest/api/fields.d.ts.map +1 -1
- package/dest/api/fields.js +1 -0
- package/dest/api/keys.d.ts +1 -1
- package/dest/api/keys.js +1 -1
- package/dest/api/node.d.ts +8 -4
- package/dest/api/node.d.ts.map +1 -1
- package/dest/api/node.js +7 -3
- package/dest/api/tx.d.ts +2 -2
- package/dest/api/tx.d.ts.map +1 -1
- package/dest/api/tx.js +1 -1
- package/dest/api/wallet.d.ts +3 -2
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +2 -1
- package/dest/contract/base_contract_interaction.d.ts +8 -10
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +5 -17
- package/dest/contract/batch_call.d.ts +3 -3
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +17 -8
- package/dest/contract/contract_function_interaction.d.ts +7 -16
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +107 -18
- package/dest/contract/deploy_method.d.ts +91 -19
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +68 -30
- package/dest/contract/get_gas_limits.js +3 -3
- package/dest/contract/interaction_options.d.ts +99 -21
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +41 -1
- package/dest/contract/protocol_contracts/auth-registry.d.ts +3 -3
- package/dest/contract/protocol_contracts/auth-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/auth-registry.js +49 -20
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts +2 -22
- package/dest/contract/protocol_contracts/contract-class-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-class-registry.js +13 -671
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts +2 -11
- package/dest/contract/protocol_contracts/contract-instance-registry.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/contract-instance-registry.js +80 -486
- package/dest/contract/protocol_contracts/fee-juice.d.ts +1 -10
- package/dest/contract/protocol_contracts/fee-juice.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/fee-juice.js +7 -413
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts +3 -3
- package/dest/contract/protocol_contracts/multi-call-entrypoint.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/multi-call-entrypoint.js +40 -15
- package/dest/contract/protocol_contracts/public-checks.d.ts +3 -3
- package/dest/contract/protocol_contracts/public-checks.d.ts.map +1 -1
- package/dest/contract/protocol_contracts/public-checks.js +40 -23
- package/dest/contract/wait_for_proven.js +1 -1
- package/dest/contract/wait_opts.d.ts +16 -0
- package/dest/contract/wait_opts.d.ts.map +1 -0
- package/dest/contract/wait_opts.js +5 -0
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -6
- package/dest/fee/private_fee_payment_method.js +10 -10
- package/dest/fee/public_fee_payment_method.js +10 -10
- package/dest/fee/sponsored_fee_payment.js +3 -3
- package/dest/utils/abi_types.d.ts +6 -1
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/abi_types.js +1 -1
- package/dest/utils/authwit.d.ts +6 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +12 -12
- package/dest/utils/node.d.ts +12 -1
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/node.js +46 -0
- package/dest/wallet/capabilities.d.ts +452 -0
- package/dest/wallet/capabilities.d.ts.map +1 -0
- package/dest/wallet/capabilities.js +3 -0
- package/dest/wallet/deploy_account_method.d.ts +31 -6
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +26 -0
- package/dest/wallet/index.d.ts +2 -1
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +1 -0
- package/dest/wallet/wallet.d.ts +1639 -93
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +186 -27
- package/package.json +20 -11
- package/src/api/abi.ts +1 -0
- package/src/api/block.ts +1 -1
- package/src/api/contract.ts +31 -9
- package/src/api/deployment.ts +0 -1
- package/src/api/events.ts +35 -27
- package/src/api/fields.ts +1 -0
- package/src/api/keys.ts +2 -2
- package/src/api/node.ts +7 -3
- package/src/api/tx.ts +2 -0
- package/src/api/wallet.ts +48 -1
- package/src/contract/base_contract_interaction.ts +28 -15
- package/src/contract/batch_call.ts +17 -14
- package/src/contract/contract_function_interaction.ts +114 -26
- package/src/contract/deploy_method.ts +172 -35
- package/src/contract/get_gas_limits.ts +3 -3
- package/src/contract/interaction_options.ts +141 -23
- package/src/contract/protocol_contracts/auth-registry.ts +13 -14
- package/src/contract/protocol_contracts/contract-class-registry.ts +4 -347
- package/src/contract/protocol_contracts/contract-instance-registry.ts +34 -234
- package/src/contract/protocol_contracts/fee-juice.ts +2 -202
- package/src/contract/protocol_contracts/multi-call-entrypoint.ts +11 -13
- package/src/contract/protocol_contracts/public-checks.ts +11 -15
- package/src/contract/wait_for_proven.ts +1 -1
- package/src/contract/wait_opts.ts +21 -0
- package/src/fee/fee_juice_payment_method_with_claim.ts +5 -5
- package/src/fee/private_fee_payment_method.ts +7 -7
- package/src/fee/public_fee_payment_method.ts +8 -8
- package/src/fee/sponsored_fee_payment.ts +3 -3
- package/src/utils/abi_types.ts +7 -0
- package/src/utils/authwit.ts +31 -21
- package/src/utils/node.ts +62 -0
- package/src/wallet/capabilities.ts +500 -0
- package/src/wallet/deploy_account_method.ts +56 -4
- package/src/wallet/index.ts +1 -0
- package/src/wallet/wallet.ts +257 -50
- package/dest/contract/deploy_sent_tx.d.ts +0 -48
- package/dest/contract/deploy_sent_tx.d.ts.map +0 -1
- package/dest/contract/deploy_sent_tx.js +0 -46
- package/dest/contract/sent_tx.d.ts +0 -50
- package/dest/contract/sent_tx.d.ts.map +0 -1
- package/dest/contract/sent_tx.js +0 -90
- package/dest/deployment/broadcast_function.d.ts +0 -24
- package/dest/deployment/broadcast_function.d.ts.map +0 -1
- package/dest/deployment/broadcast_function.js +0 -74
- package/src/contract/deploy_sent_tx.ts +0 -75
- package/src/contract/sent_tx.ts +0 -129
- package/src/deployment/broadcast_function.ts +0 -148
package/src/api/wallet.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
2
|
type Aliased,
|
|
3
3
|
type SimulateOptions,
|
|
4
|
+
type ExecuteUtilityOptions,
|
|
4
5
|
type ProfileOptions,
|
|
5
6
|
type SendOptions,
|
|
6
7
|
type BatchableMethods,
|
|
@@ -11,10 +12,16 @@ export {
|
|
|
11
12
|
type Wallet,
|
|
12
13
|
type PrivateEvent,
|
|
13
14
|
type PrivateEventFilter,
|
|
14
|
-
|
|
15
|
+
type PublicEvent,
|
|
16
|
+
type PublicEventFilter,
|
|
17
|
+
type ContractMetadata,
|
|
18
|
+
type ContractClassMetadata,
|
|
19
|
+
AppCapabilitiesSchema,
|
|
20
|
+
WalletCapabilitiesSchema,
|
|
15
21
|
ExecutionPayloadSchema,
|
|
16
22
|
GasSettingsOptionSchema,
|
|
17
23
|
WalletSimulationFeeOptionSchema,
|
|
24
|
+
WaitOptsSchema,
|
|
18
25
|
SendOptionsSchema,
|
|
19
26
|
SimulateOptionsSchema,
|
|
20
27
|
ProfileOptionsSchema,
|
|
@@ -23,9 +30,49 @@ export {
|
|
|
23
30
|
EventMetadataDefinitionSchema,
|
|
24
31
|
PrivateEventSchema,
|
|
25
32
|
PrivateEventFilterSchema,
|
|
33
|
+
PublicEventSchema,
|
|
34
|
+
PublicEventFilterSchema,
|
|
35
|
+
ContractClassMetadataSchema,
|
|
36
|
+
ContractMetadataSchema,
|
|
26
37
|
WalletSchema,
|
|
38
|
+
ContractFunctionPatternSchema,
|
|
39
|
+
AccountsCapabilitySchema,
|
|
40
|
+
GrantedAccountsCapabilitySchema,
|
|
41
|
+
ContractsCapabilitySchema,
|
|
42
|
+
GrantedContractsCapabilitySchema,
|
|
43
|
+
ContractClassesCapabilitySchema,
|
|
44
|
+
GrantedContractClassesCapabilitySchema,
|
|
45
|
+
SimulationCapabilitySchema,
|
|
46
|
+
GrantedSimulationCapabilitySchema,
|
|
47
|
+
TransactionCapabilitySchema,
|
|
48
|
+
GrantedTransactionCapabilitySchema,
|
|
49
|
+
DataCapabilitySchema,
|
|
50
|
+
GrantedDataCapabilitySchema,
|
|
51
|
+
CapabilitySchema,
|
|
52
|
+
GrantedCapabilitySchema,
|
|
27
53
|
} from '../wallet/wallet.js';
|
|
28
54
|
|
|
55
|
+
export {
|
|
56
|
+
type AppCapabilities,
|
|
57
|
+
type WalletCapabilities,
|
|
58
|
+
CAPABILITY_VERSION,
|
|
59
|
+
type Capability,
|
|
60
|
+
type GrantedCapability,
|
|
61
|
+
type ContractFunctionPattern,
|
|
62
|
+
type AccountsCapability,
|
|
63
|
+
type GrantedAccountsCapability,
|
|
64
|
+
type ContractsCapability,
|
|
65
|
+
type GrantedContractsCapability,
|
|
66
|
+
type ContractClassesCapability,
|
|
67
|
+
type GrantedContractClassesCapability,
|
|
68
|
+
type SimulationCapability,
|
|
69
|
+
type GrantedSimulationCapability,
|
|
70
|
+
type TransactionCapability,
|
|
71
|
+
type GrantedTransactionCapability,
|
|
72
|
+
type DataCapability,
|
|
73
|
+
type GrantedDataCapability,
|
|
74
|
+
} from '../wallet/capabilities.js';
|
|
75
|
+
|
|
29
76
|
export { AccountManager } from '../wallet/account_manager.js';
|
|
30
77
|
|
|
31
78
|
export { type DeployAccountOptions, DeployAccountMethod } from '../wallet/deploy_account_method.js';
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
|
-
import type { Capsule, ExecutionPayload } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { Capsule, ExecutionPayload, TxReceipt } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
5
|
import type { Wallet } from '../wallet/wallet.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
type InteractionWaitOptions,
|
|
8
|
+
type RequestInteractionOptions,
|
|
9
|
+
type SendInteractionOptions,
|
|
10
|
+
type SendInteractionOptionsWithoutWait,
|
|
11
|
+
type SendReturn,
|
|
12
|
+
type TxSendResultMined,
|
|
13
|
+
toSendOptions,
|
|
14
|
+
} from './interaction_options.js';
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* Base class for an interaction with a contract, be it a deployment, a function call, or a batch.
|
|
@@ -30,20 +37,26 @@ export abstract class BaseContractInteraction {
|
|
|
30
37
|
// docs:start:send
|
|
31
38
|
/**
|
|
32
39
|
* Sends a transaction to the contract function with the specified options.
|
|
33
|
-
*
|
|
34
|
-
* It creates and signs the transaction if necessary, and returns a SentTx instance,
|
|
35
|
-
* which can be used to track the transaction status, receipt, and events.
|
|
40
|
+
* By default, waits for the transaction to be mined and returns the receipt (or custom type).
|
|
36
41
|
* @param options - An object containing 'from' property representing
|
|
37
|
-
* the AztecAddress of the sender and optional
|
|
38
|
-
* @returns
|
|
42
|
+
* the AztecAddress of the sender, optional fee configuration, and optional wait settings
|
|
43
|
+
* @returns TReturn (if wait is undefined/WaitOpts) or TxHash (if wait is NO_WAIT)
|
|
39
44
|
*/
|
|
40
|
-
|
|
45
|
+
// Overload for when wait is not specified at all - returns { receipt: TReturn, offchainEffects }
|
|
46
|
+
public send<TReturn = TxReceipt>(options: SendInteractionOptionsWithoutWait): Promise<TxSendResultMined<TReturn>>;
|
|
47
|
+
// Generic overload for explicit wait values
|
|
48
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
49
|
+
public send<TReturn = TxReceipt, W extends InteractionWaitOptions = undefined>(
|
|
50
|
+
options: SendInteractionOptions<W>,
|
|
51
|
+
): Promise<SendReturn<W, TReturn>>;
|
|
52
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
53
|
+
public async send<TReturn = TxReceipt>(
|
|
54
|
+
options: SendInteractionOptions<InteractionWaitOptions>,
|
|
55
|
+
): Promise<SendReturn<typeof options.wait, TReturn>> {
|
|
41
56
|
// docs:end:send
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
return new SentTx(this.wallet, sendTx);
|
|
57
|
+
const executionPayload = await this.request(options);
|
|
58
|
+
const sendOptions = toSendOptions(options);
|
|
59
|
+
|
|
60
|
+
return (await this.wallet.sendTx(executionPayload, sendOptions as any)) as SendReturn<typeof options.wait, TReturn>;
|
|
48
61
|
}
|
|
49
62
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { type FunctionCall, FunctionType, decodeFromAbi } from '@aztec/stdlib/abi';
|
|
2
|
-
import {
|
|
3
|
-
ExecutionPayload,
|
|
4
|
-
TxSimulationResult,
|
|
5
|
-
UtilitySimulationResult,
|
|
6
|
-
mergeExecutionPayloads,
|
|
7
|
-
} from '@aztec/stdlib/tx';
|
|
2
|
+
import { ExecutionPayload, TxSimulationResult, UtilityExecutionResult, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
8
3
|
|
|
9
4
|
import type { BatchedMethod, Wallet } from '../wallet/wallet.js';
|
|
10
5
|
import { BaseContractInteraction } from './base_contract_interaction.js';
|
|
11
6
|
import {
|
|
12
7
|
type RequestInteractionOptions,
|
|
13
8
|
type SimulateInteractionOptions,
|
|
9
|
+
emptyOffchainOutput,
|
|
10
|
+
extractOffchainOutput,
|
|
14
11
|
toSimulateOptions,
|
|
15
12
|
} from './interaction_options.js';
|
|
16
13
|
|
|
@@ -42,9 +39,9 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
|
-
* Simulates the batch, supporting private, public and utility functions. Although this is a single
|
|
42
|
+
* Simulates/executes the batch, supporting private, public and utility functions. Although this is a single
|
|
46
43
|
* interaction with the wallet, private and public functions will be grouped into a single ExecutionPayload
|
|
47
|
-
* that the wallet will simulate as a single transaction. Utility function calls will
|
|
44
|
+
* that the wallet will simulate as a single transaction. Utility function calls will be executed
|
|
48
45
|
* one by one.
|
|
49
46
|
* @param options - An optional object containing additional configuration for the interaction.
|
|
50
47
|
* @returns The results of all the interactions that make up the batch
|
|
@@ -81,8 +78,8 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
81
78
|
// Add utility calls to batch
|
|
82
79
|
for (const [call] of utility) {
|
|
83
80
|
batchRequests.push({
|
|
84
|
-
name: '
|
|
85
|
-
args: [call, options
|
|
81
|
+
name: 'executeUtility' as const,
|
|
82
|
+
args: [call, { scope: options.from, authWitnesses: options.authWitnesses }],
|
|
86
83
|
});
|
|
87
84
|
}
|
|
88
85
|
|
|
@@ -111,9 +108,12 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
111
108
|
for (let i = 0; i < utility.length; i++) {
|
|
112
109
|
const [call, resultIndex] = utility[i];
|
|
113
110
|
const wrappedResult = batchResults[i];
|
|
114
|
-
if (wrappedResult.name === '
|
|
115
|
-
const rawReturnValues = (wrappedResult.result as
|
|
116
|
-
results[resultIndex] =
|
|
111
|
+
if (wrappedResult.name === 'executeUtility') {
|
|
112
|
+
const rawReturnValues = (wrappedResult.result as UtilityExecutionResult).result;
|
|
113
|
+
results[resultIndex] = {
|
|
114
|
+
result: rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [],
|
|
115
|
+
...emptyOffchainOutput(),
|
|
116
|
+
};
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -132,7 +132,10 @@ export class BatchCall extends BaseContractInteraction {
|
|
|
132
132
|
? simulatedTx.getPrivateReturnValues()?.nested?.[resultIndex].values
|
|
133
133
|
: simulatedTx.getPublicReturnValues()?.[resultIndex].values;
|
|
134
134
|
|
|
135
|
-
results[callIndex] =
|
|
135
|
+
results[callIndex] = {
|
|
136
|
+
result: rawReturnValues ? decodeFromAbi(call.returnTypes, rawReturnValues) : [],
|
|
137
|
+
...extractOffchainOutput(simulatedTx.offchainEffects),
|
|
138
|
+
};
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
141
|
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type ABIParameter,
|
|
3
|
+
type AbiType,
|
|
4
|
+
type FunctionAbi,
|
|
5
|
+
FunctionCall,
|
|
6
|
+
FunctionSelector,
|
|
7
|
+
FunctionType,
|
|
8
|
+
canBeMappedFromNullOrUndefined,
|
|
9
|
+
decodeFromAbi,
|
|
10
|
+
encodeArguments,
|
|
11
|
+
isOptionStruct,
|
|
12
|
+
} from '@aztec/stdlib/abi';
|
|
2
13
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import {
|
|
15
|
+
import type { Capsule, HashedValues, TxProfileResult } from '@aztec/stdlib/tx';
|
|
5
16
|
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
6
17
|
|
|
7
18
|
import type { Wallet } from '../wallet/wallet.js';
|
|
@@ -11,7 +22,9 @@ import {
|
|
|
11
22
|
type ProfileInteractionOptions,
|
|
12
23
|
type RequestInteractionOptions,
|
|
13
24
|
type SimulateInteractionOptions,
|
|
14
|
-
type
|
|
25
|
+
type SimulationResult,
|
|
26
|
+
emptyOffchainOutput,
|
|
27
|
+
extractOffchainOutput,
|
|
15
28
|
toProfileOptions,
|
|
16
29
|
toSimulateOptions,
|
|
17
30
|
} from './interaction_options.js';
|
|
@@ -31,11 +44,32 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
31
44
|
private extraHashedArgs: HashedValues[] = [],
|
|
32
45
|
) {
|
|
33
46
|
super(wallet, authWitnesses, capsules);
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
// This may feel a bit ad-hoc here, so it warrants a comment. We accept Noir Option<T> parameters, and it's natural
|
|
48
|
+
// to map JS's null/undefined to Noir Option's None. One possible way to deal with null/undefined arguments at this
|
|
49
|
+
// point in the codebase is to conclude that they are accepted since at least one Noir type (ie: Option) can be
|
|
50
|
+
// encoded from them. Then we would let `encode` deal with potential mismatches. I chose not to do that because of
|
|
51
|
+
// the pervasiveness of null/undefined in JS, and how easy it is to inadvertently pass it around. Having this check
|
|
52
|
+
// here allows us to fail at a point where the boundaries and intent are clear.
|
|
53
|
+
if (this.hasInvalidNullOrUndefinedArguments(args)) {
|
|
54
|
+
const signature = formatFunctionSignature(this.functionDao.name, this.functionDao.parameters);
|
|
55
|
+
const received = args.map(formatArg).join(', ');
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Null or undefined arguments are only allowed for Option<T> parameters in ${signature}. Received: (${received}).`,
|
|
58
|
+
);
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
|
|
62
|
+
private hasInvalidNullOrUndefinedArguments(args: any[]) {
|
|
63
|
+
return args.some((arg, index) => {
|
|
64
|
+
if (arg !== undefined && arg !== null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const parameterType = this.functionDao.parameters[index]?.type;
|
|
69
|
+
return !parameterType || !canBeMappedFromNullOrUndefined(parameterType);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
/**
|
|
40
74
|
* Returns the encoded function call wrapped by this interaction
|
|
41
75
|
* Useful when generating authwits
|
|
@@ -43,16 +77,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
43
77
|
*/
|
|
44
78
|
public async getFunctionCall() {
|
|
45
79
|
const args = encodeArguments(this.functionDao, this.args);
|
|
46
|
-
return {
|
|
80
|
+
return FunctionCall.from({
|
|
47
81
|
name: this.functionDao.name,
|
|
48
|
-
|
|
82
|
+
to: this.contractAddress,
|
|
49
83
|
selector: await FunctionSelector.fromNameAndParameters(this.functionDao.name, this.functionDao.parameters),
|
|
50
84
|
type: this.functionDao.functionType,
|
|
51
|
-
to: this.contractAddress,
|
|
52
|
-
isStatic: this.functionDao.isStatic,
|
|
53
85
|
hideMsgSender: false /** Only set to `true` for enqueued public function calls */,
|
|
86
|
+
isStatic: this.functionDao.isStatic,
|
|
87
|
+
args,
|
|
54
88
|
returnTypes: this.functionDao.returnTypes,
|
|
55
|
-
};
|
|
89
|
+
});
|
|
56
90
|
}
|
|
57
91
|
|
|
58
92
|
/**
|
|
@@ -90,21 +124,16 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
90
124
|
* function or a rich object containing extra metadata, such as estimated gas costs (if requested via options),
|
|
91
125
|
* execution statistics and emitted offchain effects
|
|
92
126
|
*/
|
|
93
|
-
public async simulate<T extends SimulateInteractionOptions>(
|
|
94
|
-
options: T,
|
|
95
|
-
): Promise<SimulationReturn<Exclude<T['fee'], undefined>['estimateGas']>>;
|
|
96
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
97
|
-
public async simulate<T extends SimulateInteractionOptions>(
|
|
98
|
-
options: T,
|
|
99
|
-
): Promise<SimulationReturn<T['includeMetadata']>>;
|
|
100
|
-
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
101
127
|
public async simulate(
|
|
102
|
-
options: SimulateInteractionOptions,
|
|
103
|
-
): Promise<
|
|
128
|
+
options: SimulateInteractionOptions = {} as SimulateInteractionOptions,
|
|
129
|
+
): Promise<SimulationResult> {
|
|
104
130
|
// docs:end:simulate
|
|
105
131
|
if (this.functionDao.functionType == FunctionType.UTILITY) {
|
|
106
132
|
const call = await this.getFunctionCall();
|
|
107
|
-
const utilityResult = await this.wallet.
|
|
133
|
+
const utilityResult = await this.wallet.executeUtility(call, {
|
|
134
|
+
scope: options.from,
|
|
135
|
+
authWitnesses: options.authWitnesses,
|
|
136
|
+
});
|
|
108
137
|
|
|
109
138
|
// Decode the raw field elements to the actual return type
|
|
110
139
|
const returnValue = utilityResult.result ? decodeFromAbi(this.functionDao.returnTypes, utilityResult.result) : [];
|
|
@@ -112,11 +141,11 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
112
141
|
if (options.includeMetadata) {
|
|
113
142
|
return {
|
|
114
143
|
stats: utilityResult.stats,
|
|
144
|
+
...emptyOffchainOutput(),
|
|
115
145
|
result: returnValue,
|
|
116
146
|
};
|
|
117
|
-
} else {
|
|
118
|
-
return returnValue;
|
|
119
147
|
}
|
|
148
|
+
return { result: returnValue, ...emptyOffchainOutput() };
|
|
120
149
|
}
|
|
121
150
|
|
|
122
151
|
const executionPayload = await this.request(options);
|
|
@@ -138,6 +167,7 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
138
167
|
}
|
|
139
168
|
|
|
140
169
|
const returnValue = rawReturnValues ? decodeFromAbi(this.functionDao.returnTypes, rawReturnValues) : [];
|
|
170
|
+
const offchainOutput = extractOffchainOutput(simulatedTx.offchainEffects);
|
|
141
171
|
|
|
142
172
|
if (options.includeMetadata || options.fee?.estimateGas) {
|
|
143
173
|
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
|
|
@@ -146,13 +176,12 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
146
176
|
);
|
|
147
177
|
return {
|
|
148
178
|
stats: simulatedTx.stats,
|
|
149
|
-
|
|
179
|
+
...offchainOutput,
|
|
150
180
|
result: returnValue,
|
|
151
181
|
estimatedGas: { gasLimits, teardownGasLimits },
|
|
152
182
|
};
|
|
153
|
-
} else {
|
|
154
|
-
return returnValue;
|
|
155
183
|
}
|
|
184
|
+
return { result: returnValue, ...offchainOutput };
|
|
156
185
|
}
|
|
157
186
|
|
|
158
187
|
/**
|
|
@@ -200,3 +229,62 @@ export class ContractFunctionInteraction extends BaseContractInteraction {
|
|
|
200
229
|
);
|
|
201
230
|
}
|
|
202
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Render an AbiType as a human readable string
|
|
235
|
+
* */
|
|
236
|
+
function formatAbiType(abiType: AbiType): string {
|
|
237
|
+
switch (abiType.kind) {
|
|
238
|
+
case 'field':
|
|
239
|
+
return 'Field';
|
|
240
|
+
case 'boolean':
|
|
241
|
+
return 'bool';
|
|
242
|
+
case 'integer':
|
|
243
|
+
return `${abiType.sign === 'signed' ? 'i' : 'u'}${abiType.width}`;
|
|
244
|
+
case 'string':
|
|
245
|
+
return `str<${abiType.length}>`;
|
|
246
|
+
case 'array':
|
|
247
|
+
return `[${formatAbiType(abiType.type)}; ${abiType.length}]`;
|
|
248
|
+
case 'struct': {
|
|
249
|
+
if (isOptionStruct(abiType)) {
|
|
250
|
+
const innerType = abiType.fields.find(f => f.name === '_value')!.type;
|
|
251
|
+
return `Option<${formatAbiType(innerType)}>`;
|
|
252
|
+
}
|
|
253
|
+
return `(${abiType.fields.map(f => `${f.name}: ${formatAbiType(f.type)}`).join(', ')})`;
|
|
254
|
+
}
|
|
255
|
+
case 'tuple':
|
|
256
|
+
return `(${abiType.fields.map(formatAbiType).join(', ')})`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Pretty print a function signature
|
|
262
|
+
*/
|
|
263
|
+
function formatFunctionSignature(name: string, parameters: ABIParameter[]): string {
|
|
264
|
+
const params = parameters.map(p => `${p.name}: ${formatAbiType(p.type)}`).join(', ');
|
|
265
|
+
return `${name}(${params})`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Non-exhaustive pretty print of JS args to display in error messages in this module
|
|
270
|
+
*/
|
|
271
|
+
function formatArg(arg: unknown): string {
|
|
272
|
+
if (arg === undefined) {
|
|
273
|
+
return 'undefined';
|
|
274
|
+
}
|
|
275
|
+
if (arg === null) {
|
|
276
|
+
return 'null';
|
|
277
|
+
}
|
|
278
|
+
if (typeof arg === 'bigint') {
|
|
279
|
+
return `${arg}n`;
|
|
280
|
+
}
|
|
281
|
+
if (Array.isArray(arg)) {
|
|
282
|
+
return `[${arg.map(formatArg).join(', ')}]`;
|
|
283
|
+
}
|
|
284
|
+
if (typeof arg === 'object') {
|
|
285
|
+
const entries = Object.entries(arg).map(([k, v]) => `${k}: ${formatArg(v)}`);
|
|
286
|
+
return `{ ${entries.join(', ')} }`;
|
|
287
|
+
}
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
289
|
+
return String(arg);
|
|
290
|
+
}
|