From f075b758a6f42be402f0baa76180355ab85422e7 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Fri, 30 Aug 2024 16:54:22 +0900 Subject: [PATCH 1/2] Get staged txs from StagePolicy --- NineChronicles.Headless/GraphTypes/NodeStatus.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/NodeStatus.cs b/NineChronicles.Headless/GraphTypes/NodeStatus.cs index 3a21cbb15..e7c2e198d 100644 --- a/NineChronicles.Headless/GraphTypes/NodeStatus.cs +++ b/NineChronicles.Headless/GraphTypes/NodeStatus.cs @@ -99,15 +99,15 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai if (!fieldContext.HasArgument("address")) { - return context.BlockChain.GetStagedTransactionIds(); + return context.BlockChain.StagePolicy.Iterate(context.BlockChain).Select(tx => tx.Id) + .ToImmutableHashSet(); } else { Address address = fieldContext.GetArgument
("address"); - IImmutableSet stagedTransactionIds = context.BlockChain.GetStagedTransactionIds(); - return stagedTransactionIds.Where(txId => - context.BlockChain.GetTransaction(txId).Signer.Equals(address)); + return context.BlockChain.StagePolicy.Iterate(context.BlockChain) + .Where(tx => tx.Signer.Equals(address)).Select(tx => tx.Id).ToImmutableHashSet(); } } ); @@ -121,7 +121,7 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai throw new InvalidOperationException($"{nameof(context.BlockChain)} is null."); } - return context.BlockChain.GetStagedTransactionIds().Count; + return context.BlockChain.StagePolicy.Iterate(context.BlockChain).ToImmutableHashSet().Count; } ); Field>( From 9f122bc20fefd51a9ade13da3a44affea6ab7faf Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Fri, 30 Aug 2024 17:07:19 +0900 Subject: [PATCH 2/2] Introduce `filtered` argument at `.nodeStatus.stagedTxIds[Count]` --- .../GraphTypes/NodeStatus.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/NodeStatus.cs b/NineChronicles.Headless/GraphTypes/NodeStatus.cs index e7c2e198d..7bf5109a7 100644 --- a/NineChronicles.Headless/GraphTypes/NodeStatus.cs +++ b/NineChronicles.Headless/GraphTypes/NodeStatus.cs @@ -87,6 +87,12 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai { Name = "address", Description = "Target address to query" + }, + new QueryArgument + { + Name = "filtered", + Description = "Whether to filter masked staged Transactions or not.", + DefaultValue = true, } ), description: "Ids of staged transactions from the current node.", @@ -97,16 +103,17 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai throw new InvalidOperationException($"{nameof(context.BlockChain)} is null."); } + var filtered = fieldContext.GetArgument("filtered"); if (!fieldContext.HasArgument("address")) { - return context.BlockChain.StagePolicy.Iterate(context.BlockChain).Select(tx => tx.Id) + return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered).Select(tx => tx.Id) .ToImmutableHashSet(); } else { Address address = fieldContext.GetArgument
("address"); - return context.BlockChain.StagePolicy.Iterate(context.BlockChain) + return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered) .Where(tx => tx.Signer.Equals(address)).Select(tx => tx.Id).ToImmutableHashSet(); } } @@ -114,6 +121,14 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai Field( name: "stagedTxIdsCount", description: "The number of ids of staged transactions from the current node.", + arguments: new QueryArguments( + new QueryArgument + { + Name = "filtered", + Description = "Whether to filter masked staged Transactions or not.", + DefaultValue = true, + } + ), resolve: fieldContext => { if (context.BlockChain is null) @@ -121,7 +136,8 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai throw new InvalidOperationException($"{nameof(context.BlockChain)} is null."); } - return context.BlockChain.StagePolicy.Iterate(context.BlockChain).ToImmutableHashSet().Count; + var filtered = fieldContext.GetArgument("filtered"); + return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered).ToImmutableHashSet().Count; } ); Field>(