Skip to content

Commit

Permalink
feat: add raw field to blockQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiker committed Dec 5, 2024
1 parent 7513c9b commit 8807eae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +81,7 @@ public async void Query()
}
}
protocolVersion
raw
}";

var store = new MemoryStore();
Expand Down Expand Up @@ -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"]))));
}
}
}
7 changes: 7 additions & 0 deletions tools/Libplanet.Explorer/GraphTypes/BlockType.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Bencodex;
using GraphQL.Types;
using Libplanet.Explorer.Interfaces;
using Libplanet.Types.Blocks;
Expand All @@ -6,6 +7,8 @@ namespace Libplanet.Explorer.GraphTypes;

public class BlockType : ObjectGraphType<Block>
{
private static readonly Codec _codec = new();

public BlockType(IBlockChainContext context)
{
Name = "Block";
Expand Down Expand Up @@ -93,5 +96,9 @@ public BlockType(IBlockChainContext context)
name: "ProtocolVersion",
description: "The protocol version number of the block.",
resolve: ctx => ctx.Source.ProtocolVersion);
Field<NonNullGraphType<ByteStringType>>(
name: "Raw",
description: "The bencodex serialization of the block",
resolve: ctx => _codec.Encode(ctx.Source.MarshalBlock()));
}
}

0 comments on commit 8807eae

Please sign in to comment.