Exemplo n.º 1
0
 public void WriteNext(ObjectStream <T> stream)
 {
     foreach (var o in stream.Enumerate())
     {
         WriteNext(o);
     }
 }
Exemplo n.º 2
0
 public void PushChanges(ObjectStream <ChainChange> changes)
 {
     foreach (var change in changes.Enumerate())
     {
         PushChange(change, null);
     }
 }
Exemplo n.º 3
0
 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();
     }
 }
Exemplo n.º 4
0
 public void PushAccountEntries(ObjectStream <AccountEntry> entries)
 {
     foreach (var entry in entries.Enumerate())
     {
         PushAccountEntry(entry);
     }
 }
Exemplo n.º 5
0
 private void AssertEmpty(ObjectStream <ChainChange> changes)
 {
     changes.Rewind();
     if (!changes.EOF)
     {
         throw new ArgumentException("This object stream should be empty", "changes");
     }
 }
Exemplo n.º 6
0
 public Account(ObjectStream <AccountEntry> entries)
 {
     if (entries == null)
     {
         entries = new StreamObjectStream <AccountEntry>();
     }
     entries.Rewind();
     _Entries = entries;
     Process();
 }
Exemplo n.º 7
0
 public PersistantChain(ObjectStream <ChainChange> changes)
 {
     if (changes == null)
     {
         changes = new StreamObjectStream <ChainChange>();
     }
     changes.Rewind();
     _Changes = changes;
     Process();
 }
Exemplo n.º 8
0
 public Chain(BlockHeader blockHeader, int height, ObjectStream <ChainChange> changes)
 {
     if (changes == null)
     {
         changes = new StreamObjectStream <ChainChange>();
     }
     AssertEmpty(changes);
     _Changes = changes;
     Initialize(blockHeader, height);
 }
Exemplo n.º 9
0
 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);
         }
     }
 }
Exemplo n.º 10
0
 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);
         }
     }
 }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
 public Account Clone(ObjectStream <AccountEntry> entries)
 {
     return(new Account(this, entries));
 }
Exemplo n.º 13
0
 public PersistantChain(Network network, ObjectStream <ChainChange> changes)
     : this(network.GetGenesis().Header, changes)
 {
 }
Exemplo n.º 14
0
 public Chain Clone(ObjectStream <ChainChange> changes)
 {
     return(new Chain(this, changes));
 }
Exemplo n.º 15
0
 public PersistantChain(BlockHeader genesis, ObjectStream <ChainChange> changes)
     : this(genesis, 0, changes)
 {
 }
Exemplo n.º 16
0
        public Chain BuildChain(ObjectStream <ChainChange> changes)
        {
            Chain chain = new Chain(changes);

            return(BuildChain(chain));
        }
Exemplo n.º 17
0
 public PersistantChain Clone(ObjectStream <ChainChange> changes)
 {
     return(new PersistantChain(this, changes));
 }