Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Error filtering the status in getOrderHistory #170

Closed
chancity opened this issue Sep 5, 2018 · 21 comments
Closed

Error filtering the status in getOrderHistory #170

chancity opened this issue Sep 5, 2018 · 21 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@chancity
Copy link

chancity commented Sep 5, 2018

If an external offer is created but never submitted getOrderHistory errors because it's populating the array with orders that are open...kin-devplatform-marketplace-server uses the same method of getting orders aswell.

https://github.com/kinecosystem/marketplace-server/blob/master/scripts/src/public/services/orders.ts#L337-L340

https://github.com/kinecosystem/kin-devplatform-marketplace-server/blob/master/scripts/src/public/services/orders.ts#L315-L318

@chancity chancity changed the title Filtering the status in getOrderHistory Error filtering the status in getOrderHistory Sep 5, 2018
@nitzantomer
Copy link
Contributor

I don't understand, what do you mean by "getOrderHistory errors"?
Do you get an actual error or the result isn't what you'd expect?
In either case, please provide the response you get (error/result).

@nitzantomer
Copy link
Contributor

@chancity ^^

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Hey hey, so what happened was I created a pay_to_user offer and before submitting the offer id my program threw and exception causing it to crash. I wasn't storing OrderIds at that time so the order was never submitted. I thought hmm here's an endpoint to view offers and orders, maybe I can find my unsubmitted order id on one of those endpoints. Nope wasn't in offers and orders is failing because and order had a status of "opened".

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Sorry I don't have the JSON error from the request but I have a pretty good idea what method in the marketplace server is throwing the exception. Here:
function orderDbToApi(order: db.Order, userId: string): Order {
if (order.status === "opened") {
throw OpenedOrdersUnreturnable();
}

@nitzantomer
Copy link
Contributor

@chancity
As I wrote in the other issue thread, opened orders are only used in the server and the client shouldn't care about them.
You are free to just create a new order for the same offer id, if the server finds an existing open order for that id then it will return the same one. If it finds an order for that id with a status other than pending then you'll get an error.

What I still don't understand is how you received an error. To which endpoint did you call when you got it?

@chancity
Copy link
Author

chancity commented Sep 6, 2018

SO on step 5 my program crashed, not related to the Market place API at all. Upon restart I called step 6 and this is were the market place API threw an exception.

When I get on my computer today I'll try to find the market place user id the exception is occurring on.

  1. /users POST
  2. /users/me/activate POST
  3. Change trust operation
  4. /offers/external/orders POST
  5. /orders/{order_id} POST //MY PROGRAM CRASHED
  6. /orders GET //ERROR OCCURRED

@nitzantomer
Copy link
Contributor

@chancity
Interesting. It shouldn't return an error on step 6, just an empty array I guess.
Please provide us with the user id, and the other arguments you're passing to the request (origin and/or offer_id).
Thanks

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Give me around 10-30 minutes and I'll have it all posted.

@chancity
Copy link
Author

chancity commented Sep 6, 2018

            var kinMarketPlaceClient = services.BuildServiceProvider().GetRequiredService<KinMarketPlaceClient>();
            var kinBlockChainHandler = services.BuildServiceProvider().GetRequiredService<KinBlockChainHandler>();
            var kinUserManager = services.BuildServiceProvider().GetRequiredService<KinUserManager>();
            var kinJwtProvider = services.BuildServiceProvider().GetRequiredService<KinJwtProvider>();

            var toUserId = "519ce80f-67e7-44af-ae14-d8e8b475c3ae";
            string fromUserId = Guid.NewGuid().ToString();
            KeyPair keyPair = KeyPair.Random();
            var deviceId = "Kin-Tip-Bot";
            //JWT stuff
            var payload = new KinJwtPayload(KinJwtClaimNames.UserId, fromUserId);
            string jwtToken = kinJwtProvider.GenerateJwtTokenAsync(KinJwtSubjectNames.Register, payload).Result;
            var jwtSignInData = new JwtSignInData(deviceId, keyPair.Address, jwtToken);
            //SignIn
            string requestId = Guid.NewGuid().ToString();
            LoginResponse signInResponse = kinMarketPlaceClient.Users(jwtSignInData, requestId, deviceId).Result;

            if (!string.IsNullOrEmpty(signInResponse.Token))
            {
                //Activate
                requestId = Guid.NewGuid().ToString();

                LoginResponse activationResponse =
                    kinMarketPlaceClient.UsersMeActivate(signInResponse.Token, requestId, deviceId).Result;

                //ChangeTrustOperation
                if (activationResponse.Activated)
                {
                    bool changeTrustResponse = kinBlockChainHandler.TryUntilActivated(keyPair).Result;

                    if (changeTrustResponse)
                    {
                        requestId = Guid.NewGuid().ToString();

                        OffersResponse offers = kinMarketPlaceClient
                            .GetOffers(activationResponse.Token, requestId, deviceId).Result;

                        OfferResponse offerToSubmit =
                            offers.offers.FirstOrDefault(x => x.content_type != "poll" && x.offer_type == "earn");

                        if (offerToSubmit != null)
                        {
                            requestId = Guid.NewGuid().ToString();


                            CreateOrderResponse createOrder = kinMarketPlaceClient.CreateOrderForOffer(offerToSubmit.id,
                                activationResponse.Token,
                                requestId,
                                deviceId).Result;

                            requestId = Guid.NewGuid().ToString();

                            OrderResponse orderResponse = kinMarketPlaceClient
                                .SubmitOrder(createOrder.id, "", activationResponse.Token, requestId, deviceId).Result;
                        }

                        var p2pOffer = new JwtBodyPartOffer($"p2p-tx-test", "1");

                        var sender = new JwtBodyPartSender(fromUserId, "p2p",
                            $"{fromUserId} sending kin to user {toUserId}");

                        var recipient =
                            new JwtBodyPartRecipient(toUserId, "p2p", $"received kin from user {fromUserId}");

                        var offerPayload = new KinJwtPayload<JwtBodyPartOffer>(KinJwtClaimNames.Offer, p2pOffer);
                        var senderPayload = new KinJwtPayload<JwtBodyPartRecipient>(KinJwtClaimNames.Sender, sender);

                        var recipientPayload =
                            new KinJwtPayload<JwtBodyPartRecipient>(KinJwtClaimNames.Recipient, recipient);

                        string jwt = kinJwtProvider.GenerateJwtTokenAsync(KinJwtSubjectNames.PayToUser, offerPayload,
                            senderPayload, recipientPayload).Result;

                        requestId = Guid.NewGuid().ToString();

                        var createOrderResponse = kinMarketPlaceClient
                            .CreateExternalOffer(new JwtRequest(jwt), activationResponse.Token, requestId, deviceId)
                            .Result;

                        //Ops FORGOT TO SEND THIS UHOH
                        //requestId = Guid.NewGuid().ToString();
                        //OrderResponse order = kinMarketPlaceClient.SubmitOrder(createOrderResponse.id, "", activationResponse.Token, requestId, deviceId).Result;


                        try
                        {
                            requestId = Guid.NewGuid().ToString();

                            OrdersResponse orders = kinMarketPlaceClient
                                .GetOrders(activationResponse.Token, requestId, deviceId).Result;
                        }
                        catch (KinApiException e)
                        {
                            Console.WriteLine(JsonConvert.SerializeObject(e.ErrorResponse, Formatting.Indented));
                        }
                    }
                }
            }```

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Use Fiddler4 to view the http traffic in the error dump.

Here's the user information: { "token":"44u1nXD0ClBSAlKXUOwJ", "activated":true, "app_id":"rced", "user_id":"f2e1472f-5112-4265-a8d4-663948bfc61b", "ecosystem_user_id":"UXVPeebOLnJFky7OsYDSs", "expiration_date":"2018-09-20T14:44:08.799Z" }

Here's the json response: { "code":5002, "error":"Internal Server Error", "message":"Opened orders should not be returned" }

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Error is thrown here and sourced from here in the market place code.

It looks like the status filtering here isn't working as intended. The error should occur on the production version too.

@chancity
Copy link
Author

chancity commented Sep 6, 2018

Also I intentionally did this for the error to occur, if I uncomment it everything is fine.

//Ops FORGOT TO SEND THIS UHOH //requestId = Guid.NewGuid().ToString(); //OrderResponse order = kinMarketPlaceClient.SubmitOrder(createOrderResponse.id, "", activationResponse.Token, requestId, deviceId).Result;

@nitzantomer
Copy link
Contributor

@chancity
Ok, we'll take a look at this, thanks.

@nitzantomer nitzantomer added the bug Something isn't working label Sep 6, 2018
@nitzantomer nitzantomer self-assigned this Sep 6, 2018
@doodyparizada
Copy link
Contributor

@chancity I had a look and I can't reproduce the error. It also never happened on both our production and playground environments.
Which server endpoint are you using? If you're running locally, which commit hash are you using?

@chancity
Copy link
Author

chancity commented Sep 8, 2018

Occurs using the devplatform branch https://api.developers.kinecosystem.com/v1

@chancity
Copy link
Author

chancity commented Sep 8, 2018

Mind sending me a snippet of the code you used to test it?

@chancity
Copy link
Author

chancity commented Sep 9, 2018

Request 73b9b317-1940-48e7-a41a-6b861bdb0565  url: https://api.developers.kinecosystem.com/v1/offers/external/orders
Request 73b9b317-1940-48e7-a41a-6b861bdb0565  data:
        {"jwt":"eyJhbGciOiJSUzUxMiIsImtpZCI6InJzNTEyXzAiLCJ0eXAiOiJKV1QifQ.eyJzdWIiOiJwYXlfdG9fdXNlciIsImV4cCI6MTUzNjQ3MzU3OSwiaWF0IjoxNTM2NDUxOTc5LCJpc3MiOiJ0ZXN0Iiwib2ZmZXIiOnsiaWQiOiJwMnAtMzY5YzE4NGEtYzRjYy00ZWQzLTg0YjctYTRiZjVmOTMyMWM4IiwiYW1vdW50IjoiMSJ9LCJzZW5kZXIiOnsidXNlcl9pZCI6ImQwYTQ4ZmJjLTYxOGEtNGEzMy1iOTAzLWNlNzZlNDk3YTgxYSIsInRpdGxlIjoicDJwIiwiZGVzY3JpcHRpb24iOiJ0byBteXNlbGYifSwicmVjaXBpZW50Ijp7InVzZXJfaWQiOiIzNjljMTg0YS1jNGNjLTRlZDMtODRiNy1hNGJmNWY5MzIxYzgiLCJ0aXRsZSI6InAycCIsImRlc2NyaXB0aW9uIjoidG8gaGltPyJ9fQ.eqY8L0owOYDOW3Td82GQMZS0tqbJRCHJF3klnEvf2BAxb5frVuLDVXHMD5Tf6kDbrhyoW_hridl3M0F25DgPQazJVa2lGy1sjHkiQ2Ntct71_fj9H3n8hoCaXrYGPOrM3j1fYZ5MK6FaPKVNHi_biZp6BL8cK1IpannSXxPf0H0"}

Response for request 73b9b317-1940-48e7-a41a-6b861bdb0565  data:
        {"id":"TZmwkD5awD0LZN5C1MWQ0","offer_id":"p2p-369c184a-c4cc-4ed3-84b7-a4bf5f9321c8","offer_type":"pay_to_user","amount":"1","title":"p2p","description":"to myself","blockchain_data":{"sender_address":"GDGP2UMFAN3IZHAPIHSPRCP6G3ZXBG4G2RV2TDBNMCC5HU3WCG3FV7IB","recipient_address":"GDOHNKXUP2AGBCVWSTH77RPYEPAX2BNSIZXNHBGM3MK35SQJQ4NLTVSM"},"expiration_date":"2018-09-09T00:22:57.781Z"}

Request fdd68f62-a3d1-4011-ae4c-372bcf13c1d2  url: https://api.developers.kinecosystem.com/v1/orders

Response for request fdd68f62-a3d1-4011-ae4c-372bcf13c1d2  data:
        {"code":5002,"error":"Internal Server Error","message":"Opened orders should not be returned"}
Error: Internal Server Error, Message: Opened orders should not be returned, Code: 5002

Request d341a535-e5ef-4356-b824-d7175a6c2359  url: https://api.developers.kinecosystem.com/v1/offers/external/orders
Request d341a535-e5ef-4356-b824-d7175a6c2359  data:
        {"jwt":"eyJhbGciOiJSUzUxMiIsImtpZCI6InJzNTEyXzAiLCJ0eXAiOiJKV1QifQ.eyJzdWIiOiJwYXlfdG9fdXNlciIsImV4cCI6MTUzNjQ3MzU3OSwiaWF0IjoxNTM2NDUxOTc5LCJpc3MiOiJ0ZXN0Iiwib2ZmZXIiOnsiaWQiOiJwMnAtZDBhNDhmYmMtNjE4YS00YTMzLWI5MDMtY2U3NmU0OTdhODFhIiwiYW1vdW50IjoiMSJ9LCJzZW5kZXIiOnsidXNlcl9pZCI6IjM2OWMxODRhLWM0Y2MtNGVkMy04NGI3LWE0YmY1ZjkzMjFjOCIsInRpdGxlIjoicDJwIiwiZGVzY3JpcHRpb24iOiJ0byBteXNlbGYifSwicmVjaXBpZW50Ijp7InVzZXJfaWQiOiJkMGE0OGZiYy02MThhLTRhMzMtYjkwMy1jZTc2ZTQ5N2E4MWEiLCJ0aXRsZSI6InAycCIsImRlc2NyaXB0aW9uIjoidG8gaGltPyJ9fQ.XdpDqOFwNfO6tYsah68tC-J-zvAQr2bLiZrv70uzoNCHvejuH1utwoaSgo0y4jXRQKwP4PSA_l-gjJszy620ciwnFrZQptBcyhGjGShuWZTSsLqDkGIiii0mqIz4JTXAolntXVHBVt3Hpr9pNlvRmKUIuDEKcQQKW3cuiRHfIy8"}

Response for request d341a535-e5ef-4356-b824-d7175a6c2359  data:
        {"id":"TzcZZWGSW0bGpO18CMxZ0","offer_id":"p2p-d0a48fbc-618a-4a33-b903-ce76e497a81a","offer_type":"pay_to_user","amount":"1","title":"p2p","description":"to myself","blockchain_data":{"sender_address":"GDOHNKXUP2AGBCVWSTH77RPYEPAX2BNSIZXNHBGM3MK35SQJQ4NLTVSM","recipient_address":"GDGP2UMFAN3IZHAPIHSPRCP6G3ZXBG4G2RV2TDBNMCC5HU3WCG3FV7IB"},"expiration_date":"2018-09-09T00:22:58.278Z"}

Request b295052b-57d1-4506-a452-874cc5d9e221  url: https://api.developers.kinecosystem.com/v1/orders

Response for request b295052b-57d1-4506-a452-874cc5d9e221  data:
        {"code":5002,"error":"Internal Server Error","message":"Opened orders should not be returned"}
Error: Internal Server Error, Message: Opened orders should not be returned, Code: 5002

@chancity
Copy link
Author

chancity commented Sep 9, 2018

Here's the code that is failing, I'm doing it intentionally but if any application were to crash after posting data to /offers/external/orders and not POST /orders/{externalOrderId} doing a GET /orders will always result in {"code":5002,"error":"Internal Server Error","message":"Opened orders should not be returned"} indefinately.

@doodyparizada
Copy link
Contributor

doodyparizada commented Sep 10, 2018

@Ronserruya @yosriz It's an issue on your branch, can you take it from here?

@nitzantomer
Copy link
Contributor

Closing this as we weren't able to reproduce it with this repo, maybe it is specific to the developer's fork.

@nitzantomer nitzantomer added invalid This doesn't seem right and removed bug Something isn't working labels Sep 13, 2018
@yosriz
Copy link

yosriz commented Sep 20, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants