Skip to content

Commit

Permalink
feat: change get methods to iworldstate
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Mar 26, 2024
1 parent 21b7ce3 commit 8d6d406
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Lib9c.DPoS/Action/DPoSModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Lib9c.DPoS.Action
{
public static class DPoSModule
{
public static IValue? GetDPoSState(this IWorld world, Address address)
public static IValue? GetDPoSState(this IWorldState world, Address address)
{
return world.GetAccount(ReservedAddress.DPoSAccountAddress).GetState(address);
return world.GetAccountState(ReservedAddress.DPoSAccountAddress).GetState(address);
}

public static IWorld SetDPoSState(this IWorld world, Address address, IValue value)
Expand Down
4 changes: 1 addition & 3 deletions Lib9c.DPoS/Control/DelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace Lib9c.DPoS.Control
{
internal static class DelegateCtrl
{
internal static Delegation? GetDelegation(
IWorld states,
Address delegationAddress)
internal static Delegation? GetDelegation(IWorldState states, Address delegationAddress)
{
if (states.GetDPoSState(delegationAddress) is { } value)
{
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/RedelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Lib9c.DPoS.Control
internal static class RedelegateCtrl
{
internal static Redelegation? GetRedelegation(
IWorld states,
IWorldState states,
Address redelegationAddress)
{
if (states.GetDPoSState(redelegationAddress) is { } value)
Expand Down
10 changes: 10 additions & 0 deletions Lib9c.DPoS/Control/UnbondingSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace Lib9c.DPoS.Control
{
internal static class UnbondingSetCtrl
{
internal static UnbondingSet? GetUnbondingSet(IWorldState states)
{
if (states.GetDPoSState(ReservedAddress.UnbondingSet) is { } value)
{
return new UnbondingSet(value);
}

return null;
}

internal static (IWorld, UnbondingSet) FetchUnbondingSet(IWorld states)
{
UnbondingSet unbondingSet;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/UndelegateCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Lib9c.DPoS.Control
internal static class UndelegateCtrl
{
internal static Undelegation? GetUndelegation(
IWorld state,
IWorldState state,
Address undelegationAddress)
{
if (state.GetDPoSState(undelegationAddress) is { } value)
Expand Down
4 changes: 1 addition & 3 deletions Lib9c.DPoS/Control/ValidatorCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorCtrl
{
internal static Validator? GetValidator(
IWorld states,
Address validatorAddress)
internal static Validator? GetValidator(IWorldState states, Address validatorAddress)
{
if (states.GetDPoSState(validatorAddress) is { } value)
{
Expand Down
14 changes: 14 additions & 0 deletions Lib9c.DPoS/Control/ValidatorDelegationSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorDelegationSetCtrl
{
internal static ValidatorDelegationSet? GetValidatorDelegationSet(
IWorldState states, Address validatorAddress)
{
Address validatorDelegationSetAddress = ValidatorDelegationSet.DeriveAddress(
validatorAddress);

if (states.GetDPoSState(validatorDelegationSetAddress) is { } value)
{
return new ValidatorDelegationSet(value);
}

return null;
}

internal static (IWorld, ValidatorDelegationSet) FetchValidatorDelegationSet(
IWorld states, Address validatorAddress)
{
Expand Down
13 changes: 11 additions & 2 deletions Lib9c.DPoS/Control/ValidatorPowerIndexCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorPowerIndexCtrl
{
internal static (IWorld, ValidatorPowerIndex) FetchValidatorPowerIndex(
IWorld states)
internal static ValidatorPowerIndex? GetValidatorPowerIndex(IWorldState states)
{
if (states.GetDPoSState(ReservedAddress.ValidatorPowerIndex) is { } value)
{
return new ValidatorPowerIndex(value);
}

return null;
}

internal static (IWorld, ValidatorPowerIndex) FetchValidatorPowerIndex(IWorld states)
{
ValidatorPowerIndex validatorPowerIndex;
if (states.GetDPoSState(ReservedAddress.ValidatorPowerIndex) is { } value)
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.DPoS/Control/ValidatorRewardsCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Lib9c.DPoS.Control
internal static class ValidatorRewardsCtrl
{
internal static ValidatorRewards? GetValidatorRewards(
IWorld states,
IWorldState states,
Address validatorAddress)
{
if (states.GetDPoSState(validatorAddress) is { } value)
Expand Down
10 changes: 10 additions & 0 deletions Lib9c.DPoS/Control/ValidatorSetCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace Lib9c.DPoS.Control
{
internal static class ValidatorSetCtrl
{
internal static ValidatorSet? GetValidatorSet(IWorldState states, Address address)
{
if (states.GetDPoSState(address) is { } value)
{
return new ValidatorSet(value);
}

return null;
}

internal static (IWorld, ValidatorSet) FetchValidatorSet(IWorld states, Address address)
{
ValidatorSet validatorSet;
Expand Down

0 comments on commit 8d6d406

Please sign in to comment.