Esempio n. 1
0
 protected override bool FlushChild(byte[] key, ICachedSource <byte[], byte[]> childCache)
 {
     if (base.FlushChild(key, childCache))
     {
         if (childCache != null)
         {
             StorageCache storageChildCache = (StorageCache)childCache; // praying to the lord this works
             AccountState storageOwnerAcct  = this.parentRepo.accountStateCache.Get(key);
             // need to update account storage root
             storageChildCache.trie.Flush();
             byte[] rootHash = storageChildCache.trie.GetRootHash();
             storageOwnerAcct.StateRoot = rootHash;
             this.parentRepo.accountStateCache.Put(key, storageOwnerAcct);
             return(true);
         }
         else
         {
             // account was deleted
             return(true);
         }
     }
     else
     {
         // no storage changes
         return(false);
     }
 }
Esempio n. 2
0
        protected override ICachedSource <byte[], byte[]> Create(byte[] key, ICachedSource <byte[], byte[]> srcCache)
        {
            AccountState  accountState = this.parentRepo.accountStateCache.Get(key);
            IPatriciaTrie storageTrie  = this.parentRepo.GetTrieWithSameCache(accountState?.StateRoot);

            return(new StorageCache(storageTrie));
        }
        public StateRepositoryRoot(ISource <byte[], byte[]> stateDS, byte[] stateRoot)
        {
            this.stateDS   = stateDS;
            this.trieCache = new WriteCache <byte[]>(stateDS, WriteCache <byte[]> .CacheType.COUNTING);
            this.stateTrie = new PatriciaTrie(stateRoot, this.trieCache);

            this.SetupAsNew();
        }
Esempio n. 4
0
        public ContractStateRoot(ISource <byte[], byte[]> stateDS, byte[] stateRoot)
        {
            this.stateDS   = stateDS;
            this.trieCache = new WriteCache <byte[]>(stateDS, WriteCache <byte[]> .CacheType.COUNTING);
            this.stateTrie = new PatriciaTrie(stateRoot, this.trieCache);

            SourceCodec <byte[], AccountState, byte[], byte[]> accountStateCodec = new SourceCodec <byte[], AccountState, byte[], byte[]>(this.stateTrie, new Serializers.NoSerializer <byte[]>(), Serializers.AccountSerializer);
            ReadWriteCache <AccountState> accountStateCache = new ReadWriteCache <AccountState>(accountStateCodec, WriteCache <AccountState> .CacheType.SIMPLE);

            MultiCacheBase <ICachedSource <byte[], byte[]> > storageCache = new MultiStorageCache(this);
            ISource <byte[], byte[]> codeCache    = new WriteCache <byte[]>(stateDS, WriteCache <byte[]> .CacheType.COUNTING);
            ISource <byte[], byte[]> unspentCache = new WriteCache <byte[]>(stateDS, WriteCache <byte[]> .CacheType.SIMPLE);
            SourceCodec <byte[], ContractUnspentOutput, byte[], byte[]> unspentCacheCodec = new SourceCodec <byte[], ContractUnspentOutput, byte[], byte[]>(unspentCache, new Serializers.NoSerializer <byte[]>(), Serializers.VinSerializer);

            this.Init(accountStateCache, codeCache, storageCache, unspentCacheCodec);
        }
 public MultiCache(ICachedSource <byte[], V> src) : base(src, WriteCache <V> .CacheType.SIMPLE)
 {
 }
 protected override ICachedSource <byte[], byte[]> Create(byte[] key, ICachedSource <byte[], byte[]> srcCache)
 {
     return(new WriteCache <byte[]>(srcCache, WriteCache <byte[]> .CacheType.SIMPLE));
 }
 public RealMultiCache(ICachedSource <byte[], ICachedSource <byte[], byte[]> > src) : base(src)
 {
 }
 protected PatriciaTrie CreateTrie(ICachedSource <byte[], byte[]> trieCache, byte[] root)
 {
     return(new PatriciaTrie(root, trieCache));
 }