private void UpdateApp(AlgodApi client, Account creator, long?appid, TEALProgram approvalProgram, TEALProgram clearProgram)
        {
            try
            {
                var transParams = client.TransactionParams();
                var tx          = Utils.GetApplicationUpdateTransaction(creator.Address, (ulong?)appid, approvalProgram, clearProgram, transParams);
                var signedTx    = creator.SignTransaction(tx);
                Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

                var id = Utils.SubmitTransaction(client, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var resp = Utils.WaitTransactionToComplete(client, id.TxId);
                Console.WriteLine("Confirmed Round is: " + resp.ConfirmedRound);
                Console.WriteLine("Application ID is: " + appid);

                DisplayInfo("Successfully Updated with  tx id: " + id.TxId);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling create application: " + e.Message);
            }
        }
        void OptIn(AlgodApi client, Account sender, long?applicationId)
        {
            try
            {
                var transParams = client.TransactionParams();
                var tx          = Utils.GetApplicationOptinTransaction(sender.Address, (ulong?)applicationId, transParams);
                var signedTx    = sender.SignTransaction(tx);
                Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

                var id = Utils.SubmitTransaction(client, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var resp = Utils.WaitTransactionToComplete(client, id.TxId);
                Console.WriteLine(string.Format("Address {0} optin to Application({1})",
                                                sender.Address.ToString(), (resp.Txn as JObject)["txn"]["apid"]));
                DisplayInfo(string.Format("Address {0} optin to Application({1})",
                                          sender.Address.ToString(), (resp.Txn as JObject)["txn"]["apid"]));
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling create application: " + e.Message);
            }
        }
        static long?CreateApp(AlgodApi client, Account creator, TEALProgram approvalProgram,
                              TEALProgram clearProgram, ulong?globalInts, ulong?globalBytes, ulong?localInts, ulong?localBytes)
        {
            try
            {
                var transParams = client.TransactionParams();
                var tx          = Utils.GetApplicationCreateTransaction(creator.Address, approvalProgram, clearProgram,
                                                                        new StateSchema(globalInts, globalBytes), new StateSchema(localInts, localBytes), transParams);
                var signedTx = creator.SignTransaction(tx);
                Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

                var id = Utils.SubmitTransaction(client, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var resp = Utils.WaitTransactionToComplete(client, id.TxId);
                Console.WriteLine("Application ID is: " + resp.ApplicationIndex.ToString());
                return(resp.ApplicationIndex);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling create application: " + e.Message);
                return(null);
            }
        }
Exemple #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;
            }
        }
Exemple #5
0
        async void CongfigureManagerRole_click(System.Object sender, System.EventArgs e)
        {
            CongfigureManagerRole.Opacity = .2;
            // 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
            var   transParams = algodApiInstance.TransactionParams();
            Asset ast         = algodApiInstance.GetAssetByID(assetID);

            // Note that configuration changes must be done by
            // The manager account, which is currently account2
            // 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 account1
            ast.Params.Manager = account1.Address.ToString();
            var tx = Utils.GetConfigAssetTransaction(account2.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
            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);
                mytx = id.TxId;
                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                CongfigureManagerRole.Opacity = 1;
                Console.WriteLine(wait);
                await SecureStorage.SetAsync(helper.StorageLastASAButton, "manage");

                buttonstate("manage");
                // var act = algodApiInstance.AssetInformation((long?)assetID).ToJson();
                // Get the asset information for the newly changed asset
                ast = algodApiInstance.GetAssetByID(assetID);
                //The manager should now be the same as the creator

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Transaction ID = " + mytx + "</h3>" +
                                  "<h3>" + "Asset ID = " + assetID.ToString() + "</h3>" +
                                  "<h3>" + "Asset Info = " + ast.ToString() + "</h3>" +
                                  "</body></html>";

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                //e.printStackTrace();
                Console.WriteLine(err.Message);
                CongfigureManagerRole.Opacity = 1;
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
        }
Exemple #6
0
        private async void CreateAsset_click(System.Object sender, System.EventArgs e)
        {
            CreateAsset.Opacity = .2;
            HtmlWebViewSource htmlSource = new HtmlWebViewSource();

            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 = 10000

            var ap = new AssetParams(creator: account1.Address.ToString(),
                                     name: "latikum22",
                                     unitName: "LAT", defaultFrozen: false, total: 10000,
                                     decimals: 0, url: "http://this.test.com",
                                     metadataHash: Encoding.ASCII.GetBytes("16efaa3924a6fd9d3a4880099a4ac65d"))
            {
                Manager = account2.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

            var tx = Utils.GetCreateAssetTransaction(ap, transParams, "asset tx message");

            // Sign the Transaction by sender
            SignedTransaction signedTx = account1.SignTransaction(tx);

            // send the transaction to the network and
            // wait for the transaction to be confirmed

            try
            {
                PostTransactionsResponse id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Transaction ID: " + id.TxId);
                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;


                var assetIDstr = assetID.ToString();
                await SecureStorage.SetAsync(helper.StorageAssetIDName, assetIDstr);

                await SecureStorage.SetAsync(helper.StorageLastASAButton, "create");

                buttonstate("create");
                CreateAsset.Opacity = 1;
                var act = algodApiInstance.GetAssetByID(assetID).ToJson();
                //   var act = algodApiInstance.AssetInformation((long?)assetID).ToJson();

                htmlSource.Html = @"<html><body><h3>" + "AssetID = " + assetID.ToString() + "</h3>" +
                                  "<h3>" + "Asset Info = " + act.ToString() + "</h3>" +
                                  "</body></html>";

                myWebView.Source = htmlSource;
            }
            catch (Exception err)
            {
                Console.WriteLine(err.StackTrace);
                CreateAsset.Opacity = 1;
                htmlSource.Html     = @"<html><body><h3>" + "Error = " + err.Message + "</h3>" +
                                      "</body></html>";
                myWebView.Source = htmlSource;
                return;
            }
            Console.WriteLine("AssetID = " + assetID);
            // now the asset already created
        }
    //Coroutines
    public IEnumerator PlayerWithAlgorandLoopCoroutine()
    {
        yield return(null);

        Debug.Log("Starting Algorand Transaction.");
        string ALGOD_API_ADDR = "https://testnet-algorand.api.purestake.io/ps2";

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

        string ALGOD_API_TOKEN = "IkwGyG4qWg8W6VegMFfCa3iIIj06wi0x6Vn7FO5j";
        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";
        string DEST_ADDR       = "KV2XGKMXGYJ6PWYQA5374BYIQBL3ONRMSIARPCFCJEAMAHQEVYPB7PL3KU";

        if (!Address.IsValid(DEST_ADDR))
        {
            Debug.LogError("The address " + DEST_ADDR + " is not valid!");
        }
        Account src = new Account(SRC_ACCOUNT);

        Debug.Log("My account address is:" + src.Address.ToString());
        yield return(null);

        AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

        TransactionParametersResponse transParams;

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

        yield return(null);

        Debug.Log("Signed transaction with txid: " + signedTx.transactionID);

        // send the transaction to the network
        try
        {
            var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
            Debug.Log("Successfully sent tx with id: " + id.TxId);
            //var resp = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
            //Debug.Log("Confirmed Round is: " + resp.ConfirmedRound);
        }
        catch (ApiException e)
        {
            // This is generally expected, but should give us an informative error message.
            Debug.LogError("Exception when calling algod#rawTransaction: " + e.Message);
        }

        yield return(null);

        Debug.Log("Algorand transaction to Player completed.");
    }
Exemple #8
0
        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[1];
            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";
            string DEST_ADDR       = "KV2XGKMXGYJ6PWYQA5374BYIQBL3ONRMSIARPCFCJEAMAHQEVYPB7PL3KU";

            if (!Address.IsValid(DEST_ADDR))
            {
                Console.WriteLine("The address " + DEST_ADDR + " is not valid!");
            }
            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);

            try
            {
                var supply = algodApiInstance.GetSupply();
                Console.WriteLine("Total Algorand Supply: " + supply.TotalMoney);
                Console.WriteLine("Online Algorand Supply: " + supply.OnlineMoney);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling algod#getSupply:" + e.Message);
            }

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

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

            try
            {
                var trans = algodApiInstance.TransactionParams();
                var lr    = trans.LastRound;
                var block = algodApiInstance.GetBlock(lr);

                Console.WriteLine("Lastround: " + trans.LastRound.ToString());
                Console.WriteLine("Block txns: " + block.Block.ToString());
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling algod#getSupply:" + e.Message);
            }

            TransactionParametersResponse transParams;

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

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

            // send the transaction to the network
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
            }
            catch (ApiException e)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
        }
        public IActionResult GroupedTransactions()
        {
            AlgodApi          algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            TransactionParams transparams      = null;

            try
            {
                transparams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            //4CLRLFJQK3WKEIHKOYTFJ5TT7W2KKQJQUXVJM4GZYLOHG5FC3C3PNF5XMQ
            var acc1 = "5LDA2DCL4BPUBWMJXLQC47XKGPLYDY2OVBNEKBXUV6GY3NIXBSDSMTIAKA";
            var acc2 = "RSVGYZ5653Z3X6GLFNBNM7NSR2OVQC6WRPPSOQLURI2H5R5DU35OYOQQ5A";
            //AE47UNNWHF2XCVFF4DAB7WPHKKNL5MFEW2YQ6DTK3HYNGO4GCG32WQAA5I
            var     Key     = "brain under subject brown letter select auto artwork inject display reflect clerk index prosper trick host true stable fork tone drum please loud abstract reject";
            Account account = new Account(Key);
            //Console.WriteLine(account.Address.ToString());
            //Console.WriteLine($"{account.Address.ToString()} and {account.ToMnemonic()}");
            //brain under subject brown letter select auto artwork inject display reflect clerk index prosper trick host true stable fork tone drum please loud abstract reject
            //LLMTMNBRXUF5ARJZLYYJEJPVOGDJ2SBYOHQDWXHOPIODS6ANXBL4S6BECE
            var accountAddress = "LLMTMNBRXUF5ARJZLYYJEJPVOGDJ2SBYOHQDWXHOPIODS6ANXBL4S6BECE";

            var accountInfo = algodApiInstance.AccountInformation("LLMTMNBRXUF5ARJZLYYJEJPVOGDJ2SBYOHQDWXHOPIODS6ANXBL4S6BECE");

            Console.WriteLine($"The address {accountAddress} has a Balance of: {accountInfo.Amount} microAlgos");
            //Let's create a grouped transaction
            var amount = Utils.AlgosToMicroalgos(1);

            var tx1 = Utils.GetPaymentTransaction(new Address(accountAddress), new Address(acc1), amount, "Perfoming First Grouped Transactions", transparams);

            var tx2 = Utils.GetPaymentTransaction(new Address(accountAddress), new Address(acc2), amount, "Perfoming Second Grouped Transactions", transparams);

            Digest gid = TxGroup.ComputeGroupID(new Algorand.Transaction[] { tx1, tx2 });

            tx1.AssignGroupID(gid);
            tx2.AssignGroupID(gid);
            var signedTx1 = account.SignTransaction(tx1);

            var signedTx2 = account.SignTransaction(tx2);

            try
            {
                List <byte> byteList = new List <byte>(Algorand.Encoder.EncodeToMsgPack(signedTx1));

                byteList.AddRange(Algorand.Encoder.EncodeToMsgPack(signedTx2));
                var acc = algodApiInstance.AccountInformation(accountAddress);

                var before = $"Account 1 Balance before: {acc.Amount.ToString()}";

                var id = algodApiInstance.RawTransaction(byteList.ToArray());

                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);

                //Console.WriteLine(wait);
                //Console.WriteLine($"Transfer sent to Tx group with id: {id}");
                acc = algodApiInstance.AccountInformation(accountAddress.ToString());
            }
            catch (ApiException err)
            {
                //Console.WriteLine($"Exception when calling algodrawtransactions: {err.Message}");
            }
            return(RedirectToAction(nameof(Index)));
        }
        public static void Main(params 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[1];
            var    client          = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);
            //// TODO: REMOVE:
            string creatorMnemonic = "benefit once mutual legal marble hurdle dress toe fuel country prepare canvas barrel divide major square name captain calm flock crumble receive economy abandon power";
            //string userMnemonic = "pledge become mouse fantasy matrix bunker ask tissue prepare vocal unit patient cliff index train network intact company across stage faculty master mom abstract above";

            ulong localInts   = 1;
            ulong localBytes  = 0;
            ulong globalInts  = 1;
            ulong globalBytes = 0;

            byte[] data = File.ReadAllBytes("V2/contract/hello_world.teal");
            var    approval_program_compiled = client.TealCompile(data);

            data = File.ReadAllBytes("V2/contract/hello_world_clear.teal");
            var clear_program_compiled = client.TealCompile(data);

            data = File.ReadAllBytes("V2/contract/hello_world_updated.teal");
            var approval_program_refactored_compiled = client.TealCompile(data);

            var admin   = new Account(creatorMnemonic);
            var creator = new Account();
            var user    = new Account();

            try
            {
                // transfer to creator and user
                var transParams = client.TransactionParams();
                var amount      = Utils.AlgosToMicroalgos(1);
                var tx          = Utils.GetPaymentTransaction(admin.Address, creator.Address, amount, "", transParams);
                var signedTx    = admin.SignTransaction(tx);
                var id          = Utils.SubmitTransaction(client, signedTx);
                var resp        = Utils.WaitTransactionToComplete(client, id.TxId);
                Console.WriteLine("Transfer to creator at round: " + resp.ConfirmedRound);

                tx       = Utils.GetPaymentTransaction(admin.Address, user.Address, amount, "", transParams);
                signedTx = admin.SignTransaction(tx);
                id       = Utils.SubmitTransaction(client, signedTx);
                resp     = Utils.WaitTransactionToComplete(client, id.TxId);
                Console.WriteLine("Transfer to user at round: " + resp.ConfirmedRound);

                var appid = CreateApp(client, creator, new TEALProgram(approval_program_compiled.Result),
                                      new TEALProgram(clear_program_compiled.Result), globalInts, globalBytes, localInts, localBytes);

                // opt-in to application
                OptIn(client, user, appid);
                OptIn(client, creator, appid);

                //call app from user account updates global storage

                CallApp(client, creator, user, appid, null,
                        new TEALProgram(approval_program_compiled.Result), "V2/contract/hello_world.teal");

                // read global state of application
                ReadGlobalState(client, creator, appid);

                // update application
                UpdateApp(client, creator, appid,
                          new TEALProgram(approval_program_refactored_compiled.Result),
                          new TEALProgram(clear_program_compiled.Result));

                //call application with updated app which updates local storage counter
                CallApp(client, creator, user, appid, null,
                        new TEALProgram(approval_program_refactored_compiled.Result), "V2/contract/hello_world_updated.teal");

                //read local state of application from user account
                ReadLocalState(client, user, appid);

                //close-out from application - removes application from balance record
                CloseOutApp(client, user, (ulong?)appid);

                //opt-in again to application
                OptIn(client, user, appid);

                //call application with arguments
                CallApp(client, creator, user, appid, null,
                        new TEALProgram(approval_program_refactored_compiled.Result), "V2/contract/hello_world_updated.teal");

                // delete application
                // clears global storage only
                // user must clear local
                DeleteApp(client, creator, appid);

                // clear application from user account
                // clears local storage
                ClearApp(client, user, appid);
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
        }
