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

♻️ ⏪ Revert changes for old queries #3579

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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add issue or PR numbers about previous feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? I guess we can refer to #3560 maybe, but I don't think it'd help much. Also the whole point of this PR is to not fix the issue since we don't want to deal with the consequences of breaking the API. 😑


[#3559]: https://github.com/planetarium/libplanet/pull/3559
[#3560]: https://github.com/planetarium/libplanet/pull/3560
Expand All @@ -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
Expand Down
31 changes: 5 additions & 26 deletions Libplanet.Explorer.Tests/Queries/StateQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public async Task States()
addresses: [""0x5003712B63baAB98094aD678EA2B24BcE445D076"", ""0x0000000000000000000000000000000000000000""],
offsetBlockHash:
""01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b""
) {
hex
}
)
}
", source: source);
Assert.Null(result.Errors);
Expand All @@ -45,14 +43,7 @@ public async Task States()
object[] states =
Assert.IsAssignableFrom<object[]>(resultDict["states"]);
Assert.Equal(2, states.Length);
Assert.Equal(
new Dictionary<string, object>()
{
{ "hex", "6e" },
},
Assert.IsAssignableFrom<IDictionary<string, object>>(states[0])
);
Assert.Null(states[1]);
Assert.Equal(new[] { new byte[] { 110, }, null }, states);
}

[Fact]
Expand Down Expand Up @@ -186,9 +177,7 @@ public async Task ThrowExecutionErrorIfViolateMutualExclusive()
""01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"",
offsetStateRootHash:
""c33b27773104f75ac9df5b0533854108bd498fab31e5236b6f1e1f6404d5ef64""
) {
hex
}
)
}
", source: source);
Assert.IsType<ExecutionErrors>(result.Errors);
Expand All @@ -205,9 +194,7 @@ public async Task StatesBySrh()
addresses: [""0x5003712B63baAB98094aD678EA2B24BcE445D076"", ""0x0000000000000000000000000000000000000000""],
offsetStateRootHash:
""c33b27773104f75ac9df5b0533854108bd498fab31e5236b6f1e1f6404d5ef64""
) {
hex
}
)
}
", source: source);
Assert.Null(result.Errors);
Expand All @@ -216,15 +203,7 @@ public async Task StatesBySrh()
Assert.IsAssignableFrom<IDictionary<string, object>>(resultData!.ToValue());
object[] states =
Assert.IsAssignableFrom<object[]>(resultDict["states"]);
Assert.Equal(2, states.Length);
Assert.Equal(
new Dictionary<string, object>()
{
{ "hex", "6e" },
},
Assert.IsAssignableFrom<IDictionary<string, object>>(states[0])
);
Assert.Null(states[1]);
Assert.Equal(new[] { new byte[] { 110, }, null }, states);
}

[Fact]
Expand Down
51 changes: 51 additions & 0 deletions Libplanet.Explorer/GraphTypes/LegacyBencodexValueType.cs
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does we haven't more good naming...? I guess if you have plan about more refactoring, maybe you need LegacyBencodexValueV2Type later. 🙄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's just more work then. To be more sensible and be managable, we need an entirely new set of "V2" scheme which doesn't share the root. Then we'd have to create an entirely new copies of query related codes, management of V1 and V2 graph types, etc. 🙄

{
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;
}
}
}
2 changes: 1 addition & 1 deletion Libplanet.Explorer/Queries/StateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class StateQuery : ObjectGraphType<IBlockChainStates>
public StateQuery()
{
Name = "StateQuery";
Field<NonNullGraphType<ListGraphType<BencodexValueType>>>(
Field<NonNullGraphType<ListGraphType<LegacyBencodexValueType>>>(
"states",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ListGraphType<NonNullGraphType<AddressType>>>>
Expand Down
Loading