@@ -46,16 +46,6 @@ const (
4646 maxRawResponseBytes = 50e6
4747)
4848
49- // APIVersion is used to define which server side API version would be used when making http requests to the server
50- type APIVersion string
51-
52- const (
53- // APIVersionV1 suggests that the RestClient would use v1 calls whenever it's available for the given request.
54- APIVersionV1 APIVersion = "v1"
55- // APIVersionV2 suggests that the RestClient would use v2 calls whenever it's available for the given request.
56- APIVersionV2 APIVersion = "v2"
57- )
58-
5949// rawRequestPaths is a set of paths where the body should not be urlencoded
6050var rawRequestPaths = map [string ]bool {
6151 "/v1/transactions" : true ,
@@ -91,27 +81,18 @@ func (e HTTPError) Error() string {
9181
9282// RestClient manages the REST interface for a calling user.
9383type RestClient struct {
94- serverURL url.URL
95- apiToken string
96- versionAffinity APIVersion
84+ serverURL url.URL
85+ apiToken string
9786}
9887
9988// MakeRestClient is the factory for constructing a RestClient for a given endpoint
10089func MakeRestClient (url url.URL , apiToken string ) RestClient {
10190 return RestClient {
102- serverURL : url ,
103- apiToken : apiToken ,
104- versionAffinity : APIVersionV1 ,
91+ serverURL : url ,
92+ apiToken : apiToken ,
10593 }
10694}
10795
108- // SetAPIVersionAffinity sets the client affinity to use a specific version of the API
109- func (client * RestClient ) SetAPIVersionAffinity (affinity APIVersion ) (previousAffinity APIVersion ) {
110- previousAffinity = client .versionAffinity
111- client .versionAffinity = affinity
112- return
113- }
114-
11596// filterASCII filter out the non-ascii printable characters out of the given input string.
11697// It's used as a security qualifier before adding network provided data into an error message.
11798// The function allows only characters in the range of [32..126], which excludes all the
@@ -251,31 +232,13 @@ func (client RestClient) post(response interface{}, path string, request interfa
251232// the StatusResponse includes data like the consensus version and current round
252233// Not supported
253234func (client RestClient ) Status () (response generatedV2.NodeStatusResponse , err error ) {
254- switch client .versionAffinity {
255- case APIVersionV2 :
256- err = client .get (& response , "/v2/status" , nil )
257- default :
258- var nodeStatus v1.NodeStatus
259- err = client .get (& nodeStatus , "/v1/status" , nil )
260- if err == nil {
261- response = fillNodeStatusResponse (nodeStatus )
262- }
263- }
235+ err = client .get (& response , "/v2/status" , nil )
264236 return
265237}
266238
267239// WaitForBlock returns the node status after waiting for the given round.
268240func (client RestClient ) WaitForBlock (round basics.Round ) (response generatedV2.NodeStatusResponse , err error ) {
269- switch client .versionAffinity {
270- case APIVersionV2 :
271- err = client .get (& response , fmt .Sprintf ("/v2/status/wait-for-block-after/%d/" , round ), nil )
272- default :
273- var nodeStatus v1.NodeStatus
274- err = client .get (& nodeStatus , fmt .Sprintf ("/v1/status/wait-for-block-after/%d/" , round ), nil )
275- if err == nil {
276- response = fillNodeStatusResponse (nodeStatus )
277- }
278- }
241+ err = client .get (& response , fmt .Sprintf ("/v2/status/wait-for-block-after/%d/" , round ), nil )
279242 return
280243}
281244
@@ -302,17 +265,7 @@ func fillNodeStatusResponse(nodeStatus v1.NodeStatus) generatedV2.NodeStatusResp
302265// blocks on the node end
303266// Not supported
304267func (client RestClient ) StatusAfterBlock (blockNum uint64 ) (response generatedV2.NodeStatusResponse , err error ) {
305- switch client .versionAffinity {
306- case APIVersionV2 :
307- err = client .get (& response , fmt .Sprintf ("/v2/status/wait-for-block-after/%d" , blockNum ), nil )
308- default :
309- var nodeStatus v1.NodeStatus
310- err = client .get (& nodeStatus , fmt .Sprintf ("/v1/status/wait-for-block-after/%d" , blockNum ), nil )
311- if err == nil {
312- response = fillNodeStatusResponse (nodeStatus )
313- }
314- }
315-
268+ err = client .get (& response , fmt .Sprintf ("/v2/status/wait-for-block-after/%d" , blockNum ), nil )
316269 return
317270}
318271
@@ -546,16 +499,9 @@ func (client RestClient) Block(round uint64) (response v1.Block, err error) {
546499
547500// RawBlock gets the encoded, raw msgpack block for the given round
548501func (client RestClient ) RawBlock (round uint64 ) (response []byte , err error ) {
549- switch client .versionAffinity {
550- case APIVersionV2 :
551- var blob Blob
552- err = client .getRaw (& blob , fmt .Sprintf ("/v2/blocks/%d" , round ), rawFormat {Format : "msgpack" })
553- response = blob
554- default :
555- var raw v1.RawBlock
556- err = client .getRaw (& raw , fmt .Sprintf ("/v1/block/%d" , round ), rawblockParams {1 })
557- response = raw
558- }
502+ var blob Blob
503+ err = client .getRaw (& blob , fmt .Sprintf ("/v2/blocks/%d" , round ), rawFormat {Format : "msgpack" })
504+ response = blob
559505 return
560506}
561507
0 commit comments