diff --git a/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs b/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs index 1c47d06289f..aa57635252a 100644 --- a/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs +++ b/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs @@ -3,6 +3,8 @@ using System.Collections.Immutable; using System.Numerics; using System.Security.Cryptography; +using Bencodex; +using Bencodex.Types; using GraphQL; using GraphQL.Execution; using GraphQL.Types; @@ -79,6 +81,7 @@ public async void Query() } } protocolVersion + raw }"; var store = new MemoryStore(); @@ -135,6 +138,11 @@ public async void Query() Assert.Equal( block.ProtocolVersion, resultData["protocolVersion"]); + + Assert.Equal( + block, + BlockMarshaler.UnmarshalBlock( + (Dictionary)new Codec().Decode(ByteUtil.ParseHex((string)resultData["raw"])))); } } } diff --git a/tools/Libplanet.Explorer/GraphTypes/BlockType.cs b/tools/Libplanet.Explorer/GraphTypes/BlockType.cs index 47801679095..94182100b70 100644 --- a/tools/Libplanet.Explorer/GraphTypes/BlockType.cs +++ b/tools/Libplanet.Explorer/GraphTypes/BlockType.cs @@ -1,3 +1,4 @@ +using Bencodex; using GraphQL.Types; using Libplanet.Explorer.Interfaces; using Libplanet.Types.Blocks; @@ -6,6 +7,8 @@ namespace Libplanet.Explorer.GraphTypes; public class BlockType : ObjectGraphType { + private static readonly Codec _codec = new(); + public BlockType(IBlockChainContext context) { Name = "Block"; @@ -93,5 +96,9 @@ public BlockType(IBlockChainContext context) name: "ProtocolVersion", description: "The protocol version number of the block.", resolve: ctx => ctx.Source.ProtocolVersion); + Field>( + name: "Raw", + description: "The bencodex serialization of the block", + resolve: ctx => _codec.Encode(ctx.Source.MarshalBlock())); } }