當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。