public async void CreateAccountStellarAsync() { KeyPair keypairtest = KeyPair.Random(); var newAccount = new CreateAccountOperation(keypairtest, "1000"); var Acc = newAccount.ToOperationBody(); Network network = new Network("Test SDF Network ; September 2015"); Server server = new Server("https://horizon-testnet.stellar.org"); //Generate a keypair from the account id. KeyPair keypair = KeyPair.FromAccountId(keypairtest.AccountId); //Load the account AccountResponse accountResponse = await server.Accounts.Account(keypairtest.AccountId); //Get the balance Balance[] balances = accountResponse.Balances; //Show the balance for (int i = 0; i < balances.Length; i++) { Balance asset = balances[i]; Console.WriteLine("Asset Code: " + asset.AssetCode); Console.WriteLine("Asset Amount: " + asset.BalanceString); } }
public void CreateAccountOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF KeyPair source = KeyPair.FromSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR KeyPair destination = KeyPair.FromSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); var balance = 1000; CreateAccountOperation operation = new CreateAccountOperation.Builder(destination, balance) .SetSourceAccount(source) .Build(); Assert.AreEqual(source.Address, operation.SourceAccount.Address); Assert.AreEqual(destination.Address, operation.Destination.Address); Assert.AreEqual(balance, operation.StartingBalance); Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAD6A==", operation.ToXdrBase64()); Stellar.Generated.Operation xdr = operation.ToXDR(); CreateAccountOperation parsedOperation = Stellar.CreateAccountOperation.FromXDR(xdr); Assert.AreEqual(source.Address, parsedOperation.SourceAccount.Address); Assert.AreEqual(destination.Address, parsedOperation.Destination.Address); Assert.AreEqual(1000, parsedOperation.StartingBalance); }
public void ExecutedServiceClient(object sender, ExecutedRoutedEventArgs e) { if (SelectedClient == null) { MessageBox.Show("Клиент не выбран!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (SelectedAccount == null && (CurrentOperationType != OperationType.CreateAccount)) { MessageBox.Show("Счет не выбран!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } var serviceMsg = string.Empty; Operation reqOper; switch (CurrentOperationType) { case OperationType.AddMoney: reqOper = new AddMoneyOperation(SelectedAccount, MoneyAmount); break; case OperationType.WithdrawMoney: reqOper = new WithdrawMoneyOperation(SelectedAccount, MoneyAmount); break; case OperationType.CreateAccount: reqOper = new CreateAccountOperation(new Account(MoneyAmount, SelectedClient)); break; case OperationType.RemoveAccount: reqOper = new RemoveAccountOperation(SelectedAccount); break; default: return; } string srvMsg; var serviceResult = someBank.ProvideService(reqOper, out srvMsg); serviceMsg = $"Клиент {SelectedClient.Surname} {SelectedClient.Name} {(serviceResult ? "обслужен" : "не обслужен")}\n" + srvMsg; ServiceMessages = serviceMsg; }
public CreateAccountViewModel(IEventAggregator aggregator, State state) { this.Title = ""; this.ConfirmButtonTitle = ""; this.ReturnToPreviousPageTitle = ""; switch (state) { case State.CreateNewAccount: this.Title = "Create an account"; this.ConfirmButtonTitle = "CREATE MY ACCOUNT"; this.ReturnToPreviousPageTitle = "HAVE AN ACCOUNT"; break; case State.RegenerateKeyPair: this.Title = "Regenerate keypair"; this.ConfirmButtonTitle = "REGENERATE KEYPAIR"; this.ReturnToPreviousPageTitle = "RETURN TO SIGN IN"; break; } this.aggregator = aggregator; this.state = state; this.NavigateToSignInCommand = new RelayCommand(() => { this.aggregator.Publish(new NavigateTo(typeof(SignInViewModel))); this.CleanupState(); }); this.CreateAccountCommand = new RelayCommand(async() => { this.ClearErrors(); if (string.IsNullOrWhiteSpace(this.Login)) { this.AddErrorFor(nameof(this.Login), "Login should be a valid email"); } if (this.IsPasswordUsed) { if (string.IsNullOrEmpty(this.Password)) { this.AddErrorFor(nameof(this.Password), "You should provide password"); } if (!string.IsNullOrEmpty(this.Password)) { if (this.Password != this.ConfirmPassword) { this.AddErrorFor(nameof(this.Password), "Passwords should match"); this.AddErrorFor(nameof(this.ConfirmPassword), "Passwords should match"); } } } if (this.HasErrors) { return; } try { this.IsBusy = true; IConfirmationRequiredOperation operation; switch (this.state) { case State.CreateNewAccount: operation = new CreateAccountOperation(this.aggregator, this.IsPasswordUsed, this.IsUploadPrivateKey); break; case State.RegenerateKeyPair: operation = new RegenerateKeyPairOperation(this.aggregator, this.IsPasswordUsed, this.IsUploadPrivateKey); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } await operation.Initiate(this.Login, this.Password); this.aggregator.Publish(new ConfirmOperation(operation)); } catch (VirgilPublicServicesException exception) when(exception.ErrorCode == 30202) { this.AddErrorFor(nameof(this.Login), exception.Message); } catch (IdentityServiceException exception) when(exception.ErrorCode == 40200) { this.AddErrorFor(nameof(this.Login), exception.Message); } catch (Exception exception) { this.RaiseErrorMessage(exception.Message); } finally { this.IsBusy = false; } }); }
static void Main(string[] args) { Bank yourFinance = new Bank(); yourFinance.EmployWorker(new Employee("Стукачев", "Станислав", OperationType.Nothing, yourFinance)); yourFinance.EmployWorker(new Employee("Куклачев", "Юрий", OperationType.AddMoney | OperationType.WithdrawMoney, yourFinance)); yourFinance.EmployWorker(new Employee("Пугачев", "Виталий", OperationType.AddMoney | OperationType.WithdrawMoney, yourFinance)); yourFinance.EmployWorker(new Employee("Калачев", "Сигизмунд", OperationType.AddMoney | OperationType.WithdrawMoney | OperationType.CreateAccount, yourFinance)); yourFinance.EmployWorker(new Employee("Деревянкин", "Денис", OperationType.AddMoney | OperationType.WithdrawMoney | OperationType.CreateAccount | OperationType.RemoveAccount, yourFinance)); List <Client> clients = new List <Client> { new Client("Иван", "Иванов", yourFinance), new Client("Петр", "Петров", yourFinance), new Client("Авраам", "Сидоров", yourFinance), new Client("Алла", "Иванова", yourFinance), new Client("Мария", "Петрова", yourFinance), }; Action <Client, Operation> showService = (client, operation) => { string outMessage = string.Empty; bool serviceResult = false; serviceResult = yourFinance.ProvideService(operation, out outMessage); Console.WriteLine($"Клиент {client.Surname} {client.Name} {(serviceResult ? "обслужен" : "не обслужен")}\n" + outMessage); }; // Продемонстрировать закрытый банк Operation reqOper = new CreateAccountOperation(new Account(0, clients[0])); Bank.CurrentTime = DateTime.Today; showService(clients[0], reqOper); Console.WriteLine(); // Продемонстрировать занятых сотрудников Bank.CurrentTime = Bank.CurrentTime.AddHours(9); foreach (var client in clients) { showService(client, new CreateAccountOperation(new Account(0, client))); } Console.WriteLine(); // Сотрудники должны освободиться Thread.Sleep(1100); showService(clients[2], new CreateAccountOperation(new Account(0, clients[2]))); showService(clients[3], new CreateAccountOperation(new Account(0, clients[3]))); Thread.Sleep(1100); showService(clients[4], new CreateAccountOperation(new Account(0, clients[4]))); Console.WriteLine(); // Продемонстрировать прочие операции со счетами reqOper = new AddMoneyOperation(clients[0].Accounts.ElementAt(0), 500); showService(clients[0], reqOper); Console.WriteLine(); reqOper = new WithdrawMoneyOperation(clients[1].Accounts.ElementAt(0), 500); showService(clients[1], reqOper); Console.WriteLine(); reqOper = new CreateAccountOperation(new Account(1000, clients[2])); showService(clients[2], reqOper); Console.WriteLine(); Thread.Sleep(1100); reqOper = new RemoveAccountOperation(clients[3].Accounts.ElementAt(0)); showService(clients[3], reqOper); Console.WriteLine(); Console.Read(); }
public ConfirmOperation(CreateAccountOperation operation) { this.Operation = operation; }