From c0f03d11b67c3b6536461d910ebe2f131376cea7 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 25 Feb 2022 21:25:29 +0100 Subject: [PATCH] fix(core): update --- ts/bobcat.classes.bobcat.ts | 23 +++++++++++------------ ts/interfaces/index.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 ts/interfaces/index.ts diff --git a/ts/bobcat.classes.bobcat.ts b/ts/bobcat.classes.bobcat.ts index 3a94f10..a4caba9 100644 --- a/ts/bobcat.classes.bobcat.ts +++ b/ts/bobcat.classes.bobcat.ts @@ -1,4 +1,5 @@ import * as plugins from './bobcat.plugins'; +import * as interfaces from './interfaces'; /** * maps to an individual bobcat miner @@ -8,11 +9,14 @@ export class Bobcat { public static async createFromNetworkAddress(networkAddressArg: string) { const newBobcat = new Bobcat(networkAddressArg); await newBobcat.gatherMinerDetails(); + await newBobcat.checkMinerStatus(); return newBobcat; } // INSTANCE public networkAddress: string; + public latestStatus: interfaces.IMinerStatus; + public latestMinerDetails: interfaces.IMinerDetailsResponse constructor(networkAddressArg: string) { this.networkAddress = networkAddressArg; @@ -23,23 +27,18 @@ export class Bobcat { */ public async checkMinerStatus() { const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`); - const body: { - "status": string, - "gap": string, - "miner_height": string, - "blockchain_height": string, - "epoch": "rpc" - } = response.body; - return response; + const body: interfaces.IMinerStatus = response.body; + this.latestStatus = body; + return this.latestStatus; } /** * gathers the miner details */ public async gatherMinerDetails() { - const response: { - - } = plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`); - + const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`); + const body: interfaces.IMinerDetailsResponse = response.body; + this.latestMinerDetails = body; + return this.latestMinerDetails; } } \ No newline at end of file diff --git a/ts/interfaces/index.ts b/ts/interfaces/index.ts new file mode 100644 index 0000000..d026b26 --- /dev/null +++ b/ts/interfaces/index.ts @@ -0,0 +1,35 @@ +export interface IMinerStatus { + status: string; + gap: string; + miner_height: string; + blockchain_height: string; + epoch: 'rpc'; +} + +export interface IMinerDetailsResponse { + ota_version: string; + region: 'region_eu868'; + frequency_plan: 'eu868'; + animal: string; + pubkey: string; + miner: { + State: 'running'; + Status: string; + Names: ['/miner']; + Image: string; + Created: number; + }; + p2p_status: string[]; + miner_height: string; + epoch: string; + ports_desc: "only need to port forward 44158. For 22, only when need remote support. public port open/close isn't accurate here, if your listen_addr is IP address, it should be OK"; + ports: { [key: string]: string }; + private_ip: string; + public_ip: string; + peerbook: string[]; + height: string[]; + temp0: string; + temp1: string; + timestamp: string; + errors: string; +}