Exemple #11
0
        // GET: BuyGames/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var buyGame = await _context.BuyGame
                          .SingleOrDefaultAsync(m => m.Id == id);

            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            //BuyerMnemonnic
            Account src = new Account("ordinary certain payment annual plate slot squeeze recycle neck whip transfer cat photo error bus frost magnet arrange filter used soon medal liquid abstract father");
            //Console.WriteLine(account3.Address.ToString());
            //var c = "AJ7GLWNUT6TEJYUGNYAZQ7342TK7DBZLWBMIMK3NBN6NZCWJHLNYCRYQ7I";
            var buyerAddress = "36DTG5ITNWLAVZBSZ6BXPWP7UTSPEOL3K4HWIEUYML7RKUCBZQP5XBR7XY";
            var b            = "EUFD3MONZCV6P65OHVHDTDY2B7OYALLNDORL2GJPB4RATJB4K2O3CUUVOU";
            var c            = "OQIM6O74DXB454SCLT7KH7GJ5HJJE6DQDPPW6JNPVSRZ6RU4GVQMGKTH2Q";
            //Console.WriteLine(account1.Address.ToString());
            //Console.WriteLine(account2.Address.ToString());
            var accountInfo = algodApiInstance.AccountInformation(c.ToString());

            Console.WriteLine(string.Format($"Account Balance: {0} microAlgos", accountInfo.Amount));
            var acts    = algodApiInstance.AccountInformation(buyerAddress.ToString());
            var befores = "Account 1 balance before: " + acts.Amount.ToString();

            Console.WriteLine(acts);
            Console.WriteLine(befores);
            TransactionParams 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(new Address(buyerAddress), new Address(b), amount, "pay message", transParams);
            var signedTx = src.SignTransaction(tx);

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

            // send the transaction to the network
            try
            {
                var ids = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + ids.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, ids.TxId));
            }
            catch (ApiException e)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
            if (buyGame == null)
            {
                return(NotFound());
            }

            return(View(buyGame));
        }
