mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Merge branch 'master' of https://github.com/benjamin-wilson/public-pool
This commit is contained in:
@@ -9,8 +9,10 @@ import { ClientStatisticsEntity } from './client-statistics.entity';
|
||||
export class ClientStatisticsService {
|
||||
|
||||
constructor(
|
||||
|
||||
|
||||
@InjectRepository(ClientStatisticsEntity)
|
||||
private clientStatisticsRepository: Repository<ClientStatisticsEntity>
|
||||
private clientStatisticsRepository: Repository<ClientStatisticsEntity>,
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -30,6 +32,38 @@ export class ClientStatisticsService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
public async getChartDataForSite() {
|
||||
|
||||
|
||||
const query = `
|
||||
WITH result_set AS (
|
||||
SELECT
|
||||
MAX(time) || 'GMT' AS label,
|
||||
(SUM(difficulty) * 4294967296) /
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60) AS data
|
||||
FROM
|
||||
client_statistics_entity AS entry
|
||||
WHERE
|
||||
entry.time > datetime("now", "-1 day")
|
||||
GROUP BY
|
||||
strftime('%Y-%m-%d %H', time, 'localtime') || (strftime('%M', time, 'localtime') / 10)
|
||||
ORDER BY
|
||||
time
|
||||
)
|
||||
SELECT *
|
||||
FROM result_set
|
||||
WHERE label <> (SELECT MAX(label) FROM result_set);
|
||||
`;
|
||||
|
||||
const result = await this.clientStatisticsRepository.query(query);
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async getHashRateForAddress(address: string) {
|
||||
|
||||
const query = `
|
||||
@@ -47,7 +81,7 @@ export class ClientStatisticsService {
|
||||
const timeDiff = result[0].timeDiff;
|
||||
const difficultySum = result[0].difficultySum;
|
||||
|
||||
return (difficultySum * 4294967296) / (timeDiff * 1000000000);
|
||||
return (difficultySum * 4294967296) / (timeDiff);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +91,7 @@ export class ClientStatisticsService {
|
||||
SELECT
|
||||
MAX(time) || 'GMT' AS label,
|
||||
(SUM(difficulty) * 4294967296) /
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60 * 1000000000) AS data
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60) AS data
|
||||
FROM
|
||||
client_statistics_entity AS entry
|
||||
WHERE
|
||||
@@ -95,7 +129,7 @@ export class ClientStatisticsService {
|
||||
const timeDiff = result[0].timeDiff;
|
||||
const difficultySum = result[0].difficultySum;
|
||||
|
||||
return (difficultySum * 4294967296) / (timeDiff * 1000000000);
|
||||
return (difficultySum * 4294967296) / (timeDiff);
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +139,7 @@ export class ClientStatisticsService {
|
||||
SELECT
|
||||
MAX(time) || 'GMT' AS label,
|
||||
(SUM(difficulty) * 4294967296) /
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60 * 1000000000) AS data
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60) AS data
|
||||
FROM
|
||||
client_statistics_entity AS entry
|
||||
WHERE
|
||||
@@ -144,7 +178,7 @@ export class ClientStatisticsService {
|
||||
const timeDiff = result[0].timeDiff;
|
||||
const difficultySum = result[0].difficultySum;
|
||||
|
||||
return (difficultySum * 4294967296) / (timeDiff * 1000000000);
|
||||
return (difficultySum * 4294967296) / (timeDiff);
|
||||
|
||||
}
|
||||
|
||||
@@ -154,7 +188,7 @@ export class ClientStatisticsService {
|
||||
SELECT
|
||||
MAX(time) || 'GMT' AS label,
|
||||
(SUM(difficulty) * 4294967296) /
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60 * 1000000000) AS data
|
||||
((JULIANDAY(MAX(time)) - JULIANDAY(MIN(time))) * 24 * 60 * 60) AS data
|
||||
FROM
|
||||
client_statistics_entity AS entry
|
||||
WHERE
|
||||
|
||||
+23
-5
@@ -1,18 +1,36 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { Controller, Get, Inject } from '@nestjs/common';
|
||||
import { Cache } from 'cache-manager';
|
||||
|
||||
import { ClientStatisticsService } from './ORM/client-statistics/client-statistics.service';
|
||||
import { ClientService } from './ORM/client/client.service';
|
||||
|
||||
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private clientService: ClientService
|
||||
@Inject(CACHE_MANAGER) private cacheManager: Cache,
|
||||
private clientService: ClientService,
|
||||
private clientStatisticsService: ClientStatisticsService
|
||||
) { }
|
||||
|
||||
@Get('info')
|
||||
public info() {
|
||||
public async info() {
|
||||
|
||||
const CACHE_KEY = 'SITE_HASHRATE_GRAPH';
|
||||
const cachedResult = await this.cacheManager.get(CACHE_KEY);
|
||||
if (cachedResult != null) {
|
||||
return {
|
||||
chartData: cachedResult
|
||||
};
|
||||
}
|
||||
|
||||
const chartData = await this.clientStatisticsService.getChartDataForSite();
|
||||
|
||||
await this.cacheManager.set(CACHE_KEY, chartData, 600)
|
||||
|
||||
return {
|
||||
chartData
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
@@ -33,9 +34,12 @@ const ORMModules = [
|
||||
database: './DB/public-pool.sqlite',
|
||||
synchronize: true,
|
||||
autoLoadEntities: true,
|
||||
cache: true,
|
||||
logging: false
|
||||
}),
|
||||
CacheModule.register(),
|
||||
ScheduleModule.forRoot(),
|
||||
|
||||
...ORMModules
|
||||
],
|
||||
controllers: [
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { Controller, Patch } from '@nestjs/common';
|
||||
import * as bitcoinMessage from 'bitcoinjs-message';
|
||||
|
||||
|
||||
@Controller('address')
|
||||
export class AddressController {}
|
||||
export class AddressController {
|
||||
|
||||
@Patch('settings')
|
||||
async settings() {
|
||||
|
||||
const publicKey = '...'; // Public key corresponding to the private key used for signing
|
||||
const message = '...'; // The message that was signed
|
||||
const signature = '...'; // The signature of the message
|
||||
|
||||
const isValid: boolean = bitcoinMessage.verify(message, publicKey, signature);
|
||||
if (isValid) {
|
||||
console.log('Signature is valid!');
|
||||
} else {
|
||||
console.log('Signature is not valid!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
|
||||
private async handleMessage(message: string) {
|
||||
console.log('Received:', message);
|
||||
console.log(`Received from ${this.extraNonce}`, message);
|
||||
|
||||
// Parse the message and check if it's the initial subscription message
|
||||
let parsedMessage = null;
|
||||
@@ -248,7 +248,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
|
||||
if (this.clientSubscription != null
|
||||
&& this.clientConfiguration != null
|
||||
// && this.clientConfiguration != null
|
||||
&& this.clientAuthorization != null
|
||||
&& this.stratumInitialized == false) {
|
||||
|
||||
@@ -298,14 +298,22 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
private async sendNewMiningJob(blockTemplate: IBlockTemplate, clearJobs: boolean) {
|
||||
|
||||
const payoutInformation = [
|
||||
{ address: 'tb1qumezefzdeqqwn5zfvgdrhxjzc5ylr39uhuxcz4', percent: 1.8 },
|
||||
{ address: this.clientAuthorization.address, percent: 98.2 }
|
||||
];
|
||||
const hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonce);
|
||||
|
||||
// const payoutInformation = [
|
||||
// { address: this.clientAuthorization.address, percent: 100 }
|
||||
// ];
|
||||
let payoutInformation;
|
||||
//10Th/s
|
||||
const noFee = hashRate < 10000000000000;
|
||||
if (noFee) {
|
||||
payoutInformation = [
|
||||
{ address: this.clientAuthorization.address, percent: 100 }
|
||||
];
|
||||
|
||||
} else {
|
||||
payoutInformation = [
|
||||
{ address: 'tb1qumezefzdeqqwn5zfvgdrhxjzc5ylr39uhuxcz4', percent: 1.5 },
|
||||
{ address: this.clientAuthorization.address, percent: 98.5 }
|
||||
];
|
||||
}
|
||||
|
||||
const job = new MiningJob(this.stratumV1JobsService.getNextId(), payoutInformation, blockTemplate, clearJobs);
|
||||
|
||||
@@ -314,7 +322,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
await this.promiseSocket.write(job.response());
|
||||
|
||||
console.log(`Sent new job to ${this.extraNonce}. (clearJobs: ${clearJobs})`)
|
||||
console.log(`Sent new job to ${this.extraNonce}. (clearJobs: ${clearJobs}, fee?: ${!noFee})`)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,11 @@ export class DiscordService implements OnModuleInit {
|
||||
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
||||
this.channelId = this.configService.get('DISCORD_BOT_CHANNEL_ID')
|
||||
|
||||
if (this.token.length < 1 || this.clientId.length < 1 || this.guildId.length < 1 || this.channelId.length < 1) {
|
||||
if (this.token == null || this.token.length < 1 ||
|
||||
this.clientId == null || this.clientId.length < 1 ||
|
||||
this.guildId == null || this.guildId.length < 1 ||
|
||||
this.channelId == null || this.channelId.length < 1
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export class TelegramService implements OnModuleInit {
|
||||
private readonly telegramSubscriptionsService: TelegramSubscriptionsService
|
||||
) {
|
||||
const token: string | null = this.configService.get('TELEGRAM_BOT_TOKEN');
|
||||
if (token.length < 1) {
|
||||
if (token == null || token.length < 1) {
|
||||
return;
|
||||
}
|
||||
this.bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
Reference in New Issue
Block a user