Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
5fb5979c91 | |||
cf61de9093 | |||
cf7c3cb910 | |||
b8eb82de12 | |||
8c01d5cabf | |||
1eef97ee9a | |||
45544fffd0 | |||
f227eaee37 | |||
74ea18dc76 | |||
c0f03d11b6 | |||
ceab0fb872 | |||
f17349309d |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/bobcat",
|
"name": "@mojoio/bobcat",
|
||||||
"version": "1.0.6",
|
"version": "1.0.12",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@mojoio/bobcat",
|
"name": "@mojoio/bobcat",
|
||||||
"version": "1.0.6",
|
"version": "1.0.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartnetwork": "^2.0.14",
|
"@pushrocks/smartnetwork": "^2.0.14",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/bobcat",
|
"name": "@mojoio/bobcat",
|
||||||
"version": "1.0.6",
|
"version": "1.0.12",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a module to talk to bobcat miners",
|
"description": "a module to talk to bobcat miners",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -8,11 +8,16 @@ import * as bobcat from '../ts/index';
|
|||||||
let testBobcatManager: bobcat.BobcatManager;
|
let testBobcatManager: bobcat.BobcatManager;
|
||||||
let testBobcat: bobcat.Bobcat;
|
let testBobcat: bobcat.Bobcat;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('should create a bobcat manager', async () => {
|
||||||
testBobcatManager = new bobcat.BobcatManager();
|
testBobcatManager = new bobcat.BobcatManager();
|
||||||
expect(testBobcatManager).toBeInstanceOf(bobcat.BobcatManager);
|
expect(testBobcatManager).toBeInstanceOf(bobcat.BobcatManager);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a bobcat', async () => {
|
||||||
|
testBobcat = new bobcat.Bobcat('bobcat.bleu.de');
|
||||||
|
expect(testBobcat).toBeInstanceOf(bobcat.Bobcat);
|
||||||
|
})
|
||||||
|
|
||||||
tap.test('should add a Bobcat miner', async () => {
|
tap.test('should add a Bobcat miner', async () => {
|
||||||
const bobcatAddresses = testQenv.getEnvVarOnDemand('BOBCATS').split(',');
|
const bobcatAddresses = testQenv.getEnvVarOnDemand('BOBCATS').split(',');
|
||||||
console.log(bobcatAddresses);
|
console.log(bobcatAddresses);
|
||||||
@ -22,9 +27,8 @@ tap.test('should add a Bobcat miner', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('', async () => {
|
tap.test('should run maintenance on bobcats', async () => {
|
||||||
testBobcat = new bobcat.Bobcat('bobcat.bleu.de');
|
await testBobcatManager.runMaintenance();
|
||||||
expect(testBobcat).toBeInstanceOf(bobcat.Bobcat);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './bobcat.plugins';
|
import * as plugins from './bobcat.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* maps to an individual bobcat miner
|
* maps to an individual bobcat miner
|
||||||
@ -7,14 +8,22 @@ export class Bobcat {
|
|||||||
// STATIC
|
// STATIC
|
||||||
public static async createFromNetworkAddress(networkAddressArg: string) {
|
public static async createFromNetworkAddress(networkAddressArg: string) {
|
||||||
const newBobcat = new Bobcat(networkAddressArg);
|
const newBobcat = new Bobcat(networkAddressArg);
|
||||||
|
try {
|
||||||
|
await newBobcat.checkMinerStatus();
|
||||||
await newBobcat.gatherMinerDetails();
|
await newBobcat.gatherMinerDetails();
|
||||||
|
} catch(err) {
|
||||||
|
console.log('initial adding completed with errors');
|
||||||
|
}
|
||||||
return newBobcat;
|
return newBobcat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public networkAddress: string;
|
public networkAddress: string;
|
||||||
constructor(networkAddress: string) {
|
public latestStatus: interfaces.IMinerStatus;
|
||||||
|
public latestMinerDetails: interfaces.IMinerDetailsResponse
|
||||||
|
|
||||||
|
constructor(networkAddressArg: string) {
|
||||||
|
this.networkAddress = networkAddressArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,23 +31,40 @@ export class Bobcat {
|
|||||||
*/
|
*/
|
||||||
public async checkMinerStatus() {
|
public async checkMinerStatus() {
|
||||||
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`);
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`);
|
||||||
const body: {
|
const body: interfaces.IMinerStatus = response.body;
|
||||||
"status": string,
|
this.latestStatus = body;
|
||||||
"gap": string,
|
return this.latestStatus;
|
||||||
"miner_height": string,
|
|
||||||
"blockchain_height": string,
|
|
||||||
"epoch": "rpc"
|
|
||||||
} = response.body;
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gathers the miner details
|
* gathers the miner details
|
||||||
*/
|
*/
|
||||||
public async gatherMinerDetails() {
|
public async gatherMinerDetails() {
|
||||||
const response: {
|
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`);
|
||||||
|
const body: interfaces.IMinerDetailsResponse = response.body;
|
||||||
|
this.latestMinerDetails = body;
|
||||||
|
return this.latestMinerDetails;
|
||||||
|
}
|
||||||
|
|
||||||
} = plugins.smartrequest.getJson(`http://${this.networkAddress}/miner.json`);
|
/**
|
||||||
|
* 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!`);
|
||||||
|
await this.restart().catch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async restart() {
|
||||||
|
const response = await plugins.smartrequest.request(`http://${this.networkAddress}/admin/reboot`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: 'Basic ' + Buffer.from('bobcat:miner').toString('base64')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(response.statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,4 +11,14 @@ export class BobcatManager {
|
|||||||
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
|
const newBobcat = await Bobcat.createFromNetworkAddress(networkAddressArg);
|
||||||
this.bobcats.push(newBobcat);
|
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
35
ts/interfaces/index.ts
Normal 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;
|
||||||
|
}
|
Reference in New Issue
Block a user