private async void StatefulContracts_Appearing(object sender, EventArgs e)
        {
            client = await helper.CreateApiInstance();

            network = await helper.GetNetwork();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            creator = accounts[0];
            user    = accounts[1];

            Console.WriteLine("creator account: " + creator.Address);
            Console.WriteLine("user account: " + user.Address);
            var nodetype = await SecureStorage.GetAsync(helper.StorageNodeType);

            //   NetworkLabel.Text = "Network: " + network + " " + nodetype;
            compileTealPrograms();
            OptInBtn.IsEnabled               = false;
            CallAppBtn.IsEnabled             = false;
            ReadLocalStateBtn.IsEnabled      = false;
            ReadGlobalStateBtn.IsEnabled     = false;
            UpdateAppBtn.IsEnabled           = false;
            CallUpdatedAppBtn.IsEnabled      = false;
            ReadLocalStateAgainBtn.IsEnabled = false;
            CloseOutAppBtn.IsEnabled         = false;
            DeleteAppBtn.IsEnabled           = false;
            ClearAppCtn.IsEnabled            = false;
        }
        //Atomic Transaction Method
        public static void AtomicTransaction()
        {
            //Performing Atomic Transactions

            //PureStake Configuration with AlgodApi
            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps2", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            //First Account Address - acc1
            var acc1 = "QQNTMX62E2UZF3264V3OB3O3F6CURWBBHR3MQZPRM26CFVMXUYWOXIKG6E";
            //Second Account Address - acc2
            var acc2 = "RP2HQNAY4F4FWJ6OGOBSLCB73PXHVAQ36R6RAQTYPUEIPR4C7M2YJS4SSE";
            //Key of the Main account that will fund other Accounts
            var key = "hood industry indicate catch erode return wage gas wrong museum lesson renew acid erupt victory swallow distance spy orchard tomorrow organ traffic hen ability drift";
            //Account that will fund other accounts
            var     accountAddress = "DZLN2QPBURBXHGHYY2Z5B3BOBZQS4BXIHJMOVXXDBDF66ZFWLFOXZG4OWE";
            Account src            = new Account(key);

            //Creating a transactionParams on the V2
            Algorand.V2.Model.TransactionParametersResponse transParams;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }

            // let's create a transaction group

            //amount to fund other accounts
            var amount = Utils.AlgosToMicroalgos(1);
            //First Transaction
            var tx = Utils.GetPaymentTransaction(new Address(accountAddress), new Address(acc1), amount, "pay message", transParams);
            //Second Transaction
            var tx2 = Utils.GetPaymentTransaction(new Address(accountAddress), new Address(acc2), amount, "pay message", transParams);
            //Grouping the Transactions (Atomic Transactions)
            Digest gid = TxGroup.ComputeGroupID(new Transaction[] { tx, tx2 });

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

            try
            {
                //contact the signed msgpack
                List <byte> byteList = new List <byte>(Algorand.Encoder.EncodeToMsgPack(signedTx));
                byteList.AddRange(Algorand.Encoder.EncodeToMsgPack(signedTx2));
                var id = algodApiInstance.RawTransaction(byteList.ToArray());
                Console.WriteLine($"Successfully sent tx group with first tx id: {id}");
                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 exit.");
        }
