Skip to content

Commit 0886a88

Browse files
authored
Merge pull request #83 from ethereum-boilerplate/bugs/issues_82_80_69
Issues 50, 69, 75, 80, 82
2 parents 24eb12d + 4952fee commit 0886a88

File tree

6 files changed

+99
-47
lines changed

6 files changed

+99
-47
lines changed

Assets/MoralisWeb3ApiSdk/Moralis/Moralis.Web3Api/Api/NativeApi.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ public async Task<string> RunContractFunction (string address, string functionNa
457457
else if (((int)response.StatusCode) == 0)
458458
throw new ApiException((int)response.StatusCode, "Error calling RunContractFunction: " + response.ErrorMessage, response.ErrorMessage);
459459

460-
return (string)ApiClient.Deserialize(response.Content, typeof(string), response.Headers);
460+
object respObject = (object)ApiClient.Deserialize(response.Content, typeof(object), response.Headers);
461+
462+
return JsonConvert.SerializeObject(respObject);
463+
461464
}
462465
}
463466
}

Assets/MoralisWeb3ApiSdk/Moralis/Moralis.Web3Api/CloudApi/NativeApi.cs

+4-31
Original file line numberDiff line numberDiff line change
@@ -413,36 +413,6 @@ public async Task<List<LogEvent>> GetContractEvents (string address, string topi
413413
/// <returns>Returns response of the function executed</returns>
414414
public async Task<string> RunContractFunction (string address, string functionName, RunContractDto abi, ChainList chain, string subdomain=null, string providerUrl=null)
415415
{
416-
417-
//// Verify the required parameter 'address' is set
418-
//if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling RunContractFunction");
419-
420-
//// Verify the required parameter 'functionName' is set
421-
//if (functionName == null) throw new ApiException(400, "Missing required parameter 'functionName' when calling RunContractFunction");
422-
423-
//// Verify the required parameter 'abi' is set
424-
//if (abi == null) throw new ApiException(400, "Missing required parameter 'abi' when calling RunContractFunction");
425-
426-
//var postBody = new Dictionary<String, object>();
427-
//var queryParams = new Dictionary<String, String>();
428-
//var headerParams = new Dictionary<String, String>();
429-
//var formParams = new Dictionary<String, String>();
430-
//var fileParams = new Dictionary<String, FileParameter>();
431-
432-
//var path = "/functions/runContractFunction";
433-
//if (address != null) postBody.Add("address", ApiClient.ParameterToString(address));
434-
//if (functionName != null) postBody.Add("function_name", ApiClient.ParameterToString(functionName));
435-
//if (abi != null) postBody.Add("abi", abi.Abi);
436-
//if (abi != null) postBody.Add("params", abi.Params);
437-
//if (abi != null) postBody.Add("params", ApiClient.ParameterToString(abi.Params));
438-
//if (subdomain != null) postBody.Add("subdomain", ApiClient.ParameterToString(subdomain));
439-
//if (providerUrl != null) postBody.Add("providerUrl", ApiClient.ParameterToString(providerUrl));
440-
//if(chain != null) postBody.Add("chain", ApiClient.ParameterToHex((long)chain));
441-
442-
//// Authentication setting, if any
443-
//String[] authSettings = new String[] { "ApiKeyAuth" };
444-
445-
//string bodyData = postBody.Count > 0 ? JsonConvert.SerializeObject(postBody) : null;
446416
// Verify the required parameter 'address' is set
447417
if (address == null) throw new ApiException(400, "Missing required parameter 'address' when calling RunContractFunction");
448418

@@ -482,7 +452,10 @@ public async Task<string> RunContractFunction (string address, string functionNa
482452
else if (((int)response.StatusCode) == 0)
483453
throw new ApiException((int)response.StatusCode, "Error calling RunContractFunction: " + response.ErrorMessage, response.ErrorMessage);
484454

485-
return ((CloudFunctionResult<string>)ApiClient.Deserialize(response.Content, typeof(CloudFunctionResult<string>), response.Headers)).Result;
455+
456+
object respObject = ((CloudFunctionResult<object>)ApiClient.Deserialize(response.Content, typeof(CloudFunctionResult<object>), response.Headers)).Result;
457+
458+
return JsonConvert.SerializeObject(respObject);
486459
}
487460
}
488461
}

Assets/MoralisWeb3ApiSdk/Moralis/Moralis.WebGL/MoralisDotNet/Platform/Objects/MoralisObject.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,56 @@ public UniTask DeleteAsync(CancellationToken cancellationToken = default)
7575
return this.ObjectService.DeleteAsync(this, sessionToken, cancellationToken);
7676
}
7777

78-
public virtual async UniTask SaveAsync(CancellationToken cancellationToken = default)
78+
public virtual async UniTask<bool> SaveAsync(CancellationToken cancellationToken = default)
7979
{
80+
try
81+
{
8082
// MoralisUser is a special case not all properties can be passed to save.
8183
if (this is MoralisUser) ((MoralisUser)this).SetSaving(true);
8284

8385
IDictionary<string, IMoralisFieldOperation> operations = this.StartSave();
8486
string resp = await this.ObjectService.SaveAsync(this, operations, sessionToken, cancellationToken);
8587

88+
Dictionary<string, object> obj = JsonUtilities.Parse(resp) as Dictionary<string, object>;
89+
90+
if (obj.ContainsKey("objectId"))
91+
{
92+
this.objectId = (string)obj["objectId"];
93+
}
94+
95+
if (obj.ContainsKey("createdAt"))
96+
{
97+
DateTime dt = DateTime.Now;
98+
if (DateTime.TryParse(obj["createdAt"].ToString(), out dt))
99+
{
100+
this.createdAt = dt;
101+
}
102+
}
103+
104+
if (obj.ContainsKey("updatedAt"))
105+
{
106+
DateTime dt = DateTime.Now;
107+
if (DateTime.TryParse(obj["updatedAt"].ToString(), out dt))
108+
{
109+
this.updatedAt = dt;
110+
}
111+
}
112+
86113
// Set user saving false so that local persistence has full object.
87114
if (this is MoralisUser) ((MoralisUser)this).SetSaving(false);
88115

89116
Console.WriteLine($"Save response: {resp}");
90117

91118
OperationSetQueue.Clear();
92119

93-
return;
120+
return true;
121+
}
122+
catch (Exception exp)
123+
{
124+
Console.WriteLine($"Save failed: {exp.Message}");
125+
}
126+
127+
return false;
94128
}
95129

