本文整理汇总了C#中BitcoinStream类的典型用法代码示例。如果您正苦于以下问题:C# BitcoinStream类的具体用法?C# BitcoinStream怎么用?C# BitcoinStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitcoinStream类属于命名空间,在下文中一共展示了BitcoinStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
using(stream.NetworkFormatScope(true))
{
ReadWriteCore(stream);
}
}
示例2: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
using(stream.SerializationTypeScope(SerializationType.Network))
{
ReadWriteCore(stream);
}
}
示例3: 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)
{
}
}
}
示例4: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref _chainHeight);
stream.ReadWrite(ref _chainTipHash);
stream.ReadWrite(ref _bitmap);
stream.ReadWrite(ref _outputs);
}
示例5: ToBytes
public byte[] ToBytes()
{
var ms = new MemoryStream();
var stream = new BitcoinStream(ms, true);
ReadWrite(stream);
return ms.ToArray();
}
示例6: 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;
}
}
示例7: 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());
}
示例8: ReadWriteCore
public override void ReadWriteCore(BitcoinStream stream)
{
var old = stream.MaxArraySize;
stream.MaxArraySize = 5000;
stream.ReadWrite(ref inventory);
stream.MaxArraySize = old;
}
示例9: 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;
}
}
示例10: 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);
}
示例11: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
stream.ReadWrite(ref _Address);
stream.ReadWrite(ref source);
stream.ReadWrite(ref nLastSuccess);
stream.ReadWrite(ref nAttempts);
}
示例12: 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;
}
}
示例13: ReadWrite
public void ReadWrite(BitcoinStream stream)
{
if(stream.ProtocolVersion >= ProtocolVersion.CADDR_TIME_VERSION)
stream.ReadWrite(ref time);
stream.ReadWrite(ref service);
stream.ReadWrite(ref ip);
using(stream.BigEndianScope())
{
stream.ReadWrite(ref port);
}
}
示例14: 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);
}
示例15: 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);
}
}