示例#3
0
        private async void ASA_Appearing(object sender, EventArgs e)
        {
            algodApiInstance = await helper.CreateApiInstance();

            network = await helper.GetNetwork();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            account1 = accounts[0];
            account2 = accounts[1];
            account3 = accounts[2];
            var nodetype = await SecureStorage.GetAsync(helper.StorageNodeType);

            NetworkLabel.Text = "Network: " + network + " " + nodetype;

            var lastASAbutton = await SecureStorage.GetAsync(helper.StorageLastASAButton);

            if (string.IsNullOrEmpty(lastASAbutton) || lastASAbutton == " ")
            {
                buttonstate("init");
            }
            else
            {
                buttonstate(lastASAbutton);
            }

            //  StorageLastASAButton
        }
        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];
            //第一个账号用于给智能合约签名,并把签名发布出去
            string  SRC_ACCOUNT  = "buzz genre work meat fame favorite rookie stay tennis demand panic busy hedgehog snow morning acquire ball grain grape member blur armor foil ability seminar";
            Account acct1        = new Account(SRC_ACCOUNT);
            var     acct2Address = "QUDVUXBX4Q3Y2H5K2AG3QWEOMY374WO62YNJFFGUTMOJ7FB74CMBKY6LPQ";

            //byte[] source = File.ReadAllBytes("V2\\contract\\sample.teal");
            byte[] program = Convert.FromBase64String("ASABASI=");

            LogicsigSignature lsig = new LogicsigSignature(program, null);

            // sign the logic signaure with an account sk
            acct1.SignLogicsig(lsig);

            var algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            Algorand.V2.Model.TransactionParametersResponse transParams;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }

            Transaction tx = Utils.GetPaymentTransaction(acct1.Address, new Address(acct2Address), 1000000,
                                                         "tx using in dryrun", transParams);

            try
            {
                //bypass verify for non-lsig
                SignedTransaction signedTx = Account.SignLogicsigTransaction(lsig, tx);
                //一切准备就绪,本可以直接发送到网络,也可使得Dryrun的方法来进行调试
                //var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                //Console.WriteLine("Successfully sent tx logic sig tx id: " + id);
                // dryrun source
                //var dryrunResponse = Utils.GetDryrunResponse(algodApiInstance, signedTx, source);
                //Console.WriteLine("Dryrun compiled repsonse : " + dryrunResponse.ToJson()); // pretty print

                // dryrun logic sig transaction
                var dryrunResponse2 = Utils.GetDryrunResponse(algodApiInstance, signedTx);
                Console.WriteLine("Dryrun source repsonse : " + dryrunResponse2.ToJson()); // pretty print
            }
            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.");
        }
示例#5
0
        public async Task <IActionResult> About()
        {
            var userIt = await _userManager.FindByNameAsync(User.Identity.Name);

            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            //BuyerMnemonnic
            Account src          = new Account(userIt.MnnemonicKey);
            var     buyerAddress = userIt.AccountAddress;
            //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));
            ViewData["acc"] = $"Account Balance: {accountInfo.Amount} microAlgos";
            var acts    = algodApiInstance.AccountInformation(buyerAddress.ToString());
            var befores = "Account 1 balance before: " + acts.Amount.ToString();

            //Console.WriteLine(acts);
            //Console.WriteLine(befores);
            ViewData["address"] = $"{userIt.AccountAddress}";
            ViewData["acts"]    = $"{acts}";
            ViewData["befores"] = $"{befores}";
            ViewData["Message"] = "Your application description page.";

            return(View());
        }