96130
/// <summary>

Assets/MoralisWeb3ApiSdk/Moralis/Moralis.WebGL/MoralisDotNet/Platform/Services/ClientServices/UniversalWebClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public async UniTask<Tuple<HttpStatusCode, string>> ExecuteAsync(WebRequest http
9191
}
9292

9393
HttpStatusCode responseStatus = HttpStatusCode.BadRequest;
94-
string responseText = null;
94+
string responseText = "{}";
9595

9696
if (Enum.IsDefined(typeof(HttpStatusCode), (int)webRequest.responseCode))
9797
{
@@ -105,7 +105,7 @@ public async UniTask<Tuple<HttpStatusCode, string>> ExecuteAsync(WebRequest http
105105
}
106106
else
107107
{
108-
responseText = webRequest.downloadHandler.text;
108+
responseText = webRequest.downloadHandler == null ? responseText : webRequest.downloadHandler.text;
109109
}
110110

111111
result = new Tuple<HttpStatusCode, string>(responseStatus, responseText);

Assets/MoralisWeb3ApiSdk/Moralis/MoralisDotNet/Platform/Objects/MoralisObject.cs

+46-11
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,57 @@ internal IDictionary<string, IMoralisFieldOperation> CurrentOperations
7272
/// <param name="cancellationToken">The cancellation token.</param>
7373
public Task DeleteAsync(CancellationToken cancellationToken = default) => TaskQueue.Enqueue(toAwait => DeleteAsync(toAwait, cancellationToken), cancellationToken);
7474

75-
public virtual async Task SaveAsync(CancellationToken cancellationToken = default)
75+
public virtual async Task<bool> SaveAsync(CancellationToken cancellationToken = default)
7676
{
77-
// MoralisUser is a special case not all properties can be passed to save.
78-
if (this is MoralisUser) ((MoralisUser)this).SetSaving(true);
77+
try
78+
{
79+
// MoralisUser is a special case not all properties can be passed to save.
80+
if (this is MoralisUser) ((MoralisUser)this).SetSaving(true);
7981

80-
IDictionary<string, IMoralisFieldOperation> operations = this.StartSave();
81-
string resp = await this.ObjectService.SaveAsync(this, operations, sessionToken, cancellationToken);
82-
83-
// Set user saving false so that local persistence has full object.
84-
if (this is MoralisUser) ((MoralisUser)this).SetSaving(false);
82+
IDictionary<string, IMoralisFieldOperation> operations = this.StartSave();
83+
string resp = await this.ObjectService.SaveAsync(this, operations, sessionToken, cancellationToken);
8584

86-
Console.WriteLine($"Save response: {resp}");
85+
Dictionary<string, object> obj = JsonUtilities.Parse(resp) as Dictionary<string, object>;
8786

88-
OperationSetQueue.Clear();
87+
if (obj.ContainsKey("objectId"))
88+
{
89+
this.objectId = (string)obj["objectId"];
90+
}
91+
92+
if (obj.ContainsKey("createdAt"))
93+
{
94+
DateTime dt = DateTime.Now;
95+
if (DateTime.TryParse(obj["createdAt"].ToString(), out dt))
96+
{
97+
this.createdAt = dt;
98+
}
99+
}
100+
101+
if (obj.ContainsKey("updatedAt"))
102+
{
103+
DateTime dt = DateTime.Now;
104+
if (DateTime.TryParse(obj["updatedAt"].ToString(), out dt))
105+
{
106+
this.updatedAt = dt;
107+
}
108+
}
109+
110+
// Set user saving false so that local persistence has full object.
111+
if (this is MoralisUser) ((MoralisUser)this).SetSaving(false);
112+
113+
Console.WriteLine($"Save response: {resp}");
114+
115+
OperationSetQueue.Clear();
116+
117+
return true;
118+
}
119+
catch (Exception exp)
120+
{
121+
Console.WriteLine($"Save failed: {exp.Message}");
122+
}
123+
124+
return false;
89125

90-
return;
91126
}
92127

93128
/// <summary>

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Change Log
2+
# 1.0.9 (2022-03-09)
3+
- Issue #82 - Web3Api Native RunContractFunction Deserialization fails
4+
- Issue #80 - WebGL, LiveQuery - DELETE: Good response has an Empty content
5+
- Issue #75 - eature Request: CreateAsync
6+
- Issue #69 - Detecting failed SaveAsync
7+
- Issue #50 - On Object Create ACL not instantiated
8+
29
# 1.0.8 (2022-03-02)
310
- Issue #32 - Replace Wallet Connect with In-Browser Wallet Interface for WebGL
411
- Issue #70 - User Save Fails

0 commit comments

Comments
 (0)