Exemple #12
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);
        }
Exemple #13
0
        // Utility function for sending a raw signed transaction to the network
        public static void Run(params string[] args) //throws Exception
        {
            string   ALGOD_API_ADDR   = "https://testnet-algorand.api.purestake.io/ps1";
            string   ALGOD_API_TOKEN  = "GeHdp7CCGt7ApLuPNppXN4LtrW07Mm1kaFNJ5Ovr";
            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            // 这三个账号只用于演示,在实际使用时永远不要直接将助记词放在代码中
            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(创建ASA)
            // Total number of this asset available for circulation
            var ap = new AssetParams(creator: acct1.Address.ToString(), assetname: "latikum22",
                                     unitname: "LAT", defaultfrozen: false, total: 10000,
                                     url: "http://this.test.com", metadatahash: Convert.ToBase64String(
                                         Encoding.ASCII.GetBytes("16efaa3924a6fd9d3a4880099a4ac65d")))
            {
                // 每种地址的意义请参照https://developer.algorand.org/docs/features/asa/
                // 默认情况下manager/reserve/freeze/clawback账号都是sender
                // 如果设置了manager,其他没有设置的地址reserve/freeze/clawback都会是manager
                Managerkey   = acct1.Address.ToString(),
                Clawbackaddr = acct2.Address.ToString(),
                Freezeaddr   = acct1.Address.ToString(),
                Reserveaddr  = acct1.Address.ToString()
            };

            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
            ulong?assetID = 0;

            try
            {
                TransactionID 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
                Algorand.Algod.Client.Model.Transaction ptx = algodApiInstance.PendingTransactionInformation(id.TxId);
                assetID = ptx.Txresults.Createdasset;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return;
            }
            Console.WriteLine("AssetID = " + assetID);
            // 现在ASA已经创建


            // 修改ASA的设置
            // 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();
            ap          = algodApiInstance.AssetInformation((long?)assetID);

            // 修改ASA设置必须由manager账号执行,在本例是中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
            ap.Managerkey = acct2.Address.ToString();
            tx            = Utils.GetConfigAssetTransaction(acct1.Address, assetID, ap, 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 = acct1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                TransactionID 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
            ap = algodApiInstance.AssetInformation((long?)assetID);
            //The manager should now be the same as the creator
            Console.WriteLine(ap);


            // 激活(Opting in)某种ASA
            // 如果你需要给其他用户转ASA,那么对方必须先激活
            // 然后才能接收ASA
            // First we update standard Transaction parameters
            // To account for changes in the state of the blockchain
            transParams = algodApiInstance.TransactionParams();
            tx          = Utils.GetActivateAssetTransaction(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.Algod.Client.Model.Account act = null;
            try
            {
                TransactionID 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)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // ASA转账
            // 激活后account3就可以接收ASA了
            // 现在我们从acctout1向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
            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
            {
                TransactionID 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.GetHolding(assetID).Amount);
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // 冻结资产
            // 如果freeze address当时没有设置,则无法冻结资产
            // 此例中冻结account3中的资产
            // 冻结事件须由freeze acount来发出,本例中为account1
            // 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(acct1.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 = acct1.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                TransactionID 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.GetHolding(assetID).ToString());
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                Console.WriteLine(e.Message);
                return;
            }

            // 撤回转账
            // 撤加转账必须由clawbackaddress发起。
            // 如果资产的manager将clawbackaddress设为空,则此操作不可执行
            // 本例中会将10个资产从account3撤回到account1
            // 此操作需要由clawbackaccount(account2)进行签名
            // 此操作发送者为原操作的发起者(acct1)
            // 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
            {
                TransactionID 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.GetHolding(assetID).Amount);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            // 销毁资产
            // 销毁资产前所有资产需要回到创建者账号中
            // 销毁资产需要由Manage Addr进行操作
            // 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 acct2
            tx = Utils.GetDestroyAssetTransaction(acct2.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 = acct2.SignTransaction(tx);
            // send the transaction to the network and
            // wait for the transaction to be confirmed
            try
            {
                TransactionID 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 acct1
                // and see that the asset is no longer there
                act = algodApiInstance.AccountInformation(acct1.Address.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
        }
Exemple #14
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();
        }
Exemple #15
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();
        }
        // GET: GameITModels/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var userIt = await _userManager.FindByNameAsync(User.Identity.Name);

            var gameITModel = await _context.GameITModel
                              .SingleOrDefaultAsync(m => m.Id == id);

            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            //BuyerMnemonnic
            Account src           = new Account(userIt.MnnemonicKey);
            var     buyerAddress  = userIt.AccountAddress;
            var     sellerAddress = gameITModel.GameAddressOwner;
            //var c = "OQIM6O74DXB454SCLT7KH7GJ5HJJE6DQDPPW6JNPVSRZ6RU4GVQMGKTH2Q";
            //Console.WriteLine(account1.Address.ToString());
            //Console.WriteLine(account2.Address.ToString());
            var accountInfo = algodApiInstance.AccountInformation(buyerAddress.ToString());

            Console.WriteLine(string.Format($"Account Balance: {0} microAlgos", accountInfo.Amount));
            var acts    = algodApiInstance.AccountInformation(buyerAddress.ToString());
            var befores = "Account 1 balance before: " + acts.Amount.ToString();

            Console.WriteLine(acts);
            Console.WriteLine(befores);
            TransactionParams transParams = null;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            var amount   = Utils.AlgosToMicroalgos(Convert.ToDouble(gameITModel.Price));
            var tx       = Utils.GetPaymentTransaction(new Address(buyerAddress), new Address(buyerAddress), amount, "pay message", transParams);
            var signedTx = src.SignTransaction(tx);

            ViewBag.Tran = $"Signed transaction with txid: {signedTx.transactionID}";
            //Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

            // send the transaction to the network
            try
            {
                var ids = Utils.SubmitTransaction(algodApiInstance, signedTx);
                ViewBag.Sent = $"Successfully sent tx with id: {ids.TxId}";
                //Console.WriteLine("Successfully sent tx with id: " + ids.TxId);
                ViewBag.WaitTran = Utils.WaitTransactionToComplete(algodApiInstance, ids.TxId);
                //Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, ids.TxId));
            }
            catch (ApiException e)
            {
                // This is generally expected, but should give us an informative error message.
                ViewBag.Exc = $"Exception when calling algod#rawTransaction: {e.Message}";
                //Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }
            ViewBag.Success = $"You have successefully arrived the end of this test, please press and key to exist.";
            //Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            //Console.ReadKey();
            if (gameITModel == null)
            {
                return(NotFound());
            }

            return(View(gameITModel));
        }
Exemple #17
0
        static void Main(string[] args)
        {
            //V2.BasicExample.Main(args); return;
            //V2.AssetExample.Main(args); return;
            //V2.AtomicTransferExample.Main(args); return;
            //V2.contract.CompileTeal.Main(args); return;
            V2.contract.ContractAccount.Main(args); return;

            //V2.contract.LogicSignature.Main(args); return;
            //V2.contract.DryrunDedugging.Main(args); return;
            //V2.IndexerExamples.Main(args); return;
            //V2.RekeyExample.Main(args); return;
            //V2.AccountTest.Main(args); return;
            //V2.contract.DryrunStatefulExample.Main(args); return;
            //V2.contract.StatefulContract.Main(args); return;


            //AssetExample.Main(args); return;
            //BidExample.Main(args); return;
            //GroupSigExample.Main(args); return;
            //LogicSigExample.Main(args); return;

            //MultisigExample.Main(args); return;

            // the SDK also support purestake, just use the two lines below replace the line 28~32
            //string ALGOD_API_ADDR = "https://testnet-algorand.api.purestake.io/ps1";
            //string ALGOD_API_TOKEN = "YOUR API PURESTAKE KEY";
            // If the protocol is not specified in the address, http is added.
            string ALGOD_API_ADDR = args[0];

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

            string ALGOD_API_TOKEN = args[1];
            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";
            string DEST_ADDR       = "7XVBE6T6FMUR6TI2XGSVSOPJHKQE2SDVPMFA3QUZNWM7IY6D4K2L23ZN2A";

            if (!Address.IsValid(DEST_ADDR))
            {
                Console.WriteLine("The address " + DEST_ADDR + " is not valid!");
            }
            Account src = new Account(SRC_ACCOUNT);

            Console.WriteLine("My account address is:" + src.Address.ToString());
            if (src.ToMnemonic() != SRC_ACCOUNT)
            {
                Console.WriteLine("ToMnemonic function is wriong!");
            }

            //sign and verify bytes function test
            var bytes    = Encoding.UTF8.GetBytes("examples");
            var siguture = src.SignBytes(bytes);

            Address srcAddr  = new Address(src.Address.ToString());
            var     verifyed = srcAddr.VerifyBytes(bytes, siguture);

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            try
            {
                Supply supply = algodApiInstance.GetSupply();
                Console.WriteLine("Total Algorand Supply: " + supply.TotalMoney);
                Console.WriteLine("Online Algorand Supply: " + supply.OnlineMoney);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling algod#getSupply:" + e.Message);
            }

            try
            {
                TransactionParams trans = algodApiInstance.TransactionParams();
                var   lr    = (long?)trans.LastRound;
                Block block = algodApiInstance.GetBlock((long?)trans.LastRound);
                Console.WriteLine("Lastround: " + trans.LastRound.ToString());
                Console.WriteLine("Block txns: " + block.Txns.ToJson());
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling algod#getSupply:" + e.Message);
            }

            TransactionParams transParams = null;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }
            var amount = Utils.AlgosToMicroalgos(1);
            var tx     = Utils.GetPaymentTransaction(src.Address, new Address(DEST_ADDR), amount, "pay message", transParams);
            //Transaction tx = new Transaction(src.Address, new Address(DEST_ADDR), amount, firstRound, lastRound, genesisID, genesisHash);
            var signedTx = src.SignTransaction(tx);

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

            // send the transaction to the network
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                Console.WriteLine(Utils.WaitTransactionToComplete(algodApiInstance, id.TxId));
            }
            catch (ApiException e)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
        }
