Skip to content

Commit

Permalink
Introduce filtered argument at .nodeStatus.stagedTxIds[Count]
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed Sep 9, 2024
1 parent 6312215 commit fc81cba
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions NineChronicles.Headless/GraphTypes/NodeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public NodeStatusType(StandaloneContext context)
{
Name = "address",
Description = "Target address to query"
},
new QueryArgument<BooleanGraphType>
{
Name = "filtered",
Description = "Whether to filter masked staged Transactions or not.",
DefaultValue = true,
}
),
description: "Ids of staged transactions from the current node.",
Expand All @@ -105,31 +111,41 @@ public NodeStatusType(StandaloneContext context)
throw new InvalidOperationException($"{nameof(context.BlockChain)} is null.");
}

var filtered = fieldContext.GetArgument<bool>("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>("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();
}
}
);
Field<IntGraphType>(
name: "stagedTxIdsCount",
description: "The number of ids of staged transactions from the current node.",
arguments: new QueryArguments(
new QueryArgument<BooleanGraphType>
{
Name = "filtered",
Description = "Whether to filter masked staged Transactions or not.",
DefaultValue = true,
}
),
resolve: fieldContext =>
{
if (context.BlockChain is null)
{
throw new InvalidOperationException($"{nameof(context.BlockChain)} is null.");
}

return context.BlockChain.StagePolicy.Iterate(context.BlockChain).ToImmutableHashSet().Count;
var filtered = fieldContext.GetArgument<bool>("filtered");
return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered).ToImmutableHashSet().Count;
}
);
Field<NonNullGraphType<BlockHeaderType>>(
Expand Down

0 comments on commit fc81cba

Please sign in to comment.