public void WriteNext(ObjectStream <T> stream) { foreach (var o in stream.Enumerate()) { WriteNext(o); } }
public void PushChanges(ObjectStream <ChainChange> changes) { foreach (var change in changes.Enumerate()) { PushChange(change, null); } }
public PersistantChain(BlockHeader blockHeader, int height, ObjectStream <ChainChange> changes) { if (changes == null) { changes = new StreamObjectStream <ChainChange>(); } _Changes = changes; changes.Rewind(); if (changes.EOF) { Initialize(blockHeader, height); } else { var first = changes.ReadNext(); if (first.BlockHeader.GetHash() != blockHeader.GetHash()) { throw new InvalidOperationException("The first block of this stream is different than the expected one at height " + height); } if (first.HeightOrBackstep != height) { throw new InvalidOperationException("The first block of this stream has height " + first.HeightOrBackstep + " but expected is " + height); } changes.Rewind(); Process(); } }
public void PushAccountEntries(ObjectStream <AccountEntry> entries) { foreach (var entry in entries.Enumerate()) { PushAccountEntry(entry); } }
private void AssertEmpty(ObjectStream <ChainChange> changes) { changes.Rewind(); if (!changes.EOF) { throw new ArgumentException("This object stream should be empty", "changes"); } }
public Account(ObjectStream <AccountEntry> entries) { if (entries == null) { entries = new StreamObjectStream <AccountEntry>(); } entries.Rewind(); _Entries = entries; Process(); }
public PersistantChain(ObjectStream <ChainChange> changes) { if (changes == null) { changes = new StreamObjectStream <ChainChange>(); } changes.Rewind(); _Changes = changes; Process(); }
public Chain(BlockHeader blockHeader, int height, ObjectStream <ChainChange> changes) { if (changes == null) { changes = new StreamObjectStream <ChainChange>(); } AssertEmpty(changes); _Changes = changes; Initialize(blockHeader, height); }
public Account(Account copied, ObjectStream <AccountEntry> entries) { if (entries == null) { entries = new StreamObjectStream <AccountEntry>(); } _Entries = entries; copied.Entries.Rewind(); entries.Rewind(); foreach (var entry in copied.Entries.Enumerate()) { if (_NextToProcess < copied._NextToProcess) { PushAccountEntry(entry); } else { entries.WriteNext(entry); } } }
public PersistantChain(PersistantChain copied, ObjectStream <ChainChange> changes) { if (changes == null) { changes = new StreamObjectStream <ChainChange>(); } AssertEmpty(changes); _Changes = changes; copied.Changes.Rewind(); foreach (var change in copied.Changes.Enumerate()) { if (_NextToProcess < copied._NextToProcess) { PushChange(change, null); } else { _Changes.WriteNext(change); } } }
public PersistantChain CreateSubChain(ChainedBlock from, bool fromIncluded, ChainedBlock to, bool toIncluded, ObjectStream <ChainChange> output = null) { if (output == null) { output = new StreamObjectStream <ChainChange>(); } var blocks = to.EnumerateToGenesis() .Skip(toIncluded ? 0 : 1) .TakeWhile(c => c.HashBlock != from.HashBlock); if (fromIncluded) { blocks = blocks.Concat(new ChainedBlock[] { from }); } var array = blocks.ToArray(); Array.Reverse(array); foreach (var b in array) { output.WriteNext(new ChainChange() { ChangeType = ChainChangeType.SetTip, BlockHeader = b.Header, HeightOrBackstep = (uint)b.Height }); } return(new PersistantChain(output)); }
public Account Clone(ObjectStream <AccountEntry> entries) { return(new Account(this, entries)); }
public PersistantChain(Network network, ObjectStream <ChainChange> changes) : this(network.GetGenesis().Header, changes) { }
public Chain Clone(ObjectStream <ChainChange> changes) { return(new Chain(this, changes)); }
public PersistantChain(BlockHeader genesis, ObjectStream <ChainChange> changes) : this(genesis, 0, changes) { }
public Chain BuildChain(ObjectStream <ChainChange> changes) { Chain chain = new Chain(changes); return(BuildChain(chain)); }
public PersistantChain Clone(ObjectStream <ChainChange> changes) { return(new PersistantChain(this, changes)); }