wallet-core pretty

This commit is contained in:
Sebastian 2023-01-09 08:33:41 -03:00
parent 417c07f3f4
commit 14f3d1e06d
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
6 changed files with 24 additions and 24 deletions

View File

@ -16,11 +16,13 @@
import test from "ava";
import { CryptoDispatcher, CryptoWorkerFactory } from "./crypto-dispatcher.js";
import { CryptoWorker, CryptoWorkerResponseMessage } from "./cryptoWorkerInterface.js";
import {
CryptoWorker,
CryptoWorkerResponseMessage,
} from "./cryptoWorkerInterface.js";
import { SynchronousCryptoWorkerFactoryNode } from "./synchronousWorkerFactoryNode.js";
import { processRequestWithImpl } from "./worker-common.js";
export class MyCryptoWorker implements CryptoWorker {
/**
* Function to be called when we receive a message from the worker thread.
@ -64,8 +66,8 @@ export class MyCryptoWorker implements CryptoWorker {
type: "success",
result: {
testResult: 42,
}
}
},
};
} else if (msg.operation === "testError") {
responseMsg = {
id: msg.id,
@ -73,8 +75,8 @@ export class MyCryptoWorker implements CryptoWorker {
error: {
code: 42,
hint: "bla",
}
}
},
};
} else if (msg.operation === "testTimeout") {
// Don't respond
return;
@ -98,8 +100,6 @@ export class MyCryptoWorker implements CryptoWorker {
}
}
export class MyCryptoWorkerFactory implements CryptoWorkerFactory {
startWorker(): CryptoWorker {
return new MyCryptoWorker();
@ -111,12 +111,10 @@ export class MyCryptoWorkerFactory implements CryptoWorkerFactory {
}
test("continues after error", async (t) => {
const cryptoDisp = new CryptoDispatcher(
new MyCryptoWorkerFactory(),
);
const cryptoDisp = new CryptoDispatcher(new MyCryptoWorkerFactory());
const resp1 = await cryptoDisp.doRpc("testSuccess", 0, {});
t.assert((resp1 as any).testResult === 42);
const exc = await t.throwsAsync(async() => {
const exc = await t.throwsAsync(async () => {
const resp2 = await cryptoDisp.doRpc("testError", 0, {});
});

View File

@ -308,11 +308,7 @@ export class CryptoDispatcher {
}
}
doRpc<T>(
operation: string,
priority: number,
req: unknown,
): Promise<T> {
doRpc<T>(operation: string, priority: number, req: unknown): Promise<T> {
if (this.stopped) {
throw new CryptoApiStoppedError();
}
@ -364,7 +360,9 @@ export class CryptoDispatcher {
const onTimeout = () => {
// FIXME: Maybe destroy and re-init worker if request is in processing
// state and really taking too long?
logger.warn(`crypto RPC call ('${operation}') has been queued for a long time`);
logger.warn(
`crypto RPC call ('${operation}') has been queued for a long time`,
);
timeoutHandle = timer.after(timeoutMs, onTimeout);
};
myProm.promise

View File

@ -27,7 +27,9 @@ import { processRequestWithImpl } from "./worker-common.js";
const logger = new Logger("nodeThreadWorker.ts");
const f = import.meta.url ? url.fileURLToPath(import.meta.url) : '__not_available__';
const f = import.meta.url
? url.fileURLToPath(import.meta.url)
: "__not_available__";
const workerCode = `
// Try loading the glue library for embedded

View File

@ -839,8 +839,8 @@ export enum RefreshOperationStatus {
* Group of refresh operations. The refreshed coins do not
* have to belong to the same exchange, but must have the same
* currency.
*
* FIXME: Should include the currency as a top-level field,
*
* FIXME: Should include the currency as a top-level field,
* but we need to write a migration for that.
*/
export interface RefreshGroupRecord {
@ -857,7 +857,7 @@ export interface RefreshGroupRecord {
/**
* Currency of this refresh group.
*
*
* FIXME: Write a migration to add this to earlier DB versions.
*/
currency: string;

View File

@ -778,7 +778,9 @@ export async function importBackup(
timestampFinished: backupRefreshGroup.timestamp_finish,
timestampCreated: backupRefreshGroup.timestamp_created,
refreshGroupId: backupRefreshGroup.refresh_group_id,
currency: Amounts.currencyOf(backupRefreshGroup.old_coins[0].input_amount),
currency: Amounts.currencyOf(
backupRefreshGroup.old_coins[0].input_amount,
),
reason,
lastErrorPerCoin: {},
oldCoinPubs: backupRefreshGroup.old_coins.map((x) => x.coin_pub),

View File

@ -175,7 +175,7 @@ export async function spendCoins(
await tx.coins.put(coin);
await tx.coinAvailability.put(coinAvailability);
}
await ws.refreshOps.createRefreshGroup(
ws,
tx,