示例#6
0
        private const string ApiToken   = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // sandbox API token

        static void Main(string[] args)
        {
            var account1 = CreateNewAccount(1);
            var account2 = CreateNewAccount(2);
            var account3 = CreateNewAccount(3);

            // Put a breakpoint on the line below to fill your test accounts with some Algo using the test net dispenser.
            var algodApi = new AlgodApi(ApiAddress, ApiToken);

            // Get the suggested transaction parameters.
            var transactionParams = algodApi.TransactionParams();

            // Send 1 Algo from account 1 to account 2.
            var paymentTransaction = Utils.GetPaymentTransaction(account1.Address, account2.Address, 1000000, "Payment", transactionParams);

            // Sign the transaction using account 1.
            var signedPaymentTransaction = account1.SignTransaction(paymentTransaction);

            Console.WriteLine("Signed transaction with transaction ID: " + signedPaymentTransaction.transactionID);

            // Send the transaction to the network.
            var id = Utils.SubmitTransaction(algodApi, signedPaymentTransaction);

            Console.WriteLine("Successfully sent transaction with ID: " + id.TxId);

            // Wait for the transaction to complete.
            var response = Utils.WaitTransactionToComplete(algodApi, id.TxId);

            Console.WriteLine("The confirmed round is: " + response.ConfirmedRound);

            GetAndPrintAccountInformation(algodApi, account1, 1);
            GetAndPrintAccountInformation(algodApi, account2, 2);
            GetAndPrintAccountInformation(algodApi, account3, 3);
        }
        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];

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            // read file - int 1
            byte[] data     = File.ReadAllBytes("V2\\contract\\sample.teal");
            var    response = algodApiInstance.TealCompile(data);

            Console.WriteLine("response: " + response);
            Console.WriteLine("Hash: " + response.Hash);
            Console.WriteLine("Result: " + response.Result);
            Console.ReadKey();

            //result
            //Hash: 6Z3C3LDVWGMX23BMSYMANACQOSINPFIRF77H7N3AWJZYV6OH6GWTJKVMXY
            //Result: ASABASI=
        }
        public static void Main(string[] args)
        {
            string ALGOD_API_ADDR = args[0];

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

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

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

            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

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

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

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

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

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

            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
        }
        public async Task <IActionResult> BuyIT(int id)
        {
            var gameITModel = await _context.GameITModel.SingleOrDefaultAsync(m => m.Id == id);

            var userIt = await _userManager.FindByNameAsync(User.Identity.Name);

            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(gameITModel.GameAddressOwner), 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();
            return(RedirectToAction(nameof(Index)));
        }
 private async void Button_Click_1(object sender, RoutedEventArgs e)
 {
     string   ALGOD_API_ADDR   = "https://testnet-algorand.api.purestake.io/ps2";
     string   ALGOD_API_TOKEN  = "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab";
     AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);
     var      accountInfo      = algodApiInstance.AccountInformation("VYFF3MXAXWGHNIAEUVINZZHEW2MH5HKTXEACXUTZ3HHADIBPT5ATJGR6K4");
     var      dialog           = new MessageDialog(string.Format("Account Balance: " + accountInfo.Amount + " MicroAlgos"));
     await dialog.ShowAsync();
 }
        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];
            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";
            //string DEST_ADDR2 = "OAMCXDCH7LIVYUF2HSNQLPENI2ZXCWBSOLUAOITT47E4FAMFGAMI4NFLYU";
            Account src = new Account(SRC_ACCOUNT);
            var     algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            Algorand.Algod.Model.TransactionParams transParams = null;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }
            // format and send logic sig
            byte[] program = { 0x01, 0x20, 0x01, 0x00, 0x22 };

            LogicsigSignature lsig = new LogicsigSignature(program, null);

            Console.WriteLine("Escrow address: " + lsig.ToAddress().ToString());

            var tx = Utils.GetPaymentTransaction(lsig.ToAddress(), src.Address, 100000, "draw algo from contract", transParams);

            if (!lsig.Verify(tx.sender))
            {
                string msg = "Verification failed";
                Console.WriteLine(msg);
            }
            else
            {
                try
                {
                    SignedTransaction stx            = Account.SignLogicsigTransaction(lsig, tx);
                    byte[]            encodedTxBytes = Encoder.EncodeToMsgPack(stx);
                    var id = algodApiInstance.RawTransaction(encodedTxBytes);
                    Console.WriteLine("Successfully sent tx logic sig tx id: " + id);
                }
                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();
        }
示例#12
0
    //Function
    public void PayPlayerwithAlgorandFunction()
    {
        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 = "Your API Key Here";
        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());

        AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

        TransactionParametersResponse transParams;

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

        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);
        }
        Debug.Log("Algorand transaction to Player completed.");
    }
