/// <summary> /// Sends a Token on the Trusted Platform and blockchain using full CryptoItem. /// Allows for fungible and nonfungible token requests /// </summary> /// <param name="identityID">Identity ID of requestor</param> /// <param name="item">CryptoItem to be sent</param> /// <param name="recipientID">Identity ID of reciving wallet</param> /// <param name="value">Number of tokens to be sent</param> /// /// <param name="value">Callback function to execute when request is fulfilled</param> /// <returns>Create request data from API</returns> public Request SendItem(int identityID, CryptoItem item, int recipientID, int value, System.Action <string> handler, bool async = false) { _query = @"mutation sendItem{CreateEnjinRequest(appId:$appId^,type:SEND,identityId:$identityId^,send_token_data:{recipient_identity_id:$recipient_id^, token_id: ""$token_id^"", "; if (item.nonFungible) { _query += @"token_index: ""$item_index^"", "; } _query += "value:$value^}){id,encodedData,state}}"; GraphQuery.variable["appId"] = Enjin.AppID.ToString(); GraphQuery.variable["identityId"] = identityID.ToString(); GraphQuery.variable["token_id"] = item.id; if (item.nonFungible) { GraphQuery.variable["item_index"] = item.index; } GraphQuery.variable["recipient_id"] = recipientID.ToString(); GraphQuery.variable["value"] = value.ToString(); GraphQuery.POST(_query, "", async, (queryReturn) => { handler?.Invoke(queryReturn); }); if (GraphQuery.queryStatus == GraphQuery.Status.Complete) { return(JsonUtility.FromJson <Request>(EnjinHelpers.GetJSONString(GraphQuery.queryReturn, 2))); } return(null); }
/// <summary> /// Updates CryptoItem information on blockchain /// </summary> /// <param name="identityID">Identity of user</param> /// <param name="item">CryptoItem to update</param> /// <param name="fieldType">What field to update</param> /// <returns></returns> public Request UpdateCryptoItem(int identityID, CryptoItem item, CryptoItemFieldType fieldType, System.Action <RequestEvent> callback) { switch (fieldType) { case CryptoItemFieldType.NAME: _query = @"mutation updateItemName{request:CreateEnjinRequest(appId:$appId^,identityId:$identityID^,type:UPDATE_NAME,update_item_name_data:{token_id:""$id^"",name:""$name^""}){id,encodedData,state}}"; GraphQuery.variable["appId"] = Enjin.AppID.ToString(); GraphQuery.variable["id"] = item.id; GraphQuery.variable["identityID"] = identityID.ToString(); GraphQuery.variable["name"] = item.name; break; case CryptoItemFieldType.MELTFEE: break; case CryptoItemFieldType.TRANSFERABLE: break; case CryptoItemFieldType.TRANSFERFEE: break; case CryptoItemFieldType.MAXMELTFEE: break; case CryptoItemFieldType.MAXTRANSFERFEE: break; } GraphQuery.POST(_query); if (Enjin.ServerResponse == ResponseCodes.SUCCESS) { Request request = JsonUtility.FromJson <Request>(EnjinHelpers.GetJSONString(GraphQuery.queryReturn, 2)); Enjin.RequestCallbacks.Add(request.id, callback); return(request); } return(null); }
/// <summary> /// Adds a fungible item to the transfer list /// </summary> /// <param name="fromAddress">Address to send item from</param> /// <param name="toAddress">Address to send item to</param> /// <param name="item">Item to send</param> /// <param name="amount">Amount of item to send.</param> public void Add(string fromAddress, string toAddress, CryptoItem item, int amount) { if (amount <= 0) { return; } if (item.nonFungible) { string tItem = @"from:""{0}"",to:""{1}"",token_id:""{2}"",token_index:""{3}"",value:""1"""; tItem = string.Format(tItem, fromAddress, toAddress, item.id, item.index); Items.Add(tItem); } else { string tItem = @"from:""{0}"",to:""{1}"",token_id:""{2}"",value:""{3}"""; tItem = string.Format(tItem, fromAddress, toAddress, item.id, amount.ToString()); Items.Add(tItem); } }
/// <summary> /// Sets the metadata URI for a cryptoItem /// </summary> /// <param name="identityID">Identity ID of user setting metadata URI</param> /// <param name="itemID">ID of cryptoItem to set metadata URI for</param> /// <param name="itemData">metadata URI data</param> /// <returns></returns> public Request SetCryptoItemURI(int identityID, CryptoItem item, string itemData, System.Action <RequestEvent> callback) { if (item.index != null) { // Validate that index is not just empty, if so set it to null if (item.index == string.Empty) { item.index = null; } } if (item.index == null) { _query = @"mutation setItemUri{request:CreateEnjinRequest(appId:$appId^,identityId:$identityID^,type:SET_ITEM_URI,set_item_uri_data:{token_id:""$itemID^"",item_uri:""$itemData^""}){id,encodedData,state}}"; } else { _query = @"mutation setURI{request:CreateEnjinRequest(appId:$appId^,identityId:$identityID^,type:SET_ITEM_URI,set_item_uri_data:{token_id:""$itemID^"",token_index:$tokenIndex^,item_uri:""$itemData^""}){id,encodedData,state}}"; GraphQuery.variable["tokenIndex"] = item.index.TrimStart('0'); } GraphQuery.variable["appId"] = Enjin.AppID.ToString(); GraphQuery.variable["identityID"] = identityID.ToString(); GraphQuery.variable["itemID"] = item.id; GraphQuery.variable["itemData"] = itemData; GraphQuery.POST(_query); if (Enjin.ServerResponse == ResponseCodes.SUCCESS) { Request request = JsonUtility.FromJson <Request>(EnjinHelpers.GetJSONString(GraphQuery.queryReturn, 2)); Enjin.RequestCallbacks.Add(request.id, callback); return(request); } return(null); }
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)); }
public static Request UpdateCryptoItem(int identityID, CryptoItem item, CryptoItemFieldType fieldType, System.Action <RequestEvent> callback) { return(_requests.UpdateCryptoItem(identityID, item, fieldType, callback)); }
public static Request SetCryptoItemURI(int identityID, CryptoItem item, string URI, System.Action <RequestEvent> callback) { return(_requests.SetCryptoItemURI(identityID, item, URI, callback)); }
public static Request UpdateCryptoItem(string senderAddress, CryptoItem item, CryptoItemFieldType fieldType, System.Action <RequestEvent> callback) { return(_requests.UpdateCryptoItem(senderAddress, item, fieldType, callback)); }
public static Request SetCryptoItemURI(string senderAddress, CryptoItem item, string URI, System.Action <RequestEvent> callback) { return(_requests.SetCryptoItemURI(senderAddress, item, URI, callback)); }