15 Commits

Author SHA1 Message Date
cf7c3cb910 1.0.11 2022-02-25 21:45:22 +01:00
b8eb82de12 fix(core): update 2022-02-25 21:45:21 +01:00
8c01d5cabf 1.0.10 2022-02-25 21:35:34 +01:00
1eef97ee9a fix(core): update 2022-02-25 21:35:34 +01:00
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
cb98b63a04 1.0.6 2022-02-25 20:36:44 +01:00
e5fe74d2d2 fix(core): update 2022-02-25 20:36:44 +01:00
babcb832f3 1.0.5 2022-02-24 20:20:29 +01:00
aa1c00cab5 1.0.4 2022-02-24 20:18:33 +01:00
2a0d2d1f6e 1.0.3 2022-02-24 20:17:42 +01:00
8 changed files with 388 additions and 161 deletions

375
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/bobcat", "name": "@mojoio/bobcat",
"version": "1.0.2", "version": "1.0.11",
"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",
@ -15,6 +15,7 @@
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78", "@gitzone/tsbundle": "^1.0.78",
"@gitzone/tstest": "^1.0.44", "@gitzone/tstest": "^1.0.44",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^4.0.7", "@pushrocks/tapbundle": "^4.0.7",
"@types/node": "^17.0.21", "@types/node": "^17.0.21",
"tslint": "^6.1.3", "tslint": "^6.1.3",
@ -36,6 +37,7 @@
"readme.md" "readme.md"
], ],
"dependencies": { "dependencies": {
"@pushrocks/smartnetwork": "^2.0.14",
"@pushrocks/smartrequest": "^1.1.56" "@pushrocks/smartrequest": "^1.1.56"
} }
} }

34
test/test.nonci.ts Normal file
View File

@ -0,0 +1,34 @@
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import { Qenv } from '@pushrocks/qenv';
const testQenv = new Qenv('./', './.nogit');
import * as bobcat from '../ts/index';
let testBobcatManager: bobcat.BobcatManager;
let testBobcat: bobcat.Bobcat;
tap.test('should create a bobcat manager', async () => {
testBobcatManager = new 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 () => {
const bobcatAddresses = testQenv.getEnvVarOnDemand('BOBCATS').split(',');
console.log(bobcatAddresses);
for (const bobcatAddress of bobcatAddresses) {
await testBobcatManager.addBobcat(bobcatAddress);
}
});
tap.test('should run maintenance on bobcats', async () => {
await testBobcatManager.runMaintenance();
})
tap.start();

View File

@ -1,17 +0,0 @@
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import * as bobcat from '../ts/index';
let testBobcatManager: bobcat.BobcatManager;
let testBobcat: bobcat.Bobcat;
tap.test('first test', async () => {
testBobcatManager = new bobcat.BobcatManager();
expect(testBobcatManager).toBeInstanceOf(bobcat.BobcatManager);
});
tap.test('', async () => {
testBobcat = new bobcat.Bobcat();
expect(testBobcat).toBeInstanceOf(bobcat.Bobcat);
})
tap.start();

View File

@ -1,8 +1,66 @@
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
*/ */
export class Bobcat { export class Bobcat {
// STATIC
public static async createFromNetworkAddress(networkAddressArg: string) {
const newBobcat = new Bobcat(networkAddressArg);
await newBobcat.checkMinerStatus().catch();
await newBobcat.gatherMinerDetails().catch();
return newBobcat;
}
// INSTANCE
public networkAddress: string;
public latestStatus: interfaces.IMinerStatus;
public latestMinerDetails: interfaces.IMinerDetailsResponse
constructor(networkAddressArg: string) {
this.networkAddress = networkAddressArg;
}
/**
* checks the status of the miner
*/
public async checkMinerStatus() {
const response = await plugins.smartrequest.getJson(`http://${this.networkAddress}/status.json`);
const body: interfaces.IMinerStatus = response.body;
this.latestStatus = body;
return this.latestStatus;
}
/**
* gathers the miner details
*/
public async gatherMinerDetails() {
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!`);
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);
}
} }

View File

@ -1,8 +1,28 @@
import * as plugins from './bobcat.plugins'; import * as plugins from './bobcat.plugins';
import { Bobcat } from './bobcat.classes.bobcat';
/** /**
* *
*/ */
export class BobcatManager { export class BobcatManager {
public bobcats: Bobcat[] = [];
public async addBobcat(networkAddressArg: string) {
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();
}
};
public async restart() {
} }
}

View File

@ -1,5 +1,7 @@
import * as smartnetwork from '@pushrocks/smartnetwork';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
export { export {
smartnetwork,
smartrequest smartrequest
} }

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