示例#13
0
        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];
            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";
            string  DEST_ADDR2       = "OAMCXDCH7LIVYUF2HSNQLPENI2ZXCWBSOLUAOITT47E4FAMFGAMI4NFLYU";
            Account src              = new Account(SRC_ACCOUNT);
            var     algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

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

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

            try
            {
                //contact the signed msgpack
                List <byte> byteList = new List <byte>(Algorand.Encoder.EncodeToMsgPack(signedTx));
                byteList.AddRange(Algorand.Encoder.EncodeToMsgPack(signedTx2));
                var id = algodApiInstance.RawTransaction(byteList.ToArray());
                Console.WriteLine("Successfully sent tx group with first tx id: " + id);
                Console.WriteLine("Confirmed Round is: " +
                                  Utils.WaitTransactionToComplete(algodApiInstance, id.TxId).ConfirmedRound);
            }
            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 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];
            //string toAddressMnemonic = "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";
            var toAddress        = new Address("7XVBE6T6FMUR6TI2XGSVSOPJHKQE2SDVPMFA3QUZNWM7IY6D4K2L23ZN2A");
            var algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            Algorand.V2.Model.TransactionParametersResponse transParams;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException e)
            {
                throw new Exception("Could not get params", e);
            }
            // format and send logic sig
            byte[]            program = Convert.FromBase64String("ASABASI="); //int 1
            LogicsigSignature lsig    = new LogicsigSignature(program, null);

            Console.WriteLine("Escrow address: " + lsig.Address.ToString());

            var tx = Utils.GetPaymentTransaction(lsig.Address, toAddress, 10000000, "draw algo from contract", transParams);

            if (!lsig.Verify(tx.sender))
            {
                string msg = "Verification failed";
                Console.WriteLine(msg);
            }
            else
            {
                try
                {
                    //签名操作
                    SignedTransaction signedTx = Account.SignLogicsigTransaction(lsig, tx);
                    var id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                    Console.WriteLine("Successfully sent tx logic sig tx id: " + id);
                    Console.WriteLine("Confirmed Round is: " +
                                      Utils.WaitTransactionToComplete(algodApiInstance, id.TxId).ConfirmedRound);
                }
                catch (ApiException e)
                {
                    // This is generally expected, but should give us an informative error message.
                    Console.WriteLine("Exception when calling algod#sendTransaction: " + e.Message);
                }
            }
            Console.WriteLine("You have successefully arrived the end of this test, please press and key to exist.");
        }
        static void CallApp(AlgodApi client, Account creator, Account user, long?applicationId, List <byte[]> args,
                            TEALProgram program, string tealFileName)
        {
            Console.WriteLine("Creator Account:" + creator.Address.ToString());
            Console.WriteLine("User Account:" + user.Address.ToString());
            try
            {
                var transParams = client.TransactionParams();
                var tx          = Utils.GetApplicationCallTransaction(user.Address, (ulong?)applicationId, transParams, args);
                var signedTx    = user.SignTransaction(tx);
                //Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);

                var cr      = client.AccountInformation(creator.Address.ToString());
                var usr     = client.AccountInformation(user.Address.ToString());
                var mydrr   = DryrunDrr(signedTx, program, cr, usr);
                var drrFile = "mydrr.dr";
                WriteDrr(drrFile, mydrr);
                Console.WriteLine("drr file created ... debugger starting - goto chrome://inspect");

                // START debugging session
                // either use from terminal in this folder
                // `tealdbg debug program.teal --dryrun-req mydrr.dr`
                //
                // or use this line to invoke debugger
                // and switch to chrome://inspect to inspect and debug
                // (program execution will continue aafter debuigging session completes)

                Excute(string.Format("tealdbg debug {0} --dryrun-req {1}", tealFileName, drrFile));

                // break here on the next line with debugger
                // run this command in this folder
                // tealdbg debug hello_world.teal --dryrun-req mydrr.dr
                // or
                // tealdbg debug hello_world_updated.teal --dryrun-req mydrr.dr

                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 at round: " + resp.ConfirmedRound);
                //System.out.println("Called app-id: " + pTrx.txn.tx.applicationId);
                if (resp.GlobalStateDelta != null)
                {
                    Console.WriteLine("    Global state: " + resp.GlobalStateDelta.ToString());
                }
                if (resp.LocalStateDelta != null)
                {
                    Console.WriteLine("    Local state: " + resp.LocalStateDelta.ToString());
                }
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling create application: " + e.Message);
            }
        }
