|
1 | 1 | import { EcdsaRAccountContract, EcdsaRSSHAccountContract } from '@aztec/accounts/ecdsa'; |
2 | 2 | import { SchnorrAccountContract } from '@aztec/accounts/schnorr'; |
3 | | -import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec/accounts/stub/ecdsa'; |
4 | | -import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr'; |
| 3 | +import { createStubAccountForAccountType, getStubArtifactForAccountType } from '@aztec/accounts/stub'; |
5 | 4 | import { getIdentities } from '@aztec/accounts/utils'; |
6 | 5 | import { type Account, type AccountContract, NO_FROM } from '@aztec/aztec.js/account'; |
7 | 6 | import { type InteractionFeeOptions, getContractClassFromArtifact, getGasLimits } from '@aztec/aztec.js/contracts'; |
@@ -32,10 +31,10 @@ import { printGasEstimates } from './options/fees.js'; |
32 | 31 | export class CLIWallet extends BaseWallet { |
33 | 32 | private accountCache = new Map<string, Account>(); |
34 | 33 | /** |
35 | | - * Per-stub-flavor cache of the stub class id and preimage. The Promise is stored (not the resolved |
| 34 | + * Per-account-type cache of the stub class id and preimage. The Promise is stored (not the resolved |
36 | 35 | * value) so concurrent first-time callers dedupe on the same hashing + registration work. |
37 | 36 | */ |
38 | | - #stubClasses = new Map<'schnorr' | 'ecdsa', Promise<ContractClassWithId & ContractClassIdPreimage>>(); |
| 37 | + #stubClasses = new Map<AccountType, Promise<ContractClassWithId & ContractClassIdPreimage>>(); |
39 | 38 |
|
40 | 39 | constructor( |
41 | 40 | pxe: PXE, |
@@ -204,27 +203,26 @@ export class CLIWallet extends BaseWallet { |
204 | 203 | throw new Error(`No contract instance found for address: ${originalAddress.address}`); |
205 | 204 | } |
206 | 205 | const { type } = await this.db!.retrieveAccount(address); |
207 | | - const isSchnorr = type === 'schnorr'; |
208 | | - const stubAccount = isSchnorr ? createStubSchnorrAccount(originalAddress) : createStubEcdsaAccount(originalAddress); |
209 | | - const { id: stubClassId } = await this.#getStubClass(isSchnorr ? 'schnorr' : 'ecdsa'); |
| 206 | + const stubAccount = createStubAccountForAccountType(type, originalAddress); |
| 207 | + const { id: stubClassId } = await this.#getStubClass(type); |
210 | 208 | const instance = { ...contractInstance, currentContractClassId: stubClassId }; |
211 | 209 | return { account: stubAccount, instance }; |
212 | 210 | } |
213 | 211 |
|
214 | 212 | /** |
215 | | - * Lazily hashes and registers the stub class for the given flavor, caching the result so |
| 213 | + * Lazily hashes and registers the stub class for the given account type, caching the result so |
216 | 214 | * subsequent simulations skip the artifact-hashing + registration round-trip. |
217 | 215 | */ |
218 | | - #getStubClass(flavor: 'schnorr' | 'ecdsa'): Promise<ContractClassWithId & ContractClassIdPreimage> { |
219 | | - let cached = this.#stubClasses.get(flavor); |
| 216 | + #getStubClass(type: AccountType): Promise<ContractClassWithId & ContractClassIdPreimage> { |
| 217 | + let cached = this.#stubClasses.get(type); |
220 | 218 | if (!cached) { |
221 | 219 | cached = (async () => { |
222 | | - const artifact = flavor === 'schnorr' ? StubSchnorrAccountContractArtifact : StubEcdsaAccountContractArtifact; |
| 220 | + const artifact = getStubArtifactForAccountType(type); |
223 | 221 | const stubClass = await getContractClassFromArtifact(artifact); |
224 | 222 | await this.pxe.registerContractClass(artifact); |
225 | 223 | return stubClass; |
226 | 224 | })(); |
227 | | - this.#stubClasses.set(flavor, cached); |
| 225 | + this.#stubClasses.set(type, cached); |
228 | 226 | } |
229 | 227 | return cached; |
230 | 228 | } |
|
0 commit comments