From 880d954548c0d24c8e00397280b40af57fa05a55 Mon Sep 17 00:00:00 2001 From: eseiker Date: Thu, 5 Dec 2024 14:35:20 +0900 Subject: [PATCH] feat: add raw field to blockQuery Co-authored-by: sky1045 --- CHANGES.md | 2 ++ test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs | 8 ++++++++ tools/Libplanet.Explorer/GraphTypes/BlockType.cs | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7a821052d79..183d226ce99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ To be released. - Changed `IMessageCodec.Encode(MessageContent, PrivateKey, AppProtocolVersion, BoundPeer, DateTimeOffset, byte[]?)` to `IMessageCodec.Encode(Message, PrivateKey)`. [[#3997]] + - (Libplanet.Explorer) Added `raw` field to `BlockType`. [[#4006]] ### Backward-incompatible network protocol changes @@ -32,6 +33,7 @@ To be released. [#3997]: https://github.com/planetarium/libplanet/pull/3997 [#3999]: https://github.com/planetarium/libplanet/pull/3999 +[#4006]: https://github.com/planetarium/libplanet/pull/4006 Version 5.4.2 diff --git a/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs b/test/Libplanet.Explorer.Tests/GraphTypes/BlockTypeTest.cs index 772c4cfc066..3005d7703ac 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())); } }