Example #1
0
 public override byte[] BitcoinSerialize()
 {
     using (var buf = new MemoryStream())
     {
         // Version, for some reason.
         buf.WriteLittleEndian(NetworkParameters.ProtocolVersion);
         // Then a vector of block hashes. This is actually a "block locator", a set of block
         // identifiers that spans the entire chain with exponentially increasing gaps between
         // them, until we end up at the genesis block. See CBlockLocator::Set()
         buf.Write(new VarInt((ulong) _locator.Count).Encode());
         foreach (var hash in _locator)
         {
             // Have to reverse as wire format is little endian.
             buf.Write(Utils.ReverseBytes(hash.Bytes));
         }
         // Next, a block ID to stop at.
         buf.Write(_stopHash.Bytes);
         return buf.ToArray();
     }
 }
Example #2
0
 private byte[] HashTransactionForSignature(SigHash type, bool anyoneCanPay)
 {
     using (var bos = new MemoryStream())
     {
         BitcoinSerializeToStream(bos);
         // We also have to write a hash type.
         var hashType = (uint) type + 1;
         if (anyoneCanPay)
             hashType |= 0x80;
         bos.WriteLittleEndian(hashType);
         // Note that this is NOT reversed to ensure it will be signed correctly. If it were to be printed out
         // however then we would expect that it is IS reversed.
         return Utils.DoubleDigest(bos.ToArray());
     }
 }