public static string ToGraphQL(TokenValueInputData data)
        {
            string val = @"{";

            if (EnjinHelpers.IsNullOrEmpty(data.index))
            {
                val += string.Format(@"id:""{0}"",value:{1}", data.id, data.value);
            }
            else
            {
                val += string.Format(@"id:""{0}"",index:{1},value:{2}", data.id, data.index, data.value);
            }

            val += @"}";
            return(val);
        }
Beispiel #2
0
        public Request CreateTradeRequest(int senderIdentityID, TokenValueInputData[] itemsFromSender,
                                          string secondPartyAddress, int?secondPartyIdentityID, TokenValueInputData[] itemsFromSecondParty)
        {
            if (EnjinHelpers.IsNullOrEmpty(itemsFromSender) || EnjinHelpers.IsNullOrEmpty(itemsFromSecondParty))
            {
                return(null);
            }

            if (secondPartyAddress == null && !secondPartyIdentityID.HasValue)
            {
                return(null);
            }

            string askingStr   = TokenValueInputData.ToGraphQL(itemsFromSecondParty);
            string offeringStr = TokenValueInputData.ToGraphQL(itemsFromSender);

            _query =
                @"mutation sendTrade{result:CreateEnjinRequest(appId:$appId^,identityId:$senderIdentityID^,type:CREATE_TRADE,create_trade_data:{asking_tokens:$askingTokens^,offering_tokens:$offeringTokens^";
            if (secondPartyAddress != null)
            {
                _query += @",second_party_address:""$secondPartyAddress^""";
                GraphQuery.variable["secondPartyAddress"] = secondPartyAddress;
            }
            else
            {
                _query += @",second_party_identity_id:$secondPartyIdentityID^";
                GraphQuery.variable["secondPartyIdentityID"] = secondPartyIdentityID.ToString();
            }

            _query += @"}){id,encodedData,state}}";

            GraphQuery.variable["appId"]            = Enjin.AppID.ToString();
            GraphQuery.variable["senderIdentityID"] = senderIdentityID.ToString();
            GraphQuery.variable["askingTokens"]     = askingStr;
            GraphQuery.variable["offeringTokens"]   = offeringStr;

            GraphQuery.POST(_query);

            if (Enjin.ServerResponse == ResponseCodes.SUCCESS)
            {
                return(JsonUtility.FromJson <Request>(EnjinHelpers.GetJSONString(GraphQuery.queryReturn, 2)));
            }

            return(null);
        }
Beispiel #3
0
        public Request CreateTradeRequest(int senderIdentityID, CryptoItem[] itemsFromSender, int[] amountsFromSender,
                                          string secondPartyAddress, int?secondPartyIdentityID, CryptoItem[] itemsFromSecondParty,
                                          int[] amountsFromSecondParty)
        {
            if (EnjinHelpers.IsNullOrEmpty(itemsFromSender) || EnjinHelpers.IsNullOrEmpty(amountsFromSender) ||
                itemsFromSender.Length != amountsFromSender.Length)
            {
                return(null);
            }

            if (EnjinHelpers.IsNullOrEmpty(itemsFromSecondParty) ||
                EnjinHelpers.IsNullOrEmpty(amountsFromSecondParty) ||
                itemsFromSecondParty.Length != amountsFromSecondParty.Length)
            {
                return(null);
            }

            TokenValueInputData[] fromSender      = new TokenValueInputData[itemsFromSender.Length];
            TokenValueInputData[] fromSecondParty = new TokenValueInputData[itemsFromSecondParty.Length];

            for (int i = 0; i < itemsFromSender.Length; i++)
            {
                CryptoItem item   = itemsFromSender[i];
                int        amount = amountsFromSender[i];
                fromSender[i] = new TokenValueInputData(item.id, item.index, amount);
            }

            for (int i = 0; i < itemsFromSecondParty.Length; i++)
            {
                CryptoItem item   = itemsFromSecondParty[i];
                int        amount = amountsFromSecondParty[i];
                fromSecondParty[i] = new TokenValueInputData(item.id, item.index, amount);
            }

            return(CreateTradeRequest(senderIdentityID, fromSender, secondPartyAddress, secondPartyIdentityID,
                                      fromSecondParty));
        }