diff --git a/src/models/MiningJob.ts b/src/models/MiningJob.ts index 91a0fa8..dd0d3f0 100644 --- a/src/models/MiningJob.ts +++ b/src/models/MiningJob.ts @@ -107,8 +107,6 @@ export class MiningJob { testBlock.timestamp = timestamp; - testBlock.checkTxRoots(); - return testBlock; } diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 389592a..071374e 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -296,15 +296,15 @@ export class StratumV1Client extends EasyUnsubscribe { private async sendNewMiningJob(blockTemplate: IBlockTemplate, clearJobs: boolean) { - // const payoutInformation = [ - // { address: 'bc1q99n3pu025yyu0jlywpmwzalyhm36tg5u37w20d', percent: 1.8 }, - // { address: this.clientAuthorization.address, percent: 98.2 } - // ]; - 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); this.stratumV1JobsService.addJob(job, clearJobs); @@ -347,7 +347,7 @@ export class StratumV1Client extends EasyUnsubscribe { console.log('!!! BLOCK FOUND !!!'); const blockHex = updatedJobBlock.toHex(false); 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 { await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty); diff --git a/src/services/bitcoin-rpc.service.ts b/src/services/bitcoin-rpc.service.ts index 3f3a04e..b2b993b 100644 --- a/src/services/bitcoin-rpc.service.ts +++ b/src/services/bitcoin-rpc.service.ts @@ -58,11 +58,12 @@ export class BitcoinRpcService { } public async SUBMIT_BLOCK(hexdata: string): Promise { - let response: string = ''; + let response: string = 'unknown'; try { - response = await this.client.submitblock({ + await this.client.submitblock({ hexdata }); + response = 'SUCCESS!'; console.log(`BLOCK SUBMISSION RESPONSE: ${response}`); console.log(hexdata); console.log(JSON.stringify(response)); diff --git a/src/services/discord.service.ts b/src/services/discord.service.ts index e0a36de..d97c953 100644 --- a/src/services/discord.service.ts +++ b/src/services/discord.service.ts @@ -1,5 +1,6 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; +import { Block } from 'bitcoinjs-lib'; import { Client, Collection, Events, GatewayIntentBits, REST, Routes, SlashCommandBuilder, TextChannel } from 'discord.js'; 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) { return; } const guild = await this.bot.guilds.fetch(this.guildId); const channel = await guild.channels.fetch(this.channelId) as TextChannel; - channel.send(`Block Found! result ${message}`) + channel.send(`Block Found! Result: ${message}, Height: ${height}`) } } \ No newline at end of file diff --git a/src/services/notification.service.ts b/src/services/notification.service.ts index fa9203e..ce76fda 100644 --- a/src/services/notification.service.ts +++ b/src/services/notification.service.ts @@ -1,4 +1,5 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; +import { Block } from 'bitcoinjs-lib'; import { DiscordService } from './discord.service'; import { TelegramService } from './telegram.service'; @@ -16,8 +17,8 @@ export class NotificationService implements OnModuleInit { } - public async notifySubscribersBlockFound(address: string, message: string) { - await this.discordService.notifySUbscribersBlockFound(message); - await this.telegramService.notifySubscribersBlockFound(address, message); + public async notifySubscribersBlockFound(address: string, height: number, block: Block, message: string) { + await this.discordService.notifySubscribersBlockFound(height, block, message); + await this.telegramService.notifySubscribersBlockFound(address, height, block, message); } } \ No newline at end of file diff --git a/src/services/telegram.service.ts b/src/services/telegram.service.ts index fe05ecf..78eec12 100644 --- a/src/services/telegram.service.ts +++ b/src/services/telegram.service.ts @@ -1,6 +1,7 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { validate } from 'bitcoin-address-validation'; +import { Block } from 'bitcoinjs-lib'; import * as TelegramBot from 'node-telegram-bot-api'; 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) { return; } const subscribers = await this.telegramSubscriptionsService.getSubscriptions(address); subscribers.forEach(subscriber => { - this.bot.sendMessage(subscriber.telegramChatId, `You found a block! ${message}`); + this.bot.sendMessage(subscriber.telegramChatId, `Block Found! Result: ${message}, Height: ${height}`); }); } } \ No newline at end of file