witness commit

This commit is contained in:
Ben
2023-07-09 16:24:01 -04:00
parent 4b4b04a52c
commit b6ddca5a8f
6 changed files with 39 additions and 23 deletions
+7 -4
View File
@@ -57,17 +57,20 @@ export class BitcoinRpcService {
}
public async SUBMIT_BLOCK(hexdata: string) {
public async SUBMIT_BLOCK(hexdata: string): Promise<string> {
let response: string = '';
try {
const res = await this.client.submitblock({
response = await this.client.submitblock({
hexdata
});
console.log(`BLOCK SUBMISSION RESPONSE: ${res}`);
console.log(`BLOCK SUBMISSION RESPONSE: ${response}`);
console.log(hexdata);
console.log(JSON.stringify(res));
console.log(JSON.stringify(response));
} catch (e) {
response = e;
console.log(`BLOCK SUBMISSION RESPONSE ERROR: ${e}`);
}
return response;
}
}
+15 -2
View File
@@ -22,6 +22,7 @@ const commands = [
@Injectable()
export class DiscordService implements OnModuleInit {
private token: string;
private clientId: string;
private guildId: string;
@@ -37,6 +38,10 @@ 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) {
return;
}
console.log('discord init')
this.commandCollection = new Collection();
@@ -49,6 +54,10 @@ export class DiscordService implements OnModuleInit {
async onModuleInit(): Promise<void> {
if (this.bot == null) {
return;
}
await this.registerCommands();
@@ -93,9 +102,13 @@ export class DiscordService implements OnModuleInit {
}
}
public async notifySUbscribersBlockFound() {
public async notifySUbscribersBlockFound(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!")
channel.send(`Block Found! result ${message}`)
}
}
+3 -3
View File
@@ -16,8 +16,8 @@ export class NotificationService implements OnModuleInit {
}
public async notifySubscribersBlockFound(address: string) {
await this.discordService.notifySUbscribersBlockFound();
await this.telegramService.notifySubscribersBlockFound(address);
public async notifySubscribersBlockFound(address: string, message: string) {
await this.discordService.notifySUbscribersBlockFound(message);
await this.telegramService.notifySubscribersBlockFound(address, message);
}
}
+5 -6
View File
@@ -14,8 +14,7 @@ export class TelegramService implements OnModuleInit {
private readonly telegramSubscriptionsService: TelegramSubscriptionsService
) {
const token: string | null = this.configService.get('TELEGRAM_BOT_TOKEN');
if (token == null || token.length < 1) {
console.log('No Telegram token found');
if (token.length < 1) {
return;
}
this.bot = new TelegramBot(token, { polling: true });
@@ -27,7 +26,7 @@ export class TelegramService implements OnModuleInit {
async onModuleInit(): Promise<void> {
if (this.bot == null) {
return null;
return;
}
this.bot.onText(/\/subscribe/, async (msg) => {
@@ -49,14 +48,14 @@ export class TelegramService implements OnModuleInit {
});
}
public async notifySubscribersBlockFound(address: string) {
public async notifySubscribersBlockFound(address: string, message: string) {
if (this.bot == null) {
return null;
return;
}
const subscribers = await this.telegramSubscriptionsService.getSubscriptions(address);
subscribers.forEach(subscriber => {
this.bot.sendMessage(subscriber.telegramChatId, 'You found a block!');
this.bot.sendMessage(subscriber.telegramChatId, `You found a block! ${message}`);
});
}
}