6 Commits

Author SHA1 Message Date
45544fffd0 1.0.9 2022-02-25 21:33:24 +01:00
f227eaee37 fix(core): update 2022-02-25 21:33:24 +01:00
74ea18dc76 1.0.8 2022-02-25 21:25:29 +01:00
c0f03d11b6 fix(core): update 2022-02-25 21:25:29 +01:00
ceab0fb872 1.0.7 2022-02-25 20:57:46 +01:00
f17349309d fix(core): update 2022-02-25 20:57:46 +01:00
5 changed files with 72 additions and 16 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@mojoio/bobcat",
"version": "1.0.6",
"version": "1.0.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@mojoio/bobcat",
"version": "1.0.6",
"version": "1.0.9",
"license": "MIT",
"dependencies": {
"@pushrocks/smartnetwork": "^2.0.14",

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/bobcat",
"version": "1.0.6",
"version": "1.0.9",
"private": false,
"description": "a module to talk to bobcat miners",
"main": "dist_ts/index.js",

View File

@ -1,4 +1,5 @@
import * as plugins from './bobcat.plugins';
import * as interfaces from './interfaces';
/**
* maps to an individual bobcat miner
@ -7,14 +8,18 @@ export class Bobcat {
// STATIC
public static async createFromNetworkAddress(networkAddressArg: string) {
const newBobcat = new Bobcat(networkAddressArg);
await newBobcat.gatherMinerDetails();
await newBobcat.checkMinerStatus().catch();
await newBobcat.gatherMinerDetails().catch();
return newBobcat;
}
// INSTANCE
public networkAddress: string;
constructor(networkAddress: string) {
public latestStatus: interfaces.IMinerStatus;
public latestMinerDetails: interfaces.IMinerDetailsResponse
constructor(networkAddressArg: string) {
this.networkAddress = networkAddressArg;
}
/**
@ -22,23 +27,29 @@ 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;
}
/**
* runs maintenance on the bobcat
*/
public async runMaintenance() {
await this.checkMinerStatus();
await this.gatherMinerDetails();
if (this.latestStatus.status !== 'Synced') {
console.log(`Miner ${this.latestMinerDetails.animal} is not synced. Restarting now!`);
}
}
}

View File

@ -11,4 +11,14 @@ export class BobcatManager {
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
this.bobcats.push(newBobcat);
}
/**
* runs the maintenance on all managed bobcats
*/
public async runMaintenance() {
console.log(`now running maintenance on ${this.bobcats.length} bobcats!`);
for (const bobcat of this.bobcats) {
await bobcat.runMaintenance();
}
};
}

35
ts/interfaces/index.ts Normal file
View File

@ -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;
}