Example #1
0
 public DependencyContainer(string host, IFeedback feedback)
 {
     Cryptography = new Cryptography();
     Network      = new P2PNetwork(feedback, host);
     ChainData    = new ChainData(feedback, Cryptography);
     Engine       = new Engine.Engine(feedback, Network, ChainData);
 }
Example #2
0
        public async Task BlockchainSync(IChainData chainData)
        {
            _feedback.SyncChainStart();
            var latestBlockPeers = await GetLatestBlockPeers();

            var networkLatestBlockIdentity = latestBlockPeers.Block;
            var peers = latestBlockPeers.Peers.ToArray();
            var localLastBlockIdentity       = chainData.GetLastBlock().Identity();
            var localLastBlockIdentityHeight = localLastBlockIdentity?.Height ?? -1;

            //Check if network has blocks to sync
            if (localLastBlockIdentityHeight < networkLatestBlockIdentity.Height)
            {
                //Calculate optimal block to retrieve
                var blocksToSync        = networkLatestBlockIdentity.Height - localLastBlockIdentityHeight;
                var syncBlockPageSize   = Math.Min(SyncBlockPageSizeMax, blocksToSync / peers.Length + 1);
                var syncStartBlockIndex = localLastBlockIdentityHeight + 1;

                _feedback.SyncChainProcessing(syncStartBlockIndex, networkLatestBlockIdentity.Height, peers.Length);
                var chainSync = new ChainSync(syncStartBlockIndex, syncBlockPageSize, peers, chainData, _feedback);
                chainSync.Sync();

                _feedback.SyncChainFinished();
            }
            else
            {
                _feedback.SyncChainAlreadyInSync();
            }
        }
Example #3
0
 public Engine(
     IFeedback feedback,
     IP2PNetwork network,
     IChainData chainData)
 {
     _feedback  = feedback;
     _network   = network;
     _chainData = chainData;
 }
Example #4
0
 public ChainSync(
     int syncBlockIndex,
     int syncBlockPageSize,
     PeerConnection[] peers,
     IChainData chainData,
     IFeedback feedback)
 {
     _syncBlockIndexCap = _syncBlockIndex = syncBlockIndex;
     _syncBlockPageSize = syncBlockPageSize;
     _peers             = peers;
     _chainData         = chainData;
     _feedback          = feedback;
 }
Example #5
0
 public static void Initialize(
     IP2PNetwork network,
     IEngine engine,
     IChainData chainData,
     Func <string, LogLevel, bool> consoleLogFilter,
     Action <IApplicationLifetime> applicationLifetimeCreated)
 {
     _network                    = network;
     _engine                     = engine;
     _chainData                  = chainData;
     _consoleLogFilter           = consoleLogFilter;
     _applicationLifetimeCreated = applicationLifetimeCreated;
 }
 public NetworkController(IP2PNetwork netwrok, IEngine engine, IChainData chainData)
 {
     _netwrok   = netwrok;
     _engine    = engine;
     _chainData = chainData;
 }