Files
public-pool/src/services/external-shares.service.ts
T
fda3f21b71 feat: external pool shares (#89)
* feat:external shares
---------

Co-authored-by: mrv777 <mrv777@users.noreply.github.com>
Co-authored-by: Benjamin Wilson <admin@opensourceminer.com>
2025-02-23 15:43:01 -05:00

32 lines
1019 B
TypeScript

import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { ExternalPoolShare } from '../models/ExternalPoolShare';
@Injectable()
export class ExternalSharesService {
private readonly shareApiUrl: string;
private readonly shareApiKey: string;
constructor(
private readonly configService: ConfigService,
private readonly httpService: HttpService
) {
this.shareApiUrl = this.configService.get('SHARE_SUBMISSION_URL') || 'https://web.public-pool.io';
this.shareApiKey = this.configService.get('SHARE_SUBMISSION_API_KEY');
}
public submitShare(share: ExternalPoolShare): void {
this.httpService.post(`${this.shareApiUrl}/api/share`, share, {
headers: {
'x-api-key': this.shareApiKey
}
}).subscribe({
next: () =>{
console.log('External share accepted');
},
error: (error) => console.error('Failed to submit share to API:', error.message)
});
}
}