51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
using Newtonsoft.Json.Linq;
|
|
using sharp.extensions;
|
|
using sharp.cryptonote;
|
|
namespace SharpMining
|
|
{
|
|
public class MiningJob
|
|
{
|
|
|
|
public MiningJob(byte[] blob, UInt64 jobid, UInt64 height, UInt64 target)
|
|
{
|
|
this.Blob = blob;
|
|
this.JobID = jobid;
|
|
this.Height = height;
|
|
this.Target = target;
|
|
|
|
Block block = new Block(blob);
|
|
|
|
Console.WriteLine( block.ToString() );
|
|
|
|
}
|
|
|
|
public byte[] Blob { get; private set; }
|
|
public UInt64 JobID { get; private set; }
|
|
public UInt64 Height { get; private set; }
|
|
public UInt64 Target { get; private set; }
|
|
public StratumConnection Miner { get; set; }
|
|
|
|
public JToken toJSON()
|
|
{
|
|
JToken job = new JObject(
|
|
new JProperty("blob", HexString.toString(Blob)),
|
|
new JProperty("job_id", HexString.toString(JobID.GetBytes())),
|
|
new JProperty("target", HexString.toString(Target.GetBytes()))
|
|
);
|
|
return job;
|
|
}
|
|
public JToken toJSON(UInt64 diff)
|
|
{
|
|
UInt64 target = (((UInt64)1<<32)-1) / diff;
|
|
JToken job = new JObject(
|
|
new JProperty("blob", Blob.Segment(0,76).toHexString()),
|
|
new JProperty("job_id", JobID.GetBytes().toHexString()),
|
|
new JProperty("target", target.GetBytes(Endianess.LittleEndian).toHexString().Substring(0,8))
|
|
);
|
|
return job;
|
|
}
|
|
|
|
}
|
|
}
|