当前位置: 首页>>代码示例>>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;未经允许,请勿转载。