Beispiel #1
0
 private static void QueryAllNFT()
 {
     Algorand.V2.Model.Account actInfo = null;
     try
     {
         // We can now list the account information for acct3
         // and see that it can accept the new asseet
         actInfo = algodApiInstance.AccountInformation(act.Address.ToString());
         Console.WriteLine(actInfo);
         foreach (var ast in actInfo.Assets)
         {
             if (ast.Creator == reliableAddress)
             {
                 var astInfo = algodApiInstance.GetAssetByID(ast.AssetId);
                 if (astInfo.Params.Total == 1 && astInfo.Params.Decimals == 0 &&
                     astInfo.Params.UnitName == "NFT")
                 {
                     Console.WriteLine(
                         string.Format("Token Name: {0}, Token Id: {1}", astInfo.Params.Name, astInfo.Index)
                         );
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return;
     }
 }
        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);
        }
        static DryrunRequest DryrunDrr(SignedTransaction signTx, TEALProgram program, Algorand.V2.Model.Account cr, Algorand.V2.Model.Account usr)
        {
            var sources = new List <DryrunSource>();

            if (program != null)
            {
                sources.Add(new DryrunSource("approv", Convert.ToBase64String(program.Bytes), 0));
            }
            var drr = new DryrunRequest(new List <SignedTransaction>()
            {
                signTx
            },
                                        new List <Algorand.V2.Model.Account>()
            {
                cr, usr
            }, sources: sources);

            return(drr);
        }
Beispiel #4
0
        async void TransferAsset_Clicked(System.Object sender, System.EventArgs e)
        {
            TransferAsset.Opacity = .2;
            // Transfer the Asset:
            // Now that account3 can receive the new asset
            // we can transfer assets in from the creator
            // to account3
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain

            var transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // We set the assetCloseTo to null so we do not close the asset out
            Address assetCloseTo = new Address();
            ulong   assetAmount  = 10;
            var     tx           = Utils.GetTransferAssetTransaction(account1.Address, account3.Address, assetID, assetAmount, transParams, null, "transfer message");
            // The transaction must be signed by the sender account
            // We are reusing the signedTx variable from the first transaction in the example
            var signedTx = account1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            string mytx;

            try
            {
                PostTransactionsResponse id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                mytx = id.TxId;
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct3
                // and see that it now has 5 of the new asset
                var act = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID).Amount);

                TransferAsset.Opacity = 1;
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "transfer");

                buttonstate("transfer");
                var asset = algodApiInstance.GetAssetByID((long?)assetID).ToJson();
                Algorand.V2.Model.Account account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

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

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                Console.WriteLine(err.Message);
                TransferAsset.Opacity = 1;
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Beispiel #5
0
        // Utility function for sending a raw signed transaction to the network
        public static void Main(params string[] args) //throws Exception
        {
            string algodApiAddrTmp = args[0];

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

            string ALGOD_API_ADDR  = algodApiAddrTmp;
            string ALGOD_API_TOKEN = args[1];

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            // Shown for demonstration purposes. NEVER reveal secret mnemonics in practice.
            // These three accounts are for testing purposes
            string account1_mnemonic = "portion never forward pill lunch organ biology"
                                       + " weird catch curve isolate plug innocent skin grunt"
                                       + " bounce clown mercy hole eagle soul chunk type absorb trim";
            string account2_mnemonic = "place blouse sad pigeon wing warrior wild script"
                                       + " problem team blouse camp soldier breeze twist mother"
                                       + " vanish public glass code arrow execute convince ability"
                                       + " there";
            string account3_mnemonic = "image travel claw climb bottom spot path roast "
                                       + "century also task cherry address curious save item "
                                       + "clean theme amateur loyal apart hybrid steak about blanket";

            Account acct1 = new Account(account1_mnemonic);
            Account acct2 = new Account(account2_mnemonic);
            Account acct3 = new Account(account3_mnemonic);
            // get last round and suggested tx fee
            // We use these to get the latest round and tx fees
            // These parameters will be required before every
            // Transaction
            // We will account for changing transaction parameters
            // before every transaction in this example
            var transParams = algodApiInstance.TransactionParams();

            // The following parameters are asset specific
            // and will be re-used throughout the example.

            // Create the Asset
            // Total number of this asset available for circulation
            var ap = new AssetParams(creator: acct1.Address.ToString(), name: "latikum22", unitName: "LAT", total: 10000,
                                     decimals: 0, url: "http://this.test.com", metadataHash: Encoding.ASCII.GetBytes("16efaa3924a6fd9d3a4880099a4ac65d"))
            {
                Manager = acct2.Address.ToString()
            };

            // Specified address can change reserve, freeze, clawback, and manager
            // you can leave as default, by default the sender will be manager/reserve/freeze/clawback
            // the following code only set the freeze to acct1
            var tx = Utils.GetCreateAssetTransaction(ap, transParams, "asset tx message");

            // Sign the Transaction by sender
            SignedTransaction signedTx = acct1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            long?assetID = 0;

            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // Now that the transaction is confirmed we can get the assetID
                var ptx = algodApiInstance.PendingTransactionInformation(id.TxId);
                assetID = ptx.AssetIndex;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return;
            }
            Console.WriteLine("AssetID = " + assetID);
            // now the asset already created


            // Change Asset Configuration:
            // Next we will change the asset configuration
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            Asset ast = algodApiInstance.GetAssetByID(assetID);

            // Note that configuration changes must be done by
            // The manager account, which is currently acct2
            // Note in this transaction we are re-using the asset
            // creation parameters and only changing the manager
            // and transaction parameters like first and last round
            // now update the manager to acct1
            ast.Params.Manager = acct1.Address.ToString();
            tx = Utils.GetConfigAssetTransaction(acct2.Address, ast, transParams, "config trans");

            // The transaction must be signed by the current manager account
            // We are reusing the signedTx variable from the first transaction in the example
            signedTx = acct2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // Next we will list the newly created asset
            // Get the asset information for the newly changed asset
            ast = algodApiInstance.GetAssetByID(assetID);
            //The manager should now be the same as the creator
            Console.WriteLine(ap);



            // Opt in to Receiving the Asset
            // Opting in to transact with the new asset
            // All accounts that want recieve the new asset
            // Have to opt in. To do this they send an asset transfer
            // of the new asset to themseleves with an ammount 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
            transParams = algodApiInstance.TransactionParams();
            tx          = Utils.GetAssetOptingInTransaction(acct3.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
            signedTx = acct3.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            Algorand.V2.Model.Account act = null;
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct3
                // and see that it can accept the new asseet
                act = algodApiInstance.AccountInformation(acct3.Address.ToString());
                Console.WriteLine(act);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            // Transfer the Asset:
            // Now that account3 can recieve the new asset
            // we can tranfer assets in from the creator
            // to account3
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // We set the assetCloseTo to null so we do not close the asset out
            Address assetCloseTo = new Address();
            ulong   assetAmount  = 10;

            tx = Utils.GetTransferAssetTransaction(acct1.Address, acct3.Address, assetID, assetAmount, transParams, null, "transfer message");
            // The transaction must be signed by the sender account
            // We are reusing the signedTx variable from the first transaction in the example
            signedTx = acct1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct3
                // and see that it now has 5 of the new asset
                act = algodApiInstance.AccountInformation(acct3.Address.ToString());
                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID).Amount);
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // Freeze the Asset:
            // The asset was created and configured to allow freezing an account
            // If the freeze address is blank, it will no longer be possible to do this.
            // In this example we will now freeze account3 from transacting with the
            // The newly created asset.
            // Thre freeze transaction is sent from the freeze acount
            // Which in this example is account2
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // The sender should be freeze account acct2
            // Theaccount to freeze should be set to acct3
            tx = Utils.GetFreezeAssetTransaction(acct2.Address, acct3.Address, assetID, true, transParams, "freeze transaction");
            // The transaction must be signed by the freeze account acct2
            // We are reusing the signedTx variable from the first transaction in the example
            signedTx = acct2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct3
                // and see that it now frozen
                // Note--currently no getter method for frozen state
                act = algodApiInstance.AccountInformation(acct3.Address.ToString());
                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID));
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }


            // Revoke the asset:
            // The asset was also created with the ability for it to be revoked by
            // clawbackaddress. If the asset was created or configured by the manager
            // not allow this by setting the clawbackaddress to a blank address
            // then this would not be possible.
            // We will now clawback the 10 assets in account3. Account2
            // is the clawbackaccount and must sign the transaction
            // The sender will be be the clawback adress.
            // the recipient will also be be the creator acct1 in this case
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            assetAmount = 10;
            tx          = Utils.GetRevokeAssetTransaction(acct2.Address, acct3.Address, acct1.Address, assetID, assetAmount, transParams, "revoke transaction");
            // The transaction must be signed by the clawback account
            // We are reusing the signedTx variable from the first transaction in the example
            signedTx = acct2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct3
                // and see that it now has 0 of the new asset
                act = algodApiInstance.AccountInformation(acct3.Address.ToString());
                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID).Amount);
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // Destroy the Asset:
            // All of the created assets should now be back in the creators
            // Account so we can delete the asset.
            // If this is not the case the asset deletion will fail
            // The address for the from field must be the creator
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // The manager must sign and submit the transaction
            // This is currently set to acct1
            tx = Utils.GetDestroyAssetTransaction(acct1.Address, assetID, transParams, "destroy transaction");
            // The transaction must be signed by the manager account
            // We are reusing the signedTx variable from the first transaction in the example
            signedTx = acct1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id);
                //waitForTransactionToComplete(algodApiInstance, signedTx.transactionID);
                //Console.ReadKey();
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                // We can now list the account information for acct1
                // and see that the asset is no longer there
                act = algodApiInstance.AccountInformation(acct1.Address.ToString());
                //Console.WriteLine("Does AssetID: " + assetID + " exist? " +
                //    act.Thisassettotal.ContainsKey(assetID));
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }
            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
        }
