@spirobel/monero-wallet-api 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  import { coordinatorMainMultithreaded } from "../scanresult/scanCoordination";
2
+ import { log } from "../../io/logging";
2
3
  export async function coordinatorMainWorker(scan_settings_path, pathPrefix, cpuPorts) {
3
- console.log("[coordinatorMainWorker] cpuPorts=" + cpuPorts?.length);
4
+ log("coordinatorMainWorker", "cpuPorts=" + cpuPorts?.length);
4
5
  try {
5
6
  const gen = coordinatorMainMultithreaded(scan_settings_path, pathPrefix, cpuPorts);
6
7
  for await (const event of gen) {
7
- // console.log("event:", event);
8
+ log("coordinatorMainWorker", ["event:", event]);
8
9
  if (event.type === "scan_ready") {
9
10
  self.postMessage({
10
11
  type: "SCAN_RESULT",
@@ -1,4 +1,5 @@
1
1
  import { sleep, ViewPair } from "../../api";
2
+ import { log } from "../../io/logging";
2
3
  import {} from "../scanresult/scanLoop";
3
4
  /**
4
5
  * handle a single scan work item dispatched from the coordinator.
@@ -7,24 +8,24 @@ import {} from "../scanresult/scanLoop";
7
8
  let callcounter = 0;
8
9
  export async function handleCpuboundScan(msg, port) {
9
10
  callcounter++;
10
- console.log("[cpubound] callcounter=" + callcounter);
11
+ log("handleCpuboundScan", "callcounter=" + callcounter);
11
12
  if (!msg) {
12
- console.log("[cpubound] no content msg! ( ScanLoopInput = undefined )");
13
+ log("handleCpuboundScan", "no content msg! ( ScanLoopInput = undefined )");
13
14
  throw new Error("[cpubound] no content msg! ( ScanLoopInput = undefined )");
14
15
  }
15
16
  if (msg === "cancel") {
16
- console.log("[cpubound] cancel msg! ( ScanLoopInput = cancel )");
17
+ log("handleCpuboundScan", "cancel msg! ( ScanLoopInput = cancel )");
17
18
  throw new Error("[cpubound] no content msg! ( ScanLoopInput = undefined )");
18
19
  }
19
- console.log("[cpubound] got scan msg, walletConfig=" +
20
+ log("handleCpuboundScan", "got scan msg, walletConfig=" +
20
21
  msg.walletConfig?.primary_address?.slice(0, 6));
21
22
  const walletConfig = msg.walletConfig;
22
23
  const item = msg;
23
24
  if (!port) {
24
- console.log("[cpubound] no port!");
25
+ log("handleCpuboundScan", "no port!");
25
26
  throw new Error("[cpubound] no port");
26
27
  }
27
- console.log("[cpubound] primed, feeding workItem uuid=" +
28
+ log("handleCpuboundScan", "primed, feeding workItem uuid=" +
28
29
  (item && typeof item === "object"
29
30
  ? item.work_uuid?.slice(0, 8)
30
31
  : "cancel"));
@@ -78,17 +79,26 @@ export async function handleCpuboundScan(msg, port) {
78
79
  // the reconciliation workitembuffer -> blocksbuffer is done on every workitembuffer marked done at the end of the workbuffer (left end)
79
80
  blockCount++;
80
81
  if (blockCount % 10 === 0) {
81
- console.log("[cpubound] scanned " +
82
- blockCount +
83
- " " +
84
- walletConfig.primary_address.slice(0, 6), "@", heighfrom, "-", heightto);
82
+ log("handleCpuboundScan", [
83
+ "scanned " +
84
+ blockCount +
85
+ " " +
86
+ walletConfig.primary_address.slice(0, 6),
87
+ "@",
88
+ heighfrom,
89
+ "-",
90
+ heightto,
91
+ ]);
85
92
  }
86
93
  await sleep(10); // make sure the loop is not tight
87
94
  }
88
- console.log("[cpubound] scan done " +
89
- blockCount +
90
- " " +
91
- walletConfig.primary_address.slice(0, 6), "@", heighfrom, "-", heightto);
95
+ log("handleCpuboundScan", [
96
+ "scan done " + blockCount + " " + walletConfig.primary_address.slice(0, 6),
97
+ "@",
98
+ heighfrom,
99
+ "-",
100
+ heightto,
101
+ ]);
92
102
  return {
93
103
  type: "Ready",
94
104
  work_uuid: item.work_uuid,
@@ -1,5 +1,7 @@
1
1
  import { coordinatorMainWorker } from "./coordinator-main";
2
- import { handleCpuboundScan, handleCpuboundScanTry, sendFromCpuWorker, } from "./cpubound-main";
2
+ import { handleCpuboundScanTry, sendFromCpuWorker } from "./cpubound-main";
3
+ import { log, setupLoggingPath } from "../../io/logging";
4
+ import { SCAN_SETTINGS_STORE_NAME_DEFAULT } from "../scanSettings";
3
5
  self.onerror = (e) => self.postMessage({ type: "ERROR", payload: e });
4
6
  self.addEventListener("unhandledrejection", (e) => self.postMessage({ type: "ERROR", payload: e.reason }));
5
7
  let SCAN_SETTINGS_PATH;
@@ -8,13 +10,13 @@ let cpuPort;
8
10
  export function CPU_PORT_HANDLER(pe) {
9
11
  if (!cpuPort)
10
12
  throw new Error("[cpubound] cpuPort is undefined in port.onmessage");
11
- console.log("[cpubound] new workitem msg received");
13
+ log("CPU_PORT_HANDLER", "new workitem msg received");
12
14
  cpuPort.postMessage({
13
15
  type: "WORKSTART",
14
16
  work_uuid: pe.data.work_uuid,
15
17
  });
16
18
  handleCpuboundScanTry(pe.data, cpuPort).then((result) => {
17
- console.log("[cpubound] work finished, sending result");
19
+ log("CPU_PORT_HANDLER", "work finished, sending result");
18
20
  if (!cpuPort)
19
21
  throw new Error("[cpubound] cpuPort is undefined in port.onmessage");
20
22
  cpuPort.onmessage = CPU_PORT_HANDLER;
@@ -23,19 +25,21 @@ export function CPU_PORT_HANDLER(pe) {
23
25
  }
24
26
  const handleMessage = async (e) => {
25
27
  const msg = e.data;
26
- console.log("[worker] msg received", msg);
28
+ log("handleMessage", ["msg received", msg]);
27
29
  if (msg.type === "setup") {
28
- SCAN_SETTINGS_PATH = msg.scan_settings_path;
30
+ const settingsPath = msg.scan_settings_path || SCAN_SETTINGS_STORE_NAME_DEFAULT;
31
+ SCAN_SETTINGS_PATH = settingsPath;
29
32
  PATH_PREFIX = msg.pathPrefix;
33
+ await setupLoggingPath(settingsPath, msg.pathPrefix ?? "", msg.role, msg.cpu_worker_id);
30
34
  if (msg.role === "cpubound") {
31
35
  cpuPort = e.ports[0];
32
36
  if (cpuPort) {
33
37
  cpuPort.onmessage = CPU_PORT_HANDLER;
34
38
  cpuPort.addEventListener("message", (e) => {
35
- console.log("[cpubound] message received", e);
39
+ log("handleMessage", ["message received", e]);
36
40
  });
37
41
  cpuPort.addEventListener("messageerror", (e) => {
38
- console.log("[cpubound] messageerror received", e);
42
+ log("handleMessage", ["messageerror received", e]);
39
43
  });
40
44
  }
41
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spirobel/monero-wallet-api",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "main": "dist/api.js",
5
5
  "module": "dist/api.js",
6
6
  "devDependencies": {