Exemple #18
0
        public static void Main(string[] args)
        {
            // If the protocol is not specified in the address, http is added.
            string ALGOD_API_ADDR = args[0];

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

            string ALGOD_API_TOKEN = args[1];
            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";
            string DEST_ADDR       = "KV2XGKMXGYJ6PWYQA5374BYIQBL3ONRMSIARPCFCJEAMAHQEVYPB7PL3KU";

            if (!Address.IsValid(DEST_ADDR))
            {
                Console.WriteLine("The address " + DEST_ADDR + " is not valid!");
            }
            Account src = new Account(SRC_ACCOUNT);

            Console.WriteLine("My account address is:" + src.Address.ToString());
            if (src.ToMnemonic() != SRC_ACCOUNT)
            {
                Console.WriteLine("ToMnemonic function is wriong!");
            }

            //sign and verify bytes function test
            var bytes    = Encoding.UTF8.GetBytes("examples");
            var siguture = src.SignBytes(bytes);

            Address srcAddr  = new Address(src.Address.ToString());
            var     verifyed = srcAddr.VerifyBytes(bytes, siguture);

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            try
            {
                Supply supply = algodApiInstance.GetSupply();
                Console.WriteLine("Total Algorand Supply: " + supply.TotalMoney);
                Console.WriteLine("Online Algorand Supply: " + supply.OnlineMoney);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling algod#getSupply:" + e.Message);
            }

            TransactionParams transParams = null;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }
            var amount = Utils.AlgosToMicroalgos(1);
            var tx     = Utils.GetPaymentTransaction(src.Address, new Address(DEST_ADDR), amount, "pay message", transParams);
            //Transaction tx = new Transaction(src.Address, new Address(DEST_ADDR), amount, firstRound, lastRound, genesisID, genesisHash);
            var signedTx = src.SignTransaction(tx);

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

            // send the transaction to the network
            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
            }
            catch (ApiException e)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }
            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
            Console.ReadKey();
        }