Beispiel #6
0
        async void DestroyAsset_Clicked(System.Object sender, System.EventArgs e)
        {
            DestroyAsset.Opacity = .2;
            // Destroy the Asset:
            // All of the created assets should now be back in the creators
            // Account so we can delete the asset.
            // If this is not the case the asset deletion will fail
            // The address for the from field must be the creator
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            var transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // The manager must sign and submit the transaction
            // This is currently set to acct1
            var tx = Utils.GetDestroyAssetTransaction(account1.Address, assetID, transParams, "destroy transaction");
            // The transaction must be signed by the manager account
            // We are reusing the signedTx variable from the first transaction in the example
            var signedTx = account1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            string mytx;

            try
            {
                PostTransactionsResponse id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                //waitForTransactionToComplete(algodApiInstance, signedTx.transactionID);
                //Console.ReadKey();
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                mytx = id.TxId;
                // We can now list the account information for acct1
                // and see that the asset is no longer there
                var act = await algodApiInstance.AccountInformationAsync(account1.Address.ToString());

                Console.WriteLine("Does AssetID: " + assetID + " exist? " +
                                  act.Assets.Find(h => h.AssetId == assetID));


                await SecureStorage.SetAsync(helper.StorageAssetIDName, "");

                myAsset.Text         = "";
                DestroyAsset.Opacity = 1;
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "destroy");

                buttonstate("destroy");
                Algorand.V2.Model.Account account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Transaction ID = " + mytx + "</h3>" +
                                  "<h3>" + "AssetID: " + assetID + " destroyed " + "</h3>" +
                                  "</body></html>";

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                DestroyAsset.Opacity = 1;
                Console.WriteLine(err.Message);
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Beispiel #7
0
        async void RevokeAsset_Clicked(System.Object sender, System.EventArgs e)
        {
            RevokeAsset.Opacity = .2;
            // Revoke the asset:
            // The asset was also created with the ability for it to be revoked by
            // clawbackaddress. If the asset was created or configured by the manager
            // not allow this by setting the clawbackaddress to a blank address
            // then this would not be possible.
            // We will now clawback the 10 assets in account3. Account2
            // is the clawbackaccount and must sign the transaction
            // The sender will be the clawback adress.
            // the recipient will also be the creator acct1 in this case
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            var transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            ulong assetAmount = 10;
            var   tx          = Utils.GetRevokeAssetTransaction(account2.Address, account3.Address, account1.Address, assetID, assetAmount, transParams, "revoke transaction");
            // The transaction must be signed by the clawback account
            // We are reusing the signedTx variable from the first transaction in the example
            var signedTx = account2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            string mytx;

            try
            {
                PostTransactionsResponse id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
                mytx = id.TxId;
                RevokeAsset.Opacity   = .4;
                RevokeAsset.IsEnabled = false;
                // We can now list the account information for acct3
                // and see that it now has 0 of the new asset
                var act = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID).Amount);
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "revoke");

                buttonstate("revoke");
                Algorand.V2.Model.Account account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

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

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                Console.WriteLine(err.Message);
                RevokeAsset.Opacity   = .4;
                RevokeAsset.IsEnabled = false;
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Beispiel #8
0
        async void FreezeAsset_Clicked(System.Object sender, System.EventArgs e)
        {
            FreezeAsset.Opacity = .2;
            // Freeze the asset
            // The asset was created and configured to allow freezing an account
            // If the freeze address is blank, it will no longer be possible to do this.
            // In this example we will now freeze account3 from transacting with the
            // The newly created asset.
            // The freeze transaction is sent from the freeze account
            // Which in this example is account2
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain

            var transParams = algodApiInstance.TransactionParams();
            // Next we set asset xfer specific parameters
            // The sender should be freeze account acct2
            // Theaccount to freeze should be set to acct3
            var tx = Utils.GetFreezeAssetTransaction(account2.Address, account3.Address, assetID, true, transParams, "freeze transaction");
            // The transaction must be signed by the freeze account acct2
            // We are reusing the signedTx variable from the first transaction in the example
            var signedTx = account2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            string mytx;

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

                var act = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

                Console.WriteLine(act.Assets.Find(h => h.AssetId == assetID));
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "freeze");

                buttonstate("freeze");
                var asset = algodApiInstance.GetAssetByID((long?)assetID).ToJson();
                Algorand.V2.Model.Account account = await algodApiInstance.AccountInformationAsync(account3.Address.ToString());

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

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                Console.WriteLine(err.Message);
                FreezeAsset.Opacity = 1;
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Beispiel #9
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;
            }
        }
