Files
public-pool/src/models/stratum-messages/MiningSubmitMessage.ts
T
2026-05-06 18:18:34 -04:00

81 lines
1.9 KiB
TypeScript

import { Expose, Transform } from 'class-transformer';
import { ArrayMaxSize, ArrayMinSize, IsArray, IsString, Length } from 'class-validator';
import { eRequestMethod } from '../enums/eRequestMethod';
import { EXTRANONCE2_SIZE_BYTES } from '../stratum.constants';
import { StratumBaseMessage } from './StratumBaseMessage';
import * as bitcoinjs from 'bitcoinjs-lib';
export class MiningSubmitMessage extends StratumBaseMessage {
@IsArray()
@ArrayMinSize(5)
@ArrayMaxSize(6)
public params: string[];
@Expose()
@IsString()
@Transform(({ value, key, obj, type }) => {
return obj.params[0];
})
public userId: string;
@Expose()
@IsString()
@Transform(({ value, key, obj, type }) => {
return obj.params[1];
})
public jobId: string;
@Expose()
@IsString()
@Length(EXTRANONCE2_SIZE_BYTES * 2, EXTRANONCE2_SIZE_BYTES * 2)
@Transform(({ value, key, obj, type }) => {
return obj.params[2];
})
public extraNonce2: string;
@Expose()
@IsString()
@Transform(({ value, key, obj, type }) => {
return obj.params[3];
})
public ntime: string;
@Expose()
@IsString()
@Transform(({ value, key, obj, type }) => {
return obj.params[4];
})
public nonce: string
@Expose()
@IsString()
@Transform(({ value, key, obj, type }) => {
return obj.params[5] == null ? '0' : obj.params[5];
})
public versionMask?: string | null;
constructor() {
super();
this.method = eRequestMethod.AUTHORIZE;
}
public response() {
return {
id: this.id,
error: null,
result: true
};
}
public hash(): string{
const buffer = Buffer.from(this.versionMask + this.nonce + this.extraNonce2 + this.ntime + this.jobId);
return bitcoinjs.crypto.hash256(buffer).toString('base64');
}
}