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

Introduce filtered argument at .nodeStatus.stagedTxIds[Count] #2563

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions NineChronicles.Headless/GraphTypes/NodeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai
{
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 @@ -97,31 +103,41 @@ public NodeStatusType(StandaloneContext context, IBlockChainRepository blockChai
throw new InvalidOperationException($"{nameof(context.BlockChain)} is null.");
}

var filtered = fieldContext.GetArgument<bool>("filtered");
if (!fieldContext.HasArgument("address"))
{
return context.BlockChain.GetStagedTransactionIds();
return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered).Select(tx => tx.Id)
.ToImmutableHashSet();
}
else
{
Address address = fieldContext.GetArgument<Address>("address");
IImmutableSet<TxId> stagedTransactionIds = context.BlockChain.GetStagedTransactionIds();

return stagedTransactionIds.Where(txId =>
context.BlockChain.GetTransaction(txId).Signer.Equals(address));
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.GetStagedTransactionIds().Count;
var filtered = fieldContext.GetArgument<bool>("filtered");
return context.BlockChain.StagePolicy.Iterate(context.BlockChain, filtered).ToImmutableHashSet().Count;
}
);
Field<NonNullGraphType<BlockHeaderType>>(
Expand Down
Loading