public static void Main(string[] args)
        {
            string ALGOD_API_ADDR = args[0];

            if (ALGOD_API_ADDR.IndexOf("//") == -1)
            {
                ALGOD_API_ADDR = "http://" + ALGOD_API_ADDR;
            }

            string  ALGOD_API_TOKEN = args.Length > 1 ? args[1] : null;
            string  SRC_ACCOUNT     = "typical permit hurdle hat song detail cattle merge oxygen crowd arctic cargo smooth fly rice vacuum lounge yard frown predict west wife latin absent cup";
            Account src             = new Account(SRC_ACCOUNT);

            Console.WriteLine("My account address is:" + src.Address.ToString());

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            var accountInfo = algodApiInstance.AccountInformation(src.Address.ToString());

            Console.WriteLine(string.Format("Account Balance: {0} microAlgos", accountInfo.Amount));

            var task = algodApiInstance.AccountInformationAsync(src.Address.ToString());

            task.Wait();
            var asyncAccountInfo = task.Result;

            Console.WriteLine(string.Format("Account Balance(Async): {0} microAlgos", asyncAccountInfo.Amount));

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
        }
        public async Task <Account[]> RestoreAccounts()
        {
            Account[] accounts = new Account[3];

            string mnemonic1 = "";
            string mnemonic2 = "";
            string mnemonic3 = "";

            try
            {
                mnemonic1 = await SecureStorage.GetAsync(StorageAccountName1);

                mnemonic2 = await SecureStorage.GetAsync(StorageAccountName2);

                mnemonic3 = await SecureStorage.GetAsync(StorageAccountName3);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
                // Possible that device doesn't support secure storage on device.
            }
            // restore accounts
            accounts[0] = new Account(mnemonic1);
            accounts[1] = new Account(mnemonic2);
            accounts[2] = new Account(mnemonic3);
            return(accounts);
        }
        public async Task <string[]> CreateAccount(string accountname)
        {
            string[] accountinfo = new string[2];
            Account  myAccount   = new Account();
            var      myMnemonic  = myAccount.ToMnemonic();

            Console.WriteLine(accountname.ToString() + " Address = " + myAccount.Address.ToString());
            Console.WriteLine(accountname.ToString() + " Mnemonic = " + myMnemonic.ToString());

            accountinfo[0] = myAccount.Address.ToString();
            accountinfo[1] = myMnemonic.ToString();
            return(accountinfo);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                Algorand.Account account = new Algorand.Account();
                var key     = account.ToMnemonic();
                var address = account.Address.ToString();
                var user    = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email, Key = key, AccountAddress = address
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);



                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <ulong?> GetAccountBalance(string accountname)
        {
            Account account   = null;
            string  myaddress = "";
            string  network   = await SecureStorage.GetAsync(StorageNetwork);

            if (!(accountname == StorageMultisig))
            {
                string mnemonic = await SecureStorage.GetAsync(accountname);

                if (mnemonic != null)
                {
                    if (mnemonic != " ")
                    {
                        account   = new Account(mnemonic);
                        myaddress = account.Address.ToString();
                    }
                }
            }
            else
            {
                // multisig address
                myaddress = await SecureStorage.GetAsync(accountname);
            }
            algodApiInstance = await CreateApiInstance();

            if (algodApiInstance != null)
            {
                if (String.IsNullOrEmpty(myaddress) || myaddress == " ")
                {
                }
                else
                {
                    //      var task = algodApiInstance.AccountInformationAsync(myaddress);
                    //      task.Wait();
                    //      var accountinfo = task.Result;

                    Algorand.V2.Model.Account accountinfo = await algodApiInstance.AccountInformationAsync(myaddress);

                    if (accountinfo != null)
                    {
                        return((ulong?)accountinfo.Amount);
                    }
                }
            }
            return((ulong?)0);
        }