Skip to content

Commit

Permalink
Serializing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MsBarber committed Nov 29, 2018
1 parent cb299c8 commit db5d019
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
34 changes: 31 additions & 3 deletions NBitcoin/Protocol/Payloads/CompactFilterCheckPointPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,39 @@ public void ReadWrite(BitcoinStream stream)
stream.ReadWrite(ref _filterType);
stream.ReadWrite(ref _stopHash);
stream.ReadWrite(ref _FilterHeadersLength);
var _tempfilterHeaders = new byte[_FilterHeadersLength.ToLong() * 32];

stream.ReadWrite(ref _tempfilterHeaders);
//when serializing(Writing) we have to fill the tempfilterHeaders
if (stream.Serializing)
{
//turn the uint256[] into a byte array to write back into the bitcoin stream
List<byte> _tempfilterHeaders = new List<byte>();
byte[] _tempFilterHeaderBytes = new byte[_FilterHeadersLength.ToLong() * 32]; //Init byte array to hold list after conversion

foreach (var hash in _filterHeaders)
{
foreach (var bytee in hash.ToBytes())
{
_tempfilterHeaders.Add(bytee);

}
}
//Write bytes
_tempFilterHeaderBytes = _tempfilterHeaders.ToArray();
stream.ReadWrite(ref _tempFilterHeaderBytes);
}

_filterHeaders = GetHashes(_tempfilterHeaders);

if (!stream.Serializing)
{
//instantiate a byte[] to hold the incoming hashes
var _tempfilterHeaders = new byte[_FilterHeadersLength.ToLong() * 32];

//Write filters to temp variable
stream.ReadWrite(ref _tempfilterHeaders);

//Convert the byte[] into "readable" uint256 hashes
_filterHeaders = GetHashes(_tempfilterHeaders);
}
}


Expand Down
34 changes: 31 additions & 3 deletions NBitcoin/Protocol/Payloads/CompactFilterHeadersPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,39 @@ public void ReadWrite(BitcoinStream stream)
stream.ReadWrite(ref _stopHash);
stream.ReadWrite(ref _previousFilterHeader);
stream.ReadWrite(ref _filterHashesLength);
var _tempfilterHeaders = new byte[_filterHashesLength.ToLong() * 32];
//var _tempfilterHeaders = new byte[_filterHashesLength.ToLong() * 32];

stream.ReadWrite(ref _tempfilterHeaders);
if (stream.Serializing)
{
//turn the uint256[] into a byte array to write back into the bitcoin stream
List<byte> _tempfilterHeaders = new List<byte>();
byte[] _tempFilterHeaderBytes = new byte[_filterHashesLength.ToLong() * 32]; //Init byte array to hold list after conversion

foreach (var hash in _filterHashes)
{
foreach (var bytee in hash.ToBytes())
{
_tempfilterHeaders.Add(bytee);

}
}
//Write bytes
_tempFilterHeaderBytes = _tempfilterHeaders.ToArray();
stream.ReadWrite(ref _tempFilterHeaderBytes);
}

_filterHashes = GetHashes(_tempfilterHeaders);

if (!stream.Serializing)
{
//instantiate a byte[] to hold the incoming hashes
var _tempfilterHeaders = new byte[_filterHashesLength.ToLong() * 32];

//Write filters to temp variable
stream.ReadWrite(ref _tempfilterHeaders);

//Convert the byte[] into "readable" uint256 hashes
_filterHashes = GetHashes(_tempfilterHeaders);
}
}

private uint256[] GetHashes(byte[] filterHeaders)
Expand Down

0 comments on commit db5d019

Please sign in to comment.