Beispiel #1
0
        public Session GetSession()
        {
            HttpWebRequest request = AccountsRequestBuilder.ConstructSessionRequest(apiKey);
            Session        session = ProcessBodylessRequest(request).ToObject <Session>();

            return(session);
        }
Beispiel #2
0
        public RequestAuthToken GetRequestAuthToken(string successUrl, string errorUrl)
        {
            HttpWebRequest   request          = AccountsRequestBuilder.ConstructAuthTokenRequest(apiKey, successUrl, errorUrl);
            RequestAuthToken requestAuthToken = ProcessBodylessRequest(request).ToObject <RequestAuthToken>();

            return(requestAuthToken);
        }
Beispiel #3
0
        public WishList GetWishList(string sessionId)
        {
            HttpWebRequest request  = AccountsRequestBuilder.ConstructWishListRequest(apiKey, sessionId);
            WishList       wishList = ProcessBodylessRequest(request).ToObject <WishList>();

            return(wishList);
        }
Beispiel #4
0
        public Login Login(string privateToken, string sessionId)
        {
            HttpWebRequest request = AccountsRequestBuilder.ConstructLoginRequest(apiKey, privateToken, sessionId);
            Login          login   = ProcessBodylessRequest(request).ToObject <Login>();

            return(login);
        }
        public async Task <AccountResponse> GetAccountDetails(string address)
        {
            try
            {
                var builder        = new AccountsRequestBuilder(_horizonUrl, _httpClientFactory.CreateClient());
                var accountDetails = await builder.Account(address);

                return(accountDetails);
            }
            catch (Exception e) when(IsNotFound(e))
            {
                // address not found
                return(null);
            }
        }
Beispiel #6
0
        public void RemoveItemFromWishList(string sessionId, string wishListItemId)
        {
            HttpWebRequest request = AccountsRequestBuilder.ConstructWishListRemoveItemRequest(apiKey, sessionId, wishListItemId);

            ProcessBodylessRequest(request, false);
        }
Beispiel #7
0
        public void AddItemToWishList(string sessionId, string productId)
        {
            HttpWebRequest request = AccountsRequestBuilder.ConstructWishListAddItemRequest(apiKey, sessionId, productId);

            ProcessBodylessRequest(request, false);
        }
Beispiel #8
0
        public void Logout(string sessionId)
        {
            HttpWebRequest request = AccountsRequestBuilder.ConstructLogoutRequest(apiKey, sessionId);

            ProcessBodylessRequest(request, false);
        }
Beispiel #9
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}"));
        }