1
1
package vsys .api .http
2
2
3
3
import javax .ws .rs .Path
4
-
5
4
import akka .http .scaladsl .marshalling .ToResponseMarshallable
6
5
import akka .http .scaladsl .server .Route
7
6
import io .netty .channel .group .ChannelGroup
@@ -13,7 +12,6 @@ import vsys.blockchain.state.ByteStr
13
12
import vsys .blockchain .transaction .TransactionParser
14
13
import vsys .network ._
15
14
import vsys .settings .{CheckpointsSettings , RestAPISettings }
16
-
17
15
import scala .concurrent .ExecutionContext .Implicits .global
18
16
import scala .concurrent .Future
19
17
@@ -31,7 +29,10 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
31
29
}
32
30
33
31
@ Path (" /address/{address}/{from}/{to}" )
34
- @ ApiOperation (value = " Address" , notes = " Get list of blocks generated by specified address" , httpMethod = " GET" )
32
+ @ ApiOperation (value = " Address" , notes = " Get a block list generated by a specified `address` and a block height range (`from`/`to`)" , httpMethod = " GET" )
33
+ @ ApiResponses (Array (
34
+ new ApiResponse (code = 200 , message = " Json response of the block list or error" )
35
+ ))
35
36
@ ApiImplicitParams (Array (
36
37
new ApiImplicitParam (name = " from" , value = " Start block height" , required = true , dataType = " integer" , paramType = " path" ),
37
38
new ApiImplicitParam (name = " to" , value = " End block height" , required = true , dataType = " integer" , paramType = " path" ),
@@ -52,10 +53,13 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
52
53
}
53
54
54
55
@ Path (" /child/{signature}" )
55
- @ ApiOperation (value = " Child" , notes = " Get children of specified block" , httpMethod = " GET" )
56
+ @ ApiOperation (value = " Child" , notes = " Get children of a specified block by the base58-encoded `signature` " , httpMethod = " GET" )
56
57
@ ApiImplicitParams (Array (
57
58
new ApiImplicitParam (name = " signature" , value = " Base58-encoded signature" , required = true , dataType = " string" , paramType = " path" )
58
59
))
60
+ @ ApiResponses (Array (
61
+ new ApiResponse (code = 200 , message = " Json response of the child block information or error" )
62
+ ))
59
63
def child : Route = (path(" child" / Segment ) & get) { encodedSignature =>
60
64
withBlock(history, encodedSignature) { block =>
61
65
complete(history.child(block).map(_.json + (" transaction count" -> Json .toJson(block.transactionData.length))).getOrElse[JsObject ](
@@ -65,7 +69,7 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
65
69
66
70
@ Path (" /delay/{signature}/{blockNum}" )
67
71
@ ApiOperation (value = " Average delay" ,
68
- notes = " Average delay in milliseconds between last `blockNum` blocks starting from block with `signature`" , httpMethod = " GET" )
72
+ notes = " Get the average delay in milliseconds between last `blockNum` blocks starting from block with `signature`" , httpMethod = " GET" , response = classOf [ Long ] )
69
73
@ ApiImplicitParams (Array (
70
74
new ApiImplicitParam (name = " signature" , value = " Base58-encoded signature" , required = true , dataType = " string" , paramType = " path" ),
71
75
new ApiImplicitParam (name = " blockNum" , value = " Number of blocks to count delay" , required = true , dataType = " string" , paramType = " path" )
@@ -78,7 +82,7 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
78
82
}
79
83
80
84
@ Path (" /height/{signature}" )
81
- @ ApiOperation (value = " Height" , notes = " Get height of a block by its Base58-encoded signature" , httpMethod = " GET" )
85
+ @ ApiOperation (value = " Height" , notes = " Get the ** block height** by its Base58-encoded ` signature` " , httpMethod = " GET" , response = classOf [ Int ] )
82
86
@ ApiImplicitParams (Array (
83
87
new ApiImplicitParam (name = " signature" , value = " Base58-encoded signature" , required = true , dataType = " string" , paramType = " path" )
84
88
))
@@ -95,13 +99,16 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
95
99
}
96
100
97
101
@ Path (" /height" )
98
- @ ApiOperation (value = " Height" , notes = " Get blockchain height" , httpMethod = " GET" )
102
+ @ ApiOperation (value = " Height" , notes = " Get blockchain height" , httpMethod = " GET" , response = classOf [ Int ] )
99
103
def height : Route = (path(" height" ) & get) {
100
104
complete(Json .obj(" height" -> history.height()))
101
105
}
102
106
103
107
@ Path (" /at/{height}" )
104
- @ ApiOperation (value = " At" , notes = " Get block at specified height" , httpMethod = " GET" )
108
+ @ ApiOperation (value = " At" , notes = " Get block at specified `height`" , httpMethod = " GET" )
109
+ @ ApiResponses (Array (
110
+ new ApiResponse (code = 200 , message = " Json response of a block details at a specified height or error" )
111
+ ))
105
112
@ ApiImplicitParams (Array (
106
113
new ApiImplicitParam (name = " height" , value = " Block height" , required = true , dataType = " integer" , paramType = " path" )
107
114
))
@@ -113,7 +120,10 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
113
120
}
114
121
115
122
@ Path (" /seq/{from}/{to}" )
116
- @ ApiOperation (value = " Seq" , notes = " Get block at specified heights" , httpMethod = " GET" )
123
+ @ ApiOperation (value = " Seq" , notes = " Get block at the specified height range (`from`/`to`)" , httpMethod = " GET" )
124
+ @ ApiResponses (Array (
125
+ new ApiResponse (code = 200 , message = " Json response of the block list or error" )
126
+ ))
117
127
@ ApiImplicitParams (Array (
118
128
new ApiImplicitParam (name = " from" , value = " Start block height" , required = true , dataType = " integer" , paramType = " path" ),
119
129
new ApiImplicitParam (name = " to" , value = " End block height" , required = true , dataType = " integer" , paramType = " path" )
@@ -130,21 +140,30 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
130
140
131
141
132
142
@ Path (" /last" )
133
- @ ApiOperation (value = " Last" , notes = " Get last block data" , httpMethod = " GET" )
143
+ @ ApiOperation (value = " Last" , notes = " Get the **last block** data" , httpMethod = " GET" )
144
+ @ ApiResponses (Array (
145
+ new ApiResponse (code = 200 , message = " Json response of the last block information or error" )
146
+ ))
134
147
def last : Route = (path(" last" ) & get) {
135
148
val height = history.height()
136
149
val lastBlock = history.blockAt(height).get
137
150
complete(lastBlock.json + (" height" -> Json .toJson(height)) + (" transaction count" -> Json .toJson(lastBlock.transactionData.length)))
138
151
}
139
152
140
153
@ Path (" /first" )
141
- @ ApiOperation (value = " First" , notes = " Get genesis block data" , httpMethod = " GET" )
154
+ @ ApiOperation (value = " First" , notes = " Get the **genesis block** data" , httpMethod = " GET" )
155
+ @ ApiResponses (Array (
156
+ new ApiResponse (code = 200 , message = " Json response of the first block details or error" )
157
+ ))
142
158
def first : Route = (path(" first" ) & get) {
143
159
complete(history.genesis.json + (" height" -> Json .toJson(1 )) + (" transaction count" -> Json .toJson(history.genesis.transactionData.length)))
144
160
}
145
161
146
162
@ Path (" /signature/{signature}" )
147
- @ ApiOperation (value = " Signature" , notes = " Get block by a specified Base58-encoded signature" , httpMethod = " GET" )
163
+ @ ApiOperation (value = " Signature" , notes = " Get block by a specified Base58-encoded `signature`" , httpMethod = " GET" )
164
+ @ ApiResponses (Array (
165
+ new ApiResponse (code = 200 , message = " Json response of the block details or error" )
166
+ ))
148
167
@ ApiImplicitParams (Array (
149
168
new ApiImplicitParam (name = " signature" , value = " Base58-encoded signature" , required = true , dataType = " string" , paramType = " path" )
150
169
))
@@ -159,13 +178,13 @@ case class BlocksApiRoute(settings: RestAPISettings, checkpointsSettings: Checkp
159
178
}
160
179
161
180
@ Path (" /checkpoint" )
162
- @ ApiOperation (value = " Checkpoint" , notes = " Broadcast checkpoint of blocks" , httpMethod = " POST" )
181
+ @ ApiOperation (value = " Checkpoint" , notes = " Broadcast the checkpoint of blocks" , httpMethod = " POST" )
163
182
@ ApiImplicitParams (Array (
164
183
new ApiImplicitParam (name = " message" , value = " Checkpoint message" , required = true , paramType = " body" ,
165
184
dataType = " vsys.network.Checkpoint" )
166
185
))
167
186
@ ApiResponses (Array (
168
- new ApiResponse (code = 200 , message = " Json with response or error " )
187
+ new ApiResponse (code = 200 , message = " Successful Operation " )
169
188
))
170
189
def checkpoint : Route = (path(" checkpoint" ) & post) {
171
190
json[Checkpoint ] { checkpoint =>
0 commit comments