public override void Rehydrate(IDataRehydrator rehydrator, IBlockchainEventsRehydrationFactory rehydrationFactory) { base.Rehydrate(rehydrator, rehydrationFactory); this.localTime = rehydrator.ReadDateTime(); this.supportedChains.Value = rehydrator.ReadByte(); }
public override ITargettedMessageSet <IBlockchainEventsRehydrationFactory> RehydrateMessage(IByteArray data, TargettedHeader header, IBlockchainEventsRehydrationFactory rehydrationFactory) { IDataRehydrator dr = DataSerializationFactory.CreateRehydrator(data); IByteArray messageBytes = NetworkMessageSet.ExtractMessageBytes(dr); NetworkMessageSet.ResetAfterHeader(dr); IDataRehydrator messageRehydrator = DataSerializationFactory.CreateRehydrator(messageBytes); short workflowType = messageRehydrator.ReadShort(); if (workflowType == 0) { throw new ApplicationException("Invalid workflow type"); } switch (workflowType) { case NeuraliumWorkflowIDs.TEST: return(new TestFactory((BlockchainServiceSet)this.serviceSet).RehydrateMessage(data, header, rehydrationFactory)); // default: // throw new ApplicationException("Workflow message factory not found"); } return(base.RehydrateMessage(data, header, rehydrationFactory)); }
public void RehydrateHeader(IDataRehydrator rehydrator) { AdaptiveLong1_9 adaptiveLong = new AdaptiveLong1_9(); // then the various bounties AmountSerializationOffsetsCalculator bountyCalculator = new AmountSerializationOffsetsCalculator(); adaptiveLong.Rehydrate(rehydrator); ushort bountySetCount = (ushort)adaptiveLong.Value; this.BountyAllocations.Clear(); if (bountySetCount > 0) { Amount bountyAmount = new Amount(); for (ushort i = 0; i < bountySetCount; i++) { bountyAmount.Rehydrate(rehydrator); decimal offset = bountyAmount.Value; Amount bountyEntry = new Amount(bountyCalculator.RebuildValue(offset)); this.BountyAllocations.Add(bountyEntry); bountyCalculator.AddLastOffset(); } } // now retrieve the network service fees this.InfrastructureServiceFees = rehydrator.ReadRehydratable <Amount>(); }
protected override void RehydrateHeader(IDataRehydrator rehydrator) { base.RehydrateHeader(rehydrator); this.Recipient.Rehydrate(rehydrator); this.Amount.Rehydrate(rehydrator); }
public override void Rehydrate(IDataRehydrator rehydrator) { base.Rehydrate(rehydrator); this.Balance.Rehydrate(rehydrator); this.AccountFreezes.Clear(); bool any = rehydrator.ReadBool(); if (any) { int count = rehydrator.ReadByte(); for (int i = 0; i < count; i++) { INeuraliumAccountFreeze freeze = new NeuraliumAccountFreeze(); freeze.FreezeId = rehydrator.ReadInt(); Amount amount = new Amount(); amount.Rehydrate(rehydrator); freeze.Amount = amount.Value; this.AccountFreezes.Add(freeze); } } }
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 void Rehydrate(IDataRehydrator rehydrator) { base.Rehydrate(rehydrator); this.FreezeId = rehydrator.ReadUShort(); this.Reason.Rehydrate(rehydrator); rehydrator.ReadRehydratableArray(this.Accounts); }
protected override void RehydrateHeader(IDataRehydrator rehydrator) { base.RehydrateHeader(rehydrator); this.AcceptSAFUTermsOfService = rehydrator.ReadBool(); this.Total.Rehydrate(rehydrator); this.DailyProtection.Rehydrate(rehydrator); this.Start = rehydrator.ReadNullableDateTime(); }
public void Rehydrate(IDataRehydrator rehydrator, IElectionContextRehydrationFactory electionContextRehydrationFactory) { this.Bounty.Rehydrate(rehydrator); this.MaintenanceServiceFeesEnabled = rehydrator.ReadBool(); this.MaintenanceServiceFees = rehydrator.ReadRehydratable <SimplePercentage>(); this.BountyAllocationMethod = BountyAllocationMethodRehydrator.Rehydrate(rehydrator); this.TransactionTipsAllocationMethod = TransactionTipsAllocationMethodRehydrator.Rehydrate(rehydrator); }
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 IOperation CreateTransactionOperation(IDataRehydrator rehydrator) { //start by peeking and reading both the transactiontype and version // var version = rehydrator.RehydrateRewind<ComponentVersion<TransactionOperationType>>(); // // if(version.Type == TransactionContentTypes.Instance.GENESIS) { // if(version == (1, 0)) { // return null; //new BlockContent(); // } // } return(null); }
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); }
protected override void RehydrateHeader(IDataRehydrator rehydrator) { base.RehydrateHeader(rehydrator); this.Total.Rehydrate(rehydrator); this.Recipients.Clear(); var parameters = new AccountIdGroupSerializer.AccountIdGroupSerializerRehydrateParameters <AccountId> { RehydrateExtraData = (accountId, offset, index, dh) => { RecipientSet entry = new RecipientSet(); entry.Recipient = accountId; entry.Amount.Rehydrate(rehydrator); this.Recipients.Add(entry); } }; AccountIdGroupSerializer.Rehydrate(rehydrator, true, parameters); }
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 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 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); }
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); }
public void Rehydrate(IDataRehydrator rehydrator, Dictionary <int, TransactionId> transactionIndexesTree) { }
public override IBlockchainDigest CreateDigest(IDehydratedBlockchainDigest dehydratedDigest) { IDataRehydrator rehydrator = DataSerializationFactory.CreateRehydrator(dehydratedDigest.Contents); return(this.CreateDigest(rehydrator)); }
public void Rehydrate(IDataRehydrator rehydrator) { this.TransactionId.Rehydrate(rehydrator); this.Amount.Rehydrate(rehydrator); rehydrator.ReadRehydratableArray(this.OutgoingSuspectTransactions); }
public void Rehydrate(IDataRehydrator rehydrator) { this.AccountId.Rehydrate(rehydrator); this.Notes.Rehydrate(rehydrator); }
public override IBlock CreateBlock(IDehydratedBlock dehydratedBlock) { IDataRehydrator bodyRehydrator = DataSerializationFactory.CreateRehydrator(dehydratedBlock.HighHeader); return(this.CreateBlock(bodyRehydrator)); }
public void Rehydrate(IDataRehydrator rehydrator) { throw new NotImplementedException(); }
public void Rehydrate(IDataRehydrator rehydrator) { this.Tip.Rehydrate(rehydrator); }
public void RehydrateDelegateAccountEntry(AccountId accountId, INeuraliumDelegateResults entry, IDataRehydrator rehydrator) { // now the bounty allocation AdaptiveLong1_9 bountyAllocationOffset = rehydrator.ReadRehydratable <AdaptiveLong1_9>(); ushort index = (ushort)bountyAllocationOffset.Value; if (index != ushort.MaxValue) { // max value means there is no bounty associated entry.BountyShare = this.BountyAllocations[index]; } }
public override ITargettedMessageSet <IBlockchainEventsRehydrationFactory> RehydrateMessage(IByteArray data, TargettedHeader header, IBlockchainEventsRehydrationFactory rehydrationFactory) { IDataRehydrator dr = DataSerializationFactory.CreateRehydrator(data); IByteArray messageBytes = NetworkMessageSet.ExtractMessageBytes(dr); NetworkMessageSet.ResetAfterHeader(dr); IDataRehydrator messageRehydrator = DataSerializationFactory.CreateRehydrator(messageBytes); IBlockchainTargettedMessageSet messageSet = null; try { if (data?.Length == 0) { throw new ApplicationException("null message"); } short workflowType = 0; ComponentVersion <SimpleUShort> version = null; messageRehydrator.Peek(rehydrator => { workflowType = rehydrator.ReadShort(); if (workflowType != NeuraliumWorkflowIDs.TEST) { throw new ApplicationException("Invalid workflow type"); } version = rehydrator.Rehydrate <ComponentVersion <SimpleUShort> >(); }); switch (version.Type.Value) { case MESS1: if (version == (1, 0)) { messageSet = this.CreateTestWorkflowTriggerSet(header); } break; case MESS2: if (version == (1, 0)) { messageSet = this.CreateServerAnswerSet(header); } break; default: throw new ApplicationException("invalid message type"); } if (messageSet?.BaseMessage == null) { throw new ApplicationException("Invalid message type or version"); } messageSet.BaseHeader = header; // set the header explicitely messageSet.RehydrateRest(dr, rehydrationFactory); } catch (Exception ex) { Log.Error(ex, "Invalid data sent"); } return(messageSet); }