*use logger

This commit is contained in:
Derrick Hammer 2022-12-07 04:27:19 -05:00
parent 30f48f81ac
commit 7fabe8e61d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 7 deletions

View File

@ -6,9 +6,11 @@ import SPVNode from "hsd/lib/node/spvnode.js";
// @ts-ignore // @ts-ignore
import { NodeClient } from "hs-client"; import { NodeClient } from "hs-client";
async function boot(config: any) { async function boot(api: PluginAPI) {
let hsdServer: SPVNode; let hsdServer: SPVNode;
const { config } = api;
let clientArgs = { let clientArgs = {
network: "main", network: "main",
host: "127.0.0.1", host: "127.0.0.1",
@ -33,20 +35,20 @@ async function boot(config: any) {
}); });
hsdServer.on("abort", async (err: any) => { hsdServer.on("abort", async (err: any) => {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
console.error("Shutdown is taking a long time. Exiting."); api.logger.error("Shutdown is taking a long time. Exiting.");
process.exit(3); process.exit(3);
}, 5000); }, 5000);
timeout.unref(); timeout.unref();
try { try {
console.error("Shutting down..."); api.logger.error("Shutting down...");
await hsdServer.close(); await hsdServer.close();
clearTimeout(timeout); clearTimeout(timeout);
console.error((err as Error).stack); api.logger.error((err as Error).stack);
process.exit(2); process.exit(2);
} catch (e: any) { } catch (e: any) {
console.error( api.logger.error(
`Error occurred during shutdown: ${(e as Error).message}` `Error occurred during shutdown: ${(e as Error).message}`
); );
process.exit(3); process.exit(3);
@ -61,7 +63,7 @@ async function boot(config: any) {
hsdServer.startSync(); hsdServer.startSync();
} catch (e: any) { } catch (e: any) {
console.error((e as Error).stack); api.logger.error((e as Error).stack);
} }
})(); })();
} else { } else {
@ -79,7 +81,7 @@ async function boot(config: any) {
const plugin: Plugin = { const plugin: Plugin = {
name: "handshake", name: "handshake",
async plugin(api: PluginAPI): Promise<void> { async plugin(api: PluginAPI): Promise<void> {
const client = await boot(api.config); const client = await boot(api);
api.registerMethod("getnameresource", { api.registerMethod("getnameresource", {
cacheable: true, cacheable: true,