allow client to suggest diff in password field "d=1234"

This commit is contained in:
Ben Wilson
2024-03-27 17:02:11 -04:00
parent 6442bb45e0
commit 32a604e745
2 changed files with 23 additions and 3 deletions
+3
View File
@@ -217,6 +217,9 @@ export class StratumV1Client {
if (errors.length === 0) { if (errors.length === 0) {
this.clientAuthorization = authorizationMessage; this.clientAuthorization = authorizationMessage;
if (this.clientSuggestedDifficulty == null && this.clientAuthorization.startingDiff != null && this.clientAuthorization.startingDiff > this.sessionDifficulty) {
this.sessionDifficulty = this.clientAuthorization.startingDiff;
}
const success = await this.write(JSON.stringify(this.clientAuthorization.response()) + '\n'); const success = await this.write(JSON.stringify(this.clientAuthorization.response()) + '\n');
if (!success) { if (!success) {
return; return;
@@ -1,5 +1,5 @@
import { Expose, Transform } from 'class-transformer'; import { Expose, Transform } from 'class-transformer';
import { ArrayMaxSize, ArrayMinSize, IsArray, IsOptional, IsString, MaxLength } from 'class-validator'; import { ArrayMaxSize, ArrayMinSize, IsArray, IsNumber, IsOptional, IsString, MaxLength } from 'class-validator';
import { eRequestMethod } from '../enums/eRequestMethod'; import { eRequestMethod } from '../enums/eRequestMethod';
import { IsBitcoinAddress } from '../validators/bitcoin-address.validator'; import { IsBitcoinAddress } from '../validators/bitcoin-address.validator';
@@ -8,7 +8,7 @@ import { StratumBaseMessage } from './StratumBaseMessage';
export class AuthorizationMessage extends StratumBaseMessage { export class AuthorizationMessage extends StratumBaseMessage {
@IsArray() @IsArray()
@ArrayMinSize(2) @ArrayMinSize(1)
@ArrayMaxSize(2) @ArrayMaxSize(2)
params: string[]; params: string[];
@@ -24,11 +24,28 @@ export class AuthorizationMessage extends StratumBaseMessage {
@IsString() @IsString()
@MaxLength(64) @MaxLength(64)
@Transform(({ value, key, obj, type }) => { @Transform(({ value, key, obj, type }) => {
return obj.params[0].split('.')[1] == null ? 'worker' : obj.params[0].split('.')[1]; const workerName = obj.params[0].split('.')[1];
if (workerName == null) {
return 'worker';
}
return workerName;
}) })
public worker: string; public worker: string;
@Expose()
@IsNumber()
@Transform(({ value, key, obj, type }) => {
const password: string | null = obj.params[1];
if (password?.includes('d=')) {
return parseInt(password.split('d=')[1]);
}
return null;
})
@IsOptional()
public startingDiff: number;
@Expose() @Expose()
@IsString() @IsString()
@Transform(({ value, key, obj, type }) => { @Transform(({ value, key, obj, type }) => {