-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Nine chronicles util backend.store (#9)
* Init * Add big integer converter * Add 0c restapi client * Configuration * Add state service * Update vscode debug setting files * Add ArenaScrapper * Add Store service * Implement bulk store * Add Store, Scrapper logging * Fix link avatar bug * Get latest block information
- Loading branch information
Showing
25 changed files
with
937 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug NineChroniclesUtilBackend", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/NineChroniclesUtilBackend/bin/Debug/net8.0/NineChroniclesUtilBackend.dll", | ||
"cwd": "${workspaceFolder}/NineChroniclesUtilBackend", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"preLaunchTask": "build", | ||
} | ||
] | ||
} | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug NineChroniclesUtilBackend", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/NineChroniclesUtilBackend/bin/Debug/net8.0/NineChroniclesUtilBackend.dll", | ||
"cwd": "${workspaceFolder}/NineChroniclesUtilBackend", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"preLaunchTask": "build-backend" | ||
}, | ||
{ | ||
"name": "Debug NineChroniclesUtilBackend.Store", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/NineChroniclesUtilBackend.Store/bin/Debug/net8.0/NineChroniclesUtilBackend.Store.dll", | ||
"cwd": "${workspaceFolder}/NineChroniclesUtilBackend.Store", | ||
"stopAtEntry": false, | ||
"console": "internalConsole", | ||
"preLaunchTask": "build-store" | ||
} | ||
] | ||
} |
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
63 changes: 63 additions & 0 deletions
63
NineChroniclesUtilBackend.Store/Client/EmptyChronicleClient.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,63 @@ | ||
using Newtonsoft.Json; | ||
using NineChroniclesUtilBackend.Store.Models; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Client; | ||
|
||
public class EmptyChronicleClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
private readonly string _baseUrl; | ||
|
||
public EmptyChronicleClient(string baseUrl) | ||
{ | ||
_baseUrl = baseUrl; | ||
_httpClient = new HttpClient(); | ||
} | ||
|
||
public async Task<StateResponse> GetStateByAddressAsync(string address, string? accountAddress = null) | ||
{ | ||
var url = $"{_baseUrl}/api/states/{address}/raw"; | ||
if (accountAddress != null) | ||
{ | ||
url += $"?account={Uri.EscapeDataString(accountAddress)}"; | ||
} | ||
|
||
var response = await _httpClient.GetAsync(url); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
|
||
var stateResponse = JsonConvert.DeserializeObject<StateResponse>(content); | ||
if (stateResponse == null) | ||
{ | ||
throw new InvalidOperationException("StateResponse is null."); | ||
} | ||
|
||
return stateResponse; | ||
} | ||
|
||
public async Task<BlockResponse> GetLatestBlock() | ||
{ | ||
var url = $"{_baseUrl}/api/blocks/latest"; | ||
|
||
var response = await _httpClient.GetAsync(url); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var content = await response.Content.ReadAsStringAsync(); | ||
|
||
var stateResponse = JsonConvert.DeserializeObject<BlockResponse>(content); | ||
if (stateResponse == null) | ||
{ | ||
throw new InvalidOperationException("StateResponse is null."); | ||
} | ||
|
||
return stateResponse; | ||
} | ||
|
||
// public async Task<StateResponse> GetBlock(int index) | ||
// { | ||
// return stateResponse; | ||
// } | ||
} |
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,8 @@ | ||
namespace NineChroniclesUtilBackend.Store; | ||
|
||
public class Configuration | ||
{ | ||
public string EmptyChronicleBaseUrl { get; init; } | ||
public string MongoDbConnectionString { get; init; } | ||
public string DatabaseName { get; set; } | ||
} |
15 changes: 15 additions & 0 deletions
15
NineChroniclesUtilBackend.Store/Events/ArenaDataCollectedEventArgs.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,15 @@ | ||
using NineChroniclesUtilBackend.Store.Models; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Events; | ||
|
||
public class ArenaDataCollectedEventArgs : EventArgs | ||
{ | ||
public ArenaData ArenaData { get; set; } | ||
public AvatarData AvatarData { get; set; } | ||
|
||
public ArenaDataCollectedEventArgs(ArenaData arenaData, AvatarData avatarData) | ||
{ | ||
ArenaData = arenaData; | ||
AvatarData = avatarData; | ||
} | ||
} |
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,13 @@ | ||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class BlockResponse | ||
{ | ||
public string Hash { get; } | ||
public long Index { get; } | ||
|
||
public BlockResponse(string hash, long index) | ||
{ | ||
Hash = hash; | ||
Index = index; | ||
} | ||
} |
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,26 @@ | ||
using Libplanet.Crypto; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class ScrapperResult | ||
{ | ||
public DateTime StartTime { get; set; } | ||
public int TotalElapsedMinutes { get; set; } | ||
public int AvatarScrappedCount { get; set; } | ||
public int ArenaScrappedCount { get; set; } | ||
public List<Address> FailedAvatarAddresses { get; } = new List<Address>(); | ||
public List<Address> FailedArenaAddresses { get; } = new List<Address>(); | ||
|
||
public override string ToString() | ||
{ | ||
var failedAvatarAddresses = string.Join(", ", FailedAvatarAddresses.Select(a => a.ToString())); | ||
var failedArenaAddresses = string.Join(", ", FailedArenaAddresses.Select(a => a.ToString())); | ||
|
||
return $"StartTime: {StartTime}, " + | ||
$"TotalElapsedMinutes: {TotalElapsedMinutes}, " + | ||
$"AvatarScrappedCount: {AvatarScrappedCount}, " + | ||
$"ArenaScrappedCount: {ArenaScrappedCount}, " + | ||
$"FailedAvatarAddresses: [{failedAvatarAddresses}], " + | ||
$"FailedArenaAddresses: [{failedArenaAddresses}]"; | ||
} | ||
} |
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,21 @@ | ||
using Nekoyume.Model.Arena; | ||
using Nekoyume.TableData; | ||
using Libplanet.Crypto; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class ArenaData : BaseData | ||
{ | ||
public ArenaScore Score { get; } | ||
public ArenaInformation Information { get; } | ||
public ArenaSheet.RoundData RoundData { get; } | ||
public Address AvatarAddress { get; } | ||
|
||
public ArenaData(ArenaScore score, ArenaInformation information, ArenaSheet.RoundData roundData, Address avatarAddress) | ||
{ | ||
Score = score; | ||
Information = information; | ||
RoundData = roundData; | ||
AvatarAddress = avatarAddress; | ||
} | ||
} |
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,17 @@ | ||
using Nekoyume.Model.State; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class AvatarData : BaseData | ||
{ | ||
public AvatarState Avatar { get; } | ||
public ItemSlotState ItemSlot { get; } | ||
public List<RuneState> RuneSlot { get; } | ||
|
||
public AvatarData(AvatarState avatar, ItemSlotState itemSlot, List<RuneState> runeSlot) | ||
{ | ||
Avatar = avatar; | ||
ItemSlot = itemSlot; | ||
RuneSlot = runeSlot; | ||
} | ||
} |
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,20 @@ | ||
using Newtonsoft.Json; | ||
using NineChroniclesUtilBackend.Store.Util; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class BaseData | ||
{ | ||
protected static JsonSerializerSettings JsonSerializerSettings => new JsonSerializerSettings | ||
{ | ||
Converters = new[] { new BigIntegerToStringConverter() }, | ||
Formatting = Formatting.Indented, | ||
// ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(), | ||
NullValueHandling = NullValueHandling.Ignore | ||
}; | ||
|
||
public string ToJson() | ||
{ | ||
return JsonConvert.SerializeObject(this, JsonSerializerSettings); | ||
} | ||
} |
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,15 @@ | ||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class StateResponse | ||
{ | ||
public string Address { get; } | ||
public string AccountAddress { get; } | ||
public string Value { get; } | ||
|
||
public StateResponse(string address, string accountAddress, string value) | ||
{ | ||
Address = address; | ||
AccountAddress = accountAddress; | ||
Value = value; | ||
} | ||
} |
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,30 @@ | ||
using Libplanet.Crypto; | ||
|
||
namespace NineChroniclesUtilBackend.Store.Models; | ||
|
||
public class StoreResult | ||
{ | ||
public DateTime StartTime { get; set; } | ||
public int TotalElapsedMinutes { get; set; } | ||
public int StoreArenaRequestCount { get; set; } | ||
public int StoreAvatarRequestCount { get; set; } | ||
public int AvatarStoredCount { get; set; } | ||
public int ArenaStoredCount { get; set; } | ||
public List<Address> FailedAvatarAddresses { get; } = new List<Address>(); | ||
public List<Address> FailedArenaAddresses { get; } = new List<Address>(); | ||
|
||
public override string ToString() | ||
{ | ||
var failedAvatarAddresses = string.Join(", ", FailedAvatarAddresses.Select(a => a.ToString())); | ||
var failedArenaAddresses = string.Join(", ", FailedArenaAddresses.Select(a => a.ToString())); | ||
|
||
return $"StartTime: {StartTime}, " + | ||
$"TotalElapsedMinutes: {TotalElapsedMinutes}, " + | ||
$"StoreArenaRequestCount: {StoreArenaRequestCount}, " + | ||
$"StoreAvatarRequestCount: {StoreAvatarRequestCount}, " + | ||
$"AvatarStoredCount: {AvatarStoredCount}, " + | ||
$"ArenaStoredCount: {ArenaStoredCount}, " + | ||
$"FailedAvatarAddresses: [{failedAvatarAddresses}], " + | ||
$"FailedArenaAddresses: [{failedArenaAddresses}]"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
NineChroniclesUtilBackend.Store/NineChroniclesUtilBackend.Store.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>dotnet-NineChroniclesUtilBackend.Store-bccda56f-4d38-484b-ab03-ebb26065c837</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Lib9c" Version="1.8.0-dev.4e2f5d9bfed5366a94e67b88c4b0e7171c0cd0d6" /> | ||
<PackageReference Include="Libplanet" Version="4.1.0-dev.20242745721" /> | ||
<PackageReference Include="MongoDB.Driver" Version="2.24.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.