mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
stratum error init
This commit is contained in:
@@ -15,10 +15,12 @@ import { EasyUnsubscribe } from '../utils/AutoUnsubscribe';
|
||||
import { IBlockTemplate } from './bitcoin-rpc/IBlockTemplate';
|
||||
import { eRequestMethod } from './enums/eRequestMethod';
|
||||
import { eResponseMethod } from './enums/eResponseMethod';
|
||||
import { eStratumErrorCode } from './enums/eStratumErrorCode';
|
||||
import { MiningJob } from './MiningJob';
|
||||
import { AuthorizationMessage } from './stratum-messages/AuthorizationMessage';
|
||||
import { ConfigurationMessage } from './stratum-messages/ConfigurationMessage';
|
||||
import { MiningSubmitMessage } from './stratum-messages/MiningSubmitMessage';
|
||||
import { StratumErrorMessage } from './stratum-messages/StratumErrorMessage';
|
||||
import { SubscriptionMessage } from './stratum-messages/SubscriptionMessage';
|
||||
import { SuggestDifficulty } from './stratum-messages/SuggestDifficultyMessage';
|
||||
import { StratumV1ClientStatistics } from './StratumV1ClientStatistics';
|
||||
@@ -107,7 +109,16 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
socket.write(JSON.stringify(this.clientSubscription.response(this.extraNonce)) + '\n');
|
||||
} else {
|
||||
console.error(errors);
|
||||
|
||||
const err = new StratumErrorMessage(
|
||||
subscriptionMessage.id,
|
||||
eStratumErrorCode.OtherUnknown,
|
||||
'Subscription error',
|
||||
errors).response();
|
||||
|
||||
console.error(err);
|
||||
socket.write(err);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export enum eStratumErrorCode {
|
||||
'OtherUnknown' = 20,
|
||||
'JobNotFound' = 21, // (=stale)
|
||||
'DuplicateShare' = 22,
|
||||
'LowDifficultyShare' = 23,
|
||||
'UnauthorizedWorker' = 24,
|
||||
'NotSubscribed' = 25
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ValidationError } from 'class-validator';
|
||||
|
||||
import { eStratumErrorCode } from '../enums/eStratumErrorCode';
|
||||
|
||||
export class StratumErrorMessage {
|
||||
|
||||
constructor(
|
||||
private id: number = null,
|
||||
private errorCode: eStratumErrorCode,
|
||||
private errorMessage: string,
|
||||
private validationErrors: ValidationError[]
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
public response(): string {
|
||||
|
||||
const error = {
|
||||
id: this.id,
|
||||
result: null,
|
||||
error: [this.errorCode, this.errorMessage, this.validationErrors.reduce((pre, cur) => `${pre}, ${cur.value}`, '')]
|
||||
}
|
||||
return JSON.stringify(error + '\n');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user