Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add missing api endpoints (#65)
- Loading branch information
1 parent
21d4e4d
commit da072b1
Showing
7 changed files
with
170 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file is part of Ark Go Client. | ||
// | ||
// (c) Ark Ecosystem <info@ark.io> | ||
// | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
|
||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// RoundsService handles communication with the rounds related | ||
// methods of the Ark Core API - Version 2. | ||
type RoundsService Service | ||
|
||
// Get the forging delegates of a round by the given id. | ||
func (s *RoundsService) Delegates(ctx context.Context, id int64) (*GetDelegates, *http.Response, error) { | ||
uri := fmt.Sprintf("rounds/%v/delegates", id) | ||
|
||
var responseStruct *GetDelegates | ||
resp, err := s.client.SendRequest(ctx, "GET", uri, nil, nil, &responseStruct) | ||
|
||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return responseStruct, resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This file is part of Ark Go Client. | ||
// | ||
// (c) Ark Ecosystem <info@ark.io> | ||
// | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
|
||
package client | ||
|
||
type RoundDelegate struct { | ||
PublicKey string `json:"publicKey,omitempty"` | ||
Votes string `json:"votes,omitempty"` | ||
} | ||
|
||
type GetDelegates struct { | ||
Data []RoundDelegate `json:"data,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// This file is part of Ark Go Client. | ||
// | ||
// (c) Ark Ecosystem <info@ark.io> | ||
// | ||
// For the full copyright and license information, please view the LICENSE | ||
// file that was distributed with this source code. | ||
|
||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
// Get the forging delegates of a round by the given id. | ||
func TestRoundsService_Delegates(t *testing.T) { | ||
client, mux, _, teardown := setupTest() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/rounds/12345/delegates", func(writer http.ResponseWriter, request *http.Request) { | ||
testMethod(t, request, "GET") | ||
fmt.Fprint(writer, | ||
`{ | ||
"data": [ | ||
{ | ||
"publicKey": "03ffc17c5528d490b045a9b710c754e00a536d05d9b0b78a9baa0533a246dcd98c", | ||
"votes": "156947252547993" | ||
} | ||
] | ||
}`) | ||
}) | ||
|
||
responseStruct, response, err := client.Rounds.Delegates(context.Background(), 12345) | ||
testGeneralError(t, "Rounds.Delegates", err) | ||
testResponseUrl(t, "Rounds.Delegates", response, "/rounds/12345/delegates") | ||
testResponseStruct(t, "Rounds.Delegates", responseStruct, &GetDelegates{ | ||
Data: []RoundDelegate{{ | ||
PublicKey: "03ffc17c5528d490b045a9b710c754e00a536d05d9b0b78a9baa0533a246dcd98c", | ||
Votes: "156947252547993", | ||
}}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters