本文整理汇总了C#中BitcoinStream.ReadWrite方法的典型用法代码示例。如果您正苦于以下问题:C# BitcoinStream.ReadWrite方法的具体用法?C# BitcoinStream.ReadWrite怎么用?C# BitcoinStream.ReadWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitcoinStream
的用法示例。
在下文中一共展示了BitcoinStream.ReadWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadData
private bool ReadData(byte[] data)
{
try
{
BitcoinStream stream = new BitcoinStream(data);
ushort marker = 0;
stream.ReadWrite(ref marker);
if(marker != Tag)
return false;
stream.ReadWrite(ref _Version);
if(_Version != 1)
return false;
ulong quantityCount = 0;
stream.ReadWriteAsVarInt(ref quantityCount);
Quantities = new ulong[quantityCount];
for(ulong i = 0 ; i < quantityCount ; i++)
{
Quantities[i] = ReadLEB128(stream);
if(Quantities[i] > MAX_QUANTITY)
return false;
}
stream.ReadWriteAsVarString(ref _Metadata);
if(stream.Inner.Position != data.Length)
return false;
return true;
}
catch(Exception)
{
return false;
}
}
示例2: Load
public void Load(BitcoinStream stream)
{
using(@lock.LockWrite())
{
try
{
int height = 0;
while(true)
{
uint256 id = null;
stream.ReadWrite<uint256>(ref id);
BlockHeader header = null;
stream.ReadWrite(ref header);
if(height == 0)
{
_BlocksByHeight.Clear();
_BlocksById.Clear();
_Tip = null;
SetTipNoLock(new ChainedBlock(header, 0));
}
else
SetTipNoLock(new ChainedBlock(header, id, Tip));
height++;
}
}
catch(EndOfStreamException)
{
}
}
}
示例3: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref _chainHeight);
stream.ReadWrite(ref _chainTipHash);
stream.ReadWrite(ref _bitmap);
stream.ReadWrite(ref _outputs);
}
示例4: ReadScript
private bool ReadScript(Script script)
{
try
{
var data = TxNullDataTemplate.Instance.ExtractScriptPubKeyParameters(script);
if(data == null)
return false;
BitcoinStream stream = new BitcoinStream(data);
ushort marker = 0;
stream.ReadWrite(ref marker);
if(marker != Tag)
return false;
stream.ReadWrite(ref _Version);
if(_Version != 1)
return false;
ulong quantityCount = 0;
stream.ReadWriteAsVarInt(ref quantityCount);
Quantities = new ulong[quantityCount];
for(ulong i = 0 ; i < quantityCount ; i++)
{
Quantities[i] = ReadLEB128(stream);
if(Quantities[i] > MAX_QUANTITY)
return false;
}
stream.ReadWriteAsVarString(ref _Metadata);
return true;
}
catch(Exception)
{
return false;
}
}
示例5: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
var len = new VarInt((ulong)_Bytes.Length);
stream.ReadWrite(ref len);
if(!stream.Serializing)
_Bytes = new byte[len.ToLong()];
stream.ReadWrite(ref _Bytes);
}
示例6: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref _Address);
stream.ReadWrite(ref source);
stream.ReadWrite(ref nLastSuccess);
stream.ReadWrite(ref nAttempts);
}
示例7: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
if(Payload == null && stream.Serializing)
throw new InvalidOperationException("Payload not affected");
if(stream.Serializing || (!stream.Serializing && !_SkipMagic))
stream.ReadWrite(ref magic);
stream.ReadWrite(ref command);
int length = 0;
uint checksum = 0;
bool hasChecksum = false;
byte[] payloadBytes = stream.Serializing ? GetPayloadBytes(stream.ProtocolVersion, out length) : null;
length = payloadBytes == null ? 0 : length;
stream.ReadWrite(ref length);
if(stream.ProtocolVersion >= ProtocolVersion.MEMPOOL_GD_VERSION)
{
if(stream.Serializing)
checksum = Hashes.Hash256(payloadBytes, 0, length).GetLow32();
stream.ReadWrite(ref checksum);
hasChecksum = true;
}
if(stream.Serializing)
{
stream.ReadWrite(ref payloadBytes, 0, length);
}
else
{
if(length > 0x02000000) //MAX_SIZE 0x02000000 Serialize.h
{
throw new FormatException("Message payload too big ( > 0x02000000 bytes)");
}
payloadBytes = _Buffer == null || _Buffer.Length < length ? new byte[length] : _Buffer;
stream.ReadWrite(ref payloadBytes, 0, length);
if(hasChecksum)
{
if(!VerifyChecksum(checksum, payloadBytes, length))
{
if(NodeServerTrace.Trace.Switch.ShouldTrace(TraceEventType.Verbose))
NodeServerTrace.Trace.TraceEvent(TraceEventType.Verbose, 0, "Invalid message checksum bytes");
throw new FormatException("Message checksum invalid");
}
}
BitcoinStream payloadStream = new BitcoinStream(payloadBytes);
payloadStream.CopyParameters(stream);
var payloadType = PayloadAttribute.GetCommandType(Command);
var unknown = payloadType == typeof(UnknowPayload);
if(unknown)
NodeServerTrace.Trace.TraceEvent(TraceEventType.Warning, 0, "Unknown command received : " + Command);
object payload = _PayloadObject;
payloadStream.ReadWrite(payloadType, ref payload);
if(unknown)
((UnknowPayload)payload)._Command = Command;
Payload = (Payload)payload;
}
}
示例8: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
var len = new VarInt((ulong)_Bytes.Length);
stream.ReadWrite(ref len);
if(!stream.Serializing)
{
if(len.ToLong() > (uint)stream.MaxArraySize)
throw new ArgumentOutOfRangeException("Array size not big");
_Bytes = new byte[len.ToLong()];
}
stream.ReadWrite(ref _Bytes);
}
示例9: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
if(stream.Serializing)
{
var b = Value.ToBytes();
stream.ReadWrite(ref b);
}
else
{
byte[] b = new byte[WIDTH_BYTE];
stream.ReadWrite(ref b);
_Value = new uint256(b);
}
}
示例10: ReadWriteCore
public override void ReadWriteCore(BitcoinStream stream)
{
if(stream.Serializing)
{
var heardersOff = headers.Select(h => new BlockHeaderWithTxCount(h)).ToList();
stream.ReadWrite(ref heardersOff);
}
else
{
headers.Clear();
List<BlockHeaderWithTxCount> headersOff = new List<BlockHeaderWithTxCount>();
stream.ReadWrite(ref headersOff);
headers.AddRange(headersOff.Select(h => h._Header));
}
}
示例11: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref _OutPoint);
if(stream.Serializing)
{
TxOutCompressor compressor = new TxOutCompressor(_Out);
stream.ReadWrite(ref compressor);
}
else
{
TxOutCompressor compressor = new TxOutCompressor();
stream.ReadWrite(ref compressor);
_Out = compressor.TxOut;
}
}
示例12: ReadWriteCore
public override void ReadWriteCore(BitcoinStream stream)
{
var old = stream.MaxArraySize;
stream.MaxArraySize = 5000;
stream.ReadWrite(ref inventory);
stream.MaxArraySize = old;
}
示例13: bloom_create_insert_serialize
public void bloom_create_insert_serialize()
{
BloomFilter filter = new BloomFilter(3, 0.01, 0, BloomFlags.UPDATE_ALL);
filter.Insert(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8"));
Assert.True(filter.Contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter doesn't contain just-inserted object!");
// One bit different in first byte
Assert.True(!filter.Contains(ParseHex("19108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter contains something it shouldn't!");
filter.Insert(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"));
Assert.True(filter.Contains(ParseHex("b5a2c786d9ef4658287ced5914b37a1b4aa32eee")), "BloomFilter doesn't contain just-inserted object (2)!");
filter.Insert(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5"));
Assert.True(filter.Contains(ParseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")), "BloomFilter doesn't contain just-inserted object (3)!");
var ms = new MemoryStream();
BitcoinStream bitcoinStream = new BitcoinStream(ms, true);
bitcoinStream.ReadWrite(filter);
var expected = ParseHex("03614e9b050000000000000001");
AssertEx.CollectionEquals(expected, ms.ToArray());
}
示例14: uitnSerializationTests
public void uitnSerializationTests()
{
MemoryStream ms = new MemoryStream();
BitcoinStream stream = new BitcoinStream(ms, true);
var v = new uint256("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
var vless = new uint256("00000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffe");
var vplus = new uint256("00000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
stream.ReadWrite(ref v);
Assert.NotNull(v);
ms.Position = 0;
stream = new BitcoinStream(ms, false);
uint256 v2 = uint256.Zero;
stream.ReadWrite(ref v2);
Assert.Equal(v, v2);
v2 = null;
ms.Position = 0;
stream.ReadWrite(ref v2);
Assert.Equal(v, v2);
List<uint256> vs = new List<uint256>()
{
v,vless,vplus
};
ms = new MemoryStream();
stream = new BitcoinStream(ms, true);
stream.ReadWrite(ref vs);
Assert.True(vs.Count == 3);
ms.Position = 0;
stream = new BitcoinStream(ms, false);
List<uint256> vs2 = new List<uint256>();
stream.ReadWrite(ref vs2);
Assert.True(vs2.SequenceEqual(vs));
ms.Position = 0;
vs2 = null;
stream.ReadWrite(ref vs2);
Assert.True(vs2.SequenceEqual(vs));
}
示例15: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWriteAsVarInt(ref _Index);
if(stream.Serializing)
{
byte[] assetId = Asset.Id.ToBytes();
stream.ReadWrite(ref assetId);
long quantity = Asset.Quantity;
stream.ReadWrite(ref quantity);
}
else
{
byte[] assetId = new byte[20];
stream.ReadWrite(ref assetId);
long quantity = 0;
stream.ReadWrite(ref quantity);
Asset = new AssetMoney(new AssetId(assetId), quantity);
}
}