コード例 #1
0
ファイル: Global.cs プロジェクト: orbitlens/centaurus
        /// <summary>
        /// Setups Global object
        /// </summary>
        /// <param name="settings">Application config</param>
        /// <param name="storage">Permanent storage object</param>
        public static async Task Setup(BaseSettings settings, IStorage storage)
        {
            ExtensionsManager = new ExtensionsManager();

            Settings = settings ?? throw new ArgumentNullException(nameof(settings));

            DynamicSerializersInitializer.Init();

            IsAlpha = Settings is AlphaSettings;

            PermanentStorage = storage;
            await PermanentStorage.OpenConnection(settings.ConnectionString);

            PersistenceManager = new PersistenceManager(PermanentStorage);

            StellarNetwork   = new StellarNetwork(Settings.NetworkPassphrase, Settings.HorizonUrl);
            QuantumProcessor = new QuantumProcessorsStorage();

            PendingUpdatesManager = new PendingUpdatesManager();
            PendingUpdatesManager.OnBatchSaved += PendingUpdatesManager_OnBatchSaved;

            AppState = IsAlpha ? new AlphaStateManager() : (StateManager) new AuditorStateManager();
            AppState.StateChanged += AppState_StateChanged;

            //try to load last settings, we need it to know current auditors
            var lastHash = new byte[] { };
            var lastApex = await PersistenceManager.GetLastApex();

            if (lastApex >= 0)
            {
                var lastQuantum = await PersistenceManager.GetQuantum(lastApex);

                lastHash = lastQuantum.Message.ComputeHash();
                logger.Trace($"Last hash is {Convert.ToBase64String(lastHash)}");
                var snapshot = await PersistenceManager.GetSnapshot(lastApex);
                await Setup(snapshot);

                if (IsAlpha)
                {
                    AppState.State = ApplicationState.Rising;//Alpha should ensure that it has all quanta from auditors
                }
                else
                {
                    AppState.State = ApplicationState.Running;
                }
            }
            else
            {
                //if no snapshot, the app is in init state
                AppState.State = ApplicationState.WaitingForInit;
            }

            var lastQuantumApex = lastApex < 0 ? 0 : lastApex;

            QuantumStorage = IsAlpha
                ? (QuantumStorageBase) new AlphaQuantumStorage(lastQuantumApex, lastHash)
                : new AuditorQuantumStorage(lastQuantumApex, lastHash);

            QuantumHandler = new QuantumHandler(QuantumStorage.CurrentApex);
        }
コード例 #2
0
        public virtual async Task Init()
        {
            DynamicSerializersInitializer.Init();

            await PermanentStorage.OpenConnection(Settings.ConnectionString);

            //try to load last settings, we need it to know current auditors
            var lastHash = new byte[] { };
            var lastApex = await PersistenceManager.GetLastApex();

            if (lastApex >= 0)
            {
                var lastQuantum = await PersistenceManager.GetQuantum(lastApex);

                lastHash = lastQuantum.Message.ComputeHash();
                var snapshot = await PersistenceManager.GetSnapshot(lastApex);
                await Setup(snapshot);

                if (IsAlpha)
                {
                    AppState.State = ApplicationState.Rising;//Alpha should ensure that it has all quanta from auditors
                }
                else
                {
                    AppState.State = ApplicationState.Running;
                }
            }
            else
            {
                //if no snapshot, the application is in initialization state
                AppState.State = ApplicationState.WaitingForInit;
            }

            var lastQuantumApex = lastApex < 0 ? 0 : lastApex;

            QuantumStorage.Init(lastQuantumApex, lastHash);
            QuantumHandler.Start();
        }
コード例 #3
0
 static CentaurusClient()
 {
     DynamicSerializersInitializer.Init();
 }
コード例 #4
0
 public void Setup()
 {
     EnvironmentHelper.SetTestEnvironmentVariable();
     DynamicSerializersInitializer.Init();
 }