@aztec/aztec.js 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f
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/account/account.d.ts +2 -3
- package/dest/account/account.d.ts.map +1 -1
- package/dest/account/account_contract.d.ts +1 -1
- package/dest/account/account_with_secret_key.d.ts +1 -2
- package/dest/account/account_with_secret_key.d.ts.map +1 -1
- package/dest/account/index.d.ts +1 -1
- package/dest/account/interface.d.ts +1 -1
- package/dest/account/signerless_account.d.ts +2 -3
- package/dest/account/signerless_account.d.ts.map +1 -1
- package/dest/api/abi.d.ts +1 -1
- package/dest/api/account.d.ts +2 -1
- package/dest/api/account.d.ts.map +1 -1
- package/dest/api/account.js +1 -0
- package/dest/api/addresses.d.ts +1 -1
- package/dest/api/authorization.d.ts +1 -1
- package/dest/api/block.d.ts +1 -1
- package/dest/api/contract.d.ts +3 -3
- package/dest/api/contract.d.ts.map +1 -1
- package/dest/api/contract.js +1 -1
- package/dest/api/crypto.d.ts +1 -1
- package/dest/api/deployment.d.ts +1 -1
- package/dest/api/eth_address.d.ts +1 -1
- package/dest/api/ethereum.d.ts +1 -1
- package/dest/api/events.d.ts +1 -1
- package/dest/api/fee.d.ts +1 -1
- package/dest/api/fee_testing.d.ts +1 -1
- package/dest/api/fields.d.ts +1 -1
- package/dest/api/keys.d.ts +1 -1
- package/dest/api/log.d.ts +1 -1
- package/dest/api/messaging.d.ts +1 -1
- package/dest/api/node.d.ts +1 -1
- package/dest/api/note.d.ts +2 -2
- package/dest/api/note.d.ts.map +1 -1
- package/dest/api/note.js +1 -1
- package/dest/api/protocol.d.ts +1 -1
- package/dest/api/trees.d.ts +1 -1
- 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/utils.d.ts +1 -1
- package/dest/api/wallet.d.ts +2 -3
- package/dest/api/wallet.d.ts.map +1 -1
- package/dest/api/wallet.js +1 -2
- package/dest/authorization/call_authorization_request.d.ts +1 -22
- package/dest/authorization/call_authorization_request.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.d.ts +2 -3
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +1 -1
- package/dest/contract/batch_call.d.ts +8 -9
- package/dest/contract/batch_call.d.ts.map +1 -1
- package/dest/contract/batch_call.js +51 -33
- package/dest/contract/checker.d.ts +1 -1
- package/dest/contract/contract.d.ts +2 -2
- package/dest/contract/contract.d.ts.map +1 -1
- package/dest/contract/contract.js +4 -5
- package/dest/contract/contract_base.d.ts +5 -12
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +5 -12
- package/dest/contract/contract_function_interaction.d.ts +4 -4
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +9 -6
- package/dest/contract/deploy_method.d.ts +8 -7
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +8 -6
- package/dest/contract/deploy_sent_tx.d.ts +12 -7
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +10 -4
- package/dest/contract/get_gas_limits.d.ts +1 -1
- package/dest/contract/interaction_options.d.ts +4 -4
- package/dest/contract/interaction_options.d.ts.map +1 -1
- package/dest/contract/interaction_options.js +4 -10
- package/dest/contract/protocol_contracts.d.ts +1 -1
- package/dest/contract/sent_tx.d.ts +1 -1
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/unsafe_contract.d.ts +1 -1
- package/dest/contract/unsafe_contract.d.ts.map +1 -1
- package/dest/contract/unsafe_contract.js +1 -1
- package/dest/contract/wait_for_proven.d.ts +1 -1
- package/dest/deployment/broadcast_function.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts +1 -1
- package/dest/deployment/contract_deployer.d.ts.map +1 -1
- package/dest/deployment/contract_deployer.js +1 -1
- package/dest/deployment/publish_class.d.ts +1 -1
- package/dest/deployment/publish_instance.d.ts +1 -1
- package/dest/ethereum/portal_manager.d.ts +1 -3
- package/dest/ethereum/portal_manager.d.ts.map +1 -1
- package/dest/ethereum/portal_manager.js +33 -6
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts +2 -2
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +2 -2
- package/dest/fee/fee_payment_method.d.ts +2 -2
- package/dest/fee/fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.d.ts +2 -2
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +3 -3
- package/dest/fee/public_fee_payment_method.d.ts +2 -2
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +3 -3
- package/dest/fee/sponsored_fee_payment.d.ts +2 -2
- package/dest/fee/sponsored_fee_payment.d.ts.map +1 -1
- package/dest/fee/sponsored_fee_payment.js +2 -2
- package/dest/utils/abi_types.d.ts +1 -1
- package/dest/utils/authwit.d.ts +6 -6
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +21 -10
- package/dest/utils/cross_chain.d.ts +1 -1
- package/dest/utils/fee_juice.d.ts +2 -2
- package/dest/utils/fee_juice.js +1 -1
- package/dest/utils/field_compressed_string.d.ts +1 -1
- package/dest/utils/field_compressed_string.d.ts.map +1 -1
- package/dest/utils/node.d.ts +2 -2
- package/dest/utils/node.d.ts.map +1 -1
- package/dest/utils/pub_key.d.ts +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts +2 -2
- package/dest/wallet/account_entrypoint_meta_payment_method.d.ts.map +1 -1
- package/dest/wallet/account_entrypoint_meta_payment_method.js +2 -2
- package/dest/wallet/account_manager.d.ts +1 -4
- package/dest/wallet/account_manager.d.ts.map +1 -1
- package/dest/wallet/account_manager.js +1 -1
- package/dest/wallet/deploy_account_method.d.ts +4 -4
- package/dest/wallet/deploy_account_method.d.ts.map +1 -1
- package/dest/wallet/deploy_account_method.js +1 -1
- package/dest/wallet/index.d.ts +1 -2
- package/dest/wallet/index.d.ts.map +1 -1
- package/dest/wallet/index.js +0 -1
- package/dest/wallet/wallet.d.ts +617 -1130
- package/dest/wallet/wallet.d.ts.map +1 -1
- package/dest/wallet/wallet.js +23 -39
- package/package.json +13 -12
- package/src/account/account.ts +1 -2
- package/src/account/signerless_account.ts +1 -2
- package/src/api/account.ts +1 -0
- package/src/api/contract.ts +2 -1
- package/src/api/note.ts +1 -1
- package/src/api/tx.ts +2 -0
- package/src/api/wallet.ts +1 -7
- package/src/contract/base_contract_interaction.ts +2 -3
- package/src/contract/batch_call.ts +65 -48
- package/src/contract/contract.ts +7 -5
- package/src/contract/contract_base.ts +5 -15
- package/src/contract/contract_function_interaction.ts +10 -11
- package/src/contract/deploy_method.ts +12 -11
- package/src/contract/deploy_sent_tx.ts +17 -10
- package/src/contract/interaction_options.ts +4 -10
- package/src/contract/unsafe_contract.ts +1 -1
- package/src/deployment/contract_deployer.ts +3 -2
- package/src/ethereum/portal_manager.ts +47 -12
- package/src/fee/fee_juice_payment_method_with_claim.ts +3 -1
- package/src/fee/fee_payment_method.ts +1 -1
- package/src/fee/private_fee_payment_method.ts +4 -2
- package/src/fee/public_fee_payment_method.ts +4 -2
- package/src/fee/sponsored_fee_payment.ts +3 -1
- package/src/utils/authwit.ts +20 -14
- package/src/utils/fee_juice.ts +1 -1
- package/src/wallet/account_entrypoint_meta_payment_method.ts +2 -1
- package/src/wallet/account_manager.ts +1 -1
- package/src/wallet/deploy_account_method.ts +3 -2
- package/src/wallet/index.ts +0 -1
- package/src/wallet/wallet.ts +28 -72
- package/dest/wallet/base_wallet.d.ts +0 -91
- package/dest/wallet/base_wallet.d.ts.map +0 -1
- package/dest/wallet/base_wallet.js +0 -238
- package/src/wallet/base_wallet.ts +0 -350
package/src/wallet/wallet.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
2
|
-
import type { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
3
2
|
import type { Fr } from '@aztec/foundation/fields';
|
|
4
3
|
import {
|
|
5
4
|
AbiTypeSchema,
|
|
6
5
|
type ContractArtifact,
|
|
7
6
|
ContractArtifactSchema,
|
|
8
7
|
type EventMetadataDefinition,
|
|
9
|
-
|
|
8
|
+
type FunctionCall,
|
|
10
9
|
FunctionType,
|
|
11
10
|
} from '@aztec/stdlib/abi';
|
|
12
11
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
@@ -16,11 +15,9 @@ import {
|
|
|
16
15
|
ContractClassWithIdSchema,
|
|
17
16
|
type ContractInstanceWithAddress,
|
|
18
17
|
ContractInstanceWithAddressSchema,
|
|
19
|
-
type ContractInstantiationData,
|
|
20
18
|
type ContractMetadata,
|
|
21
19
|
} from '@aztec/stdlib/contract';
|
|
22
20
|
import { Gas } from '@aztec/stdlib/gas';
|
|
23
|
-
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
24
21
|
import { AbiDecodedSchema, type ApiSchemaFor, type ZodFor, optional, schemas } from '@aztec/stdlib/schemas';
|
|
25
22
|
import {
|
|
26
23
|
Capsule,
|
|
@@ -31,10 +28,10 @@ import {
|
|
|
31
28
|
TxSimulationResult,
|
|
32
29
|
UtilitySimulationResult,
|
|
33
30
|
} from '@aztec/stdlib/tx';
|
|
31
|
+
import type { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
34
32
|
|
|
35
33
|
import { z } from 'zod';
|
|
36
34
|
|
|
37
|
-
import type { Contract } from '../contract/contract.js';
|
|
38
35
|
import type {
|
|
39
36
|
FeeEstimationOptions,
|
|
40
37
|
GasSettingsOption,
|
|
@@ -58,22 +55,6 @@ export type Aliased<T> = {
|
|
|
58
55
|
item: T;
|
|
59
56
|
};
|
|
60
57
|
|
|
61
|
-
/**
|
|
62
|
-
* A reduced representation of a Contract, only including its instance and artifact
|
|
63
|
-
*/
|
|
64
|
-
export type ContractInstanceAndArtifact = Pick<Contract, 'artifact' | 'instance'>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Options that can be provided to the wallet for configuration of the fee payment.
|
|
68
|
-
*/
|
|
69
|
-
export type UserFeeOptions = {
|
|
70
|
-
/**
|
|
71
|
-
* Informs the wallet that the crafted tx already contains the necessary calls to pay for its fee
|
|
72
|
-
* and who is paying
|
|
73
|
-
*/
|
|
74
|
-
embeddedPaymentMethodFeePayer?: AztecAddress;
|
|
75
|
-
} & GasSettingsOption;
|
|
76
|
-
|
|
77
58
|
/**
|
|
78
59
|
* Options for simulating interactions with the wallet. Overrides the fee settings of an interaction with
|
|
79
60
|
* a simplified version that only hints at the wallet wether the interaction contains a
|
|
@@ -81,7 +62,7 @@ export type UserFeeOptions = {
|
|
|
81
62
|
*/
|
|
82
63
|
export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
83
64
|
/** The fee options */
|
|
84
|
-
fee?:
|
|
65
|
+
fee?: GasSettingsOption & FeeEstimationOptions;
|
|
85
66
|
};
|
|
86
67
|
|
|
87
68
|
/**
|
|
@@ -91,7 +72,7 @@ export type SimulateOptions = Omit<SimulateInteractionOptions, 'fee'> & {
|
|
|
91
72
|
*/
|
|
92
73
|
export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
93
74
|
/** The fee options */
|
|
94
|
-
fee?:
|
|
75
|
+
fee?: GasSettingsOption;
|
|
95
76
|
};
|
|
96
77
|
|
|
97
78
|
/**
|
|
@@ -101,13 +82,16 @@ export type ProfileOptions = Omit<ProfileInteractionOptions, 'fee'> & {
|
|
|
101
82
|
*/
|
|
102
83
|
export type SendOptions = Omit<SendInteractionOptions, 'fee'> & {
|
|
103
84
|
/** The fee options */
|
|
104
|
-
fee?:
|
|
85
|
+
fee?: GasSettingsOption;
|
|
105
86
|
};
|
|
106
87
|
|
|
107
88
|
/**
|
|
108
89
|
* Helper type that represents all methods that can be batched.
|
|
109
90
|
*/
|
|
110
|
-
export type BatchableMethods = Pick<
|
|
91
|
+
export type BatchableMethods = Pick<
|
|
92
|
+
Wallet,
|
|
93
|
+
'registerContract' | 'sendTx' | 'registerSender' | 'simulateUtility' | 'simulateTx'
|
|
94
|
+
>;
|
|
111
95
|
|
|
112
96
|
/**
|
|
113
97
|
* From the batchable methods, we create a type that represents a method call with its name and arguments.
|
|
@@ -164,43 +148,18 @@ export type Wallet = {
|
|
|
164
148
|
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
165
149
|
getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
166
150
|
registerContract(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
registerContract(
|
|
171
|
-
instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
|
|
172
|
-
artifact: ContractArtifact,
|
|
173
|
-
): Promise<ContractInstanceWithAddress>;
|
|
174
|
-
registerContract(
|
|
175
|
-
instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact,
|
|
176
|
-
artifact: ContractArtifact | undefined,
|
|
177
|
-
secretKey: Fr | undefined,
|
|
151
|
+
instance: ContractInstanceWithAddress,
|
|
152
|
+
artifact?: ContractArtifact,
|
|
153
|
+
secretKey?: Fr,
|
|
178
154
|
): Promise<ContractInstanceWithAddress>;
|
|
179
155
|
simulateTx(exec: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
180
|
-
simulateUtility(
|
|
181
|
-
functionName: string,
|
|
182
|
-
args: any[],
|
|
183
|
-
to: AztecAddress,
|
|
184
|
-
authwits?: AuthWitness[],
|
|
185
|
-
): Promise<UtilitySimulationResult>;
|
|
156
|
+
simulateUtility(call: FunctionCall, authwits?: AuthWitness[]): Promise<UtilitySimulationResult>;
|
|
186
157
|
profileTx(exec: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
187
158
|
sendTx(exec: ExecutionPayload, opts: SendOptions): Promise<TxHash>;
|
|
188
|
-
createAuthWit(
|
|
189
|
-
from: AztecAddress,
|
|
190
|
-
messageHashOrIntent: Fr | Buffer<ArrayBuffer> | IntentInnerHash | CallIntent,
|
|
191
|
-
): Promise<AuthWitness>;
|
|
159
|
+
createAuthWit(from: AztecAddress, messageHashOrIntent: Fr | IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
192
160
|
batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>>;
|
|
193
161
|
};
|
|
194
162
|
|
|
195
|
-
export const ContractInstantiationDataSchema = z.object({
|
|
196
|
-
constructorArtifact: optional(z.union([FunctionAbiSchema, z.string()])),
|
|
197
|
-
constructorArgs: optional(z.array(z.any())),
|
|
198
|
-
skipArgsDecoding: optional(z.boolean()),
|
|
199
|
-
salt: schemas.Fr,
|
|
200
|
-
publicKeys: optional(PublicKeys.schema),
|
|
201
|
-
deployer: optional(schemas.AztecAddress),
|
|
202
|
-
});
|
|
203
|
-
|
|
204
163
|
export const FunctionCallSchema = z.object({
|
|
205
164
|
name: z.string(),
|
|
206
165
|
to: schemas.AztecAddress,
|
|
@@ -217,9 +176,10 @@ export const ExecutionPayloadSchema = z.object({
|
|
|
217
176
|
authWitnesses: z.array(AuthWitness.schema),
|
|
218
177
|
capsules: z.array(Capsule.schema),
|
|
219
178
|
extraHashedArgs: z.array(HashedValues.schema),
|
|
179
|
+
feePayer: optional(schemas.AztecAddress),
|
|
220
180
|
});
|
|
221
181
|
|
|
222
|
-
export const
|
|
182
|
+
export const GasSettingsOptionSchema = z.object({
|
|
223
183
|
gasSettings: optional(
|
|
224
184
|
z.object({
|
|
225
185
|
gasLimits: optional(Gas.schema),
|
|
@@ -228,10 +188,9 @@ export const UserFeeOptionsSchema = z.object({
|
|
|
228
188
|
maxPriorityFeePerGas: optional(z.object({ feePerDaGas: schemas.BigInt, feePerL2Gas: schemas.BigInt })),
|
|
229
189
|
}),
|
|
230
190
|
),
|
|
231
|
-
embeddedPaymentMethodFeePayer: optional(schemas.AztecAddress),
|
|
232
191
|
});
|
|
233
192
|
|
|
234
|
-
export const WalletSimulationFeeOptionSchema =
|
|
193
|
+
export const WalletSimulationFeeOptionSchema = GasSettingsOptionSchema.extend({
|
|
235
194
|
estimatedGasPadding: optional(z.number()),
|
|
236
195
|
estimateGas: optional(z.boolean()),
|
|
237
196
|
});
|
|
@@ -240,7 +199,7 @@ export const SendOptionsSchema = z.object({
|
|
|
240
199
|
from: schemas.AztecAddress,
|
|
241
200
|
authWitnesses: optional(z.array(AuthWitness.schema)),
|
|
242
201
|
capsules: optional(z.array(Capsule.schema)),
|
|
243
|
-
fee: optional(
|
|
202
|
+
fee: optional(GasSettingsOptionSchema),
|
|
244
203
|
});
|
|
245
204
|
|
|
246
205
|
export const SimulateOptionsSchema = z.object({
|
|
@@ -258,17 +217,9 @@ export const ProfileOptionsSchema = SimulateOptionsSchema.extend({
|
|
|
258
217
|
skipProofGeneration: optional(z.boolean()),
|
|
259
218
|
});
|
|
260
219
|
|
|
261
|
-
export const InstanceDataSchema = z.union([
|
|
262
|
-
schemas.AztecAddress,
|
|
263
|
-
ContractInstanceWithAddressSchema,
|
|
264
|
-
ContractInstantiationDataSchema,
|
|
265
|
-
z.object({ instance: ContractInstanceWithAddressSchema, artifact: ContractArtifactSchema }),
|
|
266
|
-
]);
|
|
267
|
-
|
|
268
220
|
export const MessageHashOrIntentSchema = z.union([
|
|
269
221
|
schemas.Fr,
|
|
270
|
-
schemas.
|
|
271
|
-
z.object({ consumer: schemas.AztecAddress, innerHash: z.union([schemas.Buffer, schemas.Fr]) }),
|
|
222
|
+
z.object({ consumer: schemas.AztecAddress, innerHash: schemas.Fr }),
|
|
272
223
|
z.object({
|
|
273
224
|
caller: schemas.AztecAddress,
|
|
274
225
|
call: FunctionCallSchema,
|
|
@@ -282,7 +233,7 @@ export const BatchedMethodSchema = z.union([
|
|
|
282
233
|
}),
|
|
283
234
|
z.object({
|
|
284
235
|
name: z.literal('registerContract'),
|
|
285
|
-
args: z.tuple([
|
|
236
|
+
args: z.tuple([ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr)]),
|
|
286
237
|
}),
|
|
287
238
|
z.object({
|
|
288
239
|
name: z.literal('sendTx'),
|
|
@@ -290,7 +241,11 @@ export const BatchedMethodSchema = z.union([
|
|
|
290
241
|
}),
|
|
291
242
|
z.object({
|
|
292
243
|
name: z.literal('simulateUtility'),
|
|
293
|
-
args: z.tuple([
|
|
244
|
+
args: z.tuple([FunctionCallSchema, optional(z.array(AuthWitness.schema))]),
|
|
245
|
+
}),
|
|
246
|
+
z.object({
|
|
247
|
+
name: z.literal('simulateTx'),
|
|
248
|
+
args: z.tuple([ExecutionPayloadSchema, SimulateOptionsSchema]),
|
|
294
249
|
}),
|
|
295
250
|
]);
|
|
296
251
|
|
|
@@ -335,12 +290,12 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
|
335
290
|
.returns(z.array(z.object({ alias: z.string(), item: schemas.AztecAddress }))),
|
|
336
291
|
registerContract: z
|
|
337
292
|
.function()
|
|
338
|
-
.args(
|
|
293
|
+
.args(ContractInstanceWithAddressSchema, optional(ContractArtifactSchema), optional(schemas.Fr))
|
|
339
294
|
.returns(ContractInstanceWithAddressSchema),
|
|
340
295
|
simulateTx: z.function().args(ExecutionPayloadSchema, SimulateOptionsSchema).returns(TxSimulationResult.schema),
|
|
341
296
|
simulateUtility: z
|
|
342
297
|
.function()
|
|
343
|
-
.args(
|
|
298
|
+
.args(FunctionCallSchema, optional(z.array(AuthWitness.schema)))
|
|
344
299
|
.returns(UtilitySimulationResult.schema),
|
|
345
300
|
profileTx: z.function().args(ExecutionPayloadSchema, ProfileOptionsSchema).returns(TxProfileResult.schema),
|
|
346
301
|
sendTx: z.function().args(ExecutionPayloadSchema, SendOptionsSchema).returns(TxHash.schema),
|
|
@@ -356,6 +311,7 @@ export const WalletSchema: ApiSchemaFor<Wallet> = {
|
|
|
356
311
|
z.object({ name: z.literal('registerContract'), result: ContractInstanceWithAddressSchema }),
|
|
357
312
|
z.object({ name: z.literal('sendTx'), result: TxHash.schema }),
|
|
358
313
|
z.object({ name: z.literal('simulateUtility'), result: UtilitySimulationResult.schema }),
|
|
314
|
+
z.object({ name: z.literal('simulateTx'), result: TxSimulationResult.schema }),
|
|
359
315
|
]),
|
|
360
316
|
),
|
|
361
317
|
),
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
2
|
-
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
3
|
-
import { ExecutionPayload } from '@aztec/entrypoints/payload';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
-
import type { ContractArtifact, EventMetadataDefinition } from '@aztec/stdlib/abi';
|
|
6
|
-
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
7
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { type ContractClassMetadata, type ContractInstanceWithAddress, type ContractInstantiationData, type ContractMetadata } from '@aztec/stdlib/contract';
|
|
9
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
10
|
-
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
11
|
-
import type { TxExecutionRequest, TxHash, TxProfileResult, TxReceipt, TxSimulationResult, UtilitySimulationResult } from '@aztec/stdlib/tx';
|
|
12
|
-
import type { Account } from '../account/account.js';
|
|
13
|
-
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
|
|
14
|
-
import type { CallIntent, IntentInnerHash } from '../utils/authwit.js';
|
|
15
|
-
import type { Aliased, BatchResults, BatchableMethods, BatchedMethod, ContractInstanceAndArtifact, ProfileOptions, SendOptions, SimulateOptions, UserFeeOptions, Wallet } from './wallet.js';
|
|
16
|
-
/**
|
|
17
|
-
* Options to configure fee payment for a transaction
|
|
18
|
-
*/
|
|
19
|
-
export type FeeOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
|
|
22
|
-
* doesn't already include one
|
|
23
|
-
*/
|
|
24
|
-
walletFeePaymentMethod?: FeePaymentMethod;
|
|
25
|
-
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
26
|
-
accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
|
|
27
|
-
/** The gas settings to use for the transaction */
|
|
28
|
-
gasSettings: GasSettings;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* A base class for Wallet implementations
|
|
32
|
-
*/
|
|
33
|
-
export declare abstract class BaseWallet implements Wallet {
|
|
34
|
-
protected readonly pxe: any;
|
|
35
|
-
protected readonly aztecNode: AztecNode;
|
|
36
|
-
protected log: import("@aztec/foundation/log").Logger;
|
|
37
|
-
protected baseFeePadding: number;
|
|
38
|
-
protected cancellableTransactions: boolean;
|
|
39
|
-
protected constructor(pxe: any, aztecNode: AztecNode);
|
|
40
|
-
protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
41
|
-
abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the list of aliased contacts associated with the wallet.
|
|
44
|
-
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
45
|
-
* - Senders: Addresses we check during synching in case they sent us notes,
|
|
46
|
-
* - Contacts: more general concept akin to a phone's contact list.
|
|
47
|
-
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
48
|
-
*/
|
|
49
|
-
getAddressBook(): Promise<Aliased<AztecAddress>[]>;
|
|
50
|
-
getChainInfo(): Promise<ChainInfo>;
|
|
51
|
-
protected createTxExecutionRequestFromPayloadAndFee(executionPayload: ExecutionPayload, from: AztecAddress, feeOptions: FeeOptions): Promise<TxExecutionRequest>;
|
|
52
|
-
createAuthWit(from: AztecAddress, messageHashOrIntent: Fr | Buffer | IntentInnerHash | CallIntent): Promise<AuthWitness>;
|
|
53
|
-
batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>>;
|
|
54
|
-
/**
|
|
55
|
-
* Returns default values for the transaction fee options
|
|
56
|
-
* if they were omitted by the user.
|
|
57
|
-
* @param from - The address where the transaction is being sent from
|
|
58
|
-
* @param userFeeOptions - User-provided fee options, which might be incomplete
|
|
59
|
-
* @returns - Populated fee options that can be used to create a transaction execution request
|
|
60
|
-
*/
|
|
61
|
-
protected getDefaultFeeOptions(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<FeeOptions>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns unreasonably high gas limits in order to execute a simulation
|
|
64
|
-
* with the goal of estimating its gas cost. It will otherwise try to respect
|
|
65
|
-
* the user-specified fee options, filling the gaps with default values as needed.
|
|
66
|
-
* @param from - The address where the transaction is being sent from
|
|
67
|
-
* @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
|
|
68
|
-
*/
|
|
69
|
-
protected getFeeOptionsForGasEstimation(from: AztecAddress, userFeeOptions?: UserFeeOptions): Promise<{
|
|
70
|
-
gasSettings: GasSettings;
|
|
71
|
-
/**
|
|
72
|
-
* A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
|
|
73
|
-
* doesn't already include one
|
|
74
|
-
*/
|
|
75
|
-
walletFeePaymentMethod?: FeePaymentMethod;
|
|
76
|
-
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
77
|
-
accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
|
|
78
|
-
}>;
|
|
79
|
-
registerSender(address: AztecAddress, _alias?: string): Promise<AztecAddress>;
|
|
80
|
-
registerContract(instanceData: AztecAddress | ContractInstanceWithAddress | ContractInstantiationData | ContractInstanceAndArtifact, artifact?: ContractArtifact, secretKey?: Fr): Promise<ContractInstanceWithAddress>;
|
|
81
|
-
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
82
|
-
profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult>;
|
|
83
|
-
sendTx(executionPayload: ExecutionPayload, opts: SendOptions): Promise<TxHash>;
|
|
84
|
-
protected contextualizeError(err: Error, ...context: string[]): Error;
|
|
85
|
-
simulateUtility(functionName: string, args: any[], to: AztecAddress, authwits?: AuthWitness[], from?: AztecAddress): Promise<UtilitySimulationResult>;
|
|
86
|
-
getContractClassMetadata(id: Fr, includeArtifact?: boolean): Promise<ContractClassMetadata>;
|
|
87
|
-
getContractMetadata(address: AztecAddress): Promise<ContractMetadata>;
|
|
88
|
-
getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
|
|
89
|
-
getPrivateEvents<T>(contractAddress: AztecAddress, event: EventMetadataDefinition, from: number, limit: number, recipients?: AztecAddress[]): Promise<T[]>;
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=base_wallet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base_wallet.d.ts","sourceRoot":"","sources":["../../src/wallet/base_wallet.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT } from '@aztec/constants';
|
|
2
|
-
import { AccountFeePaymentMethodOptions } from '@aztec/entrypoints/account';
|
|
3
|
-
import { mergeExecutionPayloads } from '@aztec/entrypoints/payload';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import { computePartialAddress, getContractClassFromArtifact, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
7
|
-
import { SimulationError } from '@aztec/stdlib/errors';
|
|
8
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
9
|
-
import { inspect } from 'util';
|
|
10
|
-
/**
|
|
11
|
-
* A base class for Wallet implementations
|
|
12
|
-
*/ export class BaseWallet {
|
|
13
|
-
pxe;
|
|
14
|
-
aztecNode;
|
|
15
|
-
log;
|
|
16
|
-
baseFeePadding;
|
|
17
|
-
cancellableTransactions;
|
|
18
|
-
// Protected because we want to force wallets to instantiate their own PXE.
|
|
19
|
-
constructor(// TODO: We cannot type here pxe because we cannot import that package as that would result in a circular
|
|
20
|
-
// dependency. This will eventually get resolved by the introduction of @aztec/wallet-sdk package.
|
|
21
|
-
pxe, aztecNode){
|
|
22
|
-
this.pxe = pxe;
|
|
23
|
-
this.aztecNode = aztecNode;
|
|
24
|
-
this.log = createLogger('aztecjs:base_wallet');
|
|
25
|
-
this.baseFeePadding = 0.5;
|
|
26
|
-
this.cancellableTransactions = false;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the list of aliased contacts associated with the wallet.
|
|
30
|
-
* This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
|
|
31
|
-
* - Senders: Addresses we check during synching in case they sent us notes,
|
|
32
|
-
* - Contacts: more general concept akin to a phone's contact list.
|
|
33
|
-
* @returns The aliased collection of AztecAddresses that form this wallet's address book
|
|
34
|
-
*/ async getAddressBook() {
|
|
35
|
-
const senders = await this.pxe.getSenders();
|
|
36
|
-
return senders.map((sender)=>({
|
|
37
|
-
item: sender,
|
|
38
|
-
alias: ''
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
async getChainInfo() {
|
|
42
|
-
const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
|
|
43
|
-
return {
|
|
44
|
-
chainId: new Fr(l1ChainId),
|
|
45
|
-
version: new Fr(rollupVersion)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
async createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions) {
|
|
49
|
-
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
50
|
-
const executionOptions = {
|
|
51
|
-
txNonce: Fr.random(),
|
|
52
|
-
cancellable: this.cancellableTransactions,
|
|
53
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
54
|
-
};
|
|
55
|
-
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
56
|
-
feeExecutionPayload,
|
|
57
|
-
executionPayload
|
|
58
|
-
]) : executionPayload;
|
|
59
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
60
|
-
return fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, executionOptions);
|
|
61
|
-
}
|
|
62
|
-
async createAuthWit(from, messageHashOrIntent) {
|
|
63
|
-
const account = await this.getAccountFromAddress(from);
|
|
64
|
-
return account.createAuthWit(messageHashOrIntent);
|
|
65
|
-
}
|
|
66
|
-
async batch(methods) {
|
|
67
|
-
const results = [];
|
|
68
|
-
for (const method of methods){
|
|
69
|
-
const { name, args } = method;
|
|
70
|
-
// Type safety is guaranteed by the BatchedMethod type, which ensures that:
|
|
71
|
-
// 1. `name` is a valid batchable method name
|
|
72
|
-
// 2. `args` matches the parameter types of that specific method
|
|
73
|
-
// 3. The return type is correctly mapped in BatchResults<T>
|
|
74
|
-
// We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
|
|
75
|
-
const fn = this[name];
|
|
76
|
-
const result = await fn.apply(this, args);
|
|
77
|
-
// Wrap result with method name for discriminated union deserialization
|
|
78
|
-
results.push({
|
|
79
|
-
name,
|
|
80
|
-
result
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return results;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Returns default values for the transaction fee options
|
|
87
|
-
* if they were omitted by the user.
|
|
88
|
-
* @param from - The address where the transaction is being sent from
|
|
89
|
-
* @param userFeeOptions - User-provided fee options, which might be incomplete
|
|
90
|
-
* @returns - Populated fee options that can be used to create a transaction execution request
|
|
91
|
-
*/ async getDefaultFeeOptions(from, userFeeOptions) {
|
|
92
|
-
const maxFeesPerGas = userFeeOptions?.gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentBaseFees()).mul(1 + this.baseFeePadding);
|
|
93
|
-
let accountFeePaymentMethodOptions;
|
|
94
|
-
// The transaction does not include a fee payment method, so we set the flag
|
|
95
|
-
// for the account to use its fee juice balance
|
|
96
|
-
if (!userFeeOptions?.embeddedPaymentMethodFeePayer) {
|
|
97
|
-
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
98
|
-
} else {
|
|
99
|
-
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
100
|
-
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
101
|
-
accountFeePaymentMethodOptions = from.equals(userFeeOptions.embeddedPaymentMethodFeePayer) ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM : AccountFeePaymentMethodOptions.EXTERNAL;
|
|
102
|
-
}
|
|
103
|
-
const gasSettings = GasSettings.default({
|
|
104
|
-
...userFeeOptions?.gasSettings,
|
|
105
|
-
maxFeesPerGas
|
|
106
|
-
});
|
|
107
|
-
this.log.debug(`Using L2 gas settings`, gasSettings);
|
|
108
|
-
return {
|
|
109
|
-
gasSettings,
|
|
110
|
-
walletFeePaymentMethod: undefined,
|
|
111
|
-
accountFeePaymentMethodOptions
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Returns unreasonably high gas limits in order to execute a simulation
|
|
116
|
-
* with the goal of estimating its gas cost. It will otherwise try to respect
|
|
117
|
-
* the user-specified fee options, filling the gaps with default values as needed.
|
|
118
|
-
* @param from - The address where the transaction is being sent from
|
|
119
|
-
* @param userFeeOptions - User-provided fee options to use as a basis for the fully populated `FeeOptions` type.
|
|
120
|
-
*/ async getFeeOptionsForGasEstimation(from, userFeeOptions) {
|
|
121
|
-
const defaultFeeOptions = await this.getDefaultFeeOptions(from, userFeeOptions);
|
|
122
|
-
const { gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas } } = defaultFeeOptions;
|
|
123
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
124
|
-
// They will be tuned down after the simulation.
|
|
125
|
-
const gasSettingsForEstimation = new GasSettings(new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT), new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT), maxFeesPerGas, maxPriorityFeesPerGas);
|
|
126
|
-
return {
|
|
127
|
-
...defaultFeeOptions,
|
|
128
|
-
gasSettings: gasSettingsForEstimation
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
registerSender(address, _alias = '') {
|
|
132
|
-
return this.pxe.registerSender(address);
|
|
133
|
-
}
|
|
134
|
-
async registerContract(instanceData, artifact, secretKey) {
|
|
135
|
-
/** Determines if the provided instance data is already a contract instance with an address. */ function isInstanceWithAddress(instanceData) {
|
|
136
|
-
return instanceData.address !== undefined;
|
|
137
|
-
}
|
|
138
|
-
/** Determines if the provided instance data is contract instantiation data */ function isContractInstantiationData(instanceData) {
|
|
139
|
-
return instanceData.salt !== undefined;
|
|
140
|
-
}
|
|
141
|
-
/** Determines if the provided instance data is already a contract */ function isContractInstanceAndArtifact(instanceData) {
|
|
142
|
-
return instanceData.instance !== undefined && instanceData.artifact !== undefined;
|
|
143
|
-
}
|
|
144
|
-
let instance;
|
|
145
|
-
if (isContractInstanceAndArtifact(instanceData)) {
|
|
146
|
-
instance = instanceData.instance;
|
|
147
|
-
await this.pxe.registerContract(instanceData);
|
|
148
|
-
} else if (isInstanceWithAddress(instanceData)) {
|
|
149
|
-
instance = instanceData;
|
|
150
|
-
await this.pxe.registerContract({
|
|
151
|
-
artifact,
|
|
152
|
-
instance
|
|
153
|
-
});
|
|
154
|
-
} else if (isContractInstantiationData(instanceData)) {
|
|
155
|
-
if (!artifact) {
|
|
156
|
-
throw new Error(`Contract artifact must be provided when registering a contract using instantiation data`);
|
|
157
|
-
}
|
|
158
|
-
instance = await getContractInstanceFromInstantiationParams(artifact, instanceData);
|
|
159
|
-
await this.pxe.registerContract({
|
|
160
|
-
artifact,
|
|
161
|
-
instance
|
|
162
|
-
});
|
|
163
|
-
} else {
|
|
164
|
-
if (!artifact) {
|
|
165
|
-
throw new Error(`Contract artifact must be provided when registering a contract using an address`);
|
|
166
|
-
}
|
|
167
|
-
const { contractInstance: maybeContractInstance } = await this.pxe.getContractMetadata(instanceData);
|
|
168
|
-
if (!maybeContractInstance) {
|
|
169
|
-
throw new Error(`Contract instance at ${instanceData.toString()} has not been registered in the wallet's PXE`);
|
|
170
|
-
}
|
|
171
|
-
instance = maybeContractInstance;
|
|
172
|
-
const thisContractClass = await getContractClassFromArtifact(artifact);
|
|
173
|
-
if (!thisContractClass.id.equals(instance.currentContractClassId)) {
|
|
174
|
-
// wallet holds an outdated version of this contract
|
|
175
|
-
await this.pxe.updateContract(instance.address, artifact);
|
|
176
|
-
instance.currentContractClassId = thisContractClass.id;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (secretKey) {
|
|
180
|
-
await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
|
|
181
|
-
}
|
|
182
|
-
return instance;
|
|
183
|
-
}
|
|
184
|
-
async simulateTx(executionPayload, opts) {
|
|
185
|
-
const feeOptions = opts.fee?.estimateGas ? await this.getFeeOptionsForGasEstimation(opts.from, opts.fee) : await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
186
|
-
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
187
|
-
return this.pxe.simulateTx(txRequest, true, opts?.skipTxValidation, opts?.skipFeeEnforcement ?? true);
|
|
188
|
-
}
|
|
189
|
-
async profileTx(executionPayload, opts) {
|
|
190
|
-
const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
191
|
-
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
|
|
192
|
-
return this.pxe.profileTx(txRequest, opts.profileMode, opts.skipProofGeneration ?? true);
|
|
193
|
-
}
|
|
194
|
-
async sendTx(executionPayload, opts) {
|
|
195
|
-
const fee = await this.getDefaultFeeOptions(opts.from, opts.fee);
|
|
196
|
-
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, fee);
|
|
197
|
-
const provenTx = await this.pxe.proveTx(txRequest);
|
|
198
|
-
const tx = await provenTx.toTx();
|
|
199
|
-
const txHash = tx.getTxHash();
|
|
200
|
-
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
201
|
-
throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
|
|
202
|
-
}
|
|
203
|
-
this.log.debug(`Sending transaction ${txHash}`);
|
|
204
|
-
await this.aztecNode.sendTx(tx).catch((err)=>{
|
|
205
|
-
throw this.contextualizeError(err, inspect(tx));
|
|
206
|
-
});
|
|
207
|
-
this.log.info(`Sent transaction ${txHash}`);
|
|
208
|
-
return txHash;
|
|
209
|
-
}
|
|
210
|
-
contextualizeError(err, ...context) {
|
|
211
|
-
let contextStr = '';
|
|
212
|
-
if (context.length > 0) {
|
|
213
|
-
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
214
|
-
}
|
|
215
|
-
if (err instanceof SimulationError) {
|
|
216
|
-
err.setAztecContext(contextStr);
|
|
217
|
-
} else {
|
|
218
|
-
this.log.error(err.name, err);
|
|
219
|
-
this.log.debug(contextStr);
|
|
220
|
-
}
|
|
221
|
-
return err;
|
|
222
|
-
}
|
|
223
|
-
simulateUtility(functionName, args, to, authwits, from) {
|
|
224
|
-
return this.pxe.simulateUtility(functionName, args, to, authwits, from);
|
|
225
|
-
}
|
|
226
|
-
getContractClassMetadata(id, includeArtifact = false) {
|
|
227
|
-
return this.pxe.getContractClassMetadata(id, includeArtifact);
|
|
228
|
-
}
|
|
229
|
-
getContractMetadata(address) {
|
|
230
|
-
return this.pxe.getContractMetadata(address);
|
|
231
|
-
}
|
|
232
|
-
getTxReceipt(txHash) {
|
|
233
|
-
return this.aztecNode.getTxReceipt(txHash);
|
|
234
|
-
}
|
|
235
|
-
getPrivateEvents(contractAddress, event, from, limit, recipients = []) {
|
|
236
|
-
return this.pxe.getPrivateEvents(contractAddress, event, from, limit, recipients);
|
|
237
|
-
}
|
|
238
|
-
}
|