From 7aa9b9d2f2fe364666467ad51526b235188db9e0 Mon Sep 17 00:00:00 2001 From: s2quake Date: Wed, 18 Dec 2024 11:28:38 +0900 Subject: [PATCH 1/3] refactor: Convert the repository class to a generic type --- Lib9c/Delegation/Delegatee.cs | 76 +++++++++++------------- Lib9c/Delegation/DelegationRepository.cs | 58 ++++++++++++++---- Lib9c/Delegation/Delegator.cs | 57 +++++++++--------- 3 files changed, 109 insertions(+), 82 deletions(-) diff --git a/Lib9c/Delegation/Delegatee.cs b/Lib9c/Delegation/Delegatee.cs index 8e16dedc10..d78b40f2d2 100644 --- a/Lib9c/Delegation/Delegatee.cs +++ b/Lib9c/Delegation/Delegatee.cs @@ -10,9 +10,10 @@ namespace Nekoyume.Delegation { - public abstract class Delegatee : IDelegatee - where T : Delegator - where TSelf : Delegatee + public abstract class Delegatee : IDelegatee + where TRepository : DelegationRepository + where TDelegatee : Delegatee + where TDelegator : Delegator { public Delegatee( Address address, @@ -26,7 +27,7 @@ public Delegatee( long unbondingPeriod, int maxUnbondLockInEntries, int maxRebondGraceEntries, - IDelegationRepository repository) + TRepository repository) : this( new DelegateeMetadata( address, @@ -46,12 +47,12 @@ public Delegatee( public Delegatee( Address address, - IDelegationRepository repository) + TRepository repository) : this(repository.GetDelegateeMetadata(address), repository) { } - private Delegatee(DelegateeMetadata metadata, IDelegationRepository repository) + private Delegatee(DelegateeMetadata metadata, TRepository repository) { Metadata = metadata; Repository = repository; @@ -65,7 +66,7 @@ private Delegatee(DelegateeMetadata metadata, IDelegationRepository repository) public DelegateeMetadata Metadata { get; } - public IDelegationRepository Repository { get; } + public TRepository Repository { get; } public Address Address => Metadata.DelegateeAddress; @@ -109,14 +110,14 @@ public BigInteger ShareFromFAV(FungibleAssetValue fav) public FungibleAssetValue FAVFromShare(BigInteger share) => Metadata.FAVFromShare(share); - public BigInteger Bond(IDelegator delegator, FungibleAssetValue fav, long height) - => Bond((T)delegator, fav, height); + BigInteger IDelegatee.Bond(IDelegator delegator, FungibleAssetValue fav, long height) + => Bond((TDelegator)delegator, fav, height); - public FungibleAssetValue Unbond(IDelegator delegator, BigInteger share, long height) - => Unbond((T)delegator, share, height); + FungibleAssetValue IDelegatee.Unbond(IDelegator delegator, BigInteger share, long height) + => Unbond((TDelegator)delegator, share, height); - public void DistributeReward(IDelegator delegator, long height) - => DistributeReward((T)delegator, height); + void IDelegatee.DistributeReward(IDelegator delegator, long height) + => DistributeReward((TDelegator)delegator, height); public void Jail(long releaseHeight) { @@ -200,7 +201,7 @@ public Address CurrentLumpSumRewardsRecordAddress() public Address LumpSumRewardsRecordAddress(long height) => Metadata.LumpSumRewardsRecordAddress(height); - public virtual BigInteger Bond(T delegator, FungibleAssetValue fav, long height) + public virtual BigInteger Bond(TDelegator delegator, FungibleAssetValue fav, long height) { DistributeReward(delegator, height); @@ -216,7 +217,7 @@ public virtual BigInteger Bond(T delegator, FungibleAssetValue fav, long height) "Cannot bond to tombstoned delegatee."); } - Bond bond = Repository.GetBond(this, delegator.Address); + Bond bond = Repository.GetBond((TDelegatee)this, delegator.Address); BigInteger share = ShareFromFAV(fav); bond = bond.AddShare(share); Metadata.AddShare(share); @@ -229,10 +230,7 @@ public virtual BigInteger Bond(T delegator, FungibleAssetValue fav, long height) return share; } - BigInteger IDelegatee.Bond(IDelegator delegator, FungibleAssetValue fav, long height) - => Bond((T)delegator, fav, height); - - public FungibleAssetValue Unbond(T delegator, BigInteger share, long height) + public FungibleAssetValue Unbond(TDelegator delegator, BigInteger share, long height) { DistributeReward(delegator, height); if (TotalShares.IsZero || TotalDelegated.RawValue.IsZero) @@ -241,7 +239,7 @@ public FungibleAssetValue Unbond(T delegator, BigInteger share, long height) "Cannot unbond without bonding."); } - Bond bond = Repository!.GetBond(this, delegator.Address); + Bond bond = Repository!.GetBond((TDelegatee)this, delegator.Address); FungibleAssetValue fav = FAVFromShare(share); bond = bond.SubtractShare(share); if (bond.Share.IsZero) @@ -259,19 +257,16 @@ public FungibleAssetValue Unbond(T delegator, BigInteger share, long height) return fav; } - FungibleAssetValue IDelegatee.Unbond(IDelegator delegator, BigInteger share, long height) - => Unbond((T)delegator, share, height); - - public void DistributeReward(T delegator, long height) + public void DistributeReward(TDelegator delegator, long height) { - Bond bond = Repository.GetBond(this, delegator.Address); + Bond bond = Repository.GetBond((TDelegatee)this, delegator.Address); BigInteger share = bond.Share; if (!share.IsZero && bond.LastDistributeHeight.HasValue) { - if (Repository.GetCurrentRewardBase(this) is RewardBase rewardBase) + if (Repository.GetCurrentRewardBase((TDelegatee)this) is RewardBase rewardBase) { - var lastRewardBase = Repository.GetRewardBase(this, bond.LastDistributeHeight.Value); + var lastRewardBase = Repository.GetRewardBase((TDelegatee)this, bond.LastDistributeHeight.Value); TransferReward(delegator, share, rewardBase, lastRewardBase); // TransferRemainders(newRecord); } @@ -297,13 +292,10 @@ IEnumerable lumpSumRewardsRecords Repository.SetBond(bond); } - void IDelegatee.DistributeReward(IDelegator delegator, long height) - => DistributeReward((T)delegator, height); - public void CollectRewards(long height) { var rewards = RewardCurrencies.Select(c => Repository.GetBalance(RewardPoolAddress, c)); - if (Repository.GetCurrentRewardBase(this) is RewardBase rewardBase) + if (Repository.GetCurrentRewardBase((TDelegatee)this) is RewardBase rewardBase) { rewardBase = rewardBase.AddRewards(rewards, TotalShares); @@ -319,7 +311,7 @@ public void CollectRewards(long height) } else { - LumpSumRewardsRecord record = Repository.GetCurrentLumpSumRewardsRecord(this) + LumpSumRewardsRecord record = Repository.GetCurrentLumpSumRewardsRecord((TDelegatee)this) ?? new LumpSumRewardsRecord( CurrentLumpSumRewardsRecordAddress(), height, @@ -334,7 +326,7 @@ record = record.AddLumpSumRewards(rewards); Repository.TransferAsset(RewardPoolAddress, record.Address, rewardsEach); } } - + Repository.SetLumpSumRewardsRecord(record); } } @@ -436,10 +428,10 @@ public void StartNewRewardPeriod(long height) MigrateLumpSumRewardsRecords(); RewardBase newRewardBase; - if (Repository.GetCurrentRewardBase(this) is RewardBase rewardBase) + if (Repository.GetCurrentRewardBase((TDelegatee)this) is RewardBase rewardBase) { newRewardBase = rewardBase.UpdateSigFig(TotalShares); - if (Repository.GetRewardBase(this, height) is not null) + if (Repository.GetRewardBase((TDelegatee)this, height) is not null) { Repository.SetRewardBase(newRewardBase); return; @@ -469,7 +461,7 @@ private List GetLumpSumRewardsRecords(long? lastRewardHeig { List records = new(); if (lastRewardHeight is null - || !(Repository.GetCurrentLumpSumRewardsRecord(this) is LumpSumRewardsRecord record)) + || !(Repository.GetCurrentLumpSumRewardsRecord((TDelegatee)this) is LumpSumRewardsRecord record)) { return records; } @@ -483,7 +475,7 @@ private List GetLumpSumRewardsRecords(long? lastRewardHeig break; } - record = Repository.GetLumpSumRewardsRecord(this, lastStartHeight) + record = Repository.GetLumpSumRewardsRecord((TDelegatee)this, lastStartHeight) ?? throw new InvalidOperationException( $"Lump sum rewards record for #{lastStartHeight} is missing"); } @@ -491,7 +483,7 @@ record = Repository.GetLumpSumRewardsRecord(this, lastStartHeight) return records; } - private void TransferReward(T delegator, BigInteger share, LumpSumRewardsRecord record) + private void TransferReward(TDelegator delegator, BigInteger share, LumpSumRewardsRecord record) { ImmutableSortedDictionary reward = record.RewardsDuringPeriod(share); foreach (var rewardEach in reward) @@ -504,7 +496,7 @@ private void TransferReward(T delegator, BigInteger share, LumpSumRewardsRecord } private void TransferReward( - T delegator, + TDelegator delegator, BigInteger share, RewardBase currentRewardBase, RewardBase? lastRewardBase) @@ -549,7 +541,7 @@ private void MigrateLumpSumRewardsRecords() var growSize = 100; var capacity = 5000; List records = new(capacity); - if (!(Repository.GetCurrentLumpSumRewardsRecord(this) is LumpSumRewardsRecord record)) + if (!(Repository.GetCurrentLumpSumRewardsRecord((TDelegatee)this) is LumpSumRewardsRecord record)) { return; } @@ -563,7 +555,7 @@ private void MigrateLumpSumRewardsRecords() } records.Add(record); - record = Repository.GetLumpSumRewardsRecord(this, lastStartHeight) + record = Repository.GetLumpSumRewardsRecord((TDelegatee)this, lastStartHeight) ?? throw new InvalidOperationException( $"Lump sum rewards record for #{lastStartHeight} is missing"); } @@ -583,7 +575,7 @@ record = Repository.GetLumpSumRewardsRecord(this, lastStartHeight) else { var newRewardBase = rewardBase.UpdateSigFig(recordEach.TotalShares); - if (Repository.GetRewardBase(this, recordEach.StartHeight) is not null) + if (Repository.GetRewardBase((TDelegatee)this, recordEach.StartHeight) is not null) { Repository.SetRewardBase(newRewardBase); } diff --git a/Lib9c/Delegation/DelegationRepository.cs b/Lib9c/Delegation/DelegationRepository.cs index 26f33397b1..0a8167e737 100644 --- a/Lib9c/Delegation/DelegationRepository.cs +++ b/Lib9c/Delegation/DelegationRepository.cs @@ -8,7 +8,10 @@ namespace Nekoyume.Delegation { - public abstract class DelegationRepository : IDelegationRepository + public abstract class DelegationRepository : IDelegationRepository + where TRepository : DelegationRepository + where TDelegatee : Delegatee + where TDelegator : Delegator { protected IWorld previousWorld; protected IAccount delegateeAccount; @@ -129,13 +132,13 @@ public DelegationRepository( /// public Address LumpSumRewardsRecordAccountAddress { get; } - public abstract IDelegatee GetDelegatee(Address address); + public abstract TDelegatee GetDelegatee(Address address); - public abstract IDelegator GetDelegator(Address address); + public abstract TDelegator GetDelegator(Address address); - public abstract void SetDelegatee(IDelegatee delegatee); + public abstract void SetDelegatee(TDelegatee delegatee); - public abstract void SetDelegator(IDelegator delegator); + public abstract void SetDelegator(TDelegator delegator); public DelegateeMetadata GetDelegateeMetadata(Address delegateeAddress) { @@ -155,7 +158,7 @@ public DelegatorMetadata GetDelegatorMetadata(Address delegatorAddress) : throw new FailedLoadStateException("DelegatorMetadata not found."); } - public Bond GetBond(IDelegatee delegatee, Address delegatorAddress) + public Bond GetBond(TDelegatee delegatee, Address delegatorAddress) { Address address = delegatee.BondAddress(delegatorAddress); IValue? value = bondAccount.GetState(address); @@ -164,7 +167,7 @@ public Bond GetBond(IDelegatee delegatee, Address delegatorAddress) : new Bond(address); } - public UnbondLockIn GetUnbondLockIn(IDelegatee delegatee, Address delegatorAddress) + public UnbondLockIn GetUnbondLockIn(TDelegatee delegatee, Address delegatorAddress) { Address address = delegatee.UnbondLockInAddress(delegatorAddress); IValue? value = unbondLockInAccount.GetState(address); @@ -181,7 +184,7 @@ public UnbondLockIn GetUnlimitedUnbondLockIn(Address address) : throw new FailedLoadStateException("UnbondLockIn not found."); } - public RebondGrace GetRebondGrace(IDelegatee delegatee, Address delegatorAddress) + public RebondGrace GetRebondGrace(TDelegatee delegatee, Address delegatorAddress) { Address address = delegatee.RebondGraceAddress(delegatorAddress); IValue? value = rebondGraceAccount.GetState(address); @@ -204,7 +207,7 @@ public UnbondingSet GetUnbondingSet() : new UnbondingSet(this); /// - public RewardBase? GetCurrentRewardBase(IDelegatee delegatee) + public RewardBase? GetCurrentRewardBase(TDelegatee delegatee) { Address address = delegatee.CurrentRewardBaseAddress(); IValue? value = rewardBaseAccount.GetState(address); @@ -214,7 +217,7 @@ public UnbondingSet GetUnbondingSet() } /// - public RewardBase? GetRewardBase(IDelegatee delegatee, long height) + public RewardBase? GetRewardBase(TDelegatee delegatee, long height) { Address address = delegatee.RewardBaseAddress(height); IValue? value = rewardBaseAccount.GetState(address); @@ -223,7 +226,7 @@ public UnbondingSet GetUnbondingSet() : null; } - public LumpSumRewardsRecord? GetLumpSumRewardsRecord(IDelegatee delegatee, long height) + public LumpSumRewardsRecord? GetLumpSumRewardsRecord(TDelegatee delegatee, long height) { Address address = delegatee.LumpSumRewardsRecordAddress(height); IValue? value = lumpSumRewardsRecordAccount.GetState(address); @@ -232,7 +235,7 @@ public UnbondingSet GetUnbondingSet() : null; } - public LumpSumRewardsRecord? GetCurrentLumpSumRewardsRecord(IDelegatee delegatee) + public LumpSumRewardsRecord? GetCurrentLumpSumRewardsRecord(TDelegatee delegatee) { Address address = delegatee.CurrentLumpSumRewardsRecordAddress(); IValue? value = lumpSumRewardsRecordAccount.GetState(address); @@ -321,5 +324,36 @@ public virtual void UpdateWorld(IWorld world) rewardBaseAccount = world.GetAccount(RewardBaseAccountAddress); lumpSumRewardsRecordAccount = world.GetAccount(LumpSumRewardsRecordAccountAddress); } + + IDelegatee IDelegationRepository.GetDelegatee(Address address) => GetDelegatee(address); + + IDelegator IDelegationRepository.GetDelegator(Address address) => GetDelegator(address); + + Bond IDelegationRepository.GetBond(IDelegatee delegatee, Address delegatorAddress) + => GetBond((TDelegatee)delegatee, delegatorAddress); + + UnbondLockIn IDelegationRepository.GetUnbondLockIn(IDelegatee delegatee, Address delegatorAddress) + => GetUnbondLockIn((TDelegatee)delegatee, delegatorAddress); + + RebondGrace IDelegationRepository.GetRebondGrace(IDelegatee delegatee, Address delegatorAddress) + => GetRebondGrace((TDelegatee)delegatee, delegatorAddress); + + RewardBase? IDelegationRepository.GetCurrentRewardBase(IDelegatee delegatee) + => GetCurrentRewardBase((TDelegatee)delegatee); + + RewardBase? IDelegationRepository.GetRewardBase(IDelegatee delegatee, long height) + => GetRewardBase((TDelegatee)delegatee, height); + + LumpSumRewardsRecord? IDelegationRepository.GetCurrentLumpSumRewardsRecord(IDelegatee delegatee) + => GetCurrentLumpSumRewardsRecord((TDelegatee)delegatee); + + LumpSumRewardsRecord? IDelegationRepository.GetLumpSumRewardsRecord(IDelegatee delegatee, long height) + => GetLumpSumRewardsRecord((TDelegatee)delegatee, height); + + void IDelegationRepository.SetDelegatee(IDelegatee delegatee) + => SetDelegatee((TDelegatee)delegatee); + + void IDelegationRepository.SetDelegator(IDelegator delegator) + => SetDelegator((TDelegator)delegator); } } diff --git a/Lib9c/Delegation/Delegator.cs b/Lib9c/Delegation/Delegator.cs index 43159d17ea..a526f860db 100644 --- a/Lib9c/Delegation/Delegator.cs +++ b/Lib9c/Delegation/Delegator.cs @@ -8,16 +8,17 @@ namespace Nekoyume.Delegation { - public abstract class Delegator : IDelegator - where T : Delegatee - where TSelf : Delegator + public abstract class Delegator : IDelegator + where TRepository : DelegationRepository + where TDelegatee : Delegatee + where TDelegator : Delegator { public Delegator( Address address, Address accountAddress, Address delegationPoolAddress, Address rewardAddress, - IDelegationRepository repository) + TRepository repository) : this( new DelegatorMetadata( address, @@ -30,12 +31,12 @@ public Delegator( public Delegator( Address address, - IDelegationRepository repository) + TRepository repository) : this(repository.GetDelegatorMetadata(address), repository) { } - private Delegator(DelegatorMetadata metadata, IDelegationRepository repository) + private Delegator(DelegatorMetadata metadata, TRepository repository) { Metadata = metadata; Repository = repository; @@ -43,7 +44,7 @@ private Delegator(DelegatorMetadata metadata, IDelegationRepository repository) public DelegatorMetadata Metadata { get; } - public IDelegationRepository Repository { get; } + public TRepository Repository { get; } public Address Address => Metadata.DelegatorAddress; @@ -60,7 +61,7 @@ private Delegator(DelegatorMetadata metadata, IDelegationRepository repository) public List MetadataBencoded => Metadata.Bencoded; public virtual void Delegate( - T delegatee, FungibleAssetValue fav, long height) + TDelegatee delegatee, FungibleAssetValue fav, long height) { if (fav.Sign <= 0) { @@ -73,18 +74,18 @@ public virtual void Delegate( throw new InvalidOperationException("Delegatee is tombstoned."); } - delegatee.Bond(this, fav, height); + delegatee.Bond((TDelegator)this, fav, height); Metadata.AddDelegatee(delegatee.Address); Repository.TransferAsset(DelegationPoolAddress, delegatee.DelegationPoolAddress, fav); - Repository.SetDelegator(this); + Repository.SetDelegator((TDelegator)this); } void IDelegator.Delegate( IDelegatee delegatee, FungibleAssetValue fav, long height) - => Delegate((T)delegatee, fav, height); + => Delegate((TDelegatee)delegatee, fav, height); public virtual void Undelegate( - T delegatee, BigInteger share, long height) + TDelegatee delegatee, BigInteger share, long height) { if (share.Sign <= 0) { @@ -105,7 +106,7 @@ public virtual void Undelegate( throw new InvalidOperationException("Undelegation is full."); } - FungibleAssetValue fav = delegatee.Unbond(this, share, height); + FungibleAssetValue fav = delegatee.Unbond((TDelegator)this, share, height); unbondLockIn = unbondLockIn.LockIn( fav, height, height + delegatee.UnbondingPeriod); @@ -119,16 +120,16 @@ public virtual void Undelegate( Repository.SetUnbondLockIn(unbondLockIn); Repository.SetUnbondingSet( Repository.GetUnbondingSet().SetUnbonding(unbondLockIn)); - Repository.SetDelegator(this); + Repository.SetDelegator((TDelegator)this); } void IDelegator.Undelegate( IDelegatee delegatee, BigInteger share, long height) - => Undelegate((T)delegatee, share, height); + => Undelegate((TDelegatee)delegatee, share, height); public virtual void Redelegate( - T srcDelegatee, T dstDelegatee, BigInteger share, long height) + TDelegatee srcDelegatee, TDelegatee dstDelegatee, BigInteger share, long height) { if (share.Sign <= 0) { @@ -148,9 +149,9 @@ public virtual void Redelegate( } FungibleAssetValue fav = srcDelegatee.Unbond( - this, share, height); + (TDelegator)this, share, height); dstDelegatee.Bond( - this, fav, height); + (TDelegator)this, fav, height); RebondGrace srcRebondGrace = Repository.GetRebondGrace(srcDelegatee, Address).Grace( dstDelegatee.Address, fav, @@ -169,15 +170,15 @@ public virtual void Redelegate( Repository.SetRebondGrace(srcRebondGrace); Repository.SetUnbondingSet( Repository.GetUnbondingSet().SetUnbonding(srcRebondGrace)); - Repository.SetDelegator(this); + Repository.SetDelegator((TDelegator)this); } void IDelegator.Redelegate( IDelegatee srcDelegatee, IDelegatee dstDelegatee, BigInteger share, long height) - => Redelegate((T)srcDelegatee, (T)dstDelegatee, share, height); + => Redelegate((TDelegatee)srcDelegatee, (TDelegatee)dstDelegatee, share, height); public void CancelUndelegate( - T delegatee, FungibleAssetValue fav, long height) + TDelegatee delegatee, FungibleAssetValue fav, long height) { if (fav.Sign <= 0) { @@ -198,7 +199,7 @@ public void CancelUndelegate( throw new InvalidOperationException("Undelegation is full."); } - delegatee.Bond(this, fav, height); + delegatee.Bond((TDelegator)this, fav, height); unbondLockIn = unbondLockIn.Cancel(fav, height); Metadata.AddDelegatee(delegatee.Address); @@ -210,22 +211,22 @@ public void CancelUndelegate( Repository.SetUnbondLockIn(unbondLockIn); Repository.SetUnbondingSet( Repository.GetUnbondingSet().SetUnbonding(unbondLockIn)); - Repository.SetDelegator(this); + Repository.SetDelegator((TDelegator)this); } void IDelegator.CancelUndelegate( IDelegatee delegatee, FungibleAssetValue fav, long height) - => CancelUndelegate((T)delegatee, fav, height); + => CancelUndelegate((TDelegatee)delegatee, fav, height); public void ClaimReward( - T delegatee, long height) + TDelegatee delegatee, long height) { - delegatee.DistributeReward(this, height); + delegatee.DistributeReward((TDelegator)this, height); delegatee.StartNewRewardPeriod(height); - Repository.SetDelegator(this); + Repository.SetDelegator((TDelegator)this); } void IDelegator.ClaimReward(IDelegatee delegatee, long height) - => ClaimReward((T)delegatee, height); + => ClaimReward((TDelegatee)delegatee, height); } } From d3b5566356abf502822beac53a4962e35e2b802c Mon Sep 17 00:00:00 2001 From: s2quake Date: Wed, 18 Dec 2024 11:29:53 +0900 Subject: [PATCH 2/3] fix: Fix build errors in lib9c --- Lib9c/Action/Guild/ClaimGuildReward.cs | 4 +- Lib9c/Action/Guild/ClaimReward.cs | 4 +- .../Migration/MigratePlanetariumValidator.cs | 8 ++-- Lib9c/Action/InitializeStates.cs | 4 +- Lib9c/Action/Stake.cs | 8 ++-- .../ClaimValidatorRewardSelf.cs | 8 ++-- .../ValidatorDelegation/DelegateValidator.cs | 8 ++-- .../ValidatorDelegation/PromoteValidator.cs | 4 +- .../ReleaseValidatorUnbondings.cs | 2 +- .../ValidatorDelegation/SlashValidator.cs | 8 ++-- .../UndelegateValidator.cs | 8 ++-- .../ValidatorDelegation/UnjailValidator.cs | 2 +- .../ValidatorDelegation/UpdateValidators.cs | 16 ++++---- Lib9c/Model/Guild/Guild.cs | 8 ++-- Lib9c/Model/Guild/GuildDelegatee.cs | 2 +- Lib9c/Model/Guild/GuildDelegator.cs | 2 +- Lib9c/Model/Guild/GuildParticipant.cs | 38 +++++++++---------- Lib9c/Model/Guild/GuildRepository.cs | 30 ++++----------- Lib9c/Module/Guild/GuildDelegateeModule.cs | 4 +- Lib9c/Module/Guild/GuildModule.cs | 2 +- Lib9c/Module/Guild/GuildParticipantModule.cs | 6 +-- .../ValidatorDelegateeModule.cs | 4 +- .../ValidatorDelegatorModule.cs | 2 +- .../ValidatorDelegation/ValidatorDelegatee.cs | 17 +++++---- .../ValidatorDelegation/ValidatorDelegator.cs | 3 +- .../ValidatorRepository.cs | 35 ++++++----------- 26 files changed, 106 insertions(+), 131 deletions(-) diff --git a/Lib9c/Action/Guild/ClaimGuildReward.cs b/Lib9c/Action/Guild/ClaimGuildReward.cs index 7a05ee74fc..c7fe23150c 100644 --- a/Lib9c/Action/Guild/ClaimGuildReward.cs +++ b/Lib9c/Action/Guild/ClaimGuildReward.cs @@ -44,8 +44,8 @@ public override IWorld Execute(IActionContext context) } var repository = new ValidatorRepository(guildRepository); - var validatorDelegatee = repository.GetValidatorDelegatee(guild.ValidatorAddress); - var validatorDelegator = repository.GetValidatorDelegator(guild.Address); + var validatorDelegatee = repository.GetDelegatee(guild.ValidatorAddress); + var validatorDelegator = repository.GetDelegator(guild.Address); validatorDelegator.ClaimReward(validatorDelegatee, context.BlockIndex); return repository.World; diff --git a/Lib9c/Action/Guild/ClaimReward.cs b/Lib9c/Action/Guild/ClaimReward.cs index 51e45fa034..955f03fac3 100644 --- a/Lib9c/Action/Guild/ClaimReward.cs +++ b/Lib9c/Action/Guild/ClaimReward.cs @@ -37,8 +37,8 @@ public override IWorld Execute(IActionContext context) var guildParticipant = repository.GetGuildParticipant(context.Signer); var guild = repository.GetGuild(guildParticipant.GuildAddress); - var guildDelegatee = repository.GetGuildDelegatee(guild.ValidatorAddress); - var guildDelegator = repository.GetGuildDelegator(context.Signer); + var guildDelegatee = repository.GetDelegatee(guild.ValidatorAddress); + var guildDelegator = repository.GetDelegator(context.Signer); guildDelegator.ClaimReward(guildDelegatee, context.BlockIndex); return repository.World; diff --git a/Lib9c/Action/Guild/Migration/MigratePlanetariumValidator.cs b/Lib9c/Action/Guild/Migration/MigratePlanetariumValidator.cs index 98ef4ee0f4..d658167d25 100644 --- a/Lib9c/Action/Guild/Migration/MigratePlanetariumValidator.cs +++ b/Lib9c/Action/Guild/Migration/MigratePlanetariumValidator.cs @@ -53,7 +53,7 @@ public override IWorld Execute(IActionContext context) planetariumGuildAddress); var validatorRepository = new ValidatorRepository(guildRepository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee( + var validatorDelegatee = validatorRepository.GetDelegatee( planetariumGuild.ValidatorAddress); var validatorSet = world.GetValidatorSet(); @@ -71,13 +71,13 @@ public override IWorld Execute(IActionContext context) } validatorDelegatee.Activate(); - validatorRepository.SetValidatorDelegatee(validatorDelegatee); + validatorRepository.SetDelegatee(validatorDelegatee); guildRepository.UpdateWorld(validatorRepository.World); - var guildDelegatee = guildRepository.GetGuildDelegatee( + var guildDelegatee = guildRepository.GetDelegatee( planetariumGuild.ValidatorAddress); guildDelegatee.Activate(); - guildRepository.SetGuildDelgatee(guildDelegatee); + guildRepository.SetDelegatee(guildDelegatee); return guildRepository.World; } diff --git a/Lib9c/Action/InitializeStates.cs b/Lib9c/Action/InitializeStates.cs index c49a1671e5..9f81f0b655 100644 --- a/Lib9c/Action/InitializeStates.cs +++ b/Lib9c/Action/InitializeStates.cs @@ -214,12 +214,12 @@ public override IWorld Execute(IActionContext context) var validatorRepository = new ValidatorRepository(states, ctx); var validatorDelegatee = validatorRepository.CreateValidatorDelegatee( validator.PublicKey, ValidatorDelegatee.DefaultCommissionPercentage); - var validatorDelegator = validatorRepository.GetValidatorDelegator(validator.OperatorAddress); + var validatorDelegator = validatorRepository.GetDelegator(validator.OperatorAddress); validatorDelegatee.Bond(validatorDelegator, delegationFAV, context.BlockIndex); var guildRepository = new GuildRepository(validatorRepository); var guildDelegatee = guildRepository.CreateGuildDelegatee(validator.OperatorAddress); - var guildDelegator = guildRepository.GetGuildDelegator(validator.OperatorAddress); + var guildDelegator = guildRepository.GetDelegator(validator.OperatorAddress); guildDelegator.Delegate(guildDelegatee, delegationFAV, context.BlockIndex); states = guildRepository.World; } diff --git a/Lib9c/Action/Stake.cs b/Lib9c/Action/Stake.cs index b59ead3e07..e9c52df9fa 100644 --- a/Lib9c/Action/Stake.cs +++ b/Lib9c/Action/Stake.cs @@ -226,15 +226,15 @@ private static IWorld ContractNewStake( if (guildRepository.TryGetGuildParticipant(agentAddress, out var guildParticipant)) { var guild = guildRepository.GetGuild(guildParticipant.GuildAddress); - var guildDelegatee = guildRepository.GetGuildDelegatee(guild.ValidatorAddress); + var guildDelegatee = guildRepository.GetDelegatee(guild.ValidatorAddress); var share = guildDelegatee.ShareFromFAV(gg); - var guildDelegator = guildRepository.GetGuildDelegator(agentAddress); + var guildDelegator = guildRepository.GetDelegator(agentAddress); guildDelegatee.Unbond(guildDelegator, share, height); var validatorRepository = new ValidatorRepository(guildRepository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(guild.ValidatorAddress); - var validatorDelegator = validatorRepository.GetValidatorDelegator(guild.Address); + var validatorDelegatee = validatorRepository.GetDelegatee(guild.ValidatorAddress); + var validatorDelegator = validatorRepository.GetDelegator(guild.Address); validatorDelegatee.Unbond(validatorDelegator, share, height); state = validatorRepository.World; diff --git a/Lib9c/Action/ValidatorDelegation/ClaimValidatorRewardSelf.cs b/Lib9c/Action/ValidatorDelegation/ClaimValidatorRewardSelf.cs index 412e86f6c5..2be341b01f 100644 --- a/Lib9c/Action/ValidatorDelegation/ClaimValidatorRewardSelf.cs +++ b/Lib9c/Action/ValidatorDelegation/ClaimValidatorRewardSelf.cs @@ -38,13 +38,13 @@ public override IWorld Execute(IActionContext context) var world = context.PreviousState; var repository = new ValidatorRepository(world, context); - var validatorDelegatee = repository.GetValidatorDelegatee(context.Signer); - var validatorDelegator = repository.GetValidatorDelegator(context.Signer); + var validatorDelegatee = repository.GetDelegatee(context.Signer); + var validatorDelegator = repository.GetDelegator(context.Signer); validatorDelegator.ClaimReward(validatorDelegatee, context.BlockIndex); var guildRepository = new GuildRepository(repository); - var guildDelegatee = guildRepository.GetGuildDelegatee(context.Signer); - var guildDelegator = guildRepository.GetGuildDelegator(context.Signer); + var guildDelegatee = guildRepository.GetDelegatee(context.Signer); + var guildDelegator = guildRepository.GetDelegator(context.Signer); guildDelegator.ClaimReward(guildDelegatee, context.BlockIndex); return guildRepository.World; diff --git a/Lib9c/Action/ValidatorDelegation/DelegateValidator.cs b/Lib9c/Action/ValidatorDelegation/DelegateValidator.cs index fbfcad76ed..0f1745a3d1 100644 --- a/Lib9c/Action/ValidatorDelegation/DelegateValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/DelegateValidator.cs @@ -51,13 +51,13 @@ public override IWorld Execute(IActionContext context) } var guildRepository = new GuildRepository(context.PreviousState, context); - var guildDelegatee = guildRepository.GetGuildDelegatee(context.Signer); - var guildDelegator = guildRepository.GetGuildDelegator(context.Signer); + var guildDelegatee = guildRepository.GetDelegatee(context.Signer); + var guildDelegator = guildRepository.GetDelegator(context.Signer); guildDelegator.Delegate(guildDelegatee, FAV, context.BlockIndex); var validatorRepository = new ValidatorRepository(guildRepository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(context.Signer); - var validatorDelegator = validatorRepository.GetValidatorDelegator(context.Signer); + var validatorDelegatee = validatorRepository.GetDelegatee(context.Signer); + var validatorDelegator = validatorRepository.GetDelegator(context.Signer); validatorDelegatee.Bond(validatorDelegator, FAV, context.BlockIndex); return validatorRepository.World; diff --git a/Lib9c/Action/ValidatorDelegation/PromoteValidator.cs b/Lib9c/Action/ValidatorDelegation/PromoteValidator.cs index 63f892c011..ee03c8cdc4 100644 --- a/Lib9c/Action/ValidatorDelegation/PromoteValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/PromoteValidator.cs @@ -85,12 +85,12 @@ public IWorld ExecutePublic(IActionContext context) var repository = new ValidatorRepository(world, context); var validatorDelegatee = repository.CreateValidatorDelegatee(PublicKey, CommissionPercentage); - var validatorDelegator = repository.GetValidatorDelegator(context.Signer); + var validatorDelegator = repository.GetDelegator(context.Signer); validatorDelegatee.Bond(validatorDelegator, FAV, context.BlockIndex); var guildRepository = new GuildRepository(repository); var guildDelegatee = guildRepository.CreateGuildDelegatee(context.Signer); - var guildDelegator = guildRepository.GetGuildDelegator(context.Signer); + var guildDelegator = guildRepository.GetDelegator(context.Signer); guildDelegator.Delegate(guildDelegatee, FAV, context.BlockIndex); return guildRepository.World; diff --git a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs index 71ff907197..aabba19fcd 100644 --- a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs +++ b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs @@ -114,7 +114,7 @@ private static bool IsValidator(IWorld world, IActionContext context, Address ad var repository = new ValidatorRepository(world, context); try { - repository.GetValidatorDelegatee(address); + repository.GetDelegatee(address); return true; } catch (FailedLoadStateException) diff --git a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs index e97424efc0..1b7014cbe6 100644 --- a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs @@ -51,7 +51,7 @@ public override IWorld Execute(IActionContext context) foreach (var abstain in abstainsToSlash) { - var validatorDelegatee = repository.GetValidatorDelegatee(abstain.Address); + var validatorDelegatee = repository.GetDelegatee(abstain.Address); if (validatorDelegatee.Jailed) { continue; @@ -61,7 +61,7 @@ public override IWorld Execute(IActionContext context) validatorDelegatee.Jail(context.BlockIndex + AbstainJailTime); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var guildDelegatee = guildRepository.GetGuildDelegatee(abstain.Address); + var guildDelegatee = guildRepository.GetDelegatee(abstain.Address); guildDelegatee.Slash(LivenessSlashFactor, context.BlockIndex, context.BlockIndex); repository.UpdateWorld(guildRepository.World); } @@ -76,12 +76,12 @@ public override IWorld Execute(IActionContext context) throw new Exception("Evidence height is greater than block index."); } - var validatorDelegatee = repository.GetValidatorDelegatee(e.TargetAddress); + var validatorDelegatee = repository.GetDelegatee(e.TargetAddress); validatorDelegatee.Slash(DuplicateVoteSlashFactor, e.Height, context.BlockIndex); validatorDelegatee.Tombstone(); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var guildDelegatee = guildRepository.GetGuildDelegatee(e.TargetAddress); + var guildDelegatee = guildRepository.GetDelegatee(e.TargetAddress); guildDelegatee.Slash(DuplicateVoteSlashFactor, e.Height, context.BlockIndex); repository.UpdateWorld(guildRepository.World); break; diff --git a/Lib9c/Action/ValidatorDelegation/UndelegateValidator.cs b/Lib9c/Action/ValidatorDelegation/UndelegateValidator.cs index 06a9898954..516ff802ca 100644 --- a/Lib9c/Action/ValidatorDelegation/UndelegateValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/UndelegateValidator.cs @@ -51,13 +51,13 @@ public override IWorld Execute(IActionContext context) } var guildRepository = new GuildRepository(context.PreviousState, context); - var guildDelegatee = guildRepository.GetGuildDelegatee(context.Signer); - var guildDelegator = guildRepository.GetGuildDelegator(context.Signer); + var guildDelegatee = guildRepository.GetDelegatee(context.Signer); + var guildDelegator = guildRepository.GetDelegator(context.Signer); guildDelegator.Undelegate(guildDelegatee, Share, context.BlockIndex); var validatorRepository = new ValidatorRepository(guildRepository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(context.Signer); - var validatorDelegator = validatorRepository.GetValidatorDelegator(context.Signer); + var validatorDelegatee = validatorRepository.GetDelegatee(context.Signer); + var validatorDelegator = validatorRepository.GetDelegator(context.Signer); validatorDelegatee.Unbond(validatorDelegator, Share, context.BlockIndex); return validatorRepository.World; diff --git a/Lib9c/Action/ValidatorDelegation/UnjailValidator.cs b/Lib9c/Action/ValidatorDelegation/UnjailValidator.cs index a232dcc717..bc060f7805 100644 --- a/Lib9c/Action/ValidatorDelegation/UnjailValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/UnjailValidator.cs @@ -33,7 +33,7 @@ public override IWorld Execute(IActionContext context) var world = context.PreviousState; var repository = new ValidatorRepository(world, context); - var delegatee = repository.GetValidatorDelegatee(context.Signer); + var delegatee = repository.GetDelegatee(context.Signer); delegatee.Unjail(context.BlockIndex); return repository.World; diff --git a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs index ff6b42355d..cf4d6bee87 100644 --- a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs +++ b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs @@ -35,26 +35,26 @@ public override IWorld Execute(IActionContext context) foreach (var deactivated in prevValidators.Select(v => v.OperatorAddress) .Except(validators.Select(v => v.OperatorAddress))) { - var validatorDelegatee = repository.GetValidatorDelegatee(deactivated); + var validatorDelegatee = repository.GetDelegatee(deactivated); validatorDelegatee.Deactivate(); - repository.SetValidatorDelegatee(validatorDelegatee); + repository.SetDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var guildDelegatee = guildRepository.GetGuildDelegatee(deactivated); + var guildDelegatee = guildRepository.GetDelegatee(deactivated); guildDelegatee.Deactivate(); - guildRepository.SetGuildDelgatee(guildDelegatee); + guildRepository.SetDelegatee(guildDelegatee); repository.UpdateWorld(guildRepository.World); } foreach (var activated in validators.Select(v => v.OperatorAddress) .Except(prevValidators.Select(v => v.OperatorAddress))) { - var validatorDelegatee = repository.GetValidatorDelegatee(activated); + var validatorDelegatee = repository.GetDelegatee(activated); validatorDelegatee.Activate(); - repository.SetValidatorDelegatee(validatorDelegatee); + repository.SetDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var guildDelegatee = guildRepository.GetGuildDelegatee(activated); + var guildDelegatee = guildRepository.GetDelegatee(activated); guildDelegatee.Activate(); - guildRepository.SetGuildDelgatee(guildDelegatee); + guildRepository.SetDelegatee(guildDelegatee); repository.UpdateWorld(guildRepository.World); } diff --git a/Lib9c/Model/Guild/Guild.cs b/Lib9c/Model/Guild/Guild.cs index c30d184cd2..ef32dcb07f 100644 --- a/Lib9c/Model/Guild/Guild.cs +++ b/Lib9c/Model/Guild/Guild.cs @@ -75,13 +75,13 @@ public Guild( public void ClaimReward(Address validatorAddress, long height) { - var guildDelegatee = Repository.GetGuildDelegatee(validatorAddress); - var guildDelegator = Repository.GetGuildDelegator(Address); + var guildDelegatee = Repository.GetDelegatee(validatorAddress); + var guildDelegator = Repository.GetDelegator(Address); guildDelegator.ClaimReward(guildDelegatee, height); var validatorRepository = new ValidatorRepository(Repository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(validatorAddress); - var validatorDelegator = validatorRepository.GetValidatorDelegator(Address); + var validatorDelegatee = validatorRepository.GetDelegatee(validatorAddress); + var validatorDelegator = validatorRepository.GetDelegator(Address); validatorDelegator.ClaimReward(validatorDelegatee, height); Repository.UpdateWorld(validatorRepository.World); diff --git a/Lib9c/Model/Guild/GuildDelegatee.cs b/Lib9c/Model/Guild/GuildDelegatee.cs index 1ffedb2514..1a852fec5a 100644 --- a/Lib9c/Model/Guild/GuildDelegatee.cs +++ b/Lib9c/Model/Guild/GuildDelegatee.cs @@ -10,7 +10,7 @@ namespace Nekoyume.Model.Guild { public class GuildDelegatee - : Delegatee, IEquatable + : Delegatee, IEquatable { public GuildDelegatee( Address address, diff --git a/Lib9c/Model/Guild/GuildDelegator.cs b/Lib9c/Model/Guild/GuildDelegator.cs index 5184114888..d36107a240 100644 --- a/Lib9c/Model/Guild/GuildDelegator.cs +++ b/Lib9c/Model/Guild/GuildDelegator.cs @@ -6,7 +6,7 @@ namespace Nekoyume.Model.Guild { public class GuildDelegator - : Delegator, IEquatable + : Delegator, IEquatable { public GuildDelegator( Address address, diff --git a/Lib9c/Model/Guild/GuildParticipant.cs b/Lib9c/Model/Guild/GuildParticipant.cs index bdf782cd5b..aa23794644 100644 --- a/Lib9c/Model/Guild/GuildParticipant.cs +++ b/Lib9c/Model/Guild/GuildParticipant.cs @@ -63,10 +63,10 @@ public GuildParticipant( public AgentAddress Address { get; } public Address DelegationPoolAddress - => Repository.GetGuildDelegator(Address).DelegationPoolAddress; + => Repository.GetDelegator(Address).DelegationPoolAddress; public Address RewardAddress - => Repository.GetGuildDelegator(Address).RewardAddress; + => Repository.GetDelegator(Address).RewardAddress; public GuildRepository Repository { get; } @@ -85,13 +85,13 @@ public void Delegate(Guild guild, FungibleAssetValue fav, long height) nameof(fav), fav, "Fungible asset value must be positive."); } - var guildDelegatee = Repository.GetGuildDelegatee(guild.ValidatorAddress); - var guildDelegator = Repository.GetGuildDelegator(Address); + var guildDelegatee = Repository.GetDelegatee(guild.ValidatorAddress); + var guildDelegator = Repository.GetDelegator(Address); guildDelegator.Delegate(guildDelegatee, fav, height); var validatorRepository = new ValidatorRepository(Repository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(guild.ValidatorAddress); - var validatorDelegator = validatorRepository.GetValidatorDelegator(guild.Address); + var validatorDelegatee = validatorRepository.GetDelegatee(guild.ValidatorAddress); + var validatorDelegator = validatorRepository.GetDelegator(guild.Address); validatorDelegatee.Bond(validatorDelegator, fav, height); Repository.UpdateWorld(validatorRepository.World); @@ -111,13 +111,13 @@ public void Undelegate(Guild guild, BigInteger share, long height) nameof(height), height, "Height must be positive."); } - var guildDelegatee = Repository.GetGuildDelegatee(guild.ValidatorAddress); - var guildDelegator = Repository.GetGuildDelegator(Address); + var guildDelegatee = Repository.GetDelegatee(guild.ValidatorAddress); + var guildDelegator = Repository.GetDelegator(Address); guildDelegator.Undelegate(guildDelegatee, share, height); var validatorRepository = new ValidatorRepository(Repository); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(guild.ValidatorAddress); - var validatorDelegator = validatorRepository.GetValidatorDelegator(guild.Address); + var validatorDelegatee = validatorRepository.GetDelegatee(guild.ValidatorAddress); + var validatorDelegator = validatorRepository.GetDelegator(guild.Address); validatorDelegatee.Unbond(validatorDelegator, share, height); Repository.UpdateWorld(validatorRepository.World); @@ -138,17 +138,17 @@ public void Redelegate( nameof(height), height, "Height must be positive."); } - var srcGuildDelegatee = Repository.GetGuildDelegatee(srcGuild.ValidatorAddress); - var dstGuildDelegator = Repository.GetGuildDelegatee(dstGuild.ValidatorAddress); - var guildDelegator = Repository.GetGuildDelegator(Address); + var srcGuildDelegatee = Repository.GetDelegatee(srcGuild.ValidatorAddress); + var dstGuildDelegator = Repository.GetDelegatee(dstGuild.ValidatorAddress); + var guildDelegator = Repository.GetDelegator(Address); guildDelegator.Redelegate(srcGuildDelegatee, dstGuildDelegator, share, height); var validatorRepository = new ValidatorRepository(Repository); - var srcValidatorDelegatee = validatorRepository.GetValidatorDelegatee(srcGuild.ValidatorAddress); - var srcValidatorDelegator = validatorRepository.GetValidatorDelegator(srcGuild.Address); + var srcValidatorDelegatee = validatorRepository.GetDelegatee(srcGuild.ValidatorAddress); + var srcValidatorDelegator = validatorRepository.GetDelegator(srcGuild.Address); var fav = srcValidatorDelegatee.Unbond(srcValidatorDelegator, share, height); - var dstValidatorDelegatee = validatorRepository.GetValidatorDelegatee(dstGuild.ValidatorAddress); - var dstValidatorDelegator = validatorRepository.GetValidatorDelegator(dstGuild.Address); + var dstValidatorDelegatee = validatorRepository.GetDelegatee(dstGuild.ValidatorAddress); + var dstValidatorDelegator = validatorRepository.GetDelegator(dstGuild.Address); dstValidatorDelegatee.Bond(dstValidatorDelegator, fav, height); Repository.UpdateWorld(validatorRepository.World); @@ -156,8 +156,8 @@ public void Redelegate( public void ClaimReward(Guild guild, long height) { - var guildDelegatee = Repository.GetGuildDelegatee(guild.ValidatorAddress); - var guildDelegator = Repository.GetGuildDelegator(Address); + var guildDelegatee = Repository.GetDelegatee(guild.ValidatorAddress); + var guildDelegator = Repository.GetDelegator(Address); guildDelegator.ClaimReward(guildDelegatee, height); } diff --git a/Lib9c/Model/Guild/GuildRepository.cs b/Lib9c/Model/Guild/GuildRepository.cs index 54bd7d223b..6cd46fa2f2 100644 --- a/Lib9c/Model/Guild/GuildRepository.cs +++ b/Lib9c/Model/Guild/GuildRepository.cs @@ -9,7 +9,8 @@ namespace Nekoyume.Model.Guild { - public class GuildRepository : DelegationRepository + public class GuildRepository + : DelegationRepository { private readonly Address guildAddress = Addresses.Guild; private readonly Address guildParticipantAddress = Addresses.GuildParticipant; @@ -45,13 +46,10 @@ public GuildRepository(IWorld world, IActionContext actionContext) .SetAccount(guildAddress, _guildAccount) .SetAccount(guildParticipantAddress, _guildParticipantAccount); - public GuildDelegatee GetGuildDelegatee(Address address) + public override GuildDelegatee GetDelegatee(Address address) => new GuildDelegatee(address, this); - public override IDelegatee GetDelegatee(Address address) - => GetGuildDelegatee(address); - - public GuildDelegator GetGuildDelegator(Address address) + public override GuildDelegator GetDelegator(Address address) { try { @@ -65,24 +63,12 @@ public GuildDelegator GetGuildDelegator(Address address) this); } } - public override IDelegator GetDelegator(Address address) - => GetGuildDelegator(address); - - public void SetGuildDelgatee(GuildDelegatee guildDelegatee) - { - SetDelegateeMetadata(guildDelegatee.Metadata); - } - public override void SetDelegatee(IDelegatee delegatee) - => SetGuildDelgatee(delegatee as GuildDelegatee); - - public void SetGuildDelegator(GuildDelegator guildDelegator) - { - SetDelegatorMetadata(guildDelegator.Metadata); - } + public override void SetDelegatee(GuildDelegatee delegatee) + => SetDelegateeMetadata(delegatee.Metadata); - public override void SetDelegator(IDelegator delegator) - => SetGuildDelegator(delegator as GuildDelegator); + public override void SetDelegator(GuildDelegator delegator) + => SetDelegatorMetadata(delegator.Metadata); public Guild GetGuild(Address address) => _guildAccount.GetState(address) is IValue bencoded diff --git a/Lib9c/Module/Guild/GuildDelegateeModule.cs b/Lib9c/Module/Guild/GuildDelegateeModule.cs index 16a721a797..4816819a56 100644 --- a/Lib9c/Module/Guild/GuildDelegateeModule.cs +++ b/Lib9c/Module/Guild/GuildDelegateeModule.cs @@ -19,7 +19,7 @@ public static bool TryGetGuildDelegatee( { try { - guildDelegatee = repository.GetGuildDelegatee(address); + guildDelegatee = repository.GetDelegatee(address); return true; } catch @@ -49,7 +49,7 @@ public static GuildDelegatee CreateGuildDelegatee( new Currency[] { repository.World.GetGoldCurrency() }, repository); - repository.SetGuildDelgatee(guildDelegatee); + repository.SetDelegatee(guildDelegatee); return guildDelegatee; } diff --git a/Lib9c/Module/Guild/GuildModule.cs b/Lib9c/Module/Guild/GuildModule.cs index 34f1a85c32..472b2faf25 100644 --- a/Lib9c/Module/Guild/GuildModule.cs +++ b/Lib9c/Module/Guild/GuildModule.cs @@ -95,7 +95,7 @@ public static GuildRepository RemoveGuild( } var validatorRepository = new ValidatorRepository(repository.World, repository.ActionContext); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(guild.ValidatorAddress); + var validatorDelegatee = validatorRepository.GetDelegatee(guild.ValidatorAddress); var bond = validatorRepository.GetBond(validatorDelegatee, guild.Address); if (bond.Share > 0) { diff --git a/Lib9c/Module/Guild/GuildParticipantModule.cs b/Lib9c/Module/Guild/GuildParticipantModule.cs index 10f69ac6cf..9ab0e4fcf2 100644 --- a/Lib9c/Module/Guild/GuildParticipantModule.cs +++ b/Lib9c/Module/Guild/GuildParticipantModule.cs @@ -72,8 +72,8 @@ public static GuildRepository MoveGuild( var srcGuild = repository.GetGuild(guildParticipant1.GuildAddress); var dstGuild = repository.GetGuild(dstGuildAddress); var validatorRepository = new ValidatorRepository(repository.World, repository.ActionContext); - var srcValidatorDelegatee = validatorRepository.GetValidatorDelegatee(srcGuild.ValidatorAddress); - var dstValidatorDelegatee = validatorRepository.GetValidatorDelegatee(dstGuild.ValidatorAddress); + var srcValidatorDelegatee = validatorRepository.GetDelegatee(srcGuild.ValidatorAddress); + var dstValidatorDelegatee = validatorRepository.GetDelegatee(dstGuild.ValidatorAddress); if (dstValidatorDelegatee.Tombstoned) { throw new InvalidOperationException("The validator of the guild to move to has been tombstoned."); @@ -118,7 +118,7 @@ public static GuildRepository LeaveGuild( var height = repository.ActionContext.BlockIndex; var guildParticipant = repository.GetGuildParticipant(agentAddress); var validatorRepository = new ValidatorRepository(repository.World, repository.ActionContext); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(guild.ValidatorAddress); + var validatorDelegatee = validatorRepository.GetDelegatee(guild.ValidatorAddress); var bond = validatorRepository.GetBond(validatorDelegatee, guild.Address); var share = bond.Share; diff --git a/Lib9c/Module/ValidatorDelegation/ValidatorDelegateeModule.cs b/Lib9c/Module/ValidatorDelegation/ValidatorDelegateeModule.cs index 7581ed37f6..f247404f94 100644 --- a/Lib9c/Module/ValidatorDelegation/ValidatorDelegateeModule.cs +++ b/Lib9c/Module/ValidatorDelegation/ValidatorDelegateeModule.cs @@ -18,7 +18,7 @@ public static bool TryGetValidatorDelegatee( { try { - validatorDelegatee = repository.GetValidatorDelegatee(address); + validatorDelegatee = repository.GetDelegatee(address); return true; } catch @@ -46,7 +46,7 @@ public static ValidatorDelegatee CreateValidatorDelegatee( new Currency[] { repository.World.GetGoldCurrency(), Currencies.Mead }, repository); - repository.SetValidatorDelegatee(validatorDelegatee); + repository.SetDelegatee(validatorDelegatee); return validatorDelegatee; } diff --git a/Lib9c/Module/ValidatorDelegation/ValidatorDelegatorModule.cs b/Lib9c/Module/ValidatorDelegation/ValidatorDelegatorModule.cs index d352e6cf51..1deb03d048 100644 --- a/Lib9c/Module/ValidatorDelegation/ValidatorDelegatorModule.cs +++ b/Lib9c/Module/ValidatorDelegation/ValidatorDelegatorModule.cs @@ -14,7 +14,7 @@ public static bool TryGetValidatorDelegator( { try { - validatorDelegator = repository.GetValidatorDelegator(address); + validatorDelegator = repository.GetDelegator(address); return true; } catch diff --git a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs index 69513711e9..92db73c64e 100644 --- a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs +++ b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs @@ -15,7 +15,8 @@ namespace Nekoyume.ValidatorDelegation { public sealed class ValidatorDelegatee - : Delegatee, IEquatable, IBencodable + : Delegatee, + IEquatable, IBencodable { public ValidatorDelegatee( Address address, @@ -139,7 +140,7 @@ public void AllocateReward( Address RewardSource, long height) { - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; FungibleAssetValue rewardAllocated = (rewardToAllocate * validatorPower).DivRem(validatorSetPower).Quotient; @@ -193,7 +194,7 @@ public void SetCommissionPercentage(BigInteger percentage, long height) } public new void Unjail(long height) { - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; var selfDelegation = FAVFromShare(repository.GetBond(this, Address).Share); if (MinSelfDelegation > selfDelegation) { @@ -210,7 +211,7 @@ public void Activate() throw new InvalidOperationException("The validator is already active."); } - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; IsActive = true; Metadata.DelegationPoolAddress = ActiveDelegationPoolAddress; @@ -230,7 +231,7 @@ public void Deactivate() throw new InvalidOperationException("The validator is already inactive."); } - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; IsActive = false; Metadata.DelegationPoolAddress = InactiveDelegationPoolAddress; @@ -245,7 +246,7 @@ public void Deactivate() public void OnDelegationChanged(object? sender, long height) { - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; if (Jailed) { @@ -270,13 +271,13 @@ public void OnDelegationChanged(object? sender, long height) public void OnEnjailed(object? sender, EventArgs e) { - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; repository.SetValidatorList(repository.GetValidatorList().RemoveValidator(Validator.PublicKey)); } public void OnUnjailed(object? sender, EventArgs e) { - ValidatorRepository repository = (ValidatorRepository)Repository; + ValidatorRepository repository = Repository; repository.SetValidatorList(repository.GetValidatorList().SetValidator(Validator)); } diff --git a/Lib9c/ValidatorDelegation/ValidatorDelegator.cs b/Lib9c/ValidatorDelegation/ValidatorDelegator.cs index 206df3bf6d..1ccdfb5583 100644 --- a/Lib9c/ValidatorDelegation/ValidatorDelegator.cs +++ b/Lib9c/ValidatorDelegation/ValidatorDelegator.cs @@ -6,7 +6,8 @@ namespace Nekoyume.ValidatorDelegation { public sealed class ValidatorDelegator - : Delegator, IEquatable + : Delegator, + IEquatable { public ValidatorDelegator( Address address, diff --git a/Lib9c/ValidatorDelegation/ValidatorRepository.cs b/Lib9c/ValidatorDelegation/ValidatorRepository.cs index 7e4a6d5760..814141b92d 100644 --- a/Lib9c/ValidatorDelegation/ValidatorRepository.cs +++ b/Lib9c/ValidatorDelegation/ValidatorRepository.cs @@ -9,7 +9,8 @@ namespace Nekoyume.ValidatorDelegation { - public sealed class ValidatorRepository : DelegationRepository + public sealed class ValidatorRepository + : DelegationRepository { private readonly Address validatorListAddress = Addresses.ValidatorList; @@ -41,7 +42,7 @@ public ValidatorRepository(IWorld world, IActionContext actionContext) public override IWorld World => base.World .SetAccount(validatorListAddress, _validatorListAccount); - public ValidatorDelegatee GetValidatorDelegatee(Address address) + public override ValidatorDelegatee GetDelegatee(Address address) => delegateeAccount.GetState(address) is IValue bencoded ? new ValidatorDelegatee( address, @@ -49,10 +50,7 @@ public ValidatorDelegatee GetValidatorDelegatee(Address address) this) : throw new FailedLoadStateException("Delegatee does not exist."); - public override IDelegatee GetDelegatee(Address address) - => GetValidatorDelegatee(address); - - public ValidatorDelegator GetValidatorDelegator(Address address) + public override ValidatorDelegator GetDelegator(Address address) { try { @@ -67,9 +65,6 @@ public ValidatorDelegator GetValidatorDelegator(Address address) } } - public override IDelegator GetDelegator(Address address) - => new ValidatorDelegator(address, this); - public ValidatorList GetValidatorList() { IValue? value = _validatorListAccount.GetState(ValidatorList.Address); @@ -78,23 +73,15 @@ public ValidatorList GetValidatorList() : new ValidatorList(); } - public void SetValidatorDelegatee(ValidatorDelegatee validatorDelegatee) + public override void SetDelegatee(ValidatorDelegatee delegatee) { delegateeAccount = delegateeAccount.SetState( - validatorDelegatee.Address, validatorDelegatee.Bencoded); - SetDelegateeMetadata(validatorDelegatee.Metadata); - } - - public override void SetDelegatee(IDelegatee delegatee) - => SetValidatorDelegatee((ValidatorDelegatee)delegatee); - - public void SetValidatorDelegator(ValidatorDelegator validatorDelegator) - { - SetDelegatorMetadata(validatorDelegator.Metadata); + delegatee.Address, delegatee.Bencoded); + SetDelegateeMetadata(delegatee.Metadata); } - public override void SetDelegator(IDelegator delegator) - => SetValidatorDelegator((ValidatorDelegator)delegator); + public override void SetDelegator(ValidatorDelegator delegator) + => SetDelegatorMetadata(delegator.Metadata); public void SetValidatorList(ValidatorList validatorList) { @@ -104,9 +91,9 @@ public void SetValidatorList(ValidatorList validatorList) public void SetCommissionPercentage(Address address, BigInteger commissionPercentage, long height) { - ValidatorDelegatee validatorDelegatee = GetValidatorDelegatee(address); + ValidatorDelegatee validatorDelegatee = GetDelegatee(address); validatorDelegatee.SetCommissionPercentage(commissionPercentage, height); - SetValidatorDelegatee(validatorDelegatee); + SetDelegatee(validatorDelegatee); } public override void UpdateWorld(IWorld world) From 7a395e616fe62cebca8c2b342f6651345a6c61b5 Mon Sep 17 00:00:00 2001 From: s2quake Date: Wed, 18 Dec 2024 11:30:03 +0900 Subject: [PATCH 3/3] test: Fix build errors in test --- .Lib9c.Tests/Action/Guild/ClaimRewardTest.cs | 4 ++-- .Lib9c.Tests/Action/Guild/GuildTestBase.cs | 2 +- .../MigratePlanetariumValidatorTest.cs | 10 +++++----- .Lib9c.Tests/Action/StakeTest.cs | 2 +- .../AllocateGuildRewardTest.cs | 2 +- .../DelegateValidatorTest.cs | 6 +++--- .../PromoteValidatorTest.cs | 2 +- .../ReleaseValidatorUnbondingsTest.cs | 2 +- .../SetValidatorCommissionTest.cs | 8 ++++---- .../ValidatorDelegation/SlashValidatorTest.cs | 14 ++++++------- .../UndelegateValidatorTest.cs | 20 +++++++++---------- .../UnjailValidatorTest.cs | 2 +- .../UpdateValidatorsTest.cs | 2 +- .../ValidatorDelegationTestBase.cs | 8 ++++---- .Lib9c.Tests/Delegation/DummyDelegatee.cs | 4 ++-- .Lib9c.Tests/Delegation/DummyDelegator.cs | 4 ++-- .Lib9c.Tests/Delegation/DummyRepository.cs | 10 +++++----- .Lib9c.Tests/Delegation/TestDelegatee.cs | 2 +- .Lib9c.Tests/Delegation/TestDelegator.cs | 2 +- .Lib9c.Tests/Delegation/TestRepository.cs | 10 +++++----- 20 files changed, 58 insertions(+), 58 deletions(-) diff --git a/.Lib9c.Tests/Action/Guild/ClaimRewardTest.cs b/.Lib9c.Tests/Action/Guild/ClaimRewardTest.cs index 8a9e537bb8..e5ba128fd4 100644 --- a/.Lib9c.Tests/Action/Guild/ClaimRewardTest.cs +++ b/.Lib9c.Tests/Action/Guild/ClaimRewardTest.cs @@ -249,7 +249,7 @@ private void ExecuteWithFixture(IClaimRewardFixture fixture) // Calculate expected values for comparison with actual values. var expectedRepository = new ValidatorRepository(world, actionContext); var expectedGuildRepository = new GuildRepository(expectedRepository); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedTotalShares = expectedDelegatee.TotalShares; var expectedValidatorShare = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address).Share; @@ -346,7 +346,7 @@ var expectedProposerReward // Then var validatorRepository = new ValidatorRepository(world, actionContext); var guildRepository = new GuildRepository(world, actionContext); - var delegatee = validatorRepository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = validatorRepository.GetDelegatee(validatorKey.Address); var actualRemainGuildReward = world.GetBalance(delegatee.RewardRemainderPoolAddress, GuildAllocateRewardCurrency); var actualValidatorBalance = world.GetBalance(StakeState.DeriveAddress(validatorKey.Address), DelegationCurrency); var actualValidatorGuildReward = world.GetBalance(validatorKey.Address, GuildAllocateRewardCurrency); diff --git a/.Lib9c.Tests/Action/Guild/GuildTestBase.cs b/.Lib9c.Tests/Action/Guild/GuildTestBase.cs index 922c0fa4c6..eabad4b164 100644 --- a/.Lib9c.Tests/Action/Guild/GuildTestBase.cs +++ b/.Lib9c.Tests/Action/Guild/GuildTestBase.cs @@ -97,7 +97,7 @@ protected static IWorld EnsureToSlashValidator( var guildRepository = new GuildRepository( validatorRepository.World, validatorRepository.ActionContext); - var guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress); + var guildDelegatee = guildRepository.GetDelegatee(validatorAddress); guildDelegatee.Slash(slashFactor, blockHeight, blockHeight); return guildRepository.World; diff --git a/.Lib9c.Tests/Action/Guild/Migration/MigratePlanetariumValidatorTest.cs b/.Lib9c.Tests/Action/Guild/Migration/MigratePlanetariumValidatorTest.cs index cd15015166..4122d65c4e 100644 --- a/.Lib9c.Tests/Action/Guild/Migration/MigratePlanetariumValidatorTest.cs +++ b/.Lib9c.Tests/Action/Guild/Migration/MigratePlanetariumValidatorTest.cs @@ -36,8 +36,8 @@ public void Execute() var guildRepository = new GuildRepository(world, new ActionContext { }); var validatorRepository = new ValidatorRepository(world, new ActionContext { }); - var guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress); - var validatorDelegatee = validatorRepository.GetValidatorDelegatee(validatorAddress); + var guildDelegatee = guildRepository.GetDelegatee(validatorAddress); + var validatorDelegatee = validatorRepository.GetDelegatee(validatorAddress); Assert.False(validatorDelegatee.IsActive); Assert.Equal(ValidatorDelegatee.InactiveDelegationPoolAddress, guildDelegatee.DelegationPoolAddress); @@ -55,10 +55,10 @@ public void Execute() guildRepository = new GuildRepository(world, new ActionContext { }); validatorRepository = new ValidatorRepository(world, new ActionContext { }); - guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress); - validatorDelegatee = validatorRepository.GetValidatorDelegatee(validatorAddress); + guildDelegatee = guildRepository.GetDelegatee(validatorAddress); + validatorDelegatee = validatorRepository.GetDelegatee(validatorAddress); - Assert.True(validatorRepository.GetValidatorDelegatee(validatorAddress).IsActive); + Assert.True(validatorRepository.GetDelegatee(validatorAddress).IsActive); Assert.Equal(ValidatorDelegatee.ActiveDelegationPoolAddress, guildDelegatee.DelegationPoolAddress); Assert.Equal(ValidatorDelegatee.ActiveDelegationPoolAddress, validatorDelegatee.DelegationPoolAddress); Assert.Equal(delegated, world.GetBalance(ValidatorDelegatee.ActiveDelegationPoolAddress, Currencies.GuildGold)); diff --git a/.Lib9c.Tests/Action/StakeTest.cs b/.Lib9c.Tests/Action/StakeTest.cs index c2f2d499f3..58f8c4898c 100644 --- a/.Lib9c.Tests/Action/StakeTest.cs +++ b/.Lib9c.Tests/Action/StakeTest.cs @@ -569,7 +569,7 @@ private IWorld Execute( if (guildRepository.TryGetGuildParticipant(new AgentAddress(signer), out var guildParticipant)) { var guild = guildRepository.GetGuild(guildParticipant.GuildAddress); - var validator = guildRepository.GetGuildDelegatee(guild.ValidatorAddress); + var validator = guildRepository.GetDelegatee(guild.ValidatorAddress); var bond = guildRepository.GetBond(validator, signer); var amountNCG = _ncg * amount; var expectedGG = DelegationUtil.GetGuildCoinFromNCG(amountNCG); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/AllocateGuildRewardTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/AllocateGuildRewardTest.cs index 9451670e5b..8a85a4c724 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/AllocateGuildRewardTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/AllocateGuildRewardTest.cs @@ -230,7 +230,7 @@ var expectedProposerReward } var validatorAddress = vote.ValidatorPublicKey.Address; - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorAddress); + var actualDelegatee = actualRepository.GetDelegatee(validatorAddress); var validatorRewardAddress = actualDelegatee.DistributionPoolAddress(); var actualDelegationBalance = world.GetBalance(validatorAddress, DelegationCurrency); var actualCommission = world.GetBalance(validatorAddress, GuildAllocateRewardCurrency); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/DelegateValidatorTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/DelegateValidatorTest.cs index 246c1df300..52481ee576 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/DelegateValidatorTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/DelegateValidatorTest.cs @@ -64,7 +64,7 @@ public void Execute() // Then var repository = new ValidatorRepository(world, actionContext); - var validator = repository.GetValidatorDelegatee(validatorKey.Address); + var validator = repository.GetDelegatee(validatorKey.Address); var bond = repository.GetBond(validator, validatorKey.Address); var validatorList = repository.GetValidatorList(); @@ -222,7 +222,7 @@ private void ExecuteWithFixture(IDelegateValidatorFixture fixture) // When var expectedRepository = new ValidatorRepository(world, new ActionContext()); - var expectedValidator = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedValidator = expectedRepository.GetDelegatee(validatorKey.Address); var expectedValidatorBalance = validatorBalance - validatorCash - validatorCashToDelegate; var expectedPower = validatorCash.RawValue + validatorCashToDelegate.RawValue; @@ -237,7 +237,7 @@ private void ExecuteWithFixture(IDelegateValidatorFixture fixture) // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualValidator = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualValidator = actualRepository.GetDelegatee(validatorKey.Address); var actualValidatorBalance = GetBalance(world, validatorKey.Address); var actualPower = actualValidator.Power; var actualBond = actualRepository.GetBond(actualValidator, validatorKey.Address); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/PromoteValidatorTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/PromoteValidatorTest.cs index 81b7d0e1bf..06947c2200 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/PromoteValidatorTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/PromoteValidatorTest.cs @@ -45,7 +45,7 @@ public void Execute() // Then var repository = new ValidatorRepository(world, actionContext); - var validator = repository.GetValidatorDelegatee(validatorKey.Address); + var validator = repository.GetDelegatee(validatorKey.Address); var bond = repository.GetBond(validator, validatorKey.Address); var validatorList = repository.GetValidatorList(); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/ReleaseValidatorUnbondingsTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/ReleaseValidatorUnbondingsTest.cs index 79b1840e4f..5b961f5790 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/ReleaseValidatorUnbondingsTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/ReleaseValidatorUnbondingsTest.cs @@ -38,7 +38,7 @@ public void Execute() // When var expectedRepository = new GuildRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetGuildDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedUnbondingSet = expectedRepository.GetUnbondingSet(); var expectedReleaseCount = expectedUnbondingSet.UnbondingRefs.Count; var expectedDepositGold = expectedDelegatee.FAVFromShare(share); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs index 1b6ef02a35..5239bb8d3a 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/SetValidatorCommissionTest.cs @@ -83,7 +83,7 @@ public void Execute() // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualPercentage = actualDelegatee.CommissionPercentage; Assert.Equal(11, actualPercentage); @@ -119,7 +119,7 @@ public void Execute_Theory(int oldCommissionPercentage, int newCommissionPercent // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualPercentage = actualDelegatee.CommissionPercentage; Assert.Equal(newCommissionPercentage, actualPercentage); @@ -235,7 +235,7 @@ public void Execute_Theory_WitValue(int period) // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualPercentage = actualDelegatee.CommissionPercentage; Assert.Equal(expectedCommission, actualPercentage); @@ -280,7 +280,7 @@ public void Execute_With_SameValue_Throw() // When var repository = new ValidatorRepository(world, new ActionContext()); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); var commissionPercentage = delegatee.CommissionPercentage; var setValidatorCommission = new SetValidatorCommission( commissionPercentage: commissionPercentage); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/SlashValidatorTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/SlashValidatorTest.cs index 27699ba63a..437ac8016c 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/SlashValidatorTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/SlashValidatorTest.cs @@ -49,7 +49,7 @@ public void Execute() // When var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedValidatorShare = expectedRepository.GetBond( expectedDelegatee, validatorKey.Address).Share; @@ -96,7 +96,7 @@ public void Execute() // Then var balance = GetBalance(world, validatorKey.Address); var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualValidatorShare = actualRepository.GetBond(actualDelegatee, validatorKey.Address).Share; Assert.True(actualDelegatee.Jailed); @@ -165,7 +165,7 @@ public void Execute_ByAbstain() // Then var repository = new ValidatorRepository(world, actionContext); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); Assert.True(delegatee.Jailed); Assert.False(delegatee.Tombstoned); } @@ -184,7 +184,7 @@ public void Execute_ToJailedValidator_ThenNothingHappens() // When var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedJailed = expectedDelegatee.Jailed; var evidence = CreateDuplicateVoteEvidence(validatorKey, height - 1); var lastCommit = new BlockCommit( @@ -205,7 +205,7 @@ public void Execute_ToJailedValidator_ThenNothingHappens() // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualJailed = actualDelegatee.Jailed; Assert.Equal(expectedJailed, actualJailed); @@ -224,7 +224,7 @@ public void Execute_ByAbstain_ToJailedValidator_ThenNothingHappens() world = EnsureJailedValidator(world, validatorKey, ref height); var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedTotalDelegated = expectedDelegatee.TotalDelegated; // When @@ -249,7 +249,7 @@ public void Execute_ByAbstain_ToJailedValidator_ThenNothingHappens() // Then var actualRepisitory = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepisitory.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepisitory.GetDelegatee(validatorKey.Address); var actualTotalDelegated = actualDelegatee.TotalDelegated; Assert.True(actualDelegatee.Jailed); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/UndelegateValidatorTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/UndelegateValidatorTest.cs index c6638b28ee..d5b82968a8 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/UndelegateValidatorTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/UndelegateValidatorTest.cs @@ -53,7 +53,7 @@ public void Execute() // When var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address); var undelegateValidator = new UndelegateValidator(expectedBond.Share); actionContext = new ActionContext @@ -66,7 +66,7 @@ public void Execute() world = undelegateValidator.Execute(actionContext); var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualValidatorList = actualRepository.GetValidatorList(); var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address); @@ -182,7 +182,7 @@ public void Execute_FromJailedValidator() BlockIndex = height, }; var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address); var undelegateValidator = new UndelegateValidator(10); @@ -190,7 +190,7 @@ public void Execute_FromJailedValidator() // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address); Assert.Equal(expectedBond.Share - 10, actualBond.Share); @@ -215,7 +215,7 @@ public void Execute_FromTombstonedValidator() BlockIndex = height, }; var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address); var undelegateValidator = new UndelegateValidator(10); @@ -223,7 +223,7 @@ public void Execute_FromTombstonedValidator() // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address); Assert.Equal(expectedBond.Share - 10, actualBond.Share); @@ -244,7 +244,7 @@ public void Execute_JailsValidatorWhenUndelegationCausesLowDelegation() // When var expectedRepository = new ValidatorRepository(world, actionContext); - var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address); var expectedJailed = expectedDelegatee.Jailed; var undelegateValidator = new UndelegateValidator(10); @@ -258,7 +258,7 @@ public void Execute_JailsValidatorWhenUndelegationCausesLowDelegation() // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address); var actualJailed = actualDelegatee.Jailed; var actualJailedUntil = actualDelegatee.JailedUntil; @@ -280,7 +280,7 @@ private void ExecuteWithFixture(IUndelegateValidatorFixture fixture) // When var expectedRepository = new ValidatorRepository(world, new ActionContext()); - var expectedValidator = expectedRepository.GetValidatorDelegatee(validatorKey.Address); + var expectedValidator = expectedRepository.GetDelegatee(validatorKey.Address); var expectedValidatorBalance = validatorBalance - validatorCash; var expectedValidatorPower = expectedValidator.Power - fixture.ValidatorInfo.SubtractShare; @@ -296,7 +296,7 @@ private void ExecuteWithFixture(IUndelegateValidatorFixture fixture) // Then var actualRepository = new ValidatorRepository(world, actionContext); - var actualValidator = actualRepository.GetValidatorDelegatee(validatorKey.Address); + var actualValidator = actualRepository.GetDelegatee(validatorKey.Address); var actualValidatorBalance = GetBalance(world, validatorKey.Address); var actualValiatorPower = actualValidator.Power; diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/UnjailValidatorTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/UnjailValidatorTest.cs index 6bf61fd62e..49916366e1 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/UnjailValidatorTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/UnjailValidatorTest.cs @@ -44,7 +44,7 @@ public void Execute() // Then var repository = new ValidatorRepository(world, actionContext); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); Assert.False(delegatee.Jailed); Assert.Equal(-1, delegatee.JailedUntil); Assert.False(delegatee.Tombstoned); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/UpdateValidatorsTest.cs b/.Lib9c.Tests/Action/ValidatorDelegation/UpdateValidatorsTest.cs index 54741e28f9..91379c1287 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/UpdateValidatorsTest.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/UpdateValidatorsTest.cs @@ -90,7 +90,7 @@ public void Execute_ExcludesTombstonedValidator() var actualRepository = new ValidatorRepository(world, actionContext); var actualValidators = actualRepository.GetValidatorList() .ActiveSet().OrderBy(item => item.OperatorAddress).ToList(); - var tombstonedValidator = actualRepository.GetValidatorDelegatee(validatorKeys[0].Address); + var tombstonedValidator = actualRepository.GetDelegatee(validatorKeys[0].Address); Assert.True(tombstonedValidator.Tombstoned); Assert.Equal(expectedValidators.Count - 1, actualValidators.Count); diff --git a/.Lib9c.Tests/Action/ValidatorDelegation/ValidatorDelegationTestBase.cs b/.Lib9c.Tests/Action/ValidatorDelegation/ValidatorDelegationTestBase.cs index d7ace7f651..6a068ccafc 100644 --- a/.Lib9c.Tests/Action/ValidatorDelegation/ValidatorDelegationTestBase.cs +++ b/.Lib9c.Tests/Action/ValidatorDelegation/ValidatorDelegationTestBase.cs @@ -263,7 +263,7 @@ protected static IWorld EnsureJailedValidator( } var repository = new ValidatorRepository(world, new ActionContext()); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); if (delegatee.Jailed) { throw new ArgumentException( @@ -282,7 +282,7 @@ protected static IWorld EnsureJailedValidator( world, validatorKey.PublicKey, lastCommit, blockHeight); blockHeight++; repository = new ValidatorRepository(world, new ActionContext()); - delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + delegatee = repository.GetDelegatee(validatorKey.Address); if (delegatee.Jailed) { break; @@ -328,7 +328,7 @@ protected static IWorld EnsureUnjailedValidator( } var repository = new ValidatorRepository(world, new ActionContext()); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); if (!delegatee.Jailed) { throw new ArgumentException( @@ -439,7 +439,7 @@ protected static IWorld EnsureCommissionChangedValidator( var cooldown = ValidatorDelegatee.CommissionPercentageUpdateCooldown; var repository = new ValidatorRepository(world, new ActionContext()); - var delegatee = repository.GetValidatorDelegatee(validatorKey.Address); + var delegatee = repository.GetDelegatee(validatorKey.Address); var currentCommission = delegatee.CommissionPercentage; var increment = commissionPercentage > currentCommission ? 1 : -1; var preferredHeight = delegatee.CommissionPercentageLastUpdateHeight + cooldown; diff --git a/.Lib9c.Tests/Delegation/DummyDelegatee.cs b/.Lib9c.Tests/Delegation/DummyDelegatee.cs index 1ffaa83a82..9a417d35de 100644 --- a/.Lib9c.Tests/Delegation/DummyDelegatee.cs +++ b/.Lib9c.Tests/Delegation/DummyDelegatee.cs @@ -3,9 +3,9 @@ using Libplanet.Types.Assets; using Nekoyume.Delegation; -public sealed class DummyDelegatee : Delegatee +public sealed class DummyDelegatee : Delegatee { - public DummyDelegatee(Address address, IDelegationRepository repository) + public DummyDelegatee(Address address, DummyRepository repository) : base(address, repository) { } diff --git a/.Lib9c.Tests/Delegation/DummyDelegator.cs b/.Lib9c.Tests/Delegation/DummyDelegator.cs index d7b0223f56..91f8ff0698 100644 --- a/.Lib9c.Tests/Delegation/DummyDelegator.cs +++ b/.Lib9c.Tests/Delegation/DummyDelegator.cs @@ -1,9 +1,9 @@ using Libplanet.Crypto; using Nekoyume.Delegation; -public sealed class DummyDelegator : Delegator +public sealed class DummyDelegator : Delegator { - public DummyDelegator(Address address, IDelegationRepository repository) + public DummyDelegator(Address address, DummyRepository repository) : base(address, repository) { } diff --git a/.Lib9c.Tests/Delegation/DummyRepository.cs b/.Lib9c.Tests/Delegation/DummyRepository.cs index 2293822e19..2395975a0a 100644 --- a/.Lib9c.Tests/Delegation/DummyRepository.cs +++ b/.Lib9c.Tests/Delegation/DummyRepository.cs @@ -7,7 +7,7 @@ namespace Nekoyume.Delegation using Libplanet.Types.Assets; using Nekoyume.Action; - public class DummyRepository : DelegationRepository + public class DummyRepository : DelegationRepository { public DummyRepository(IWorld world, IActionContext context) : base( @@ -50,10 +50,10 @@ public override DummyDelegator GetDelegator(Address address) } } - public override void SetDelegatee(IDelegatee delegatee) - => SetDelegateeMetadata(((DummyDelegatee)delegatee).Metadata); + public override void SetDelegatee(DummyDelegatee delegatee) + => SetDelegateeMetadata(delegatee.Metadata); - public override void SetDelegator(IDelegator delegator) - => SetDelegatorMetadata(((DummyDelegator)delegator).Metadata); + public override void SetDelegator(DummyDelegator delegator) + => SetDelegatorMetadata(delegator.Metadata); } } diff --git a/.Lib9c.Tests/Delegation/TestDelegatee.cs b/.Lib9c.Tests/Delegation/TestDelegatee.cs index f1cfc67963..673d5e8778 100644 --- a/.Lib9c.Tests/Delegation/TestDelegatee.cs +++ b/.Lib9c.Tests/Delegation/TestDelegatee.cs @@ -4,7 +4,7 @@ namespace Lib9c.Tests.Delegation using Libplanet.Types.Assets; using Nekoyume.Delegation; - public sealed class TestDelegatee : Delegatee + public sealed class TestDelegatee : Delegatee { public TestDelegatee(Address address, TestRepository repository) : base(address, repository) diff --git a/.Lib9c.Tests/Delegation/TestDelegator.cs b/.Lib9c.Tests/Delegation/TestDelegator.cs index fa1c4c2e99..a5beaa1eaf 100644 --- a/.Lib9c.Tests/Delegation/TestDelegator.cs +++ b/.Lib9c.Tests/Delegation/TestDelegator.cs @@ -3,7 +3,7 @@ namespace Lib9c.Tests.Delegation using Libplanet.Crypto; using Nekoyume.Delegation; - public sealed class TestDelegator : Delegator + public sealed class TestDelegator : Delegator { public TestDelegator(Address address, TestRepository repo) : base(address, repo) diff --git a/.Lib9c.Tests/Delegation/TestRepository.cs b/.Lib9c.Tests/Delegation/TestRepository.cs index ccd60898c6..d7c68796f8 100644 --- a/.Lib9c.Tests/Delegation/TestRepository.cs +++ b/.Lib9c.Tests/Delegation/TestRepository.cs @@ -8,7 +8,7 @@ namespace Nekoyume.Delegation using Libplanet.Types.Assets; using Nekoyume.Action; - public class TestRepository : DelegationRepository + public class TestRepository : DelegationRepository { private readonly IActionContext _context; @@ -54,11 +54,11 @@ public override TestDelegator GetDelegator(Address address) } } - public override void SetDelegatee(IDelegatee delegatee) - => SetDelegateeMetadata(((TestDelegatee)delegatee).Metadata); + public override void SetDelegatee(TestDelegatee delegatee) + => SetDelegateeMetadata(delegatee.Metadata); - public override void SetDelegator(IDelegator delegator) - => SetDelegatorMetadata(((TestDelegator)delegator).Metadata); + public override void SetDelegator(TestDelegator delegator) + => SetDelegatorMetadata(delegator.Metadata); public void MintAsset(Address recipient, FungibleAssetValue value) => previousWorld = previousWorld.MintAsset(_context, recipient, value);