void ASCContractAccount_Clicked(System.Object sender, System.EventArgs e)
        {
            StackASCContractAccount.IsEnabled = false;
            ASCContractAccount.Opacity        = .2;
            ASCContractAccount.IsEnabled      = false;
            Algorand.V2.Model.TransactionParametersResponse transParams = null;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            // format and send logic sig
            // int 1, returns true
            // byte[] program = { 0x01, 0x20, 0x01, 0x01, 0x22 };
            // int 0, returns false, so rawTransaction will fail below
            // byte[] program = Convert.FromBase64String("ASABASI=");
            //  byte[] program = { 0x01, 0x20, 0x01, 0x00, 0x22 };
            byte[]            program = { 0x01, 0x20, 0x01, 0x01, 0x22 };
            LogicsigSignature lsig    = new LogicsigSignature(program, null);

            Console.WriteLine("Escrow address: " + lsig.ToAddress().ToString());
            var tx = Utils.GetPaymentTransaction(lsig.Address, account1.Address, 100000, "draw algo from contract", transParams);

            //  Algorand.Transaction tx = Utils.GetLogicSignatureTransaction(lsig, account1.Address, transParams, "logic sig message");
            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);
                    // int 0 is the teal program, which returns false,
                    // so rawTransaction will fail below
                    var id = algodApiInstance.RawTransaction(encodedTxBytes);
                    Console.WriteLine("Successfully sent tx logic sig tx id: " + id);
                    var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                    Console.WriteLine(wait);
                    var htmlSource = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body>" +
                                      "<h3>" + "Successfully sent tx logic sig tx: " + wait + "</h3>" +
                                      "</body></html>";
                    myWebView.Source             = htmlSource;
                    ASCContractAccount.IsEnabled = true;
                }
                catch (ApiException err)
                {
                    // This is generally expected, but should give us an informative error message.
                    Console.WriteLine("Fail expected");
                    Console.WriteLine("Exception when calling algod#rawTransaction: " + err.Message);
                    var htmlSource = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body>" +
                                      "<h3>" + "Expected error: Exception when calling algod#rawTransaction: " + err.Message + "</h3>" +
                                      "</body></html>";
                    myWebView.Source             = htmlSource;
                    ASCContractAccount.IsEnabled = true;
                }
            }
            StackASCContractAccount.IsEnabled = true;
            ASCContractAccount.Opacity        = 1;
        }
Ejemplo n.º 2
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();
        }
        void ASCAccountDelegation_Clicked(System.Object sender, System.EventArgs e)
        {
            ASCAccountDelegation.Opacity        = .2;
            StackASCAccountDelegation.IsEnabled = false;
            ASCAccountDelegation.IsEnabled      = false;
            Algorand.V2.Model.TransactionParametersResponse transParams = null;
            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            // format and send logic sig
            // int 1, returns true
            // byte[] program = { 0x01, 0x20, 0x01, 0x01, 0x22 };
            // int 0, returns false, so rawTransaction will fail below
            // byte[] program = { 0x01, 0x20, 0x01, 0x00, 0x22 };
            byte[] program = { 0x01, 0x20, 0x01, 0x01, 0x22 };

            LogicsigSignature lsig = new LogicsigSignature(program, null);

            // sign the logic signature with an account sk
            account1.SignLogicsig(lsig);

            Console.WriteLine("Escrow address: " + lsig.ToAddress().ToString());
            Transaction tx = Utils.GetPaymentTransaction(new Address(account1.Address.ToString()), new Address(account2.Address.ToString()), 1000000,
                                                         "draw algo with logic signature", transParams);

            //  Algorand.Transaction tx = Utils.GetLogicSignatureTransaction(account1.Address, account2.Address, transParams, "logic sig message");
            try
            {
                SignedTransaction stx            = Account.SignLogicsigTransaction(lsig, tx);
                byte[]            encodedTxBytes = Encoder.EncodeToMsgPack(stx);
                // int 0 is the teal program, which returns false,
                // so rawTransaction will fail below

                var id = Utils.SubmitTransaction(algodApiInstance, stx);

                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                Console.WriteLine(wait);
                Console.WriteLine("Successfully sent tx logic sig tx id: " + id);
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body>" +
                                  "<h3>" + "Successfully sent tx logic sig tx: " + wait + "</h3>" +
                                  "</body></html>";
                myWebView.Source = htmlSource;
                ASCAccountDelegation.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);
                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html  = @"<html><body><h3> Expected error: Exception when calling algod#rawTransaction: " + err.Message + "</h3>" + "</body></html>";
                myWebView.Source = htmlSource;
                ASCAccountDelegation.IsEnabled = true;
            }
            ASCAccountDelegation.Opacity        = 1;
            StackASCAccountDelegation.IsEnabled = true;
        }