Skip to content

Commit

Permalink
feat: Add state query for guild
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Dec 17, 2024
1 parent 6270340 commit 856a271
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
38 changes: 38 additions & 0 deletions NineChronicles.Headless/GraphTypes/GuildType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using GraphQL.Types;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;
using Nekoyume.Model.Guild;

namespace NineChronicles.Headless.GraphTypes;

public class GuildType : ObjectGraphType<GuildType>
{
public Address Address { get; set; }

public Address ValidatorAddress { get; set; }

public Address GuildMasterAddress { get; set; }

public GuildType()
{
Field<NonNullGraphType<AddressType>>(
nameof(Address),
description: "Address of the guild",
resolve: context => context.Source.Address);
Field<NonNullGraphType<AddressType>>(
nameof(ValidatorAddress),
description: "Validator address of the guild",
resolve: context => context.Source.ValidatorAddress);
Field<NonNullGraphType<AddressType>>(
nameof(GuildMasterAddress),
description: "Guild master address of the guild",
resolve: context => context.Source.GuildMasterAddress);
}

public static GuildType FromDelegatee(Guild guild) => new GuildType
{
Address = guild.Address,
ValidatorAddress = guild.ValidatorAddress,
GuildMasterAddress = guild.GuildMasterAddress,
};
}
10 changes: 7 additions & 3 deletions NineChronicles.Headless/GraphTypes/StateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public StateQuery()
}
);

Field<AddressType>(
Field<GuildType>(
name: "guild",
description: "State for guild.",
arguments: new QueryArguments(
Expand All @@ -740,9 +740,13 @@ public StateQuery()
}

var repository = new GuildRepository(new World(context.Source.WorldState), new HallowActionContext { });
var joinedGuild = (Address?)repository.GetJoinedGuild(agentAddress);
if (repository.GetJoinedGuild(agentAddress) is { } guildAddress)
{
var guild = repository.GetGuild(guildAddress);
return GuildType.FromDelegatee(guild);
}

return joinedGuild;
return null;
}
);

Expand Down

0 comments on commit 856a271

Please sign in to comment.