Esempio n. 1
0
 public Blockchain(NeoSystem system, IStore store)
 {
     this.system  = system;
     this.MemPool = new MemoryPool(system, ProtocolSettings.Default.MemoryPoolMaxTransactions);
     this.Store   = store;
     this.View    = new ReadOnlyView(store);
     lock (lockObj)
     {
         if (singleton != null)
         {
             throw new InvalidOperationException();
         }
         header_index.AddRange(View.HeaderHashList.Find().OrderBy(p => (uint)p.Key).SelectMany(p => p.Value.Hashes));
         stored_header_count += (uint)header_index.Count;
         if (stored_header_count == 0)
         {
             header_index.AddRange(View.Blocks.Find().OrderBy(p => p.Value.Index).Select(p => p.Key));
         }
         else
         {
             HashIndexState hashIndex = View.HeaderHashIndex.Get();
             if (hashIndex.Index >= stored_header_count)
             {
                 DataCache <UInt256, TrimmedBlock> cache = View.Blocks;
                 for (UInt256 hash = hashIndex.Hash; hash != header_index[(int)stored_header_count - 1];)
                 {
                     header_index.Insert((int)stored_header_count, hash);
                     hash = cache[hash].PrevHash;
                 }
             }
         }
         if (header_index.Count == 0)
         {
             Persist(GenesisBlock);
         }
         else
         {
             UpdateCurrentSnapshot();
             MemPool.LoadPolicy(currentSnapshot);
         }
         singleton = this;
     }
 }
Esempio n. 2
0
 public Blockchain(NeoSystem system, Store store)
 {
     this.system  = system;
     this.MemPool = new MemoryPool(system, MemoryPoolMaxTransactions);
     this.Store   = store;
     lock (lockObj)
     {
         if (singleton != null)
         {
             throw new InvalidOperationException();
         }
         header_index.AddRange(store.GetHeaderHashList().Find().OrderBy(p => (uint)p.Key).SelectMany(p => p.Value.Hashes));
         stored_header_count += (uint)header_index.Count;
         if (stored_header_count == 0)
         {
             header_index.AddRange(store.GetBlocks().Find().OrderBy(p => p.Value.TrimmedBlock.Index).Select(p => p.Key));
         }
         else
         {
             HashIndexState hashIndex = store.GetHeaderHashIndex().Get();
             if (hashIndex.Index >= stored_header_count)
             {
                 DataCache <UInt256, BlockState> cache = store.GetBlocks();
                 for (UInt256 hash = hashIndex.Hash; hash != header_index[(int)stored_header_count - 1];)
                 {
                     header_index.Insert((int)stored_header_count, hash);
                     hash = cache[hash].TrimmedBlock.PrevHash;
                 }
             }
         }
         if (header_index.Count == 0)
         {
             Persist(GenesisBlock);
         }
         else
         {
             UpdateCurrentSnapshot();
         }
         singleton = this;
     }
 }