Skip to content

Commit

Permalink
feat: Add features for guild migration
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Oct 30, 2024
1 parent 23722ec commit e8e6ee6
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 389 deletions.
113 changes: 0 additions & 113 deletions .Lib9c.Benchmarks/Actions/MigratePledgeToGuild.cs

This file was deleted.

192 changes: 0 additions & 192 deletions .Lib9c.Tests/Action/Guild/Migration/MigratePledgeToGuildTest.cs

This file was deleted.

10 changes: 5 additions & 5 deletions Lib9c/Action/Guild/MakeGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public override IWorld Execute(IActionContext context)
var validatorAddress = ValidatorAddress;

// TODO: Remove this check when to deliver features to users.
// if (context.Signer != GuildConfig.PlanetariumGuildOwner)
// {
// throw new InvalidOperationException(
// $"This action is not allowed for {context.Signer}.");
// }
if (context.Signer != GuildConfig.PlanetariumGuildOwner)
{
throw new InvalidOperationException(
$"This action is not allowed for {context.Signer}.");
}

repository.MakeGuild(guildAddress, validatorAddress);
return repository.World;
Expand Down
8 changes: 8 additions & 0 deletions Lib9c/Action/Guild/Migration/GuildMigrationConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Nekoyume.Action.Guild.Migration
{
// TODO: [GuildMigration] Remove this class when the migration is done.
public static class GuildMigrationConfig
{
public static readonly long MigrateDelegationHeight = 55555L;
}
}
61 changes: 61 additions & 0 deletions Lib9c/Action/Guild/Migration/LegacyModels/LegacyGuild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using Bencodex;
using Bencodex.Types;
using Nekoyume.TypedAddress;

namespace Nekoyume.Action.Guild.Migration.LegacyModels
{
// TODO: [GuildMigration] Remove this class when the migration is done.
public class LegacyGuild : IEquatable<LegacyGuild>, IBencodable
{
private const string StateTypeName = "guild";
private const long StateVersion = 1;

public readonly AgentAddress GuildMasterAddress;

public LegacyGuild(AgentAddress guildMasterAddress)
{
GuildMasterAddress = guildMasterAddress;
}

public LegacyGuild(List list) : this(new AgentAddress(list[2]))
{
if (list[0] is not Text text || text != StateTypeName || list[1] is not Integer integer)
{
throw new InvalidCastException();
}

if (integer > StateVersion)
{
throw new FailedLoadStateException("Un-deserializable state.");
}
}

public List Bencoded => List.Empty
.Add(StateTypeName)
.Add(StateVersion)
.Add(GuildMasterAddress.Bencoded);

IValue IBencodable.Bencoded => Bencoded;

public bool Equals(LegacyGuild other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return GuildMasterAddress.Equals(other.GuildMasterAddress);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((LegacyGuild)obj);
}

public override int GetHashCode()
{
return GuildMasterAddress.GetHashCode();
}
}
}
Loading

0 comments on commit e8e6ee6

Please sign in to comment.