-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into store-all-avatar-fr…
…om-every-transactions # Conflicts: # Mimir.Worker/BlockPoller.cs # Mimir.Worker/Initializer.cs
- Loading branch information
Showing
7 changed files
with
179 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Libplanet.Crypto; | ||
using Nekoyume.TableData; | ||
|
||
namespace Mimir.Worker.Models; | ||
|
||
public class TableSheetData : BaseData | ||
{ | ||
public Address Address { get; } | ||
public string Name { get; } | ||
public ISheet Sheet { get; } | ||
public string Raw { get; } | ||
|
||
public TableSheetData(Address address, string name, ISheet sheet, string raw) | ||
{ | ||
Address = address; | ||
Name = name; | ||
Sheet = sheet; | ||
Raw = raw; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Bencodex; | ||
using Bencodex.Types; | ||
using Libplanet.Common; | ||
using Mimir.Worker.Models; | ||
using Mimir.Worker.Services; | ||
using Nekoyume; | ||
using Nekoyume.Action; | ||
using Nekoyume.TableData; | ||
|
||
namespace Mimir.Worker.Scrapper; | ||
|
||
public class TableSheetScrapper( | ||
ILogger<TableSheetScrapper> logger, | ||
IStateService service, | ||
MongoDbStore store | ||
) | ||
{ | ||
private readonly ILogger<TableSheetScrapper> _logger = logger; | ||
|
||
private readonly IStateService _stateService = service; | ||
private readonly MongoDbStore _store = store; | ||
|
||
public async Task ExecuteAsync(CancellationToken cancellationToken) | ||
{ | ||
var latestBlockIndex = await service.GetLatestIndex(); | ||
var stateGetter = _stateService.At(); | ||
|
||
var sheetTypes = typeof(ISheet) | ||
.Assembly.GetTypes() | ||
.Where(type => | ||
type.Namespace is { } @namespace | ||
&& @namespace.StartsWith($"{nameof(Nekoyume)}.{nameof(Nekoyume.TableData)}") | ||
&& !type.IsAbstract | ||
&& typeof(ISheet).IsAssignableFrom(type) | ||
); | ||
|
||
foreach (var sheetType in sheetTypes) | ||
{ | ||
if (sheetType == typeof(ItemSheet) || sheetType == typeof(QuestSheet)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (sheetType == typeof(WorldBossKillRewardSheet) || sheetType == typeof(WorldBossBattleRewardSheet)) | ||
{ | ||
// Handle later; | ||
continue; | ||
} | ||
|
||
var sheetAddress = Addresses.TableSheet.Derive(sheetType.Name); | ||
var sheetState = await _stateService.GetState(sheetAddress); | ||
if (sheetState is not Text sheetValue) | ||
{ | ||
throw new ArgumentException(nameof(sheetType)); | ||
} | ||
|
||
var sheetInstance = Activator.CreateInstance(sheetType); | ||
if (sheetInstance is not ISheet sheet) | ||
{ | ||
throw new InvalidCastException($"Type {sheetType.Name} cannot be cast to ISheet."); | ||
} | ||
|
||
sheet.Set(sheetValue.Value); | ||
|
||
var sheetData = new TableSheetData( | ||
sheetAddress, | ||
sheetType.Name, | ||
sheet, | ||
ByteUtil.Hex(new Codec().Encode(sheetState)) | ||
); | ||
await _store.InsertTableSheets(sheetData); | ||
} | ||
} | ||
} |
Oops, something went wrong.