wallet-core pretty
This commit is contained in:
parent
417c07f3f4
commit
14f3d1e06d
@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
import test from "ava";
|
import test from "ava";
|
||||||
import { CryptoDispatcher, CryptoWorkerFactory } from "./crypto-dispatcher.js";
|
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 { SynchronousCryptoWorkerFactoryNode } from "./synchronousWorkerFactoryNode.js";
|
||||||
import { processRequestWithImpl } from "./worker-common.js";
|
import { processRequestWithImpl } from "./worker-common.js";
|
||||||
|
|
||||||
|
|
||||||
export class MyCryptoWorker implements CryptoWorker {
|
export class MyCryptoWorker implements CryptoWorker {
|
||||||
/**
|
/**
|
||||||
* Function to be called when we receive a message from the worker thread.
|
* Function to be called when we receive a message from the worker thread.
|
||||||
@ -64,8 +66,8 @@ export class MyCryptoWorker implements CryptoWorker {
|
|||||||
type: "success",
|
type: "success",
|
||||||
result: {
|
result: {
|
||||||
testResult: 42,
|
testResult: 42,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
} else if (msg.operation === "testError") {
|
} else if (msg.operation === "testError") {
|
||||||
responseMsg = {
|
responseMsg = {
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
@ -73,8 +75,8 @@ export class MyCryptoWorker implements CryptoWorker {
|
|||||||
error: {
|
error: {
|
||||||
code: 42,
|
code: 42,
|
||||||
hint: "bla",
|
hint: "bla",
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
} else if (msg.operation === "testTimeout") {
|
} else if (msg.operation === "testTimeout") {
|
||||||
// Don't respond
|
// Don't respond
|
||||||
return;
|
return;
|
||||||
@ -98,8 +100,6 @@ export class MyCryptoWorker implements CryptoWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class MyCryptoWorkerFactory implements CryptoWorkerFactory {
|
export class MyCryptoWorkerFactory implements CryptoWorkerFactory {
|
||||||
startWorker(): CryptoWorker {
|
startWorker(): CryptoWorker {
|
||||||
return new MyCryptoWorker();
|
return new MyCryptoWorker();
|
||||||
@ -111,12 +111,10 @@ export class MyCryptoWorkerFactory implements CryptoWorkerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("continues after error", async (t) => {
|
test("continues after error", async (t) => {
|
||||||
const cryptoDisp = new CryptoDispatcher(
|
const cryptoDisp = new CryptoDispatcher(new MyCryptoWorkerFactory());
|
||||||
new MyCryptoWorkerFactory(),
|
|
||||||
);
|
|
||||||
const resp1 = await cryptoDisp.doRpc("testSuccess", 0, {});
|
const resp1 = await cryptoDisp.doRpc("testSuccess", 0, {});
|
||||||
t.assert((resp1 as any).testResult === 42);
|
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, {});
|
const resp2 = await cryptoDisp.doRpc("testError", 0, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -308,11 +308,7 @@ export class CryptoDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doRpc<T>(
|
doRpc<T>(operation: string, priority: number, req: unknown): Promise<T> {
|
||||||
operation: string,
|
|
||||||
priority: number,
|
|
||||||
req: unknown,
|
|
||||||
): Promise<T> {
|
|
||||||
if (this.stopped) {
|
if (this.stopped) {
|
||||||
throw new CryptoApiStoppedError();
|
throw new CryptoApiStoppedError();
|
||||||
}
|
}
|
||||||
@ -364,7 +360,9 @@ export class CryptoDispatcher {
|
|||||||
const onTimeout = () => {
|
const onTimeout = () => {
|
||||||
// FIXME: Maybe destroy and re-init worker if request is in processing
|
// FIXME: Maybe destroy and re-init worker if request is in processing
|
||||||
// state and really taking too long?
|
// 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);
|
timeoutHandle = timer.after(timeoutMs, onTimeout);
|
||||||
};
|
};
|
||||||
myProm.promise
|
myProm.promise
|
||||||
|
@ -27,7 +27,9 @@ import { processRequestWithImpl } from "./worker-common.js";
|
|||||||
|
|
||||||
const logger = new Logger("nodeThreadWorker.ts");
|
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 = `
|
const workerCode = `
|
||||||
// Try loading the glue library for embedded
|
// Try loading the glue library for embedded
|
||||||
|
@ -839,8 +839,8 @@ export enum RefreshOperationStatus {
|
|||||||
* Group of refresh operations. The refreshed coins do not
|
* Group of refresh operations. The refreshed coins do not
|
||||||
* have to belong to the same exchange, but must have the same
|
* have to belong to the same exchange, but must have the same
|
||||||
* currency.
|
* 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.
|
* but we need to write a migration for that.
|
||||||
*/
|
*/
|
||||||
export interface RefreshGroupRecord {
|
export interface RefreshGroupRecord {
|
||||||
@ -857,7 +857,7 @@ export interface RefreshGroupRecord {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Currency of this refresh group.
|
* Currency of this refresh group.
|
||||||
*
|
*
|
||||||
* FIXME: Write a migration to add this to earlier DB versions.
|
* FIXME: Write a migration to add this to earlier DB versions.
|
||||||
*/
|
*/
|
||||||
currency: string;
|
currency: string;
|
||||||
|
@ -778,7 +778,9 @@ export async function importBackup(
|
|||||||
timestampFinished: backupRefreshGroup.timestamp_finish,
|
timestampFinished: backupRefreshGroup.timestamp_finish,
|
||||||
timestampCreated: backupRefreshGroup.timestamp_created,
|
timestampCreated: backupRefreshGroup.timestamp_created,
|
||||||
refreshGroupId: backupRefreshGroup.refresh_group_id,
|
refreshGroupId: backupRefreshGroup.refresh_group_id,
|
||||||
currency: Amounts.currencyOf(backupRefreshGroup.old_coins[0].input_amount),
|
currency: Amounts.currencyOf(
|
||||||
|
backupRefreshGroup.old_coins[0].input_amount,
|
||||||
|
),
|
||||||
reason,
|
reason,
|
||||||
lastErrorPerCoin: {},
|
lastErrorPerCoin: {},
|
||||||
oldCoinPubs: backupRefreshGroup.old_coins.map((x) => x.coin_pub),
|
oldCoinPubs: backupRefreshGroup.old_coins.map((x) => x.coin_pub),
|
||||||
|
@ -175,7 +175,7 @@ export async function spendCoins(
|
|||||||
await tx.coins.put(coin);
|
await tx.coins.put(coin);
|
||||||
await tx.coinAvailability.put(coinAvailability);
|
await tx.coinAvailability.put(coinAvailability);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ws.refreshOps.createRefreshGroup(
|
await ws.refreshOps.createRefreshGroup(
|
||||||
ws,
|
ws,
|
||||||
tx,
|
tx,
|
||||||
|
Loading…
Reference in New Issue
Block a user