by
84k 18
0
4
78k
0
Top 1% !
Pearl of Wisdom
Tagged
Specified
Popularity: 32853rd place

Published on:

Architecturex86_64
LanguageC#
Windows VersionWindows7

SerializeHeader: Block headers are sent in a headers packet in response to a getheaders message.

Block headers are sent in a headers packet in response to a getheaders message.

<remarks>
https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers
</remarks>
<example>
nodejs: https://github.com/zone117x/node-stratum-pool/blob/master/lib/blockTemplate.js#L85
</example>
<param name="job"></param>
<param name="merkleRoot"></param>
<param name="nTime"></param>
<param name="nonce"></param>
<returns></returns>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1373923/SerializeHeader--Block-headers-are-sent-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.IO; using System.Text; using CoiniumServ.Jobs; using CoiniumServ.Utils.Extensions; using CoiniumServ.Utils.Helpers; using Gibbed.IO; /// <summary> /// Block headers are sent in a headers packet in response to a getheaders message. /// </summary> /// <remarks> /// https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers /// </remarks> /// <example> /// nodejs: https://github.com/zone117x/node-stratum-pool/blob/master/lib/blockTemplate.js#L85 /// </example> /// <param name="job"></param> /// <param name="merkleRoot"></param> /// <param name="nTime"></param> /// <param name="nonce"></param> /// <returns></returns> public static byte[] SerializeHeader(IJob job, byte[] merkleRoot, UInt32 nTime, UInt32 nonce) { byte[] result; using (var stream = new MemoryStream()) { stream.WriteValueU32(nonce.BigEndian()); stream.WriteValueU32(Convert.ToUInt32(job.EncodedDifficulty, 16).BigEndian()); stream.WriteValueU32(nTime.BigEndian()); stream.WriteBytes(merkleRoot); stream.WriteBytes(job.PreviousBlockHash.HexToByteArray()); stream.WriteValueU32(job.BlockTemplate.Version.BigEndian()); result = stream.ToArray(); result = result.ReverseBytes(); } return result; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus