Exemplo n.º 1
0
        private async Task DisplayAccount(string accountname)
        {
            Account account;
            string  mnemonic = "";

            try
            {
                mnemonic = await SecureStorage.GetAsync(accountname);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
                // Possible that device doesn't support secure storage on device.
            }

            //restore account from mnemonic
            account = new Account(mnemonic);

            // Algorand.V2.Model.Account accountinfo = algodApiInstance.AccountInformation(account.Address.ToString());
            var accountinfo = await algodApiInstance.AccountInformationAsync(account.Address.ToString());


            Debug.WriteLine("accountinfo: " + accountinfo);

            var htmlSource = new HtmlWebViewSource();

            htmlSource.Html = @"<html><body><h3>" + " Address = " + account.Address.ToString() + "</h3>" +
                              "<h3>" + "Account amount (micro algos) = " + accountinfo.Amount.ToString() + "</h3>" +
                              "<p>Info = " + accountinfo.ToJson() + " </p>" +
                              "</body></html>";

            myWebView.Source  = htmlSource;
            myWebViewp.Source = htmlSource;
        }
        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 <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);
        }
Exemplo n.º 4
0
        async void OptIn_Clicked(System.Object sender, System.EventArgs e)
        {
            OptIn.Opacity = .2;

            // Opt in to Receiving the Asset

            // Opting in to transact with the new asset
            // All accounts that want receive the new asset
            // Have to opt in. To do this they send an asset transfer
            // of the new asset to themselves with an amount of 0
            // In this example we are setting up the 3rd recovered account to
            // receive the new asset
            // First, we update standard Transaction parameters
            // To account for changes in the state of the blockchain

            var transParams = algodApiInstance.TransactionParams();
            //  var tx = Utils.GetActivateAssetTransaction(account3.Address, assetID, transParams, "opt in transaction");
            var tx = Utils.GetAssetOptingInTransaction(account3.Address, assetID, transParams, "opt in transaction");

            // The transaction must be signed by the current manager account
            // We are reusing the signedTx variable from the first transaction in the example
            var signedTx = account3.SignTransaction(tx);

            // send the transaction to the network and
            // wait for the transaction to be confirmed
            Algorand.V2.Model.Account account = null;
            string mytx;

            try
            {
                PostTransactionsResponse id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                mytx          = id.TxId;
                OptIn.Opacity = 1;
                Console.WriteLine(wait);
                // We can now list the account information for acct3
                // and see that it can accept the new asset

                account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                var assetholding = account.Assets;
                Console.WriteLine(assetholding);
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "optin");

                buttonstate("optin");

                account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Transaction ID = " + mytx + "</h3>" +
                                  "<h3>" + "Account 3 Asset Amount = " + account.Assets.Find(h => h.AssetId == assetID).Amount + "</h3>" +
                                  "<h3>" + "Asset ID = " + assetID.ToString() + "</h3>" +
                                  "</body></html>";

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                Console.WriteLine(err.Message);
                OptIn.Opacity = 1;
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Exemplo n.º 5
0
        async void AtomicTransfer_Clicked(System.Object sender, System.EventArgs e)
        {
            //var transParams = algodApiInstance.TransactionParams();
            AtomicTransfer.Opacity         = .2;
            StackAtomicTransfers.IsEnabled = false;
            Algorand.V2.Model.TransactionParametersResponse transParams = null;
            AtomicTransfer.IsEnabled = false;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            // let's create a transaction group
            var amount = Utils.AlgosToMicroalgos(1);
            var tx     = Utils.GetPaymentTransaction(account1.Address, account2.Address, amount, "pay message", transParams);
            var tx2    = Utils.GetPaymentTransaction(account1.Address, account3.Address, amount, "pay message", transParams);
            //SignedTransaction signedTx2 = src.SignTransactionWithFeePerByte(tx2, feePerByte);
            Digest gid = TxGroup.ComputeGroupID(new Algorand.Transaction[] { tx, tx2 });

            tx.AssignGroupID(gid);
            tx2.AssignGroupID(gid);
            // already updated the groupid, sign
            var signedTx  = account1.SignTransaction(tx);
            var signedTx2 = account1.SignTransaction(tx2);

            try
            {
                //contact the signed msgpack
                List <byte> byteList = new List <byte>(Algorand.Encoder.EncodeToMsgPack(signedTx));
                byteList.AddRange(Algorand.Encoder.EncodeToMsgPack(signedTx2));
                var act = await algodApiInstance.AccountInformationAsync(account1.Address.ToString());

                var before = "Account 1 balance before: " + act.Amount.ToString();
                var id     = algodApiInstance.RawTransaction(byteList.ToArray());
                var wait   = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                Console.WriteLine(wait);

                // Console.WriteLine("Successfully sent tx group with first tx id: " + id);

                act = await algodApiInstance.AccountInformationAsync(account1.Address.ToString());

                await SecureStorage.SetAsync(helper.StorageAtomicTransaction, wait.ToString());

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + before + " </h3>" +
                                  "<h3>" + wait + "</h3>" + "<h3> Account 1 balance after: " + act.Amount.ToString() + "</h3></body></html>";

                myWebView.Source         = htmlSource;
                AtomicTransfer.IsEnabled = true;
            }
            catch (ApiException err)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + err.Message);
                AtomicTransfer.IsEnabled = true;
            }
            AtomicTransfer.Opacity         = 1;
            StackAtomicTransfers.IsEnabled = true;
            AtomicTransferInfo.IsEnabled   = true;
            buttonstate();
        }