Beispiel #10
0
        public async void Transaction_Clicked(System.Object sender, System.EventArgs e)
        {
            // restore accounts

            var accounts = await helper.RestoreAccounts();

            Account           account1 = accounts[0];
            Account           account2 = accounts[1];
            Account           account3 = accounts[2];
            HtmlWebViewSource htmlSource;
            // transfer from Account 1 to 2
            TransactionParametersResponse transParams = null;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            var amount   = Utils.AlgosToMicroalgos(1);
            var tx       = Utils.GetPaymentTransaction(account1.Address, account2.Address, amount, "pay message", transParams);
            var signedTx = account1.SignTransaction(tx);

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);
            PostTransactionsResponse id = null;

            //  string wait = "";
            // send the transaction to the network
            try
            {
                id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);

                Console.WriteLine("Successful! " + wait.Txn);
                await DisplayAccount(helper.StorageAccountName2);
            }
            catch (ApiException err)
            {
                // This should give us an informative error message.
                //   await SecureStorage.SetAsync("Transaction", err.Message);
                Console.WriteLine("Exception when calling algod#rawTransaction: " + err.Message);

                if (err.Message.Contains("overspend"))
                {
                    var network = await SecureStorage.GetAsync(helper.StorageNetwork);

                    htmlSource      = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body><h3>" + network + " Account has insuficent funds. " + "</h3>" +
                                      "<h3>" + network + " add funds and try again. " + "</h3>" +
                                      "<p>Account = " + account1.Address.ToString() + "</p>" +
                                      "</body></html>";

                    myWebView.Source  = htmlSource;
                    myWebViewp.Source = htmlSource;
                }
                htmlSource      = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3> Transaction ID = " + err.Message + "</h3>" +
                                  "</body></html>";

                myWebView.Source  = htmlSource;
                myWebViewp.Source = htmlSource;
                //  Entry4.Text = "Transaction ID = " + err.Message;
            }

            if (!(String.IsNullOrEmpty(id.TxId)))
            {
                await SecureStorage.SetAsync(helper.StorageTransaction, id.TxId.ToString());

                GetTransaction.IsVisible = true;
            }


            buttonstate();


            var mytx = await SecureStorage.GetAsync(helper.StorageTransaction);

            if (!(mytx == null || mytx == ""))

            {
                Algorand.V2.Model.Account accountinfo = await algodApiInstance.AccountInformationAsync(account2.Address.ToString());

                Debug.WriteLine("Account 2 info: " + accountinfo);
                htmlSource = new HtmlWebViewSource();

                htmlSource.Html = @"<html><body><h3> Transaction ID = " + mytx.ToString() + " </h3>" +
                                  "<h3>" + "Account 2 info = " + accountinfo.ToJson() + "</h3>" +
                                  "</body></html>";

                myWebView.Source  = htmlSource;
                myWebViewp.Source = htmlSource;
            }
            await DisplayAccount(helper.StorageAccountName2);
        }