Skip to content

Commit

Permalink
fix: Add code to check validator delegation information
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Jan 6, 2025
1 parent 09704ac commit 5601115
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
1 change: 0 additions & 1 deletion NineChronicles.Headless/GraphTypes/DelegatorType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Numerics;
using GraphQL.Types;
using Libplanet.Types.Assets;
using Nekoyume.ValidatorDelegation;

namespace NineChronicles.Headless.GraphTypes;

Expand Down
41 changes: 31 additions & 10 deletions NineChronicles.Headless/GraphTypes/StateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using Nekoyume.Module.Guild;
using Nekoyume.TypedAddress;
using Nekoyume.ValidatorDelegation;
using Nekoyume.Module.ValidatorDelegation;

namespace NineChronicles.Headless.GraphTypes
{
Expand Down Expand Up @@ -797,22 +798,42 @@ public StateQuery()
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "agentAddress",
Description = "Address of agent."
Name = "address",
Description = "Agent or Validator address."
}
),
resolve: context =>
{
var address = context.GetArgument<Address>("agentAddress");
var address = context.GetArgument<Address>("address");
var agentAddress = new AgentAddress(address);
var repository = new GuildRepository(new World(context.Source.WorldState), new HallowActionContext { });
if (repository.TryGetGuildParticipant(agentAddress, out var guildParticipant))
var guildRepository = new GuildRepository(
new World(context.Source.WorldState), new HallowActionContext { });
if (guildRepository.TryGetGuildParticipant(agentAddress, out var guildParticipant))
{
var guild = guildRepository.GetGuild(guildParticipant.GuildAddress);
var guildDelegatee = guildRepository.GetDelegatee(guild.ValidatorAddress);
var bond = guildRepository.GetBond(guildDelegatee, guildParticipant.Address);
var totalDelegated = guildDelegatee.Metadata.TotalDelegatedFAV;
var totalShare = guildDelegatee.Metadata.TotalShares;
var lastDistributeHeight = bond.LastDistributeHeight ?? -1;
var share = bond.Share;
var fav = (share * totalDelegated).DivRem(totalShare).Quotient;
return new DelegatorType
{
LastDistributeHeight = lastDistributeHeight,
Share = share,
Fav = fav,
};
}

var validatorAddress = address;
var validatorRepository = new ValidatorRepository(
new World(context.Source.WorldState), new HallowActionContext { });
if (validatorRepository.TryGetValidatorDelegatee(validatorAddress, out var validatorDelegatee))
{
var guild = repository.GetGuild(guildParticipant.GuildAddress);
var delegatee = repository.GetDelegatee(guild.ValidatorAddress);
var bond = repository.GetBond(delegatee, guildParticipant.Address);
var totalDelegated = delegatee.Metadata.TotalDelegatedFAV;
var totalShare = delegatee.Metadata.TotalShares;
var bond = validatorRepository.GetBond(validatorDelegatee, address);
var totalDelegated = validatorDelegatee.Metadata.TotalDelegatedFAV;
var totalShare = validatorDelegatee.Metadata.TotalShares;
var lastDistributeHeight = bond.LastDistributeHeight ?? -1;
var share = bond.Share;
var fav = (share * totalDelegated).DivRem(totalShare).Quotient;
Expand Down

0 comments on commit 5601115

Please sign in to comment.