示例#16
0
        private void InCreaseKarmaForTheRestraunt(RestaurantEntity restaurantEntity)
        {
            if (restaurantEntity == null)
            {
                return;
            }
            try
            {
                Console.WriteLine("Increasing Karma on the BlockChain");
                string ALGOD_API_ADDR  = "http://hackathon.algodev.network:9100";
                string ALGOD_API_TOKEN =
                    "ef920e2e7e002953f4b29a8af720efe8e4ecc75ff102b165e0472834b25832c1"; //find in the algod.token
                var algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

                var   transParams = algodApiInstance.TransactionParams();
                ulong?feePerByte  = transParams.Fee;
                var   genesisHash = new Digest(Convert.FromBase64String(transParams.Genesishashb64));
                var   genesisID   = transParams.GenesisID;
                var   s           = algodApiInstance.GetStatus();
                var   firstRound  = s.LastRound;
                Console.WriteLine("Current Round: " + firstRound);

                ulong? amount      = 100000;
                ulong? lastRound   = firstRound + 1000; // 1000 is the max tx window
                string SRC_ACCOUNT =
                    "typical permit hurdle hat song detail cattle merge oxygen crowd arctic cargo smooth fly rice vacuum lounge yard frown predict west wife latin absent cup";
                Account     src = new Account(SRC_ACCOUNT);
                Transaction tx  = new Transaction(src.Address, new Address(restaurantEntity.AlgorandAddress), amount, firstRound, lastRound, genesisID,
                                                  genesisHash);
                SignedTransaction signedTx = src.SignTransactionWithFeePerByte(tx, feePerByte.Value);

                //encode to msg-pack
                var encodedMsg = Algorand.Encoder.EncodeToMsgPack(signedTx);
                var id         = algodApiInstance.RawTransaction(encodedMsg);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
            }
            catch (Exception e)
            {
                // This is generally expected, but should give us an informative error message.
                Console.WriteLine("Exception when calling algod#rawTransaction: " + e.Message);
            }

            try
            {
                Console.WriteLine("Increasing Karma on The DB");
                restaurantEntity.KarmaScore++;
                _gretaFoodDb.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Was not manage to increase karma in the DB");
            }
        }
示例#17
0
        private static string BuildPost(string BuyerAddress, string SellerAddress, string GameToBuy, string Amount)
        {
            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            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 a = "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(a.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(a), 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 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();
            return("a");
        }
        private async void DryrunDebugging_Appearing(object sender, EventArgs e)
        {
            client = await helper.CreateApiInstance();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            account1 = accounts[0];
            account2 = accounts[1];

            Console.WriteLine("Account 1: " + account1.Address);
            Console.WriteLine("Account 2: " + account2.Address);
        }
示例#19
0
 /// <summary>
 /// wait transaction to complete
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="txID"></param>
 /// <returns></returns>
 public static string WaitTransactionToComplete(AlgodApi instance, string txID) //throws Exception
 {
     while (true)
     {
         //Check the pending tranactions
         var b3 = instance.PendingTransactionInformation(txID);
         if (b3.Round != null && b3.Round > 0)
         {
             return("Transaction " + b3.Tx + " confirmed in round " + b3.Round);
         }
         // loops 4 times per second, > 5 times per second will fail using TestNet Purestake Free verison
         // also blocks are created in under 5 seconds so no real need to poll constantly -
         // a few times per second should be fine
         System.Threading.Thread.Sleep(250);
     }
 }
        public static void FundMethod(string key, string receiver, int amount, string senderAddr)
        {
            string   ALGOD_API_ADDR   = "https://testnet-algorand.api.purestake.io/ps2"; //find in algod.net
            string   ALGOD_API_TOKEN  = "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab";      //find in algod.token
            string   SRC_ACCOUNT      = key;
            string   DEST_ADDR        = receiver;
            Account  src              = new Account(SRC_ACCOUNT);
            AlgodApi algodApiInstance = new AlgodApi(ALGOD_API_ADDR, ALGOD_API_TOKEN);

            try
            {
                var trans = algodApiInstance.TransactionParams();
            }
            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 amountsent = Utils.AlgosToMicroalgos(amount);
            var tx         = Utils.GetPaymentTransaction(src.Address, new Address(DEST_ADDR), amountsent, "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);
            }
        }
        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);
        }
        private async void Rekey_Appearing(object sender, EventArgs e)
        {
            client = await helper.CreateApiInstance();

            // network = await helper.GetNetwork();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            account1 = accounts[0];
            account2 = accounts[1];
            account3 = accounts[2];

            Console.WriteLine("Account 1 = " + account1.Address);
            Console.WriteLine("Account 2 = " + account2.Address);
            Console.WriteLine("Account 3 = " + account3.Address);
        }
 static 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);
         var id          = Utils.SubmitTransaction(client, signedTx);
         Console.WriteLine("Successfully sent tx with id: " + id.TxId);
         var resp = Utils.WaitTransactionToComplete(client, id.TxId);
         Console.WriteLine("Optin to Application ID: " + (resp.Txn as JObject)["txn"]["apid"]);
     }
     catch (ApiException e)
     {
         Console.WriteLine("Exception when calling create application: " + e.Message);
     }
 }
 private static 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);
         var id          = Utils.SubmitTransaction(client, signedTx);
         Console.WriteLine("Successfully sent tx with id: " + id.TxId);
         var resp = Utils.WaitTransactionToComplete(client, id.TxId);
         Console.WriteLine("Updated the application ID is: " + appid);
     }
     catch (ApiException e)
     {
         Console.WriteLine("Exception when calling create application: " + e.Message);
     }
 }
 public static void CloseOutApp(AlgodApi client, Account sender, ulong?appId)
 {
     try
     {
         var transParams = client.TransactionParams();
         var tx          = Utils.GetApplicationCloseTransaction(sender.Address, appId, transParams);
         var signedTx    = sender.SignTransaction(tx);
         var id          = Utils.SubmitTransaction(client, signedTx);
         Console.WriteLine("Successfully sent tx with id: " + id.TxId);
         var resp = Utils.WaitTransactionToComplete(client, id.TxId);
         Console.WriteLine("Close out Application ID is: " + appId);
     }
     catch (ApiException e)
     {
         Console.WriteLine("Exception when calling create application: " + e.Message);
     }
 }
