proxy diff working

This commit is contained in:
Ben Wilson
2023-08-13 23:26:06 -04:00
parent 5369b2dc12
commit 42235736fa
15 changed files with 504 additions and 20 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ export class AppService implements OnModuleInit {
@Cron(CronExpression.EVERY_HOUR)
private async deleteOldStatistics() {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
if (process.env.ENABLE_SOLO == 'true' && (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0')) {
const deletedStatistics = await this.clientStatisticsService.deleteOldStatistics();
console.log(`Deleted ${deletedStatistics.affected} old statistics`);
const deletedClients = await this.clientService.deleteOldClients();
@@ -38,7 +38,7 @@ export class AppService implements OnModuleInit {
@Cron(CronExpression.EVERY_5_MINUTES)
private async killDeadClients() {
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
if (process.env.ENABLE_SOLO == 'true' && (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0')) {
await this.clientService.killDeadClients();
}
}
+36
View File
@@ -0,0 +1,36 @@
import { HttpService } from '@nestjs/axios';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { map } from 'rxjs';
@Injectable()
export class BraiinsService implements OnModuleInit {
constructor(private readonly httpService: HttpService) {
}
onModuleInit() {
// this.getUserProfile().subscribe((res) => {
// console.log(`Braiins:`)
// console.log(res);
// })
// this.getBlockRewards(new Date(0), new Date()).subscribe(res => {
// console.log(`Braiins:`)
// console.log(res);
// })
}
public getUserProfile() {
return this.httpService.get(`https://pool.braiins.com/accounts/profile/json/BTC`, { headers: { 'SlushPool-Auth-Token': process.env.BRAIINS_ACCESS_TOKEN } }).pipe(
map(res => res.data)
)
}
public getBlockRewards(from: Date, to: Date) {
return this.httpService.get(`https://pool.braiins.com/accounts/block_rewards/json/BTC?from=${from.toISOString().split('T')[0]}&to=${to.toISOString().split('T')[0]}`, { headers: { 'SlushPool-Auth-Token': process.env.BRAIINS_ACCESS_TOKEN } }).pipe(
map(res => res.data)
);
}
}
+54
View File
@@ -0,0 +1,54 @@
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
@Injectable()
export class BTCPayService {
constructor(private readonly httpService: HttpService) {
}
public createUser() {
const user = {
email: 'MyTestUser@gmail.com',
password: 'NOTVERYSECURE',
isAdministrator: false
}
this.httpService.post(`/api/v1/users`, user)
}
public createNewStore() {
const token = 'APIKEYTOKEN';
const store = {
Name: 'STORENAME'
}
this.httpService.post(`/api/v1/stores`, store, { headers: { Authorization: 'token ' + token } })
}
public createPullPayment() {
const token = 'APIKEYTOKEN';
const pullPayment = {
name: 'string',
description: 'string',
amount: '0.1',
currency: 'BTC',
period: 604800,
BOLT11Expiration: 30,
autoApproveClaims: false,
startsAt: 1592312018,
expiresAt: 1593129600,
paymentMethods: [
'BTC'
]
}
this.httpService.post(`/api/v1/stores/{storeId}/pull-payments`, pullPayment, { headers: { Authorization: 'token ' + token } })
}
}
+29
View File
@@ -0,0 +1,29 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Server, Socket } from 'net';
import { ProxyClient } from '../models/ProxyClient';
@Injectable()
export class ProxyService implements OnModuleInit {
constructor() {
}
async onModuleInit(): Promise<void> {
if (process.env.ENABLE_PROXY == 'true') {
console.log('Connecting to braiins');
const proxyServer = new Server(async (socket: Socket) => {
const proxyClient = new ProxyClient(socket);
});
proxyServer.listen(process.env.PROXY_PORT, () => {
console.log(`Proxy server is listening on port ${process.env.PROXY_PORT}`);
});
}
}
}
-1
View File
@@ -91,7 +91,6 @@ export class StratumV1JobsService {
tempCoinbaseTx.ins[0].witness = [Buffer.alloc(32, 0)];
transactions.unshift(tempCoinbaseTx);
const transactionBuffers = transactions.map(tx => tx.getHash(false));
const merkleTree = merkle(transactionBuffers, bitcoinjs.crypto.hash256);
+7 -9
View File
@@ -28,15 +28,13 @@ export class StratumV1Service implements OnModuleInit {
}
async onModuleInit(): Promise<void> {
//await this.clientStatisticsService.deleteAll();
await this.clientService.deleteAll();
this.startSocketServer();
if (process.env.ENABLE_SOLO == 'true') {
//await this.clientStatisticsService.deleteAll();
await this.clientService.deleteAll();
this.startSocketServer();
}
}
private startSocketServer() {
@@ -70,8 +68,8 @@ export class StratumV1Service implements OnModuleInit {
});
server.listen(3333, () => {
console.log(`Bitcoin Stratum server is listening on port ${3333}`);
server.listen(process.env.STRATUM_PORT, () => {
console.log(`Stratum server is listening on port ${process.env.STRATUM_PORT}`);
});
}