notification messages, dev fee

This commit is contained in:
Ben
2023-07-09 20:15:37 -04:00
parent 9083501e6f
commit e9ae1853af
6 changed files with 20 additions and 18 deletions
-2
View File
@@ -107,8 +107,6 @@ export class MiningJob {
testBlock.timestamp = timestamp; testBlock.timestamp = timestamp;
testBlock.checkTxRoots();
return testBlock; return testBlock;
} }
+7 -7
View File
@@ -296,15 +296,15 @@ export class StratumV1Client extends EasyUnsubscribe {
private async sendNewMiningJob(blockTemplate: IBlockTemplate, clearJobs: boolean) { private async sendNewMiningJob(blockTemplate: IBlockTemplate, clearJobs: boolean) {
// const payoutInformation = [
// { address: 'bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d', percent: 1.8 },
// { address: this.clientAuthorization.address, percent: 98.2 }
// ];
const payoutInformation = [ const payoutInformation = [
{ address: this.clientAuthorization.address, percent: 100 } { address: 'tb1qumezefzdeqqwn5zfvgdrhxjzc5ylr39uhuxcz4', percent: 1.8 },
{ address: this.clientAuthorization.address, percent: 98.2 }
]; ];
// const payoutInformation = [
// { address: this.clientAuthorization.address, percent: 100 }
// ];
const job = new MiningJob(this.stratumV1JobsService.getNextId(), payoutInformation, blockTemplate, clearJobs); const job = new MiningJob(this.stratumV1JobsService.getNextId(), payoutInformation, blockTemplate, clearJobs);
this.stratumV1JobsService.addJob(job, clearJobs); this.stratumV1JobsService.addJob(job, clearJobs);
@@ -347,7 +347,7 @@ export class StratumV1Client extends EasyUnsubscribe {
console.log('!!! BLOCK FOUND !!!'); console.log('!!! BLOCK FOUND !!!');
const blockHex = updatedJobBlock.toHex(false); const blockHex = updatedJobBlock.toHex(false);
const result = await this.bitcoinRpcService.SUBMIT_BLOCK(blockHex); const result = await this.bitcoinRpcService.SUBMIT_BLOCK(blockHex);
await this.notificationService.notifySubscribersBlockFound(this.clientAuthorization.address, result); await this.notificationService.notifySubscribersBlockFound(this.clientAuthorization.address, job.blockTemplate.height, updatedJobBlock, result);
} }
try { try {
await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty); await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty);
+3 -2
View File
@@ -58,11 +58,12 @@ export class BitcoinRpcService {
} }
public async SUBMIT_BLOCK(hexdata: string): Promise<string> { public async SUBMIT_BLOCK(hexdata: string): Promise<string> {
let response: string = ''; let response: string = 'unknown';
try { try {
response = await this.client.submitblock({ await this.client.submitblock({
hexdata hexdata
}); });
response = 'SUCCESS!';
console.log(`BLOCK SUBMISSION RESPONSE: ${response}`); console.log(`BLOCK SUBMISSION RESPONSE: ${response}`);
console.log(hexdata); console.log(hexdata);
console.log(JSON.stringify(response)); console.log(JSON.stringify(response));
+3 -2
View File
@@ -1,5 +1,6 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { Block } from 'bitcoinjs-lib';
import { Client, Collection, Events, GatewayIntentBits, REST, Routes, SlashCommandBuilder, TextChannel } from 'discord.js'; import { Client, Collection, Events, GatewayIntentBits, REST, Routes, SlashCommandBuilder, TextChannel } from 'discord.js';
interface IDiscordCommand { interface IDiscordCommand {
@@ -102,13 +103,13 @@ export class DiscordService implements OnModuleInit {
} }
} }
public async notifySUbscribersBlockFound(message: string) { public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
if (this.bot == null) { if (this.bot == null) {
return; return;
} }
const guild = await this.bot.guilds.fetch(this.guildId); const guild = await this.bot.guilds.fetch(this.guildId);
const channel = await guild.channels.fetch(this.channelId) as TextChannel; const channel = await guild.channels.fetch(this.channelId) as TextChannel;
channel.send(`Block Found! result ${message}`) channel.send(`Block Found! Result: ${message}, Height: ${height}`)
} }
} }
+4 -3
View File
@@ -1,4 +1,5 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common';
import { Block } from 'bitcoinjs-lib';
import { DiscordService } from './discord.service'; import { DiscordService } from './discord.service';
import { TelegramService } from './telegram.service'; import { TelegramService } from './telegram.service';
@@ -16,8 +17,8 @@ export class NotificationService implements OnModuleInit {
} }
public async notifySubscribersBlockFound(address: string, message: string) { public async notifySubscribersBlockFound(address: string, height: number, block: Block, message: string) {
await this.discordService.notifySUbscribersBlockFound(message); await this.discordService.notifySubscribersBlockFound(height, block, message);
await this.telegramService.notifySubscribersBlockFound(address, message); await this.telegramService.notifySubscribersBlockFound(address, height, block, message);
} }
} }
+3 -2
View File
@@ -1,6 +1,7 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { validate } from 'bitcoin-address-validation'; import { validate } from 'bitcoin-address-validation';
import { Block } from 'bitcoinjs-lib';
import * as TelegramBot from 'node-telegram-bot-api'; import * as TelegramBot from 'node-telegram-bot-api';
import { TelegramSubscriptionsService } from 'src/ORM/telegram-subscriptions/telegram-subscriptions.service'; import { TelegramSubscriptionsService } from 'src/ORM/telegram-subscriptions/telegram-subscriptions.service';
@@ -48,14 +49,14 @@ export class TelegramService implements OnModuleInit {
}); });
} }
public async notifySubscribersBlockFound(address: string, message: string) { public async notifySubscribersBlockFound(address: string, height: number, block: Block, message: string) {
if (this.bot == null) { if (this.bot == null) {
return; return;
} }
const subscribers = await this.telegramSubscriptionsService.getSubscriptions(address); const subscribers = await this.telegramSubscriptionsService.getSubscriptions(address);
subscribers.forEach(subscriber => { subscribers.forEach(subscriber => {
this.bot.sendMessage(subscriber.telegramChatId, `You found a block! ${message}`); this.bot.sendMessage(subscriber.telegramChatId, `Block Found! Result: ${message}, Height: ${height}`);
}); });
} }
} }