2022-02-24 19:16:21 +00:00
|
|
|
import * as plugins from './bobcat.plugins';
|
2022-02-25 20:25:29 +00:00
|
|
|
import * as interfaces from './interfaces';
|
2022-02-24 19:16:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* maps to an individual bobcat miner
|
|
|
|
*/
|
|
|
|
export class Bobcat {
|
2022-02-25 19:36:44 +00:00
|
|
|
// STATIC
|
|
|
|
public static async createFromNetworkAddress(networkAddressArg: string) {
|
|
|
|
const newBobcat = new Bobcat(networkAddressArg);
|
|
|
|
await newBobcat.gatherMinerDetails();
|
2022-02-25 20:25:29 +00:00
|
|
|
await newBobcat.checkMinerStatus();
|
2022-02-25 19:36:44 +00:00
|
|
|
return newBobcat;
|
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
public networkAddress: string;
|
2022-02-25 20:25:29 +00:00
|
|
|
public latestStatus: interfaces.IMinerStatus;
|
|
|
|
public latestMinerDetails: interfaces.IMinerDetailsResponse
|
2022-02-25 19:36:44 +00:00
|
|
|
|
2022-02-25 19:57:46 +00:00
|
|
|
constructor(networkAddressArg: string) {
|
|
|
|
this.networkAddress = networkAddressArg;
|
2022-02-25 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks the status of the miner
|
|
|
|
*/
|
|
|
|
public async checkMinerStatus() {
|
|
|
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`);
|
2022-02-25 20:25:29 +00:00
|
|
|
const body: interfaces.IMinerStatus = response.body;
|
|
|
|
this.latestStatus = body;
|
|
|
|
return this.latestStatus;
|
2022-02-25 19:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gathers the miner details
|
|
|
|
*/
|
|
|
|
public async gatherMinerDetails() {
|
2022-02-25 20:25:29 +00:00
|
|
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`);
|
|
|
|
const body: interfaces.IMinerDetailsResponse = response.body;
|
|
|
|
this.latestMinerDetails = body;
|
|
|
|
return this.latestMinerDetails;
|
2022-02-25 19:36:44 +00:00
|
|
|
}
|
2022-02-24 19:16:21 +00:00
|
|
|
}
|