Example #1
0
        public void TestAssetTypeCreditAlphaNum4()
        {
            var code        = "USDA";
            var issuer      = KeyPair.Random();
            var asset       = new AssetTypeCreditAlphaNum4(code, issuer);
            var thisXdr     = asset.ToXdr();
            var parsedAsset = (AssetTypeCreditAlphaNum4)Asset.FromXdr(thisXdr);

            Assert.AreEqual(code, asset.Code);
            Assert.AreEqual(issuer.AccountId, parsedAsset.Issuer.AccountId);
        }
Example #2
0
        public async Task SendPQTPayment(string FromSecret, string ToAccount, double amount)
        {
            Network network = new Network("Public Global Stellar Network ; September 2015");
            Server  server  = new Server("https://horizon.stellar.org");

            Network.UsePublicNetwork();

            KeyPair fromKeypair        = KeyPair.FromSecretSeed(FromSecret);
            KeyPair destinationKeyPair = KeyPair.FromAccountId(ToAccount);


            AccountResponse issuerAccountResponse = null;
            var             t = Task.Run(async() =>
            {
                issuerAccountResponse = await server.Accounts.Account(fromKeypair);
            });

            t.Wait();


            Account fromAccount = new Account(issuerAccountResponse.KeyPair, issuerAccountResponse.SequenceNumber);



            KeyPair issuerKeypair = KeyPair.FromAccountId(asset_issuer);
            Asset   asset         = new AssetTypeCreditAlphaNum4(asset_code, issuerKeypair);

            PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, amount.ToString()).SetSourceAccount(fromAccount.KeyPair).Build();

            Transaction transaction = new Transaction.Builder(fromAccount).AddOperation(operation).Build();

            //Try to send the transaction
            try
            {
                transaction.Sign(fromKeypair);

                var tSign = Task.Run(async() =>
                {
                    await server.SubmitTransaction(transaction);
                });
                tSign.Wait();
            }
            catch (Exception exception)
            {
                Console.WriteLine("Send Transaction Failed");
                Console.WriteLine("Exception: " + exception.Message);
            }
        }
Example #3
0
        public void TestPathPaymentStrictReceiveOperation()
        {
            // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF
            var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK");
            // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR
            var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII");
            // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4
            var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG");

            // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV
            var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5");
            // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR
            var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ");

            Asset sendAsset  = new AssetTypeNative();
            var   sendMax    = "0.0001";
            Asset destAsset  = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId);
            var   destAmount = "0.0001";

            Asset[] path = { new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) };

            var operation = new PathPaymentStrictReceiveOperation.Builder(
                sendAsset, sendMax, destination, destAsset, destAmount)
                            .SetPath(path)
                            .SetSourceAccount(source)
                            .Build();

            var xdr             = operation.ToXdr();
            var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr);

            Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue);
            Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue);
            Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative);
            Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId);
            Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId);
            Assert.AreEqual(sendMax, parsedOperation.SendMax);
            Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4);
            Assert.AreEqual(destAmount, parsedOperation.DestAmount);
            Assert.AreEqual(path.Length, parsedOperation.Path.Length);
            Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold);

            Assert.AreEqual(
                "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==",
                operation.ToXdrBase64());
        }
Example #4
0
        // [ValidateAntiForgeryToken]
        public async Task <string> Create([Bind("ID,TokenName,Amount,Destination,SendStart")] Send send)
        {
            send.Destination = send.Destination.ToUpper();
            send.TokenName   = send.TokenName.ToUpper();

            if (send.Destination[0] != 'G' || send.Destination.Length != 56)
            {
                ModelState.AddModelError("Address", "Address is not in a proper format (begins with a G and is 56 characters long");
            }

            string[] tokenNames = { "XLM", "SECOND", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", "YEAR", "MASLOW1", "MASLOW2", "MASLOW3", "MASLOW4", "MASLOW5" };
            if (!(tokenNames.Contains(send.TokenName)))
            {
                ModelState.AddModelError("TokenName", "Token is not supported.");
            }


            if (!(send.Amount > 0))
            {
                ModelState.AddModelError("Amount", "The amount sent has to be a positive integer.");
            }


            Network.UsePublicNetwork();
            var server = new Server("https://horizon.stellar.org");

            KeyPair source      = KeyPair.FromSecretSeed(Environment.GetEnvironmentVariable("SECRET_KEY_" + send.TokenName));
            KeyPair destination = KeyPair.FromAccountId(send.Destination);

            send.Source = Environment.GetEnvironmentVariable("SECRET_KEY_" + send.TokenName);

            await server.Accounts.Account(destination);

            AccountResponse sourceAccount = await server.Accounts.Account(source);

            var sendingAccountPubKey             = Environment.GetEnvironmentVariable("PUBLIC_KEY_" + send.TokenName);
            AccountsRequestBuilder accReqBuilder = new AccountsRequestBuilder(new Uri("https://horizon.stellar.org/accounts/" + sendingAccountPubKey));
            var accountResponse = await accReqBuilder.Account(new Uri("https://horizon.stellar.org/accounts/" + sendingAccountPubKey));

            Asset tst;

            if (send.TokenName == "XLM")
            {
                // TODO implement this in the future
                tst = new AssetTypeNative(); // https://elucidsoft.github.io/dotnet-stellar-sdk/api/stellar_dotnetcore_sdk.AssetTypeNative.html
            }
            else if (send.TokenName.Length <= 4)
            {
                tst = new AssetTypeCreditAlphaNum4(send.TokenName, KeyPair.FromAccountId(Environment.GetEnvironmentVariable("ISSUER_KEY_" + send.TokenName)));
            }
            else
            {
                tst = new AssetTypeCreditAlphaNum12(send.TokenName, KeyPair.FromAccountId(Environment.GetEnvironmentVariable("ISSUER_KEY_" + send.TokenName)));
            }

            Transaction transaction = new Transaction.Builder(new stellar_dotnetcore_sdk.Account(KeyPair.FromAccountId(sendingAccountPubKey), accountResponse.SequenceNumber))
                                      .AddOperation(new PaymentOperation.Builder(destination, tst, Convert.ToString(send.Amount)).Build())
                                      .AddMemo(Memo.Text("Test Transaction"))
                                      .Build();

            transaction.Sign(source);

            string status = "";

            try
            {
                if (ModelState.IsValid)
                {
                    SubmitTransactionResponse response = await server.SubmitTransaction(transaction);

                    status += "Success!";
                    return(HtmlEncoder.Default.Encode($"SendsController POST CREATE {status} 1 {source} 2  3  4 "));
                }
            }
            catch (Exception e)
            {
                status += "ERROR" + e.Message;
            }
            return(HtmlEncoder.Default.Encode($"INVALID {send.ID}, {send.TokenName}"));
        }