static Stratum.Notification.NewJob MakeJob(ReplicationData.Job repl) { var jobid = "abcd"; var cbHead = HexHelp.DecodeHex(repl.cbHead); var cbTail = HexHelp.DecodeHex(repl.cbTail); var parsedMerkle = DecodeMerkles(repl.merkles); var bver = HexHelp.DecodeHex(repl.blockVersion); var ndiff = HexHelp.DecodeHex(repl.networkDiff); var ntime = HexHelp.DecodeHex(repl.networkTime); var res = new Stratum.Notification.NewJob(jobid, bver, null, cbHead, cbTail, ndiff, ntime, true); HexHelp.DecodeInto(res.prevBlock.blob, repl.prevHash); res.merkles.AddRange(parsedMerkle); return(res); }
static public Notification.NewJob MiningNotify(object?evargs) { if (null == evargs) { throw new MissingRequiredException("mining.notify: no payload given"); } if (evargs is not JArray concrete) { throw new MissingRequiredException("mining.notify: payload must be an array"); } if (concrete.Count != 9 && concrete.Count != 10) { throw new BadParseException("mining.notify: element count mismatch, won't be able to parse"); } var getTrie = concrete.Count == 10; byte[]? trie = null; var index = 0; var jobid = concrete[index++].Value <string>(); var prevHashHexstr = concrete[index++].Value <string>(); if (getTrie) { var triestr = concrete[index++].Value <string>(); trie = HexHelp.DecodeHex(triestr); } var coinbaseFirst = concrete[index++].Value <string>(); var coinBaseSecond = concrete[index++].Value <string>(); var merkles = concrete[index++] as JArray ?? throw new BadParseException("mining.notify: merkles must be an array"); var version = HexHelp.DecodeHex(concrete[index++].Value <string>()); var nbits = HexHelp.DecodeHex(concrete[index++].Value <string>()); var ntime = HexHelp.DecodeHex(concrete[index++].Value <string>()); var flush = concrete[index++].Value <bool>(); var cbFirst = HexHelp.DecodeHex(coinbaseFirst); var cbTail = HexHelp.DecodeHex(coinBaseSecond); var res = new Notification.NewJob(jobid, version, trie, cbFirst, cbTail, nbits, ntime, flush); HexHelp.DecodeInto(res.prevBlock.blob, prevHashHexstr); var decodedMerkles = merkles.Select(el => AsMerkle(el)); res.merkles.AddRange(decodedMerkles); return(res); }
public void NewJob(Notification.NewJob job) { currently = job; nonce2Off = job.cbHead.Length + extraNonceOne.Length; var coinbase = MakeCoinbaseTemplate(job.cbHead, extraNonceOne, nonce2Off, nonce2.ByteCount, job.cbTail); StampNonce2(coinbase, nonce2Off, nonce2); var merkle = MakeNewMerkles(initialMerkle, job.merkles, coinbase); SwapUintBytes(merkle); // that's from stratum documentation var header = job.blockVer.Concat(job.prevBlock.blob).Concat(merkle); if (job.trie != null) { header = header.Concat(job.trie); // not present in stratum v1 docs nor in M8M but sgminer has it (?) } header = header.Concat(job.ntime).Concat(job.networkDiff); header = header.Concat(noncePad); // nonce to be tested header = header.Concat(workPadding); this.header = header.ToArray(); // But legacy miners have a quirk. They just zero out the whole thing (at least in the code I have checked). this.header[^ 45] = 0;
public NewJobReceivedEventArgs(Notification.NewJob newJob) { this.newJob = newJob; }