Exemple #19
0
        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;
            var    account1_passphrase = "fringe model trophy claw stove perfect address market license abstract master slender choice around field embark sudden carbon exclude abuse square bulb front ability violin";
            var    account2_passphrase = "impulse nation creek toy carpet amused dream can small long disorder source mail game category damp spread length cupboard theory either baby squeeze about orbit";
            var    account3_passphrase = "fade exit sword someone lock minimum scout keen label dance jaguar select conduct luxury rose idea solid major solid lens globe agent assume abstract alien";


            var account1 = new Account(account1_passphrase);
            var account2 = new Account(account2_passphrase);
            //    private_key = mnemonic.to_private_key(account3_passphrase)
            var account3 = new Account(account3_passphrase);

            Console.WriteLine(string.Format("Account 1 : {0}", account1.Address));
            Console.WriteLine(string.Format("Account 2 : {0}", account2.Address));
            Console.WriteLine(string.Format("Account 3 : {0}", account3.Address));

            //Part 1
            //build transaction

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);
            var      trans            = algodApiInstance.TransactionParams();

            Console.WriteLine("Lastround: " + trans.LastRound.ToString());


            bool firstRun = false;

            if (firstRun)
            {
                ulong?amount = 0;
                //opt-in send tx to same address as sender and use 0 for amount w rekey account to account 1
                var tx = Utils.GetPaymentTransaction(account3.Address, account3.Address, amount, "pay message", trans);
                tx.RekeyTo = account1.Address;

                var signedTx = account3.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("Confirmed Round is: " +
                                      Utils.WaitTransactionToComplete(algodApiInstance, id.TxId).ConfirmedRound);
                }
                catch (Exception e)
                {
                    //e.printStackTrace();
                    Console.WriteLine(e.Message);
                    return;
                }
            }

            var act = algodApiInstance.AccountInformation(account3.Address.ToString());

            Console.WriteLine(act);

            ulong?amount2 = 1000000;
            var   tx2     = Utils.GetPaymentTransaction(account3.Address, account2.Address, amount2, "pay message", trans);

            tx2.RekeyTo = account1.Address;
            var signedTx2 = account1.SignTransaction(tx2);

            try
            {
                var id = Utils.SubmitTransaction(algodApiInstance, signedTx2);
                Console.WriteLine("Transaction ID: " + id);
                Console.WriteLine("Confirmed Round is: " +
                                  Utils.WaitTransactionToComplete(algodApiInstance, id.TxId).ConfirmedRound);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }