-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
NineChronicles.Headless/Services/RestAPIAccessControlService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Libplanet.Crypto; | ||
using Nekoyume.Blockchain; | ||
using Serilog; | ||
|
||
namespace NineChronicles.Headless.Services | ||
{ | ||
public class RestAPIAccessControlService : IAccessControlService | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly string _baseUrl; | ||
|
||
public RestAPIAccessControlService(string baseUrl) | ||
{ | ||
_baseUrl = baseUrl; | ||
_httpClient = new HttpClient | ||
{ | ||
Timeout = TimeSpan.FromMilliseconds(500) | ||
}; | ||
} | ||
|
||
public int? GetTxQuota(Address address) | ||
{ | ||
try | ||
{ | ||
string requestUri = $"{_baseUrl}/entries/{address}"; | ||
HttpResponseMessage response = _httpClient.GetAsync(requestUri).GetAwaiter().GetResult(); | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
string resultString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); | ||
return Convert.ToInt32(resultString); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error(ex, "Error occurred while calling Rest API."); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters