Exemple #1
0
 public static void EncodeBlockHeader(BinaryWriter writer, BlockHeader blockHeader)
 {
     writer.WriteUInt32(blockHeader.Version);
     writer.WriteUInt256(blockHeader.PreviousBlock);
     writer.WriteUInt256(blockHeader.MerkleRoot);
     writer.WriteUInt32((uint)blockHeader.Time.ToUnixTimeSeconds());
     writer.WriteUInt32(blockHeader.Bits);
     writer.WriteUInt32(blockHeader.Nonce);
 }
Exemple #2
0
        public static byte[] EncodeBlockHeader(UInt32 Version, UInt256 PreviousBlock, UInt256 MerkleRoot, DateTimeOffset Time, UInt32 Bits, UInt32 Nonce)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.WriteUInt32(Version);
                writer.WriteUInt256(PreviousBlock);
                writer.WriteUInt256(MerkleRoot);
                writer.WriteUInt32((uint)Time.ToUnixTimeSeconds());
                writer.WriteUInt32(Bits);
                writer.WriteUInt32(Nonce);

                return stream.ToArray();
            }
        }
Exemple #3
0
 public static void EncodeGetBlocksPayload(BinaryWriter writer, GetBlocksPayload getBlocksPayload)
 {
     writer.WriteUInt32(getBlocksPayload.Version);
     writer.WriteList(getBlocksPayload.BlockLocatorHashes, locatorHash => writer.WriteUInt256(locatorHash));
     writer.WriteUInt256(getBlocksPayload.HashStop);
 }
Exemple #4
0
 public static void EncodeInventoryVector(BinaryWriter writer, InventoryVector invVector)
 {
     writer.WriteUInt32(invVector.Type);
     writer.WriteUInt256(invVector.Hash);
 }
Exemple #5
0
 public static void EncodeTxOutputKey(BinaryWriter writer, TxOutputKey txOutputKey)
 {
     writer.WriteUInt256(txOutputKey.TxHash);
     writer.WriteUInt32(txOutputKey.TxOutputIndex);
 }
Exemple #6
0
 public static void EncodeBlockTxNode(BinaryWriter writer, BlockTxNode blockTx)
 {
     writer.WriteInt32(blockTx.Index);
     writer.WriteInt32(blockTx.Depth);
     writer.WriteUInt256(blockTx.Hash);
     writer.WriteBool(blockTx.Pruned);
     if (!blockTx.Pruned)
         writer.WriteBytes(blockTx.TxBytes.ToArray());
 }
Exemple #7
0
 public static void EncodeTxLookupKey(BinaryWriter writer, TxLookupKey txLookupKey)
 {
     writer.WriteUInt256(txLookupKey.BlockHash);
     writer.WriteInt32(txLookupKey.TxIndex);
 }
Exemple #8
0
 public static void EncodeUnmintedTx(BinaryWriter writer, UnmintedTx unmintedTx)
 {
     writer.WriteUInt256(unmintedTx.TxHash);
     EncodePrevTxOutputList(writer, unmintedTx.PrevTxOutputs);
 }
Exemple #9
0
 public static void EncodeUnspentTx(BinaryWriter writer, UnspentTx unspentTx)
 {
     writer.WriteUInt256(unspentTx.TxHash);
     writer.WriteInt32(unspentTx.BlockIndex);
     writer.WriteInt32(unspentTx.TxIndex);
     writer.WriteUInt32(unspentTx.TxVersion);
     writer.WriteBool(unspentTx.IsCoinbase);
     writer.WriteVarBytes(unspentTx.OutputStates.ToByteArray());
     writer.WriteInt32(unspentTx.OutputStates.Length);
 }
Exemple #10
0
 public static void EncodeSpentTx(BinaryWriter writer, SpentTx spentTx)
 {
     writer.WriteUInt256(spentTx.TxHash);
     writer.WriteInt32(spentTx.ConfirmedBlockIndex);
     writer.WriteInt32(spentTx.TxIndex);
     writer.WriteInt32(spentTx.OutputCount);
 }
Exemple #11
0
 public static void EncodeUInt256(BinaryWriter writer, UInt256 value)
 {
     writer.WriteUInt256(value);
 }
Exemple #12
0
 public static void EncodeTxInput(BinaryWriter writer, TxInput txInput)
 {
     writer.WriteUInt256(txInput.PrevTxOutputKey.TxHash);
     writer.WriteUInt32(txInput.PrevTxOutputKey.TxOutputIndex);
     writer.WriteVarBytes(txInput.ScriptSignature.ToArray());
     writer.WriteUInt32(txInput.Sequence);
 }
Exemple #13
0
 public static void EncodeChainedHeader(BinaryWriter writer, ChainedHeader chainedHeader)
 {
     writer.WriteUInt256(chainedHeader.Hash);
     EncodeBlockHeader(writer, chainedHeader.BlockHeader);
     writer.WriteInt32(chainedHeader.Height);
     writer.WriteVarBytes(chainedHeader.TotalWork.ToByteArray());
     writer.WriteInt64(chainedHeader.DateSeen.UtcTicks);
 }
Exemple #14
0
 public static void EncodeUnmintedTx(BinaryWriter writer, UnmintedTx unmintedTx)
 {
     writer.WriteUInt256(unmintedTx.TxHash);
     writer.WriteList(unmintedTx.PrevOutputTxKeys, x => EncodeTxLookupKey(writer, x));
 }
Exemple #15
0
        public static void EncodeBlockTx(BinaryWriter writer, BlockTx blockTx)
        {
            var txBytes = blockTx.Transaction != null ? EncodeTransaction(blockTx.Transaction) : new byte[0];

            writer.WriteInt32(blockTx.Index);
            writer.WriteInt32(blockTx.Depth);
            writer.WriteUInt256(blockTx.Hash);
            writer.WriteBool(blockTx.Pruned);
            if (!blockTx.Pruned)
                EncodeTransaction(writer, blockTx.Transaction);
        }