aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts79
1 files changed, 33 insertions, 46 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 2d0878afc..ead0ee407 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -127,6 +127,8 @@ import {
codecForRecoverStoredBackupRequest,
codecForTestingSetTimetravelRequest,
setDangerousTimetravel,
+ TestingWaitTransactionRequest,
+ codecForUpdateExchangeEntryRequest,
} from "@gnu-taler/taler-util";
import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http";
import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
@@ -198,7 +200,6 @@ import {
downloadTosFromAcceptedFormat,
getExchangeDetails,
getExchangeRequestTimeout,
- provideExchangeRecordInTx,
updateExchangeFromUrl,
updateExchangeFromUrlHandler,
} from "./operations/exchanges.js";
@@ -250,6 +251,7 @@ import {
runIntegrationTest,
runIntegrationTest2,
testPay,
+ waitTransactionState,
waitUntilDone,
waitUntilRefreshesDone,
withdrawTestBalance,
@@ -532,10 +534,12 @@ async function fillDefaults(ws: InternalWalletState): Promise<void> {
logger.trace("defaults already applied");
return;
}
- for (const baseUrl of ws.config.builtin.exchanges) {
- await addPresetExchangeEntry(tx, baseUrl);
- const now = AbsoluteTime.now();
- provideExchangeRecordInTx(ws, tx, baseUrl, now);
+ for (const exch of ws.config.builtin.exchanges) {
+ await addPresetExchangeEntry(
+ tx,
+ exch.exchangeBaseUrl,
+ exch.currencyHint,
+ );
}
await tx.config.put({
key: ConfigRecordKey.CurrencyDefaultsApplied,
@@ -923,9 +927,9 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> {
ageCommitmentProof: c.ageCommitmentProof,
spend_allocation: c.spendAllocation
? {
- amount: c.spendAllocation.amount,
- id: c.spendAllocation.id,
- }
+ amount: c.spendAllocation.amount,
+ id: c.spendAllocation.id,
+ }
: undefined,
});
}
@@ -1069,8 +1073,7 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
case WalletApiOperation.WithdrawTestkudos: {
await withdrawTestBalance(ws, {
amount: "TESTKUDOS:10",
- bankAccessApiBaseUrl:
- "https://bank.test.taler.net/demobanks/default/access-api/",
+ corebankApiBaseUrl: "https://bank.test.taler.net/",
exchangeBaseUrl: "https://exchange.test.taler.net/",
});
return {
@@ -1120,6 +1123,11 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
});
return {};
}
+ case WalletApiOperation.UpdateExchangeEntry: {
+ const req = codecForUpdateExchangeEntryRequest().decode(payload);
+ await updateExchangeFromUrl(ws, req.exchangeBaseUrl, {});
+ return {};
+ }
case WalletApiOperation.ListExchanges: {
return await getExchanges(ws);
}
@@ -1261,7 +1269,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
`templates/${url.templateId}`,
url.merchantBaseUrl,
);
- const httpReq = await ws.http.postJson(reqUrl.href, templateDetails);
+ const httpReq = await ws.http.fetch(reqUrl.href, {
+ method: "POST",
+ body: templateDetails,
+ });
const resp = await readSuccessResponseJsonOrThrow(
httpReq,
codecForMerchantPostOrderResponse(),
@@ -1411,6 +1422,11 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
const resp = await getBackupRecovery(ws);
return resp;
}
+ case WalletApiOperation.TestingWaitTransactionState: {
+ const req = payload as TestingWaitTransactionRequest;
+ await waitTransactionState(ws, req.transactionId, req.txState);
+ return {};
+ }
case WalletApiOperation.GetScopedCurrencyInfo: {
// Ignore result, just validate in this mock implementation
codecForGetCurrencyInfoRequest().decode(payload);
@@ -1489,40 +1505,6 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
trustedExchanges: [],
};
}
- case WalletApiOperation.WithdrawFakebank: {
- const req = codecForWithdrawFakebankRequest().decode(payload);
- const amount = Amounts.parseOrThrow(req.amount);
- const details = await getExchangeWithdrawalInfo(
- ws,
- req.exchange,
- amount,
- undefined,
- );
- const wres = await createManualWithdrawal(ws, {
- amount: amount,
- exchangeBaseUrl: req.exchange,
- });
- const paytoUri = details.exchangePaytoUris[0];
- const pt = parsePaytoUri(paytoUri);
- if (!pt) {
- throw Error("failed to parse payto URI");
- }
- const components = pt.targetPath.split("/");
- const creditorAcct = components[components.length - 1];
- logger.info(`making testbank transfer to '${creditorAcct}'`);
- const fbReq = await ws.http.postJson(
- new URL(`${creditorAcct}/admin/add-incoming`, req.bank).href,
- {
- amount: Amounts.stringify(amount),
- reserve_pub: wres.reservePub,
- debit_account:
- "payto://x-taler-bank/localhost/testdebtor?receiver-name=Foo",
- },
- );
- const fbResp = await readSuccessResponseJsonOrThrow(fbReq, codecForAny());
- logger.info(`started fakebank withdrawal: ${j2s(fbResp)}`);
- return {};
- }
case WalletApiOperation.TestCrypto: {
return await ws.cryptoApi.hashString({ str: "hello world" });
}
@@ -1691,7 +1673,12 @@ export class Wallet {
public static defaultConfig: Readonly<WalletConfig> = {
builtin: {
- exchanges: ["https://exchange.demo.taler.net/"],
+ exchanges: [
+ {
+ exchangeBaseUrl: "https://exchange.demo.taler.net/",
+ currencyHint: "KUDOS",
+ },
+ ],
},
features: {
allowHttp: false,