Пример #1
0
        public override IFinalElectionResults RehydrateFinalResults(IDataRehydrator rehydrator, Dictionary <int, TransactionId> transactionIndexesTree)
        {
            var version = rehydrator.RehydrateRewind <ComponentVersion <ElectionContextType> >();

            IFinalElectionResults result = null;

            if (version.Type == ElectionContextTypes.Instance.Active)
            {
                if (version == (1, 0))
                {
                    result = new NeuraliumActiveFinalElectionResults();
                }
            }

            if (version.Type == ElectionContextTypes.Instance.Passive)
            {
                if (version == (1, 0))
                {
                    result = new NeuraliumPassiveFinalElectionResults();
                }
            }

            if (result == null)
            {
                throw new ApplicationException("Invalid context type");
            }

            result.Rehydrate(rehydrator, transactionIndexesTree);

            return(result);
        }
        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 IElectionContext CreateElectionContext(IByteArray compressedContext)
        {
            GzipCompression compressor = new GzipCompression();

            IByteArray decompressedContext = compressor.Decompress(compressedContext);

            IDataRehydrator electionContextRehydrator = DataSerializationFactory.CreateRehydrator(decompressedContext);

            var version = electionContextRehydrator.RehydrateRewind <ComponentVersion <ElectionContextType> >();

            IElectionContext context = null;

            if (version.Type == ElectionContextTypes.Instance.Active)
            {
                if (version == (1, 0))
                {
                    context = new NeuraliumActiveElectionContext();
                }
            }

            if (version.Type == ElectionContextTypes.Instance.Passive)
            {
                if (version == (1, 0))
                {
                    context = new NeuraliumPassiveElectionContext();
                }
            }

            if (context == null)
            {
                throw new ApplicationException("Unrecognized election context version.");
            }

            context.Rehydrate(electionContextRehydrator, this);

            decompressedContext.Return();

            return(context);
        }
        public static IBountyAllocationMethod Rehydrate(IDataRehydrator rehydrator)
        {
            var version = rehydrator.RehydrateRewind <ComponentVersion <BountyAllocationMethodType> >();

            IBountyAllocationMethod bountyAllocationMethod = null;

            if (version.Type == BountyAllocationMethodTypes.Instance.EqualSplit)
            {
                if (version == (1, 0))
                {
                    bountyAllocationMethod = new EqualSplitBountyAllocationMethod();
                }
            }

            if (bountyAllocationMethod == null)
            {
                throw new ApplicationException("Invalid candidacy selector type");
            }

            bountyAllocationMethod.Rehydrate(rehydrator);

            return(bountyAllocationMethod);
        }
Пример #6
0
        public static ITransactionTipsAllocationMethod Rehydrate(IDataRehydrator rehydrator)
        {
            var version = rehydrator.RehydrateRewind <ComponentVersion <TransactionTipsAllocationMethodType> >();

            ITransactionTipsAllocationMethod allocationMethod = null;

            if (version.Type == TransactionTipsAllocationMethodTypes.Instance.LowestToHighest)
            {
                if (version == (1, 0))
                {
                    allocationMethod = new LowestToHighestTransactionTipsAllocationMethod();
                }
            }

            if (allocationMethod == null)
            {
                throw new ApplicationException("Invalid candidacy selector type");
            }

            allocationMethod.Rehydrate(rehydrator);

            return(allocationMethod);
        }
        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);
        }