/// <summary>
        /// Deserializes binary data to an object of specific type.
        /// </summary>
        /// <param name="bytes">Binary data representing a serialized object.</param>
        /// <param name="type">Type of the serialized object.</param>
        /// <returns>Deserialized object.</returns>
        internal object Deserializer(byte[] bytes, Type type)
        {
            if (type == typeof(Coins))
            {
                var coin = new Coins();
                coin.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(coin);
            }

            if (type == typeof(BlockHeader))
            {
                BlockHeader header = this.Network.Consensus.ConsensusFactory.CreateBlockHeader();
                header.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(header);
            }

            if (type == typeof(RewindData))
            {
                var rewind = new RewindData();
                rewind.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(rewind);
            }

            if (type == typeof(uint256))
            {
                return(new uint256(bytes));
            }

            if (type == typeof(Block))
            {
                return(Block.Load(bytes, this.Network));
            }

            if (type == typeof(BlockStake))
            {
                return(BlockStake.Load(bytes, this.Network));
            }

            if (type == typeof(HashHeightPair))
            {
                return(HashHeightPair.Load(bytes));
            }

            throw new NotSupportedException();
        }
示例#2
0
        public Coins ToCoins()
        {
            var coins = new Coins
            {
                CoinBase  = this.IsCoinbase,
                Height    = this.Height,
                Version   = this.Version,
                CoinStake = this.IsCoinstake,
                Time      = this.Time
            };

            foreach (var output in this._Outputs)
            {
                coins.Outputs.Add(output == null ? Coins.NullTxOut : output);
            }
            coins.ClearUnspendable();
            return(coins);
        }
示例#3
0
        /// <summary>
        /// Deserializes binary data to an object of specific type.
        /// </summary>
        /// <param name="bytes">Binary data representing a serialized object.</param>
        /// <param name="type">Type of the serialized object.</param>
        /// <returns>Deserialized object.</returns>
        internal object Deserializer(byte[] bytes, Type type)
        {
            if (type == typeof(Coins))
            {
                Coins coin = new Coins();
                coin.ReadWrite(bytes);
                return(coin);
            }

            if (type == typeof(BlockHeader))
            {
                BlockHeader header = new BlockHeader();
                header.ReadWrite(bytes);
                return(header);
            }

            if (type == typeof(RewindData))
            {
                RewindData rewind = new RewindData();
                rewind.ReadWrite(bytes);
                return(rewind);
            }

            if (type == typeof(uint256))
            {
                return(new uint256(bytes));
            }

            if (type == typeof(Block))
            {
                return(new Block(bytes));
            }

            if (type == typeof(BlockStake))
            {
                return(new BlockStake(bytes));
            }

            throw new NotSupportedException();
        }
示例#4
0
 public UnspentOutputs(uint256 txId, Coins coins)
 {
     this._TransactionId = txId;
     this.SetCoins(coins);
 }
示例#5
0
        /// <summary>
        /// Deserializes binary data to an object of specific type.
        /// </summary>
        /// <param name="bytes">Binary data representing a serialized object.</param>
        /// <param name="type">Type of the serialized object.</param>
        /// <returns>Deserialized object.</returns>
        internal object Deserializer(byte[] bytes, Type type)
        {
            if (type == typeof(Coins))
            {
                var coin = new Coins();
                coin.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(coin);
            }

            if (type == typeof(BlockHeader))
            {
                BlockHeader header = this.Network.Consensus.ConsensusFactory.CreateBlockHeader();
                header.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(header);
            }

            if (type == typeof(RewindData))
            {
                var rewind = new RewindData();
                rewind.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(rewind);
            }

            if (type == typeof(uint256))
            {
                return(new uint256(bytes));
            }

            if (type == typeof(Block))
            {
                return(Block.Load(bytes, this.Network));
            }

            if (type == typeof(BlockStake))
            {
                return(BlockStake.Load(bytes, this.Network));
            }

            if (type == typeof(HashHeightPair))
            {
                return(HashHeightPair.Load(bytes));
            }

            if (type == typeof(ProvenBlockHeader))
            {
                ProvenBlockHeader provenBlockHeader =
                    ((PosConsensusFactory)this.Network.Consensus.ConsensusFactory).CreateProvenBlockHeader();

                provenBlockHeader.ReadWrite(bytes, this.Network.Consensus.ConsensusFactory);
                return(provenBlockHeader);
            }

            if (typeof(IBitcoinSerializable).IsAssignableFrom(type))
            {
                var result = (IBitcoinSerializable)Activator.CreateInstance(type);
                result.ReadWrite(bytes);
                return(result);
            }

            throw new NotSupportedException();
        }