public override ITransaction CreateTransaction(IDehydratedTransaction dehydratedTransaction)
        {
            IDataRehydrator rehydrator = DataSerializationFactory.CreateRehydrator(dehydratedTransaction.Header);

            var version = new ComponentVersion <TransactionType>();

            version.Rehydrate(rehydrator);

            rehydrator.Rewind2Start();

            return(this.CreateTransation(version));
        }
        public override IBlockchainMessage CreateMessage(IDehydratedBlockchainMessage dehydratedMessage)
        {
            IDataRehydrator bodyRehydrator = DataSerializationFactory.CreateRehydrator(dehydratedMessage.Contents);

            //start by peeking and reading both the transactiontype and version
            var version = bodyRehydrator.RehydrateRewind <ComponentVersion <BlockchainMessageType> >();

            bodyRehydrator.Rewind2Start();

            if (version.Type == BlockchainMessageTypes.Instance.DEBUG)
            {
                if (version == (1, 0))
                {
                    return(new NeuraliumDebugMessage());
                }
            }
            else if (version.Type == BlockchainMessageTypes.Instance.ELECTIONS_REGISTRATION)
            {
                if (version == (1, 0))
                {
                    return(new NeuraliumElectionsRegistrationMessage());
                }
            }
            else if (version.Type == BlockchainMessageTypes.Instance.ACTIVE_ELECTION_CANDIDACY)
            {
                if (version == (1, 0))
                {
                    // a very rare case where it is not scopped for the chain
                    return(new ActiveElectionCandidacyMessage());
                }
            }
            else if (version.Type == BlockchainMessageTypes.Instance.PASSIVE_ELECTION_CANDIDACY)
            {
                if (version == (1, 0))
                {
                    // a very rare case where it is not scopped for the chain
                    return(new PassiveElectionCandidacyMessage());
                }
            }
            else
            {
                throw new ApplicationException("Invalid blockchain message type");
            }

            return(null);
        }
        public override IBlockchainDigest CreateDigest(IDataRehydrator rehydrator)
        {
            //start by peeking and reading both the transactiontype and version
            var version = rehydrator.RehydrateRewind <ComponentVersion <BlockchainDigestsType> >();

            rehydrator.Rewind2Start();

            if (version.Type == BlockchainDigestsTypes.Instance.Basic)
            {
                if (version == (1, 0))
                {
                    return(new NeuraliumBlockchainDigest());
                }
            }
            else
            {
                throw new ApplicationException("Invalid digest type");
            }

            return(null);
        }
        public override IBlock CreateBlock(IDataRehydrator bodyRehydrator)
        {
            //start by peeking and reading both the transactiontype and version
            var version = bodyRehydrator.RehydrateRewind <ComponentVersion <BlockType> >();

            bodyRehydrator.Rewind2Start();

            IBlock block = null;

            if (version.Type == BlockTypes.Instance.Genesis)
            {
                if (version == (1, 0))
                {
                    block = new NeuraliumGenesisBlock();
                }
            }
            else if (version.Type == BlockTypes.Instance.Simple)
            {
                if (version == (1, 0))
                {
                    block = new NeuraliumSimpleBlock();
                }
            }
            else if (version.Type == BlockTypes.Instance.Election)
            {
                if (version == (1, 0))
                {
                    block = new NeuraliumElectionBlock();
                }
            }
            else
            {
                throw new ApplicationException("Invalid block type");
            }

            return(block);
        }