Ejemplo n.º 1
0
        public void Apply(ShaMap sa)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var mod in Modified)
            {
                var modded = sa.UpdateItem(mod, B.GetItem(mod).Copy());
                if (!modded)
                {
                    throw new InvalidOperationException();
                }
            }

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var add in Added)
            {
                var added = sa.AddItem(add, B.GetItem(add).Copy());
                if (!added)
                {
                    throw new InvalidOperationException();
                }
            }
            if (Deleted.Select(sa.RemoveLeaf).Any(removed => !removed))
            {
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 2
0
        public static ShaMapDiff Find(ShaMap a, ShaMap b)
        {
            var diff = new ShaMapDiff(a, b);

            diff.Find();
            return(diff);
        }
Ejemplo n.º 3
0
        public void Apply(ShaMap sa)
        {
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var mod in Modified)
            {
                var modded = sa.UpdateItem(mod, B.GetItem(mod).Copy());
                if (!modded)
                {
                    throw new InvalidOperationException();
                }
            }

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var add in Added)
            {
                var added = sa.AddItem(add, B.GetItem(add).Copy());
                if (!added)
                {
                    throw new InvalidOperationException();
                }
            }
            if (Deleted.Select(sa.RemoveLeaf).Any(removed = \ > \ !removed))
            {
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 4
0
 private ShaMapDiff(ShaMap a,
                    ShaMap b,
                    SortedSet<Hash256> modified = null,
                    SortedSet<Hash256> deleted = null,
                    SortedSet<Hash256> added = null)
 {
     A = a;
     B = b;
     Modified = modified ?? new SortedSet<Hash256>();
     Deleted = deleted ?? new SortedSet<Hash256>();
     Added = added ?? new SortedSet<Hash256>();
 }
Ejemplo n.º 5
0
 private ShaMapDiff(ShaMap a,
                    ShaMap b,
                    SortedSet \ \ modified = null,
                    SortedSet \ \ deleted  = null,
                    SortedSet \ \ added    = null)
 {
     A        = a;
     B        = b;
     Modified = modified ?? new SortedSet \ \ ();
     Deleted  = deleted ?? new SortedSet \ \ ();
     Added    = added ?? new SortedSet \ \ ();
 }
 private ShaMapDiff(ShaMap a,
                    ShaMap b,
                    SortedSet <Hash256> modified = null,
                    SortedSet <Hash256> deleted  = null,
                    SortedSet <Hash256> added    = null)
 {
     A        = a;
     B        = b;
     Modified = modified ?? new SortedSet <Hash256>();
     Deleted  = deleted ?? new SortedSet <Hash256>();
     Added    = added ?? new SortedSet <Hash256>();
 }
Ejemplo n.º 7
0
 private static ShaMap ParseAccountState(JArray state)
 {
     var stateMap = new ShaMap();
     var entries = state.Select((t) =>
     {
         StObject so = t["json"];
         Assert.AreEqual(t["binary"].ToString(), so.ToHex(), t.ToString() + " " + so.ToJson());
         return new LedgerEntry(so);
     });
     foreach (var ledgerEntry in entries)
     {
         stateMap.AddItem(ledgerEntry.Index(), ledgerEntry);
     }
     return stateMap;
 }
Ejemplo n.º 8
0
 public static ShaMapDiff Find(ShaMap a, ShaMap b)
 {
     var diff = new ShaMapDiff(a, b);
     diff.Find();
     return diff;
 }
Ejemplo n.º 9
0
        private static void TestLedgerTreeHashing(JObject ledger)
        {
            var txMap = new ShaMap();
            var stateMap = new ShaMap();

            var expectedTxHash = ledger["transaction_hash"].ToString();
            var expectedStateHash = ledger["account_hash"].ToString();

            var transactions = ledger["transactions"].Select(TransactionResult.FromJson);
            var state = ledger["accountState"].Select((t) => new LedgerEntry(t));

            foreach (var tr in transactions)
            {
                txMap.AddItem(tr.Hash(), tr);
            }

            foreach (var le in state)
            {
                stateMap.AddItem(le.Index(), le);
            }

            Assert.AreEqual(expectedTxHash, txMap.Hash().ToString());
            Assert.AreEqual(expectedStateHash, stateMap.Hash().ToString());
        }
Ejemplo n.º 10
0
 public void EmptyMapHasZeroHash()
 {
     var shamap = new ShaMap();
     Assert.AreEqual(Hash256.Zero, shamap.Hash());
 }