public async Task Init()
        {
            if (Global.AppState.State != ApplicationState.WaitingForInit)
            {
                throw new InvalidOperationException("Alpha is not in the waiting for initialization state.");
            }

            var alphaAccountData = await DoesAlphaAccountExist();

            if (alphaAccountData == null)
            {
                throw new InvalidOperationException($"The vault ({Global.Settings.KeyPair.AccountId}) is not yet funded");
            }

            var txCursor = await BuildAndConfigureVault(alphaAccountData);

            SetIdToAssets();

            var initQuantum = new ConstellationInitQuantum
            {
                Assets            = constellationInitInfo.Assets.ToList(),
                Auditors          = constellationInitInfo.Auditors.Select(key => (RawPubKey)key.PublicKey).ToList(),
                Vault             = Global.Settings.KeyPair.PublicKey,
                MinAccountBalance = constellationInitInfo.MinAccountBalance,
                MinAllowedLotSize = constellationInitInfo.MinAllowedLotSize,
                PrevHash          = new byte[] { },
                RequestRateLimits = constellationInitInfo.RequestRateLimits,
                TxCursor          = txCursor
            };

            var envelope = initQuantum.CreateEnvelope();

            await Global.QuantumHandler.HandleAsync(envelope);
        }
Beispiel #2
0
        /// <summary>
        /// This method inits Global, generates genesis snapshot and adds clients to constellation
        /// </summary>
        /// <param name="clients">Clients to add to constellation</param>
        /// <param name="auditors">Auditors to add to constellation</param>
        /// <param name="settings">Settings that will be used to init Global</param>
        public static async Task Setup(List <KeyPair> clients, List <KeyPair> auditors, BaseSettings settings, IStorage storage)
        {
            await Global.Setup(settings, storage);

            var assets = new List <AssetSettings> {
                new AssetSettings {
                    Id = 1, Code = "X", Issuer = KeyPair.Random()
                }
            };

            var initQuantum = new ConstellationInitQuantum
            {
                Apex              = 1,
                Assets            = assets,
                Auditors          = auditors.Select(a => (RawPubKey)a.PublicKey).ToList(),
                MinAccountBalance = 1,
                MinAllowedLotSize = 1,
                Vault             = settings is AlphaSettings ? settings.KeyPair.PublicKey : ((AuditorSettings)settings).AlphaKeyPair.PublicKey,
                PrevHash          = new byte[] { },
                RequestRateLimits = new RequestRateLimits {
                    HourLimit = 1000, MinuteLimit = 100
                }
            };

            if (!Global.IsAlpha)
            {
                initQuantum.Timestamp = DateTime.UtcNow.Ticks;
            }

            var envelope = initQuantum.CreateEnvelope();

            if (!Global.IsAlpha)
            {
                var alphaKeyPair = KeyPair.FromSecretSeed(TestEnvironment.AlphaKeyPair.SecretSeed);
                envelope.Sign(alphaKeyPair);
            }

            await Global.QuantumHandler.HandleAsync(envelope);

            var deposits = new List <PaymentBase>();
            Action <byte[], int> addAssetsFn = (acc, asset) =>
            {
                deposits.Add(new Deposit
                {
                    Destination   = acc,
                    Amount        = 10000,
                    Asset         = asset,
                    PaymentResult = PaymentResults.Success
                });
            };

            for (int i = 0; i < clients.Count; i++)
            {
                //add xlm
                addAssetsFn(clients[i].PublicKey, 0);
                for (var c = 0; c < assets.Count; c++)
                {
                    addAssetsFn(clients[i].PublicKey, assets[c].Id);
                }
            }

            var depositQuantum = new TxCommitQuantum
            {
                Apex     = 2,
                PrevHash = Global.QuantumStorage.LastQuantumHash,
                Source   = new TxNotification
                {
                    TxCursor = 2,
                    Payments = deposits
                }.CreateEnvelope()
            };

            depositQuantum.Source.Sign(TestEnvironment.Auditor1KeyPair);

            await Global.QuantumHandler.HandleAsync(depositQuantum.CreateEnvelope());

            //save all effects
            await SnapshotHelper.ApplyUpdates();
        }