Skip to content

Commit

Permalink
Merge pull request #4006 from eseiker/blockquery-raw
Browse files Browse the repository at this point in the history
feat: add raw field to blockQuery
  • Loading branch information
riemannulus authored Dec 20, 2024
2 parents 57c20c1 + 880d954 commit 5fd31e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
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 5fd31e2

Please sign in to comment.