Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add raw field to blockQuery #4006

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
}
Loading