diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-05 19:38:19 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-05 19:38:19 +0100 |
commit | f67d7f54f9d0fed97446898942e3dfee67ee2985 (patch) | |
tree | 2b81738025e8f61250ede10908cbf81071e16975 /src/headless | |
parent | 829acdd3d98f1014747f15ecb619b6fbaa06b640 (diff) | |
download | wallet-core-f67d7f54f9d0fed97446898942e3dfee67ee2985.tar.xz |
threads, retries and notifications WIP
Diffstat (limited to 'src/headless')
-rw-r--r-- | src/headless/helpers.ts | 44 | ||||
-rw-r--r-- | src/headless/integrationtest.ts | 6 | ||||
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 4 |
3 files changed, 18 insertions, 36 deletions
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts index e5338369e..cfc7e3695 100644 --- a/src/headless/helpers.ts +++ b/src/headless/helpers.ts @@ -21,35 +21,22 @@ /** * Imports. */ -import { Wallet, OperationFailedAndReportedError } from "../wallet"; -import { Notifier, Badge } from "../walletTypes"; +import { Wallet } from "../wallet"; import { MemoryBackend, BridgeIDBFactory, shimIndexedDB } from "idb-bridge"; -import { SynchronousCryptoWorkerFactory } from "../crypto/synchronousWorker"; import { openTalerDb } from "../db"; import Axios from "axios"; -import querystring = require("querystring"); import { HttpRequestLibrary } from "../util/http"; import * as amounts from "../util/amounts"; import { Bank } from "./bank"; import fs = require("fs"); -import { NodeCryptoWorkerFactory } from "../crypto/nodeProcessWorker"; import { Logger } from "../util/logging"; +import { NodeThreadCryptoWorkerFactory } from "../crypto/workers/nodeThreadWorker"; +import { NotificationType } from "../walletTypes"; const logger = new Logger("helpers.ts"); -class ConsoleBadge implements Badge { - startBusy(): void { - } - stopBusy(): void { - } - showNotification(): void { - } - clearNotification(): void { - } -} - export class NodeHttpLib implements HttpRequestLibrary { async get(url: string): Promise<import("../util/http").HttpResponse> { try { @@ -97,7 +84,6 @@ export interface DefaultNodeWalletArgs { */ persistentStoragePath?: string; - /** * Handler for asynchronous notifications from the wallet. */ @@ -116,15 +102,7 @@ export interface DefaultNodeWalletArgs { export async function getDefaultNodeWallet( args: DefaultNodeWalletArgs = {}, ): Promise<Wallet> { - const myNotifier: Notifier = { - notify() { - if (args.notifyHandler) { - args.notifyHandler(""); - } - } - } - const myBadge = new ConsoleBadge(); BridgeIDBFactory.enableTracing = false; const myBackend = new MemoryBackend(); @@ -180,14 +158,14 @@ export async function getDefaultNodeWallet( myUnsupportedUpgrade, ); - const worker = new SynchronousCryptoWorkerFactory(); + //const worker = new SynchronousCryptoWorkerFactory(); //const worker = new NodeCryptoWorkerFactory(); + const worker = new NodeThreadCryptoWorkerFactory(); + return new Wallet( myDb, myHttpLib, - myBadge, - myNotifier, worker, ); } @@ -217,6 +195,14 @@ export async function withdrawTestBalance( ["x-taler-bank"], ); + const donePromise = new Promise((resolve, reject) => { + myWallet.addNotificationListener((n) => { + if (n.type === NotificationType.ReserveDepleted && n.reservePub === reservePub ) { + resolve(); + } + }); + }); + await bank.createReserve( bankUser, amount, @@ -225,5 +211,5 @@ export async function withdrawTestBalance( ); await myWallet.confirmReserve({ reservePub: reserveResponse.reservePub }); - await myWallet.runUntilReserveDepleted(reservePub); + await donePromise; } diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts index 91adfaa6d..632ce8f60 100644 --- a/src/headless/integrationtest.ts +++ b/src/headless/integrationtest.ts @@ -82,9 +82,5 @@ export async function runIntegrationTest(args: { throw Error("payment did not succeed"); } - await myWallet.runPending(); - //const refreshRes = await myWallet.refreshDirtyCoins(); - //console.log(`waited to refresh ${refreshRes.numRefreshed} coins`); - - myWallet.stop(); + await myWallet.runUntilDone(); } diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 9598b9d98..931cac087 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -19,14 +19,14 @@ import fs = require("fs"); import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers"; import { MerchantBackendConnection } from "./merchant"; import { runIntegrationTest } from "./integrationtest"; -import { Wallet, OperationFailedAndReportedError } from "../wallet"; +import { Wallet } from "../wallet"; import qrcodeGenerator = require("qrcode-generator"); import * as clk from "./clk"; import { BridgeIDBFactory, MemoryBackend } from "idb-bridge"; import { Logger } from "../util/logging"; import * as Amounts from "../util/amounts"; import { decodeCrock } from "../crypto/talerCrypto"; -import { Bank } from "./bank"; +import { OperationFailedAndReportedError } from "../wallet-impl/errors"; const logger = new Logger("taler-wallet-cli.ts"); |