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 Aug 30, 2024
1 parent 11b8caa commit e97ef84
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 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 @@ -104,32 +110,42 @@ 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 e97ef84

Please sign in to comment.