Skip to content

Commit

Permalink
Merge tag '4.0.3' into merge/4.0.3-to-main
Browse files Browse the repository at this point in the history
Libplanet 4.0.3
  • Loading branch information
greymistcube committed Feb 6, 2024
2 parents 6301df4 + c57e506 commit a6715fa
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 38 deletions.
17 changes: 17 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ To be released.
[#3644]: https://github.com/planetarium/libplanet/pull/3644


Version 4.0.3
-------------

Released on February 6, 2024.

- (Libplanet.Explorer) Revert GraphQL types to make it more compatible
with old schema. [[#3657]]
- Rolled back `TxResultType`'s name to auto generated `TxResultType`
from specified `TxResult`.
- Rolled back `BlockHash` and `TxId` to be handled as `IDGraphType`
instead of `BlockHashType` and `TxIdType` in legacy queries.
- Rolled back `HashDigest<SHA256>` to be handled as `HashDigestSHA256Type`
instead of `HashDigestType<T>` in legacy queries.

[#3657]: https://github.com/planetarium/libplanet/pull/3657


Version 4.0.2
-------------

Expand Down
4 changes: 2 additions & 2 deletions Libplanet.Explorer/GraphTypes/BlockCommitType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public BlockCommitType()
description: "The round of the block commit.",
resolve: x => x.Source.Round
);
Field<NonNullGraphType<BlockHashType>>(
Field<NonNullGraphType<IdGraphType>>(
name: "BlockHash",
description: "The hash of the block which contains block commit.",
resolve: ctx => ctx.Source.BlockHash
resolve: ctx => ctx.Source.BlockHash.ToString()
);
Field<NonNullGraphType<ListGraphType<NonNullGraphType<VoteType>>>>(
name: "Votes",
Expand Down
12 changes: 6 additions & 6 deletions Libplanet.Explorer/GraphTypes/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public BlockType(IBlockChainContext context)
Name = "Block";

// We need multiple row of description for clearer, not confusing explanation of field.
Field<NonNullGraphType<BlockHashType>>(
Field<NonNullGraphType<IdGraphType>>(
"Hash",
description: "A block's hash.",
resolve: ctx => ctx.Source.Hash
resolve: ctx => ctx.Source.Hash.ToString()
);
Field<NonNullGraphType<LongGraphType>>(
name: "Index",
Expand Down Expand Up @@ -47,11 +47,11 @@ public BlockType(IBlockChainContext context)
}
);
Field(x => x.Timestamp);
Field<NonNullGraphType<HashDigestType<SHA256>>>(
Field<NonNullGraphType<ByteStringType>>(
name: "StateRootHash",
description: "The hash of the resulting states after evaluating transactions " +
"and a block action (if exists)",
resolve: ctx => ctx.Source.StateRootHash);
resolve: ctx => ctx.Source.StateRootHash.ToByteArray());
Field<ByteStringType>(
name: "Signature",
description: "The digital signature of the whole block content (except for hash, " +
Expand Down Expand Up @@ -82,9 +82,9 @@ public BlockType(IBlockChainContext context)
deprecationReason: "Block does not have Nonce field in PBFT.",
resolve: _ => new byte[] { }
);
Field<NonNullGraphType<HashDigestType<SHA256>>>(
Field<NonNullGraphType<ByteStringType>>(
name: "PreEvaluationHash",
description: "The hash of PreEvaluationBlock.",
resolve: ctx => ctx.Source.PreEvaluationHash);
resolve: ctx => ctx.Source.PreEvaluationHash.ToByteArray());
}
}
4 changes: 2 additions & 2 deletions Libplanet.Explorer/GraphTypes/CurrencyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public CurrencyType()
"Whether the total supply of this currency is trackable.",
resolve: context => context.Source.TotalSupplyTrackable
);
Field<NonNullGraphType<HashDigestType<SHA1>>>(
Field<NonNullGraphType<ByteStringType>>(
"hash",
"The deterministic hash derived from other fields.",
resolve: context => context.Source.Hash
resolve: context => context.Source.Hash.ToByteArray()
);
}
}
44 changes: 44 additions & 0 deletions Libplanet.Explorer/GraphTypes/HashDigestSHA256Type.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#nullable disable
using System;
using System.Security.Cryptography;
using GraphQL.Language.AST;
using GraphQL.Types;
using Libplanet.Common;

namespace Libplanet.Explorer.GraphTypes
{
public class HashDigestSHA256Type : StringGraphType
{
public HashDigestSHA256Type()
{
Name = "HashDigest_SHA256";
}

public override object Serialize(object value)
{
if (value is HashDigest<SHA256> hash)
{
return hash.ToString();
}

return value;
}

public override object ParseValue(object value) =>
value switch
{
null => null,
string hex => HashDigest<SHA256>.FromString(hex),
_ => throw new ArgumentException(
$"Expected a hexadecimal string but {value}", nameof(value)),
};

public override object ParseLiteral(IValue value) =>
value switch
{
StringValue str => ParseValue(str.Value),
_ => throw new ArgumentException(
$"Expected a hexadecimal string but {value}", nameof(value)),
};
}
}
4 changes: 2 additions & 2 deletions Libplanet.Explorer/GraphTypes/TransactionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public TransactionType(IBlockChainContext context)
{
Name = "Transaction";

Field<NonNullGraphType<TxIdType>>(
Field<NonNullGraphType<IdGraphType>>(
name: "Id",
description: "A unique identifier derived from this transaction content.",
resolve: ctx => ctx.Source.Id
resolve: ctx => ctx.Source.Id.ToString()
);
Field<NonNullGraphType<LongGraphType>>(
name: "Nonce",
Expand Down
6 changes: 2 additions & 4 deletions Libplanet.Explorer/GraphTypes/TxResultType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public class TxResultType : ObjectGraphType<TxResult>
{
public TxResultType()
{
Name = "TxResult";

Field<NonNullGraphType<TxStatusType>>(
nameof(TxResult.TxStatus),
description: "The transaction status.",
Expand All @@ -27,14 +25,14 @@ public TxResultType()
resolve: context => context.Source.BlockHash
);

Field<HashDigestType<SHA256>>(
Field<HashDigestSHA256Type>(
nameof(TxResult.InputState),
description: "The input state's root hash " +
"which the target transaction executed.",
resolve: context => context.Source.InputState
);

Field<HashDigestType<SHA256>>(
Field<HashDigestSHA256Type>(
nameof(TxResult.OutputState),
description: "The output state's root hash " +
"which the target transaction executed.",
Expand Down
10 changes: 5 additions & 5 deletions Libplanet.Explorer/Queries/BlockQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public BlockQuery()
Field<BlockType>(
"block",
arguments: new QueryArguments(
new QueryArgument<BlockHashType> { Name = "hash" },
new QueryArgument<LongGraphType> { Name = "index" }
new QueryArgument<IdGraphType> { Name = "hash" },
new QueryArgument<IdGraphType> { Name = "index" }
),
resolve: context =>
{
BlockHash? hash = context.GetArgument<BlockHash?>("hash");
long? index = context.GetArgument<long?>("index");
string hash = context.GetArgument<string>("hash");
long? index = context.GetArgument<long?>("index", null);

if (!(hash is null ^ index is null))
{
Expand All @@ -81,7 +81,7 @@ public BlockQuery()

if (hash is { } nonNullHash)
{
return ExplorerQuery.GetBlockByHash(nonNullHash);
return ExplorerQuery.GetBlockByHash(BlockHash.FromString(nonNullHash));
}

if (index is { } nonNullIndex)
Expand Down
36 changes: 24 additions & 12 deletions Libplanet.Explorer/Queries/StateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public StateQuery()
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ListGraphType<NonNullGraphType<AddressType>>>>
{ Name = "addresses" },
new QueryArgument<BlockHashType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestType<SHA256>> { Name = "offsetStateRootHash" }
new QueryArgument<IdGraphType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestSHA256Type> { Name = "offsetStateRootHash" }
),
resolve: ResolveStates
);
Expand All @@ -42,8 +42,8 @@ public StateQuery()
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>> { Name = "owner" },
new QueryArgument<NonNullGraphType<CurrencyInputType>> { Name = "currency" },
new QueryArgument<BlockHashType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestType<SHA256>> { Name = "offsetStateRootHash" }
new QueryArgument<IdGraphType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestSHA256Type> { Name = "offsetStateRootHash" }
),
resolve: ResolveBalance
);
Expand All @@ -52,17 +52,17 @@ public StateQuery()
description: "Retrieves total supply from the legacy account.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<CurrencyInputType>> { Name = "currency" },
new QueryArgument<BlockHashType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestType<SHA256>> { Name = "offsetStateRootHash" }
new QueryArgument<IdGraphType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestSHA256Type> { Name = "offsetStateRootHash" }
),
resolve: ResolveTotalSupply
);
Field<ListGraphType<NonNullGraphType<ValidatorType>>>(
"validators",
description: "Retrieves validator set from the legacy account.",
arguments: new QueryArguments(
new QueryArgument<BlockHashType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestType<SHA256>> { Name = "offsetStateRootHash" }
new QueryArgument<IdGraphType> { Name = "offsetBlockHash" },
new QueryArgument<HashDigestSHA256Type> { Name = "offsetStateRootHash" }
),
resolve: ResolveValidatorSet
);
Expand Down Expand Up @@ -94,7 +94,10 @@ private static object ResolveWorldState(IResolveFieldContext<IBlockChainStates>
private static object? ResolveStates(IResolveFieldContext<IBlockChainStates> context)
{
Address[] addresses = context.GetArgument<Address[]>("addresses");
BlockHash? offsetBlockHash = context.GetArgument<BlockHash?>("offsetBlockHash");
BlockHash? offsetBlockHash =
context.GetArgument<string?>("offsetBlockHash") is { } blockHashString
? BlockHash.FromString(blockHashString)
: null;
HashDigest<SHA256>? offsetStateRootHash = context
.GetArgument<HashDigest<SHA256>?>("offsetStateRootHash");

Expand Down Expand Up @@ -128,7 +131,10 @@ private static object ResolveBalance(IResolveFieldContext<IBlockChainStates> con
{
Address owner = context.GetArgument<Address>("owner");
Currency currency = context.GetArgument<Currency>("currency");
BlockHash? offsetBlockHash = context.GetArgument<BlockHash?>("offsetBlockHash");
BlockHash? offsetBlockHash =
context.GetArgument<string?>("offsetBlockHash") is { } blockHashString
? BlockHash.FromString(blockHashString)
: null;
HashDigest<SHA256>? offsetStateRootHash = context
.GetArgument<HashDigest<SHA256>?>("offsetStateRootHash");

Expand Down Expand Up @@ -161,7 +167,10 @@ private static object ResolveBalance(IResolveFieldContext<IBlockChainStates> con
private static object? ResolveTotalSupply(IResolveFieldContext<IBlockChainStates> context)
{
Currency currency = context.GetArgument<Currency>("currency");
BlockHash? offsetBlockHash = context.GetArgument<BlockHash?>("offsetBlockHash");
BlockHash? offsetBlockHash =
context.GetArgument<string?>("offsetBlockHash") is { } blockHashString
? BlockHash.FromString(blockHashString)
: null;
HashDigest<SHA256>? offsetStateRootHash = context
.GetArgument<HashDigest<SHA256>?>("offsetStateRootHash");

Expand Down Expand Up @@ -199,7 +208,10 @@ private static object ResolveBalance(IResolveFieldContext<IBlockChainStates> con

private static object? ResolveValidatorSet(IResolveFieldContext<IBlockChainStates> context)
{
BlockHash? offsetBlockHash = context.GetArgument<BlockHash?>("offsetBlockHash");
BlockHash? offsetBlockHash =
context.GetArgument<string?>("offsetBlockHash") is { } blockHashString
? BlockHash.FromString(blockHashString)
: null;
HashDigest<SHA256>? offsetStateRootHash = context
.GetArgument<HashDigest<SHA256>?>("offsetStateRootHash");

Expand Down
20 changes: 15 additions & 5 deletions Libplanet.Explorer/Queries/TransactionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public TransactionQuery(IBlockChainContext context)
Name = "signer",
DefaultValue = null,
},
new QueryArgument<AddressType>
{
Name = "involvedAddress",
DefaultValue = null,
},
new QueryArgument<BooleanGraphType>
{
Name = "desc",
Expand Down Expand Up @@ -66,6 +71,11 @@ public TransactionQuery(IBlockChainContext context)
Name = "signer",
DefaultValue = null,
},
new QueryArgument<AddressType>
{
Name = "involvedAddress",
DefaultValue = null,
},
new QueryArgument<BooleanGraphType>
{
Name = "desc",
Expand Down Expand Up @@ -97,10 +107,10 @@ public TransactionQuery(IBlockChainContext context)
Field<TransactionType>(
"transaction",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<TxIdType>> { Name = "id" }
new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "id" }
),
resolve: context =>
ExplorerQuery.GetTransaction(context.GetArgument<TxId>("id"))
resolve: context => ExplorerQuery.GetTransaction(
new TxId(ByteUtil.ParseHex(context.GetArgument<string>("id"))))
);

Field<NonNullGraphType<ByteStringType>>(
Expand Down Expand Up @@ -195,7 +205,7 @@ public TransactionQuery(IBlockChainContext context)
Field<NonNullGraphType<TxResultType>>(
name: "transactionResult",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<TxIdType>>
new QueryArgument<NonNullGraphType<IdGraphType>>
{
Name = "txId",
Description = "transaction id.",
Expand All @@ -206,7 +216,7 @@ public TransactionQuery(IBlockChainContext context)
var blockChain = _context.BlockChain;
var store = _context.Store;
var index = _context.Index;
var txId = context.GetArgument<TxId>("txId");
var txId = new TxId(ByteUtil.ParseHex(context.GetArgument<string>("txId")));

if (GetBlockContainingTx(_context, txId) is { } block)
{
Expand Down

0 comments on commit a6715fa

Please sign in to comment.