diff --git a/CHANGES.md b/CHANGES.md index c06bb5bc2d9..98c9042b20f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -42,6 +42,10 @@ be compatible with this version, specifically, those that ran with - (Libplanet.Store) Added `FullNode.RemoveChild()` method. [[#3576]] - (Libplanet.Action) Added `IAccount.RemoveState()` interface method. [[#3577]] + - (Libplanet.Explorer) Added `LegacyBencodexValueType` class that is + a copy of an old `BencodexValueType` with its name changed + for backwards compatibility. Changed old `states` query + to use `LegacyBencodexValueType` instead of `BencodexValueType`. [[#3579]] [#3559]: https://github.com/planetarium/libplanet/pull/3559 [#3560]: https://github.com/planetarium/libplanet/pull/3560 @@ -54,6 +58,7 @@ be compatible with this version, specifically, those that ran with [#3574]: https://github.com/planetarium/libplanet/pull/3574 [#3576]: https://github.com/planetarium/libplanet/pull/3576 [#3577]: https://github.com/planetarium/libplanet/pull/3577 +[#3579]: https://github.com/planetarium/libplanet/pull/3579 Version 3.9.2 diff --git a/Libplanet.Explorer.Tests/Queries/StateQueryTest.cs b/Libplanet.Explorer.Tests/Queries/StateQueryTest.cs index f820cab6bbf..fe1e2fad5ef 100644 --- a/Libplanet.Explorer.Tests/Queries/StateQueryTest.cs +++ b/Libplanet.Explorer.Tests/Queries/StateQueryTest.cs @@ -33,9 +33,7 @@ public async Task States() addresses: [""0x5003712B63baAB98094aD678EA2B24BcE445D076"", ""0x0000000000000000000000000000000000000000""], offsetBlockHash: ""01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"" - ) { - hex - } + ) } ", source: source); Assert.Null(result.Errors); @@ -45,14 +43,7 @@ public async Task States() object[] states = Assert.IsAssignableFrom(resultDict["states"]); Assert.Equal(2, states.Length); - Assert.Equal( - new Dictionary() - { - { "hex", "6e" }, - }, - Assert.IsAssignableFrom>(states[0]) - ); - Assert.Null(states[1]); + Assert.Equal(new[] { new byte[] { 110, }, null }, states); } [Fact] @@ -186,9 +177,7 @@ public async Task ThrowExecutionErrorIfViolateMutualExclusive() ""01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"", offsetStateRootHash: ""c33b27773104f75ac9df5b0533854108bd498fab31e5236b6f1e1f6404d5ef64"" - ) { - hex - } + ) } ", source: source); Assert.IsType(result.Errors); @@ -205,9 +194,7 @@ public async Task StatesBySrh() addresses: [""0x5003712B63baAB98094aD678EA2B24BcE445D076"", ""0x0000000000000000000000000000000000000000""], offsetStateRootHash: ""c33b27773104f75ac9df5b0533854108bd498fab31e5236b6f1e1f6404d5ef64"" - ) { - hex - } + ) } ", source: source); Assert.Null(result.Errors); @@ -216,15 +203,7 @@ public async Task StatesBySrh() Assert.IsAssignableFrom>(resultData!.ToValue()); object[] states = Assert.IsAssignableFrom(resultDict["states"]); - Assert.Equal(2, states.Length); - Assert.Equal( - new Dictionary() - { - { "hex", "6e" }, - }, - Assert.IsAssignableFrom>(states[0]) - ); - Assert.Null(states[1]); + Assert.Equal(new[] { new byte[] { 110, }, null }, states); } [Fact] diff --git a/Libplanet.Explorer/GraphTypes/LegacyBencodexValueType.cs b/Libplanet.Explorer/GraphTypes/LegacyBencodexValueType.cs new file mode 100644 index 00000000000..8e10ed415ce --- /dev/null +++ b/Libplanet.Explorer/GraphTypes/LegacyBencodexValueType.cs @@ -0,0 +1,51 @@ +using System; +using Bencodex; +using GraphQL.Language.AST; +using GraphQL.Types; +using Libplanet.Common; + +namespace Libplanet.Explorer.GraphTypes +{ + public class LegacyBencodexValueType : StringGraphType + { + private static readonly Codec _codec = new(); + + public LegacyBencodexValueType() + { + Name = "LegacyBencodexValue"; + } + + public override object? Serialize(object? value) + { + if (value is Bencodex.Types.IValue iv) + { + return _codec.Encode(iv); + } + + return value; + } + + public override object? ParseValue(object? value) + { + return value switch + { + null => null, + string hex => _codec.Decode(ByteUtil.ParseHex(hex)), + _ => throw new ArgumentException( + $"Expected a hexadecimal string but {value}", + nameof(value) + ), + }; + } + + public override object? ParseLiteral(IValue? value) + { + if (value is StringValue) + { + return ParseValue(value.Value); + } + + return null; + } + } +} diff --git a/Libplanet.Explorer/Queries/StateQuery.cs b/Libplanet.Explorer/Queries/StateQuery.cs index 353a29d1f0a..962145f6261 100644 --- a/Libplanet.Explorer/Queries/StateQuery.cs +++ b/Libplanet.Explorer/Queries/StateQuery.cs @@ -15,7 +15,7 @@ public class StateQuery : ObjectGraphType public StateQuery() { Name = "StateQuery"; - Field>>( + Field>>( "states", arguments: new QueryArguments( new QueryArgument>>>