예제 #1
0
 public override void ReadWriteCore(BitcoinStream stream)
 {
     stream.ReadWrite(ref version);
     using (stream.ProtocolVersionScope(version))
     {
         stream.ReadWrite(ref services);
         stream.ReadWrite(ref timestamp);
         using (stream.SerializationTypeScope(SerializationType.Hash))                 //No time field in version message
         {
             stream.ReadWrite(ref addr_recv);
         }
         if (version >= 106)
         {
             using (stream.SerializationTypeScope(SerializationType.Hash))                     //No time field in version message
             {
                 stream.ReadWrite(ref addr_from);
             }
             stream.ReadWrite(ref nonce);
             stream.ReadWrite(ref user_agent);
             if (!stream.ProtocolCapabilities.SupportUserAgent)
             {
                 if (user_agent.Length != 0)
                 {
                     throw new FormatException("Should not find user agent for current version " + version);
                 }
             }
             stream.ReadWrite(ref start_height);
             if (version >= 70001)
             {
                 stream.ReadWrite(ref relay);
             }
         }
     }
 }
예제 #2
0
 public void ReadWrite(BitcoinStream stream)
 {
     using (stream.SerializationTypeScope(SerializationType.Network))
     {
         this.ReadWriteCore(stream);
     }
 }
예제 #3
0
파일: Payload.cs 프로젝트: crowar/NBitcoin
		public void ReadWrite(BitcoinStream stream)
		{
			using(stream.SerializationTypeScope(SerializationType.Network))
			{
				ReadWriteCore(stream);
			}
		}
예제 #4
0
        /// <summary>
        /// This method should be removed once PR https://github.com/MetacoSA/NBitcoin/pull/1005
        /// will be merged to master and new package will be released.
        /// Original code stores the calculated hash and returns it once it has been calculated so it's more optimal
        /// </summary>
        public static uint256 GetHash(this Transaction tx, int maxArraySize)
        {
            // try to use original implementation because it's more efficient
            try
            {
                return(tx.GetHash());
            }
            catch (ArgumentOutOfRangeException)
            {
                // catch ArgumentOutOfRangeException in case Tx is bigger than 1MB
                // and parse it again by increasing the maxArraySize
            }

            using var hs = new HashStream();
            var stream = new BitcoinStream(hs, true)
            {
                TransactionOptions = TransactionOptions.None,
                ConsensusFactory   = tx.GetConsensusFactory(),
                MaxArraySize       = maxArraySize
            };

            stream.SerializationTypeScope(SerializationType.Hash);
            tx.ReadWrite(stream);
            return(hs.GetHash());
        }