当前位置: 首页>>代码示例>>C#>>正文


C# BitcoinStream类代码示例

本文整理汇总了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);
     }
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:7,代码来源:Payload.cs

示例2: ReadWrite

		public void ReadWrite(BitcoinStream stream)
		{
			using(stream.SerializationTypeScope(SerializationType.Network))
			{
				ReadWriteCore(stream);
			}
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:7,代码来源:Payload.cs

示例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)
				{
				}
			}
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:30,代码来源:ConcurrentChain.cs

示例4: ReadWrite

		public void ReadWrite(BitcoinStream stream)
		{
			stream.ReadWrite(ref _chainHeight);
			stream.ReadWrite(ref _chainTipHash);
			stream.ReadWrite(ref _bitmap);
			stream.ReadWrite(ref _outputs);
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:7,代码来源:UTxOutpusPayload.cs

示例5: ToBytes

 public byte[] ToBytes()
 {
     var ms = new MemoryStream();
     var stream = new BitcoinStream(ms, true);
     ReadWrite(stream);
     return ms.ToArray();
 }
开发者ID:LedgerHQ,项目名称:ledger-dotnet-api,代码行数:7,代码来源:TrustedInput.cs

示例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;
			}
		}
开发者ID:xcrash,项目名称:NBitcoin,代码行数:35,代码来源:ColorMarker.cs

示例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());
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:25,代码来源:bloom_tests.cs

示例8: ReadWriteCore

 public override void ReadWriteCore(BitcoinStream stream)
 {
     var old = stream.MaxArraySize;
     stream.MaxArraySize = 5000;
     stream.ReadWrite(ref inventory);
     stream.MaxArraySize = old;
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:7,代码来源:InvPayload.cs

示例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;
			}
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:34,代码来源:ColorMarker.cs

示例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);
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:8,代码来源:VarString.cs

示例11: ReadWrite

			public void ReadWrite(BitcoinStream stream)
			{
				stream.ReadWrite(ref _Address);
				stream.ReadWrite(ref source);
				stream.ReadWrite(ref nLastSuccess);
				stream.ReadWrite(ref nAttempts);

			}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:8,代码来源:AddressManager.cs

示例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;
			}
		}
开发者ID:n1rvana,项目名称:NBitcoin,代码行数:58,代码来源:Message.cs

示例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);
     }
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:11,代码来源:NetworkAddress.cs

示例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);
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:12,代码来源:VarString.cs

示例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);
				}
			}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:14,代码来源:UInt2561.cs


注:本文中的BitcoinStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。