當前位置: 首頁>>代碼示例>>C#>>正文


C# BitcoinStream.CopyParameters方法代碼示例

本文整理匯總了C#中BitcoinStream.CopyParameters方法的典型用法代碼示例。如果您正苦於以下問題:C# BitcoinStream.CopyParameters方法的具體用法?C# BitcoinStream.CopyParameters怎麽用?C# BitcoinStream.CopyParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BitcoinStream的用法示例。


在下文中一共展示了BitcoinStream.CopyParameters方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: UpdatePayload

		private void UpdatePayload(BitcoinStream stream)
		{
			MemoryStream ms = new MemoryStream();
			var seria = new BitcoinStream(ms, true);
			seria.CopyParameters(stream);
			ReadWritePayloadFields(seria);
			payload = new VarString(ms.ToArray());
		}
開發者ID:woutersmit,項目名稱:NBitcoin,代碼行數:8,代碼來源:AlertPayload.cs

示例3: ReadWriteCore

		public override void ReadWriteCore(BitcoinStream stream)
		{
			stream.ReadWrite(ref payload);
			if(!stream.Serializing)
			{
				var payloadStream = new BitcoinStream(payload.GetString());
				payloadStream.CopyParameters(stream);

				ReadWritePayloadFields(payloadStream);

			}

			stream.ReadWrite(ref signature);
		}
開發者ID:woutersmit,項目名稱:NBitcoin,代碼行數:14,代碼來源:AlertPayload.cs

示例4: ReadWrite

        public void ReadWrite(BitcoinStream stream)
        {
            bool verifyChechksum = false;
            if(stream.Serializing || (!stream.Serializing && !_SkipMagic))
                stream.ReadWrite(ref magic);
            stream.ReadWrite(ref command);
            stream.ReadWrite(ref length);
            if(stream.ProtocolVersion >= ProtocolVersion.MEMPOOL_GD_VERSION)
            {
                stream.ReadWrite(ref checksum);
                verifyChechksum = true;
            }
            if(stream.Serializing)
            {
                stream.ReadWrite(ref payload);
            }
            else
            {
                NodeServerTrace.Trace.TraceEvent(TraceEventType.Verbose, 0, "Message type readen : " + Command);
                if(length > 0x02000000) //MAX_SIZE 0x02000000 Serialize.h
                {
                    throw new FormatException("Message payload too big ( > 0x02000000 bytes)");
                }
                payload = new byte[length];
                stream.ReadWrite(ref payload);

                if(verifyChechksum)
                {
                    if(!VerifyChecksum())
                    {
                        NodeServerTrace.Trace.TraceEvent(TraceEventType.Verbose, 0, "Invalid message checksum bytes : "
                                                            + Encoders.Hex.EncodeData(this.ToBytes()));
                        throw new FormatException("Message checksum invalid");
                    }
                }
                BitcoinStream payloadStream = new BitcoinStream(payload);
                payloadStream.CopyParameters(stream);

                var payloadType = PayloadAttribute.GetCommandType(Command);
                if(payloadType == typeof(UnknowPayload))
                    NodeServerTrace.Trace.TraceEvent(TraceEventType.Warning, 0, "Unknown command received : " + Command);
                payloadStream.ReadWrite(payloadType, ref _PayloadObject);
            }
        }
開發者ID:nikropht,項目名稱:NBitcoin,代碼行數:44,代碼來源:Message.cs


注:本文中的BitcoinStream.CopyParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。