diff options
Diffstat (limited to 'packages/taler-wallet-core/src/deposits.ts')
-rw-r--r-- | packages/taler-wallet-core/src/deposits.ts | 221 |
1 files changed, 105 insertions, 116 deletions
diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts index 9db8cfc27..3abb614bd 100644 --- a/packages/taler-wallet-core/src/deposits.ts +++ b/packages/taler-wallet-core/src/deposits.ts @@ -109,7 +109,11 @@ import { notifyTransition, parseTransactionIdentifier, } from "./transactions.js"; -import { InternalWalletState, getDenomInfo } from "./wallet.js"; +import { + InternalWalletState, + WalletExecutionContext, + getDenomInfo, +} from "./wallet.js"; import { getCandidateWithdrawalDenomsTx } from "./withdraw.js"; /** @@ -122,7 +126,7 @@ export class DepositTransactionContext implements TransactionContext { readonly taskId: TaskIdStr; constructor( - public ws: InternalWalletState, + public wex: WalletExecutionContext, public depositGroupId: string, ) { this.transactionId = constructTransactionIdentifier({ @@ -137,7 +141,7 @@ export class DepositTransactionContext implements TransactionContext { async deleteTransaction(): Promise<void> { const depositGroupId = this.depositGroupId; - const ws = this.ws; + const ws = this.wex; // FIXME: We should check first if we are in a final state // where deletion is allowed. await ws.db.runReadWriteTx(["depositGroups", "tombstones"], async (tx) => { @@ -153,8 +157,8 @@ export class DepositTransactionContext implements TransactionContext { } async suspendTransaction(): Promise<void> { - const { ws, depositGroupId, transactionId, taskId: retryTag } = this; - const transitionInfo = await ws.db.runReadWriteTx( + const { wex, depositGroupId, transactionId, taskId: retryTag } = this; + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -191,13 +195,13 @@ export class DepositTransactionContext implements TransactionContext { }; }, ); - ws.taskScheduler.stopShepherdTask(retryTag); - notifyTransition(ws, transactionId, transitionInfo); + wex.taskScheduler.stopShepherdTask(retryTag); + notifyTransition(wex, transactionId, transitionInfo); } async abortTransaction(): Promise<void> { - const { ws, depositGroupId, transactionId, taskId: retryTag } = this; - const transitionInfo = await ws.db.runReadWriteTx( + const { wex, depositGroupId, transactionId, taskId: retryTag } = this; + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -224,17 +228,17 @@ export class DepositTransactionContext implements TransactionContext { return undefined; }, ); - ws.taskScheduler.stopShepherdTask(retryTag); - notifyTransition(ws, transactionId, transitionInfo); - ws.taskScheduler.startShepherdTask(retryTag); - ws.notify({ + wex.taskScheduler.stopShepherdTask(retryTag); + notifyTransition(wex, transactionId, transitionInfo); + wex.taskScheduler.startShepherdTask(retryTag); + wex.ws.notify({ type: NotificationType.BalanceChange, hintTransactionId: transactionId, }); } async resumeTransaction(): Promise<void> { - const { ws, depositGroupId, transactionId, taskId: retryTag } = this; + const { wex: ws, depositGroupId, transactionId, taskId: retryTag } = this; const transitionInfo = await ws.db.runReadWriteTx( ["depositGroups"], async (tx) => { @@ -277,8 +281,8 @@ export class DepositTransactionContext implements TransactionContext { } async failTransaction(): Promise<void> { - const { ws, depositGroupId, transactionId, taskId: retryTag } = this; - const transitionInfo = await ws.db.runReadWriteTx( + const { wex, depositGroupId, transactionId, taskId } = this; + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -303,9 +307,9 @@ export class DepositTransactionContext implements TransactionContext { return undefined; }, ); - ws.taskScheduler.stopShepherdTask(retryTag); - notifyTransition(ws, transactionId, transitionInfo); - ws.notify({ + wex.taskScheduler.stopShepherdTask(taskId); + notifyTransition(wex, transactionId, transitionInfo); + wex.ws.notify({ type: NotificationType.BalanceChange, hintTransactionId: transactionId, }); @@ -410,9 +414,8 @@ export function computeDepositTransactionActions( } async function refundDepositGroup( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, - cancellationToken: CancellationToken, ): Promise<TaskRunResult> { const newTxPerCoin = [...depositGroup.statusPerCoin]; logger.info(`status per coin: ${j2s(depositGroup.statusPerCoin)}`); @@ -424,7 +427,7 @@ async function refundDepositGroup( break; default: { const coinPub = depositGroup.payCoinSelection.coinPubs[i]; - const coinExchange = await ws.db.runReadOnlyTx( + const coinExchange = await wex.db.runReadOnlyTx( ["coins"], async (tx) => { const coinRecord = await tx.coins.get(coinPub); @@ -436,7 +439,7 @@ async function refundDepositGroup( // We use a constant refund transaction ID, since there can // only be one refund. const rtid = 1; - const sig = await ws.cryptoApi.signRefund({ + const sig = await wex.cryptoApi.signRefund({ coinPub, contractTermsHash: depositGroup.contractTermsHash, merchantPriv: depositGroup.merchantPriv, @@ -452,10 +455,10 @@ async function refundDepositGroup( rtransaction_id: rtid, }; const refundUrl = new URL(`coins/${coinPub}/refund`, coinExchange); - const httpResp = await ws.http.fetch(refundUrl.href, { + const httpResp = await wex.http.fetch(refundUrl.href, { method: "POST", body: refundReq, - cancellationToken, + cancellationToken: wex.cancellationToken, }); logger.info( `coin ${i} refund HTTP status for coin: ${httpResp.status}`, @@ -486,7 +489,7 @@ async function refundDepositGroup( const currency = Amounts.currencyOf(depositGroup.totalPayCost); - const res = await ws.db.runReadWriteTx( + const res = await wex.db.runReadWriteTx( [ "depositGroups", "refreshGroups", @@ -510,7 +513,7 @@ async function refundDepositGroup( let refreshRes: CreateRefreshGroupResult | undefined = undefined; if (isDone) { refreshRes = await createRefreshGroup( - ws, + wex, tx, currency, refreshCoins, @@ -529,7 +532,7 @@ async function refundDepositGroup( if (res?.refreshRes) { for (const notif of res.refreshRes.notifications) { - ws.notify(notif); + wex.ws.notify(notif); } } @@ -550,7 +553,7 @@ async function refundDepositGroup( * transaction of processDepositGroup? */ async function waitForRefreshOnDepositGroup( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, ): Promise<TaskRunResult> { const abortRefreshGroupId = depositGroup.abortRefreshGroupId; @@ -559,7 +562,7 @@ async function waitForRefreshOnDepositGroup( tag: TransactionType.Deposit, depositGroupId: depositGroup.depositGroupId, }); - const transitionInfo = await ws.db.runReadWriteTx( + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups", "refreshGroups"], async (tx) => { const refreshGroup = await tx.refreshGroups.get(abortRefreshGroupId); @@ -593,8 +596,8 @@ async function waitForRefreshOnDepositGroup( }, ); - notifyTransition(ws, transactionId, transitionInfo); - ws.notify({ + notifyTransition(wex, transactionId, transitionInfo); + wex.ws.notify({ type: NotificationType.BalanceChange, hintTransactionId: transactionId, }); @@ -602,24 +605,22 @@ async function waitForRefreshOnDepositGroup( } async function processDepositGroupAborting( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, - cancellationToken: CancellationToken, ): Promise<TaskRunResult> { logger.info("processing deposit tx in 'aborting'"); const abortRefreshGroupId = depositGroup.abortRefreshGroupId; if (!abortRefreshGroupId) { logger.info("refunding deposit group"); - return refundDepositGroup(ws, depositGroup, cancellationToken); + return refundDepositGroup(wex, depositGroup); } logger.info("waiting for refresh"); - return waitForRefreshOnDepositGroup(ws, depositGroup); + return waitForRefreshOnDepositGroup(wex, depositGroup); } async function processDepositGroupPendingKyc( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, - cancellationToken: CancellationToken, ): Promise<TaskRunResult> { const { depositGroupId } = depositGroup; const transactionId = constructTransactionIdentifier({ @@ -640,9 +641,9 @@ async function processDepositGroupPendingKyc( ); url.searchParams.set("timeout_ms", "10000"); logger.info(`kyc url ${url.href}`); - const kycStatusRes = await ws.http.fetch(url.href, { + const kycStatusRes = await wex.http.fetch(url.href, { method: "GET", - cancellationToken, + cancellationToken: wex.cancellationToken, }); if ( kycStatusRes.status === HttpStatusCode.Ok || @@ -650,7 +651,7 @@ async function processDepositGroupPendingKyc( // remove after the exchange is fixed or clarified kycStatusRes.status === HttpStatusCode.NoContent ) { - const transitionInfo = await ws.db.runReadWriteTx( + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const newDg = await tx.depositGroups.get(depositGroupId); @@ -667,7 +668,7 @@ async function processDepositGroupPendingKyc( return { oldTxState, newTxState }; }, ); - notifyTransition(ws, transactionId, transitionInfo); + notifyTransition(wex, transactionId, transitionInfo); } else if (kycStatusRes.status === HttpStatusCode.Accepted) { // FIXME: Do we have to update the URL here? } else { @@ -682,7 +683,7 @@ async function processDepositGroupPendingKyc( * and transition the transaction to the KYC required state. */ async function transitionToKycRequired( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, kycInfo: KycPendingInfo, exchangeUrl: string, @@ -700,7 +701,7 @@ async function transitionToKycRequired( exchangeUrl, ); logger.info(`kyc url ${url.href}`); - const kycStatusReq = await ws.http.fetch(url.href, { + const kycStatusReq = await wex.http.fetch(url.href, { method: "GET", }); if (kycStatusReq.status === HttpStatusCode.Ok) { @@ -709,7 +710,7 @@ async function transitionToKycRequired( } else if (kycStatusReq.status === HttpStatusCode.Accepted) { const kycStatus = await kycStatusReq.json(); logger.info(`kyc status: ${j2s(kycStatus)}`); - const transitionInfo = await ws.db.runReadWriteTx( + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -731,7 +732,7 @@ async function transitionToKycRequired( return { oldTxState, newTxState }; }, ); - notifyTransition(ws, transactionId, transitionInfo); + notifyTransition(wex, transactionId, transitionInfo); return TaskRunResult.finished(); } else { throw Error(`unexpected response from kyc-check (${kycStatusReq.status})`); @@ -739,15 +740,14 @@ async function transitionToKycRequired( } async function processDepositGroupPendingTrack( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, - cancellationToken: CancellationToken, ): Promise<TaskRunResult> { const { depositGroupId } = depositGroup; for (let i = 0; i < depositGroup.statusPerCoin.length; i++) { const coinPub = depositGroup.payCoinSelection.coinPubs[i]; // FIXME: Make the URL part of the coin selection? - const exchangeBaseUrl = await ws.db.runReadWriteTx( + const exchangeBaseUrl = await wex.db.runReadWriteTx( ["coins"], async (tx) => { const coinRecord = await tx.coins.get(coinPub); @@ -766,11 +766,10 @@ async function processDepositGroupPendingTrack( if (depositGroup.statusPerCoin[i] !== DepositElementStatus.Wired) { const track = await trackDeposit( - ws, + wex, depositGroup, coinPub, exchangeBaseUrl, - cancellationToken, ); if (track.type === "accepted") { @@ -784,7 +783,7 @@ async function processDepositGroupPendingTrack( requirementRow, }; return transitionToKycRequired( - ws, + wex, depositGroup, kycInfo, exchangeBaseUrl, @@ -801,7 +800,7 @@ async function processDepositGroupPendingTrack( } const fee = await getExchangeWireFee( - ws, + wex, payto.targetType, exchangeBaseUrl, track.execution_time, @@ -825,7 +824,7 @@ async function processDepositGroupPendingTrack( } if (updatedTxStatus !== undefined) { - await ws.db.runReadWriteTx(["depositGroups"], async (tx) => { + await wex.db.runReadWriteTx(["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); if (!dg) { return; @@ -855,7 +854,7 @@ async function processDepositGroupPendingTrack( let allWired = true; - const transitionInfo = await ws.db.runReadWriteTx( + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -884,9 +883,9 @@ async function processDepositGroupPendingTrack( tag: TransactionType.Deposit, depositGroupId, }); - notifyTransition(ws, transactionId, transitionInfo); + notifyTransition(wex, transactionId, transitionInfo); if (allWired) { - ws.notify({ + wex.ws.notify({ type: NotificationType.BalanceChange, hintTransactionId: transactionId, }); @@ -899,13 +898,13 @@ async function processDepositGroupPendingTrack( } async function processDepositGroupPendingDeposit( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, cancellationToken?: CancellationToken, ): Promise<TaskRunResult> { logger.info("processing deposit group in pending(deposit)"); const depositGroupId = depositGroup.depositGroupId; - const contractTermsRec = await ws.db.runReadOnlyTx( + const contractTermsRec = await wex.db.runReadOnlyTx( ["contractTerms"], async (tx) => { return tx.contractTerms.get(depositGroup.contractTermsHash); @@ -932,7 +931,7 @@ async function processDepositGroupPendingDeposit( // FIXME: Cache these! const depositPermissions = await generateDepositPermissions( - ws, + wex, depositGroup.payCoinSelection, contractData, ); @@ -981,7 +980,7 @@ async function processDepositGroupPendingDeposit( const url = new URL(`batch-deposit`, exchangeUrl); logger.info(`depositing to ${url.href}`); logger.trace(`deposit request: ${j2s(batchReq)}`); - const httpResp = await ws.http.fetch(url.href, { + const httpResp = await wex.http.fetch(url.href, { method: "POST", body: batchReq, cancellationToken: cancellationToken, @@ -991,7 +990,7 @@ async function processDepositGroupPendingDeposit( codecForBatchDepositSuccess(), ); - await ws.db.runReadWriteTx(["depositGroups"], async (tx) => { + await wex.db.runReadWriteTx(["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); if (!dg) { return; @@ -1007,7 +1006,7 @@ async function processDepositGroupPendingDeposit( }); } - const transitionInfo = await ws.db.runReadWriteTx( + const transitionInfo = await wex.db.runReadWriteTx( ["depositGroups"], async (tx) => { const dg = await tx.depositGroups.get(depositGroupId); @@ -1022,7 +1021,7 @@ async function processDepositGroupPendingDeposit( }, ); - notifyTransition(ws, transactionId, transitionInfo); + notifyTransition(wex, transactionId, transitionInfo); return TaskRunResult.progress(); } @@ -1030,11 +1029,10 @@ async function processDepositGroupPendingDeposit( * Process a deposit group that is not in its final state yet. */ export async function processDepositGroup( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroupId: string, - cancellationToken: CancellationToken, ): Promise<TaskRunResult> { - const depositGroup = await ws.db.runReadOnlyTx( + const depositGroup = await wex.db.runReadOnlyTx( ["depositGroups"], async (tx) => { return tx.depositGroups.get(depositGroupId); @@ -1047,21 +1045,13 @@ export async function processDepositGroup( switch (depositGroup.operationStatus) { case DepositOperationStatus.PendingTrack: - return processDepositGroupPendingTrack( - ws, - depositGroup, - cancellationToken, - ); + return processDepositGroupPendingTrack(wex, depositGroup); case DepositOperationStatus.PendingKyc: - return processDepositGroupPendingKyc(ws, depositGroup, cancellationToken); + return processDepositGroupPendingKyc(wex, depositGroup); case DepositOperationStatus.PendingDeposit: - return processDepositGroupPendingDeposit( - ws, - depositGroup, - cancellationToken, - ); + return processDepositGroupPendingDeposit(wex, depositGroup); case DepositOperationStatus.Aborting: - return processDepositGroupAborting(ws, depositGroup, cancellationToken); + return processDepositGroupAborting(wex, depositGroup); } return TaskRunResult.finished(); @@ -1071,12 +1061,12 @@ export async function processDepositGroup( * FIXME: Consider moving this to exchanges.ts. */ async function getExchangeWireFee( - ws: InternalWalletState, + wex: WalletExecutionContext, wireType: string, baseUrl: string, time: TalerProtocolTimestamp, ): Promise<WireFee> { - const exchangeDetails = await ws.db.runReadOnlyTx( + const exchangeDetails = await wex.db.runReadOnlyTx( ["exchangeDetails", "exchanges"], async (tx) => { const ex = await tx.exchanges.get(baseUrl); @@ -1116,11 +1106,10 @@ async function getExchangeWireFee( } async function trackDeposit( - ws: InternalWalletState, + wex: WalletExecutionContext, depositGroup: DepositGroupRecord, coinPub: string, exchangeUrl: string, - cancellationToken: CancellationToken, ): Promise<TrackTransaction> { const wireHash = hashWire( depositGroup.wire.payto_uri, @@ -1131,7 +1120,7 @@ async function trackDeposit( `deposits/${wireHash}/${depositGroup.merchantPub}/${depositGroup.contractTermsHash}/${coinPub}`, exchangeUrl, ); - const sigResp = await ws.cryptoApi.signTrackTransaction({ + const sigResp = await wex.cryptoApi.signTrackTransaction({ coinPub, contractTermsHash: depositGroup.contractTermsHash, merchantPriv: depositGroup.merchantPriv, @@ -1141,9 +1130,9 @@ async function trackDeposit( url.searchParams.set("merchant_sig", sigResp.sig); // Not doing long-polling yet as it looks like it's broken in the exchange (2024-02-20) // url.searchParams.set("timeout_ms", "30000"); - const httpResp = await ws.http.fetch(url.href, { + const httpResp = await wex.http.fetch(url.href, { method: "GET", - cancellationToken, + cancellationToken: wex.cancellationToken, }); logger.trace(`deposits response status: ${httpResp.status}`); switch (httpResp.status) { @@ -1177,7 +1166,7 @@ async function trackDeposit( * as it doesn't prepare anything */ export async function prepareDepositGroup( - ws: InternalWalletState, + wex: WalletExecutionContext, req: PrepareDepositRequest, ): Promise<PrepareDepositResponse> { const p = parsePaytoUri(req.depositPaytoUri); @@ -1188,7 +1177,7 @@ export async function prepareDepositGroup( const exchangeInfos: { url: string; master_pub: string }[] = []; - await ws.db.runReadOnlyTx(["exchangeDetails", "exchanges"], async (tx) => { + await wex.db.runReadOnlyTx(["exchangeDetails", "exchanges"], async (tx) => { const allExchanges = await tx.exchanges.iter().toArray(); for (const e of allExchanges) { const details = await getExchangeWireDetailsInTx(tx, e.baseUrl); @@ -1227,7 +1216,7 @@ export async function prepareDepositGroup( refund_deadline: TalerProtocolTimestamp.zero(), }; - const { h: contractTermsHash } = await ws.cryptoApi.hashString({ + const { h: contractTermsHash } = await wex.cryptoApi.hashString({ str: canonicalJson(contractTerms), }); @@ -1237,7 +1226,7 @@ export async function prepareDepositGroup( "", ); - const payCoinSel = await selectPayCoinsNew(ws, { + const payCoinSel = await selectPayCoinsNew(wex, { auditors: [], exchanges: contractData.allowedExchanges, wireMethod: contractData.wireMethod, @@ -1257,16 +1246,16 @@ export async function prepareDepositGroup( ); } - const totalDepositCost = await getTotalPaymentCost(ws, payCoinSel.coinSel); + const totalDepositCost = await getTotalPaymentCost(wex, payCoinSel.coinSel); const effectiveDepositAmount = await getCounterpartyEffectiveDepositAmount( - ws, + wex, p.targetType, payCoinSel.coinSel, ); const fees = await getTotalFeesForDepositAmount( - ws, + wex, p.targetType, amount, payCoinSel.coinSel, @@ -1288,7 +1277,7 @@ export function generateDepositGroupTxId(): string { } export async function createDepositGroup( - ws: InternalWalletState, + wex: WalletExecutionContext, req: CreateDepositGroupRequest, ): Promise<CreateDepositGroupResponse> { const p = parsePaytoUri(req.depositPaytoUri); @@ -1300,7 +1289,7 @@ export async function createDepositGroup( const exchangeInfos: { url: string; master_pub: string }[] = []; - await ws.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { + await wex.db.runReadOnlyTx(["exchanges", "exchangeDetails"], async (tx) => { const allExchanges = await tx.exchanges.iter().toArray(); for (const e of allExchanges) { const details = await getExchangeWireDetailsInTx(tx, e.baseUrl); @@ -1319,8 +1308,8 @@ export async function createDepositGroup( AbsoluteTime.addDuration(now, Duration.fromSpec({ minutes: 5 })), ); const nowRounded = AbsoluteTime.toProtocolTimestamp(now); - const noncePair = await ws.cryptoApi.createEddsaKeypair({}); - const merchantPair = await ws.cryptoApi.createEddsaKeypair({}); + const noncePair = await wex.cryptoApi.createEddsaKeypair({}); + const merchantPair = await wex.cryptoApi.createEddsaKeypair({}); const wireSalt = encodeCrock(getRandomBytes(16)); const wireHash = hashWire(req.depositPaytoUri, wireSalt); const contractTerms: MerchantContractTerms = { @@ -1346,7 +1335,7 @@ export async function createDepositGroup( refund_deadline: TalerProtocolTimestamp.zero(), }; - const { h: contractTermsHash } = await ws.cryptoApi.hashString({ + const { h: contractTermsHash } = await wex.cryptoApi.hashString({ str: canonicalJson(contractTerms), }); @@ -1356,7 +1345,7 @@ export async function createDepositGroup( "", ); - const payCoinSel = await selectPayCoinsNew(ws, { + const payCoinSel = await selectPayCoinsNew(wex, { auditors: [], exchanges: contractData.allowedExchanges, wireMethod: contractData.wireMethod, @@ -1376,7 +1365,7 @@ export async function createDepositGroup( ); } - const totalDepositCost = await getTotalPaymentCost(ws, payCoinSel.coinSel); + const totalDepositCost = await getTotalPaymentCost(wex, payCoinSel.coinSel); let depositGroupId: string; if (req.transactionId) { @@ -1391,7 +1380,7 @@ export async function createDepositGroup( const infoPerExchange: Record<string, DepositInfoPerExchange> = {}; - await ws.db.runReadOnlyTx(["coins"], async (tx) => { + await wex.db.runReadOnlyTx(["coins"], async (tx) => { for (let i = 0; i < payCoinSel.coinSel.coinPubs.length; i++) { const coin = await tx.coins.get(payCoinSel.coinSel.coinPubs[i]); if (!coin) { @@ -1415,7 +1404,7 @@ export async function createDepositGroup( const counterpartyEffectiveDepositAmount = await getCounterpartyEffectiveDepositAmount( - ws, + wex, p.targetType, payCoinSel.coinSel, ); @@ -1453,10 +1442,10 @@ export async function createDepositGroup( infoPerExchange, }; - const ctx = new DepositTransactionContext(ws, depositGroupId); + const ctx = new DepositTransactionContext(wex, depositGroupId); const transactionId = ctx.transactionId; - const newTxState = await ws.db.runReadWriteTx( + const newTxState = await wex.db.runReadWriteTx( [ "depositGroups", "coins", @@ -1467,7 +1456,7 @@ export async function createDepositGroup( "contractTerms", ], async (tx) => { - await spendCoins(ws, tx, { + await spendCoins(wex, tx, { allocationId: transactionId, coinPubs: payCoinSel.coinSel.coinPubs, contributions: payCoinSel.coinSel.coinContributions.map((x) => @@ -1484,7 +1473,7 @@ export async function createDepositGroup( }, ); - ws.notify({ + wex.ws.notify({ type: NotificationType.TransactionStateTransition, transactionId, oldTxState: { @@ -1493,12 +1482,12 @@ export async function createDepositGroup( newTxState, }); - ws.notify({ + wex.ws.notify({ type: NotificationType.BalanceChange, hintTransactionId: transactionId, }); - ws.taskScheduler.startShepherdTask(ctx.taskId); + wex.taskScheduler.startShepherdTask(ctx.taskId); return { depositGroupId, @@ -1511,7 +1500,7 @@ export async function createDepositGroup( * account after depositing, not considering aggregation. */ export async function getCounterpartyEffectiveDepositAmount( - ws: InternalWalletState, + wex: WalletExecutionContext, wireType: string, pcs: PayCoinSelection, ): Promise<AmountJson> { @@ -1519,7 +1508,7 @@ export async function getCounterpartyEffectiveDepositAmount( const fees: AmountJson[] = []; const exchangeSet: Set<string> = new Set(); - await ws.db.runReadOnlyTx( + await wex.db.runReadOnlyTx( ["coins", "denominations", "exchangeDetails", "exchanges"], async (tx) => { for (let i = 0; i < pcs.coinPubs.length; i++) { @@ -1528,7 +1517,7 @@ export async function getCounterpartyEffectiveDepositAmount( throw Error("can't calculate deposit amount, coin not found"); } const denom = await getDenomInfo( - ws, + wex, tx, coin.exchangeBaseUrl, coin.denomPubHash, @@ -1574,7 +1563,7 @@ export async function getCounterpartyEffectiveDepositAmount( * specified amount using the selected coins and the wire method. */ async function getTotalFeesForDepositAmount( - ws: InternalWalletState, + wex: WalletExecutionContext, wireType: string, total: AmountJson, pcs: PayCoinSelection, @@ -1585,7 +1574,7 @@ async function getTotalFeesForDepositAmount( const exchangeSet: Set<string> = new Set(); const currency = Amounts.currencyOf(total); - await ws.db.runReadOnlyTx( + await wex.db.runReadOnlyTx( ["coins", "denominations", "exchanges", "exchangeDetails"], async (tx) => { for (let i = 0; i < pcs.coinPubs.length; i++) { @@ -1594,7 +1583,7 @@ async function getTotalFeesForDepositAmount( throw Error("can't calculate deposit amount, coin not found"); } const denom = await getDenomInfo( - ws, + wex, tx, coin.exchangeBaseUrl, coin.denomPubHash, @@ -1606,7 +1595,7 @@ async function getTotalFeesForDepositAmount( exchangeSet.add(coin.exchangeBaseUrl); const allDenoms = await getCandidateWithdrawalDenomsTx( - ws, + wex, tx, coin.exchangeBaseUrl, currency, @@ -1619,7 +1608,7 @@ async function getTotalFeesForDepositAmount( allDenoms, denom, amountLeft, - ws.config.testing.denomselAllowLate, + wex.ws.config.testing.denomselAllowLate, ); refreshFee.push(refreshCost); } |