Beispiel #1
0
        internal static object NBitcoinDeserialize(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();
        }
Beispiel #2
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 (typeof(IBitcoinSerializable).IsAssignableFrom(type))
            {
                var result = (IBitcoinSerializable)Activator.CreateInstance(type);
                result.ReadWrite(bytes);
                return(result);
            }

            throw new NotSupportedException();
        }
Beispiel #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))
            {
                var coin = new Coins();
                coin.ReadWrite(bytes, network: this.Network);
                return(coin);
            }

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

            if (type == typeof(RewindData))
            {
                var rewind = new RewindData();
                rewind.ReadWrite(bytes, network: this.Network);
                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(new BlockStake(bytes));
            }

            throw new NotSupportedException();
        }