Skip to content

Commit a009b62

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/barretenberg
2 parents 3a8e555 + 9ce04f0 commit a009b62

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

yarn-project/cli-wallet/src/storage/wallet_db.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ export class WalletDB {
7070
return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
7171
}
7272

73+
async peekBridgedFeeJuice(recipient: AztecAddress, log: LogFn) {
74+
const stackPointer =
75+
(await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:stackPointer`))?.readInt8() || 0;
76+
const result = await this.#bridgedFeeJuice.getAsync(`${recipient.toString()}:${stackPointer}`);
77+
if (!result) {
78+
throw new Error(
79+
`No stored fee juice available for recipient ${recipient.toString()}. Please provide claim amount and secret. Stack pointer ${stackPointer}`,
80+
);
81+
}
82+
const [amountStr, secretStr, leafIndexStr] = result.toString().split(':');
83+
log(`Peeked ${amountStr} fee juice for recipient ${recipient.toString()}. Stack pointer ${stackPointer}`);
84+
return { amount: BigInt(amountStr), secret: secretStr, leafIndex: BigInt(leafIndexStr) };
85+
}
86+
7387
async storeAccount(
7488
address: AztecAddress,
7589
{

yarn-project/cli-wallet/src/utils/options/fees.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function parsePaymentMethod(
115115
payment: string,
116116
log: LogFn,
117117
db?: WalletDB,
118+
estimateOnly?: boolean,
118119
): (wallet: Wallet, from: AztecAddress, gasSettings: GasSettings) => Promise<FeePaymentMethod | undefined> {
119120
const parsed = payment.split(',').reduce(
120121
(acc, item) => {
@@ -149,7 +150,7 @@ export function parsePaymentMethod(
149150
amount: claimAmount,
150151
secret: claimSecret,
151152
leafIndex: messageLeafIndex,
152-
} = await db.popBridgedFeeJuice(from, log));
153+
} = estimateOnly ? await db.peekBridgedFeeJuice(from, log) : await db.popBridgedFeeJuice(from, log));
153154
} else {
154155
({ claimAmount, claimSecret, messageLeafIndex } = parsed);
155156
}
@@ -266,9 +267,10 @@ export class CLIFeeArgs {
266267
}
267268

268269
static parse(args: RawCliFeeArgs, log: LogFn, db?: WalletDB): CLIFeeArgs {
270+
const estimateOnly = !!args.estimateGasOnly;
269271
return new CLIFeeArgs(
270-
!!args.estimateGasOnly,
271-
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db),
272+
estimateOnly,
273+
parsePaymentMethod(args.payment ?? 'method=fee_juice', log, db, estimateOnly),
272274
parseGasSettings(args),
273275
);
274276
}

0 commit comments

Comments
 (0)