mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
proxy diff working
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 } })
|
||||
}
|
||||
}
|
||||
@@ -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}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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}`);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user