1
- using System ;
2
1
using GraphQL ;
3
2
using GraphQL . Types ;
4
- using Libplanet . Common ;
5
3
using Libplanet . Explorer . GraphTypes ;
6
4
using Libplanet . Types . Blocks ;
7
5
using Libplanet . Types . Evidence ;
@@ -20,75 +18,47 @@ public EvidenceQuery()
20
18
Field < NonNullGraphType < ListGraphType < NonNullGraphType < EvidenceType > > > > (
21
19
"committedEvidence" ,
22
20
arguments : new QueryArguments (
23
- new QueryArgument < BlockHashType >
24
- {
25
- Name = "blockHash" ,
26
- DefaultValue = null ,
27
- } ,
28
- new QueryArgument < BooleanGraphType >
29
- {
30
- Name = "desc" ,
31
- DefaultValue = false ,
32
- } ,
33
- new QueryArgument < IntGraphType >
34
- {
35
- Name = "offset" ,
36
- DefaultValue = 0 ,
37
- } ,
38
- new QueryArgument < IntGraphType >
39
- {
40
- Name = "limit" ,
41
- DefaultValue = MaxLimit ,
42
- }
21
+ new QueryArgument < IdGraphType > { Name = "hash" } ,
22
+ new QueryArgument < IdGraphType > { Name = "index" }
43
23
) ,
44
24
resolve : context =>
45
25
{
46
- var blockHash = context . GetArgument < BlockHash ? > ( "blockHash" ) ;
47
- bool desc = context . GetArgument < bool > ( "desc" ) ;
48
- int offset = context . GetArgument < int > ( "offset" ) ;
49
- int ? limit = context . GetArgument < int ? > ( "limit" ) ;
26
+ string hash = context . GetArgument < string > ( "hash" ) ;
27
+ long ? index = context . GetArgument < long ? > ( "index" , null ) ;
50
28
51
- return ExplorerQuery . ListCommitEvidence ( blockHash , desc , offset , limit ) ;
52
- }
53
- ) ;
54
-
55
- Field < NonNullGraphType < ListGraphType < NonNullGraphType < EvidenceType > > > > (
56
- "pendingEvidence" ,
57
- arguments : new QueryArguments (
58
- new QueryArgument < BooleanGraphType >
29
+ if ( ! ( hash is null ^ index is null ) )
59
30
{
60
- Name = "desc" ,
61
- DefaultValue = false ,
62
- } ,
63
- new QueryArgument < IntGraphType >
31
+ throw new ExecutionError (
32
+ "The parameters hash and index are mutually exclusive; " +
33
+ "give only one at a time." ) ;
34
+ }
35
+
36
+ if ( hash is { } nonNullHash )
64
37
{
65
- Name = "offset" ,
66
- DefaultValue = 0 ,
67
- } ,
68
- new QueryArgument < IntGraphType >
38
+ return ExplorerQuery . ListCommitEvidence ( BlockHash . FromString ( nonNullHash ) ) ;
39
+ }
40
+
41
+ if ( index is { } nonNullIndex )
69
42
{
70
- Name = "limit" ,
71
- DefaultValue = MaxLimit ,
43
+ return ExplorerQuery . ListCommitEvidence ( nonNullIndex ) ;
72
44
}
73
- ) ,
74
- resolve : context =>
75
- {
76
- bool desc = context . GetArgument < bool > ( "desc" ) ;
77
- int offset = context . GetArgument < int > ( "offset" ) ;
78
- int ? limit = context . GetArgument < int ? > ( "limit" , null ) ;
79
45
80
- return ExplorerQuery . ListPendingEvidence ( desc , offset , limit ) ;
46
+ throw new ExecutionError ( "Unexpected block query" ) ;
81
47
}
82
48
) ;
83
49
50
+ Field < NonNullGraphType < ListGraphType < NonNullGraphType < EvidenceType > > > > (
51
+ "pendingEvidence" ,
52
+ resolve : context => ExplorerQuery . ListPendingEvidence ( )
53
+ ) ;
54
+
84
55
Field < EvidenceType > (
85
56
"Evidence" ,
86
57
arguments : new QueryArguments (
87
58
new QueryArgument < EvidenceIdType > { Name = "id" }
88
59
) ,
89
60
resolve : context => ExplorerQuery . GetEvidence (
90
- new EvidenceId ( ByteUtil . ParseHex ( context . GetArgument < string > ( "id" )
91
- ?? throw new ExecutionError ( "Given id cannot be null." ) ) ) )
61
+ context . GetArgument < EvidenceId > ( "id" ) )
92
62
) ;
93
63
}
94
64
}
0 commit comments