Пример #1
0
        public BlockQuery()
        {
            Field <NonNullGraphType <ListGraphType <NonNullGraphType <BlockType <T> > > > >(
                "blocks",
                arguments: new QueryArguments(
                    new QueryArgument <BooleanGraphType>
            {
                Name         = "desc",
                DefaultValue = false,
            },
                    new QueryArgument <IntGraphType>
            {
                Name         = "offset",
                DefaultValue = 0,
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            },
                    new QueryArgument <BooleanGraphType>
            {
                Name         = "excludeEmptyTxs",
                DefaultValue = false,
            },
                    new QueryArgument <AddressType> {
                Name = "miner"
            }
                    ),
                resolve: context =>
            {
                bool desc            = context.GetArgument <bool>("desc");
                long offset          = context.GetArgument <long>("offset");
                int?limit            = context.GetArgument <int?>("limit", null);
                bool excludeEmptyTxs = context.GetArgument <bool>("excludeEmptyTxs");
                Address?miner        = context.GetArgument <Address?>("miner", null);
                return(ExplorerQuery <T> .ListBlocks(desc, offset, limit, excludeEmptyTxs, miner));
            }
                );

            Field <BlockType <T> >(
                "block",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "hash"
            },
                    new QueryArgument <IdGraphType> {
                Name = "index"
            }
                    ),
                resolve: context =>
            {
                string hash = context.GetArgument <string>("hash");
                long?index  = context.GetArgument <long?>("index", null);

                if (!(hash is null ^ index is null))
                {
                    throw new GraphQL.ExecutionError(
                        "The parameters hash and index are mutually exclusive; " +
                        "give only one at a time.");
                }

                if (hash is string hashNotNull)
                {
                    return(ExplorerQuery <T> .GetBlockByHash(BlockHash.FromString(hashNotNull)));
                }

                if (index is long indexNotNull)
                {
                    return(ExplorerQuery <T> .GetBlockByIndex(indexNotNull));
                }

                throw new GraphQL.ExecutionError("Unexpected block query");
            }
Пример #2
0
        public TransactionQuery()
        {
            Field <NonNullGraphType <ListGraphType <NonNullGraphType <TransactionType <T> > > > >(
                "transactions",
                arguments: new QueryArguments(
                    new QueryArgument <AddressType>
            {
                Name         = "signer",
                DefaultValue = null,
            },
                    new QueryArgument <AddressType>
            {
                Name         = "involvedAddress",
                DefaultValue = null,
            },
                    new QueryArgument <BooleanGraphType>
            {
                Name         = "desc",
                DefaultValue = false,
            },
                    new QueryArgument <IntGraphType>
            {
                Name         = "offset",
                DefaultValue = 0,
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            }
                    ),
                resolve: context =>
            {
                var signer   = context.GetArgument <Address?>("signer");
                var involved = context.GetArgument <Address?>("involvedAddress");
                bool desc    = context.GetArgument <bool>("desc");
                long offset  = context.GetArgument <long>("offset");
                int?limit    = context.GetArgument <int?>("limit", null);

                return(ExplorerQuery <T> .ListTransactions(signer, involved, desc, offset, limit));
            }
                );

            Field <NonNullGraphType <ListGraphType <NonNullGraphType <TransactionType <T> > > > >(
                "stagedTransactions",
                arguments: new QueryArguments(
                    new QueryArgument <AddressType>
            {
                Name         = "signer",
                DefaultValue = null,
            },
                    new QueryArgument <AddressType>
            {
                Name         = "involvedAddress",
                DefaultValue = null,
            },
                    new QueryArgument <BooleanGraphType>
            {
                Name         = "desc",
                DefaultValue = false,
            },
                    new QueryArgument <IntGraphType>
            {
                Name         = "offset",
                DefaultValue = 0,
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            }
                    ),
                resolve: context =>
            {
                var signer   = context.GetArgument <Address?>("signer");
                var involved = context.GetArgument <Address?>("involvedAddress");
                bool desc    = context.GetArgument <bool>("desc");
                int offset   = context.GetArgument <int>("offset");
                int?limit    = context.GetArgument <int?>("limit", null);

                return(ExplorerQuery <T> .ListStagedTransactions(
                           signer,
                           involved,
                           desc,
                           offset,
                           limit
                           ));
            }
                );

            Field <TransactionType <T> >(
                "transaction",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            }
                    ),
                resolve: context =>
            {
                var id = new TxId(
                    ByteUtil.ParseHex(context.GetArgument <string>("id"))
                    );
                return(ExplorerQuery <T> .GetTransaction(id));
            }
                );

            Name = "TransactionQuery";
        }