Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Mimir.MongoDB.CollectionNames #327

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/ActionPointDocument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record ActionPointDocument(Address Address, int Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record ActionPointDocument(Address Address, int Object) : MimirBsonDocument(Address);
3 changes: 1 addition & 2 deletions Mimir.MongoDB/Bson/AgentDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record AgentDocument(Address Address, AgentState Object)
: MimirBsonDocument(Address);
public record AgentDocument(Address Address, AgentState Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/AllRuneDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record AllRuneDocument(Address Address, AllRuneState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record AllRuneDocument(Address Address, AllRuneState Object) : MimirBsonDocument(Address);
3 changes: 1 addition & 2 deletions Mimir.MongoDB/Bson/ArenaRankingDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public record ArenaRankingDocument(
int Round,
ArenaInformation ArenaInformation,
ArenaScore ArenaScore,
SimplifiedAvatarState SimpleAvatar
)
SimplifiedAvatarState SimpleAvatar)
{
public int Rank { get; set; }
}
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/BalanceDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record BalanceDocument(Address Address, FungibleAssetValue Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record BalanceDocument(Address Address, FungibleAssetValue Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/CollectionDocument.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

/// <summary>
/// Not MongoDB collection, it is a NineChronicles' collection state.
/// </summary>
/// <param name="Object"></param>
public record CollectionDocument(Address Address, CollectionState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record CollectionDocument(Address Address, CollectionState Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/CombinationSlotStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record CombinationSlotStateDocument(
Address Address,
Address AvatarAddress,
int SlotIndex,
CombinationSlotState Object
) : MimirBsonDocument(Address) { }
CombinationSlotState Object)
: MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/DailyRewardDocument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record DailyRewardDocument(Address Address, long Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record DailyRewardDocument(Address Address, long Object) : MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/InventoryDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.Items;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record InventoryDocument(Address Address, Inventory Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record InventoryDocument(Address Address, Inventory Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/ItemSlotDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record ItemSlotDocument(Address Address, ItemSlotState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record ItemSlotDocument(Address Address, ItemSlotState Object) : MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/PetStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record PetStateDocument(Address Address, PetState Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record PetStateDocument(Address Address, PetState Object) : MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/ProductDocument.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Lib9c.Models.Market;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record ProductDocument : MimirBsonDocument
{
public Address AvatarAddress { get; init; }
Expand Down
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/ProductsStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record ProductsStateDocument(Address Address, ProductsState Object, Address AvatarAddress)
: MimirBsonDocument(Address) { }
: MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/QuestListDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// using Libplanet.Crypto;
// using Nekoyume.Model.Quest;
// using MongoDB.Bson.Serialization.Attributes;

// namespace Mimir.MongoDB.Bson;

// [BsonIgnoreExtraElements]
// public record QuestListDocument(Address Address, QuestList Object) : IMimirBsonDocument(Address) { }
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/RaiderStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record RaiderStateDocument(Address Address, RaiderState Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record RaiderStateDocument(Address Address, RaiderState Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/RuneSlotDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record RuneSlotDocument(Address Address, RuneSlotState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record RuneSlotDocument(Address Address, RuneSlotState Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/SheetDocument.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Bencodex.Types;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.TableData;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record SheetDocument(
Address Address,
ISheet Object,
string Name,
IValue RawState
) : MimirBsonDocument(Address);
IValue RawState)
: MimirBsonDocument(Address);
10 changes: 6 additions & 4 deletions Mimir.MongoDB/Bson/StakeDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// using Libplanet.Crypto;
// using Nekoyume.Model.Stake;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.Model.Stake;

// namespace Mimir.MongoDB.Bson;
namespace Mimir.MongoDB.Bson;

// public record StakeDocument(Address Address, StakeStateV2 Object) : IMimirBsonDocument(Address) { }
// [BsonIgnoreExtraElements]
// public record StakeDocument(Address Address, StakeStateV2 Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/WorldBossKillRewardRecordDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldBossKillRewardRecordDocument(
Address Address,
Address AvatarAddress,
WorldBossKillRewardRecord Object
) : MimirBsonDocument(Address) { }
WorldBossKillRewardRecord Object)
: MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/WorldBossStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldBossStateDocument(
Address Address,
int RaidId,
WorldBossState Object
) : MimirBsonDocument(Address) { }
WorldBossState Object)
: MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/WorldInformationDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Bencodex.Types;
using Libplanet.Crypto;
using Lib9c.Models.Extensions;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.Model;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldInformationDocument : MimirBsonDocument
{
public IDictionary<int, WorldInformation.World> Object { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
using Lib9c;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;

namespace Mimir.Worker.Constants
namespace Mimir.MongoDB
{
public static class CollectionNames
{
public static readonly Currency OdinNCGCurrency = Currency.Legacy(

Check warning on line 10 in Mimir.MongoDB/CollectionNames.cs

View workflow job for this annotation

GitHub Actions / Test (Mimir.Worker.Tests)

'Currency.Legacy(string, byte, Address)' is obsolete: 'Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.'

Check warning on line 10 in Mimir.MongoDB/CollectionNames.cs

View workflow job for this annotation

GitHub Actions / Test (Mimir.Worker.Tests)

'Currency.Legacy(string, byte, Address)' is obsolete: 'Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.'
"NCG",
2,
new Address("0x47d082a115c63e7b58b1532d20e631538eafadde"));

public static readonly Currency HeimdallNCGCurrency = Currency.Legacy(

Check warning on line 15 in Mimir.MongoDB/CollectionNames.cs

View workflow job for this annotation

GitHub Actions / Test (Mimir.Worker.Tests)

'Currency.Legacy(string, byte, IImmutableSet<Address>?)' is obsolete: 'Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.'

Check warning on line 15 in Mimir.MongoDB/CollectionNames.cs

View workflow job for this annotation

GitHub Actions / Test (Mimir.Worker.Tests)

'Currency.Legacy(string, byte, IImmutableSet<Address>?)' is obsolete: 'Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.'
"NCG",
2,
null);

public static readonly Dictionary<Type, string> CollectionAndStateTypeMappings = new();
public static readonly Dictionary<Address, string> CollectionAndAddressMappings = new();

Expand All @@ -28,45 +38,36 @@
// CollectionAndAddressMappings.Add(Nekoyume.Addresses.AdventureBoss, "adventure_boss_season_info");

CollectionAndAddressMappings.Add(
new Address(AddressHandlerMappings.OdinNCGCurrency.Hash.ToByteArray()),
"balance_ncg"
);
new Address(OdinNCGCurrency.Hash.ToByteArray()),
"balance_ncg");
CollectionAndAddressMappings.Add(
new Address(Currencies.Crystal.Hash.ToByteArray()),
"balance_crystal"
);
"balance_crystal");
CollectionAndAddressMappings.Add(
new Address(Currencies.StakeRune.Hash.ToByteArray()),
"balance_stake_rune"
);
"balance_stake_rune");
CollectionAndAddressMappings.Add(
new Address(Currencies.DailyRewardRune.Hash.ToByteArray()),
"balance_daily_reward_rune"
);
"balance_daily_reward_rune");
CollectionAndAddressMappings.Add(
new Address(Currencies.Garage.Hash.ToByteArray()),
"balance_garage"
);
"balance_garage");
CollectionAndAddressMappings.Add(
new Address(Currencies.Mead.Hash.ToByteArray()),
"balance_mead"
);
"balance_mead");
CollectionAndAddressMappings.Add(
new Address(Currencies.FreyaBlessingRune.Hash.ToByteArray()),
"balance_freya_blessing_rune"
);
"balance_freya_blessing_rune");
CollectionAndAddressMappings.Add(
new Address(Currencies.FreyaLiberationRune.Hash.ToByteArray()),
"balance_freya_liberation_rune"
);
"balance_freya_liberation_rune");
CollectionAndAddressMappings.Add(
new Address(Currencies.OdinWeaknessRune.Hash.ToByteArray()),
"balance_weakness_rune"
);
"balance_weakness_rune");
CollectionAndAddressMappings.Add(
new Address(Currencies.OdinWisdomRune.Hash.ToByteArray()),
"balance_wisdom_rune"
);
"balance_wisdom_rune");
CollectionAndStateTypeMappings.Add(typeof(MetadataDocument), "metadata");
CollectionAndStateTypeMappings.Add(typeof(SheetDocument), "table_sheet");
CollectionAndStateTypeMappings.Add(typeof(AgentDocument), "agent");
CollectionAndStateTypeMappings.Add(typeof(AvatarDocument), "avatar");
Expand All @@ -83,8 +84,7 @@
CollectionAndStateTypeMappings.Add(typeof(WorldBossStateDocument), "world_boss");
CollectionAndStateTypeMappings.Add(
typeof(WorldBossKillRewardRecordDocument),
"world_boss_kill_reward_record"
);
"world_boss_kill_reward_record");
CollectionAndStateTypeMappings.Add(typeof(RaiderStateDocument), "raider");
// CollectionAndStateTypeMappings.Add(typeof(StakeDocument), "stake");
CollectionAndStateTypeMappings.Add(typeof(CombinationSlotStateDocument), "combination_slot");
Expand Down
3 changes: 1 addition & 2 deletions Mimir.Worker/ActionHandler/CombinationSlotStateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Globalization;
using Bencodex.Types;
using Lib9c.Models.Extensions;
using Lib9c.Models.States;
using Libplanet.Crypto;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Constants;
using Mimir.Worker.Exceptions;
using Mimir.Worker.Services;
using MongoDB.Driver;
Expand Down
2 changes: 1 addition & 1 deletion Mimir.Worker/ActionHandler/PatchTableHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Immutable;
using Bencodex.Types;
using Lib9c.Models.Extensions;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Constants;
using Mimir.Worker.Exceptions;
using Mimir.Worker.Services;
using MongoDB.Driver;
Expand Down
2 changes: 1 addition & 1 deletion Mimir.Worker/ActionHandler/PetStateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using Bencodex.Types;
using Lib9c.Models.Extensions;
using Libplanet.Crypto;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Constants;
using Mimir.Worker.Exceptions;
using Mimir.Worker.Services;
using MongoDB.Driver;
Expand Down
7 changes: 1 addition & 6 deletions Mimir.Worker/ActionHandler/ProductsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
using System.Text.RegularExpressions;
using Bencodex.Types;
using Lib9c.Models.Items;
using Lib9c.Models.Market;
using Lib9c.Models.States;
using Libplanet.Crypto;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Constants;
using Mimir.Worker.Exceptions;
using Mimir.Worker.Services;
using MongoDB.Driver;
using Nekoyume.Battle;
using Nekoyume.Helper;
using Nekoyume.TableData;
using Nekoyume.TableData.Crystal;
using Serilog;

namespace Mimir.Worker.ActionHandler;
Expand Down
2 changes: 1 addition & 1 deletion Mimir.Worker/ActionHandler/RaidHandler.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Lib9c.Abstractions;
using Libplanet.Action;
using Libplanet.Crypto;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Worker.CollectionUpdaters;
using Mimir.Worker.Constants;
using Mimir.Worker.Services;
using MongoDB.Driver;
using Nekoyume;
Expand Down
Loading
Loading