public NodeStatusType() { Field <NonNullGraphType <BooleanGraphType> >(name: "bootstrapEnded", resolve: context => context.Source.BootstrapEnded); Field <NonNullGraphType <BooleanGraphType> >(name: "preloadEnded", resolve: context => context.Source.PreloadEnded); Field <NonNullGraphType <BlockHeaderType> >(name: "tip", resolve: context => BlockHeaderType.FromBlock(context.Source.BlockChain.Tip)); Field <NonNullGraphType <ListGraphType <BlockHeaderType> > >( name: "topmostBlocks", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "limit", Description = "The number of blocks to get." }, new QueryArgument <AddressType> { Name = "miner", Description = "List only blocks mined by the given address. " + "(List everything if omitted.)", DefaultValue = null, } ), description: "The topmost blocks from the current node.", resolve: context => { IEnumerable <Block <NCAction> > blocks = GetTopmostBlocks(context.Source.BlockChain); if (context.GetArgument <Address?>("miner") is { } miner) { blocks = blocks.Where(b => b.Miner.Equals(miner)); } return(blocks .Take(context.GetArgument <int>("limit")) .Select(BlockHeaderType.FromBlock)); }); Field <ListGraphType <TxIdType> >( name: "stagedTxIds", description: "Staged TxIds from the current node.", resolve: context => context.Source.Store?.IterateStagedTransactionIds() ); Field <NonNullGraphType <BlockHeaderType> >(name: "genesis", resolve: context => BlockHeaderType.FromBlock(context.Source.BlockChain.Genesis)); Field <NonNullGraphType <BooleanGraphType> >(name: "isMining", description: "Whether it is mining.", resolve: context => context.Source.IsMining ); }
public NodeStatusType(StandaloneContext context) { Field <NonNullGraphType <BooleanGraphType> >( name: "bootstrapEnded", description: "Whether the current libplanet node has ended bootstrapping.", resolve: _ => context.BootstrapEnded ); Field <NonNullGraphType <BooleanGraphType> >( name: "preloadEnded", description: "Whether the current libplanet node has ended preloading.", resolve: _ => context.PreloadEnded ); Field <NonNullGraphType <BlockHeaderType> >( name: "tip", description: "Block header of the tip block from the current canonical chain.", resolve: _ => context.BlockChain is { } blockChain ? BlockHeaderType.FromBlock(blockChain.Tip) : null ); Field <NonNullGraphType <ListGraphType <BlockHeaderType> > >( name: "topmostBlocks", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "limit", Description = "The number of blocks to get." }, new QueryArgument <AddressType> { Name = "miner", Description = "List only blocks mined by the given address. " + "(List everything if omitted.)", DefaultValue = null, } ), description: "The topmost blocks from the current node.", resolve: fieldContext => { if (context.BlockChain is null) { throw new InvalidOperationException($"{nameof(context.BlockChain)} is null."); } IEnumerable <Block <NCAction> > blocks = GetTopmostBlocks(context.BlockChain); if (fieldContext.GetArgument <Address?>("miner") is { } miner) { blocks = blocks.Where(b => b.Miner.Equals(miner)); } return(blocks .Take(fieldContext.GetArgument <int>("limit")) .Select(BlockHeaderType.FromBlock)); }); Field <ListGraphType <TxIdType> >( name: "stagedTxIds", arguments: new QueryArguments( new QueryArgument <AddressType> { Name = "address", Description = "Target address to query" } ), description: "Ids of staged transactions from the current node.", resolve: fieldContext => { if (context.BlockChain is null) { throw new InvalidOperationException($"{nameof(context.BlockChain)} is null."); } if (!fieldContext.HasArgument("address")) { return(context.BlockChain.GetStagedTransactionIds()); } else { Address address = fieldContext.GetArgument <Address>("address"); IImmutableSet <TxId> stagedTransactionIds = context.BlockChain.GetStagedTransactionIds(); return(stagedTransactionIds.Where(txId => context.BlockChain.GetTransaction(txId).Signer.Equals(address))); } } ); Field <NonNullGraphType <BlockHeaderType> >( name: "genesis", description: "Block header of the genesis block from the current chain.", resolve: fieldContext => context.BlockChain is { } blockChain ? BlockHeaderType.FromBlock(blockChain.Genesis) : null ); Field <NonNullGraphType <BooleanGraphType> >( name: "isMining", description: "Whether the current node is mining.", resolve: _ => context.IsMining ); }