示例#26
0
        private async void Accounts_Appearing(object sender, EventArgs e)
        {
            algodApiInstance = await helper.CreateApiInstance();

            network = await helper.GetNetwork();

            buttonstate();
            if (Device.Idiom == TargetIdiom.Phone)
            {
                StackPhone.IsVisible  = true;
                StackTablet.IsVisible = false;
            }
            else
            {
                StackPhone.IsVisible  = false;
                StackTablet.IsVisible = true;
            }
        }
        static public void ReadGlobalState(AlgodApi client, Account account, long?appId)
        {
            var acctResponse        = client.AccountInformation(account.Address.ToString());
            var createdApplications = acctResponse.CreatedApps;

            for (int i = 0; i < createdApplications.Count; i++)
            {
                if (createdApplications[i].Id == appId)
                {
                    var outStr = "Application global state: ";
                    foreach (var v in createdApplications[i].Params.GlobalState)
                    {
                        outStr += v.ToString();
                    }
                    Console.WriteLine(outStr);
                }
            }
        }
        static public void ReadLocalState(AlgodApi client, Account account, long?appId)
        {
            var acctResponse          = client.AccountInformation(account.Address.ToString());
            var applicationLocalState = acctResponse.AppsLocalState;

            for (int i = 0; i < applicationLocalState.Count; i++)
            {
                if (applicationLocalState[i].Id == appId)
                {
                    var outStr = "User's application local state: ";
                    foreach (var v in applicationLocalState[i].KeyValue)
                    {
                        outStr += v.ToString();
                    }
                    Console.WriteLine(outStr);
                }
            }
        }
示例#29
0
        private async void AtomicTransfers_Appearing(object sender, EventArgs e)
        {
            algodApiInstance = await helper.CreateApiInstance();

            network = await helper.GetNetwork();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            account1 = accounts[0];
            account2 = accounts[1];
            account3 = accounts[2];

            nodetype = await SecureStorage.GetAsync(helper.StorageNodeType);

            NetworkLabel.Text = "Network: " + network + " " + nodetype;
            buttonstate();
        }
示例#30
0
        static void Main(string[] args)
        {
            Account account = new Account();
            var     a       = "YTZVLL4XHBHMMZ2YOFNYFICMRVKTQAYHGOKEPNIA35HACBNVHNOOCYTN6I";

            if (Address.IsValid(a))
            {
                Console.WriteLine("Address is Valid");
            }
            else
            {
                Console.WriteLine("Address is not Valid");
            }
            AlgodApi algodApiInstance = new AlgodApi("https://testnet-algorand.api.purestake.io/ps1", "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab");
            var      accountInfo      = algodApiInstance.AccountInformation(a.ToString());

            Console.WriteLine($"Acccount Balance of {a} is {accountInfo.Amount}");
        }