mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { Expose, Transform } from 'class-transformer';
|
|
import { IsArray, IsString, MaxLength } from 'class-validator';
|
|
|
|
import { eRequestMethod } from '../enums/eRequestMethod';
|
|
import { StratumBaseMessage } from './StratumBaseMessage';
|
|
|
|
export class SubscriptionMessage extends StratumBaseMessage {
|
|
|
|
|
|
@IsArray()
|
|
params: string[];
|
|
|
|
@Expose()
|
|
@IsString()
|
|
@MaxLength(128)
|
|
@Transform(({ value, key, obj, type }) => {
|
|
return obj.params[0] == null ? 'unknown' : SubscriptionMessage.refineUserAgent(obj.params[0]);
|
|
})
|
|
public userAgent: string;
|
|
|
|
constructor() {
|
|
super();
|
|
this.method = eRequestMethod.SUBSCRIBE;
|
|
}
|
|
|
|
public response(clientId: string) {
|
|
return {
|
|
id: this.id,
|
|
error: null,
|
|
result: [
|
|
[
|
|
['mining.notify', clientId]
|
|
],
|
|
clientId, //Extranonce1 - Hex-encoded, per-connection unique string which will be used for coinbase serialization later. Keep it safe!
|
|
4 //Extranonce2_size - Represents expected length of extranonce2 which will be generated by the miner.
|
|
]
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static refineUserAgent(userAgent: string): string {
|
|
userAgent = userAgent.split(' ')[0].split('/')[0].split('V')[0];
|
|
|
|
if (userAgent.includes('bosminer')) {
|
|
userAgent = 'Braiins OS';
|
|
} else if (userAgent.includes('cpuminer')) {
|
|
userAgent = 'cpuminer';
|
|
}
|
|
return userAgent;
|
|
}
|
|
} |