Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml

@shahin-hq shahin-hq Jul 29, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update these values to make the workflow work.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.23"
go-version: "^1.25"
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Cache Go modules
uses: actions/cache@v2
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
Expand Down
21 changes: 10 additions & 11 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type Hosts struct {

type Client struct {
httpClient *http.Client
Hosts Hosts
Hosts Hosts

common Service
common Service

ApiNodes *ApiNodesService
Blocks *BlocksService
Blockchain *BlockchainService
Commits *CommitsService
Delegates *DelegatesService
Validators *ValidatorsService
Node *NodeService
Peers *PeersService
Rounds *RoundsService
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewClient(httpClient *http.Client, hosts Hosts) *Client {
c.Blocks = (*BlocksService)(&c.common)
c.Blockchain = (*BlockchainService)(&c.common)
c.Commits = (*CommitsService)(&c.common)
c.Delegates = (*DelegatesService)(&c.common)
c.Validators = (*ValidatorsService)(&c.common)
c.Node = (*NodeService)(&c.common)
c.Peers = (*PeersService)(&c.common)
c.Rounds = (*RoundsService)(&c.common)
Expand All @@ -75,16 +75,15 @@ func NewClient(httpClient *http.Client, hosts Hosts) *Client {
return c
}


func (c *Client) SendRequest(ctx context.Context, method string, endpoint string, queryString interface{}, body interface{}, model interface{}, hostType string) (*http.Response, error) {
var host string
switch hostType {
case "transactions":
host = c.Hosts.Transactions
case "evm":
host = c.Hosts.EVM
default:
host = c.Hosts.API
case "transactions":
host = c.Hosts.Transactions
case "evm":
host = c.Hosts.EVM
default:
host = c.Hosts.API
}

parsedHost, err := url.Parse(host)
Expand Down
72 changes: 0 additions & 72 deletions client/delegates.go

This file was deleted.

55 changes: 0 additions & 55 deletions client/delegates_responses.go

This file was deleted.

10 changes: 5 additions & 5 deletions client/rounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
// 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)
// Get the forging validators of a round by the given id.
func (s *RoundsService) Validators(ctx context.Context, id int64) (*GetValidators, *http.Response, error) {
uri := fmt.Sprintf("rounds/%v/validators", id)

var responseStruct *GetDelegates
var responseStruct *GetValidators
resp, err := s.client.SendRequest(ctx, "GET", uri, nil, nil, &responseStruct, "api")

if err != nil {
Expand Down Expand Up @@ -57,4 +57,4 @@ func (s *RoundsService) Show(ctx context.Context, id int64) (*GetRound, *http.Re
}

return responseStruct, resp, err
}
}
12 changes: 6 additions & 6 deletions client/rounds_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type RoundData struct {

// GetRounds represents the response from the /api/rounds endpoint.
type GetRounds struct {
Meta Meta `json:"meta"`
Meta Meta `json:"meta"`
Data []RoundData `json:"data"`
}

Expand All @@ -26,13 +26,13 @@ type GetRound struct {
Data RoundData `json:"data"`
}

// RoundDelegate represents the delegates of the round.
type RoundDelegate struct {
// RoundValidator represents the validators of the round.
type RoundValidator struct {
PublicKey string `json:"publicKey,omitempty"`
Votes string `json:"votes,omitempty"`
}

// GetDelegates represents the response from the /api/rounds/<id>/delegates endpoint.
type GetDelegates struct {
Data []RoundDelegate `json:"data,omitempty"`
// GetValidators represents the response from the /api/rounds/<id>/validators endpoint.
type GetValidators struct {
Data []RoundValidator `json:"data,omitempty"`
}
21 changes: 9 additions & 12 deletions client/rounds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"testing"
)

// Get the forging delegates of a round by the given id.
func TestRoundsService_Delegates(t *testing.T) {
// Get the forging validators of a round by the given id.
func TestRoundsService_Validators(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/rounds/12345/delegates", func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc("/rounds/12345/validators", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
fmt.Fprint(writer,
`{
Expand All @@ -32,19 +32,17 @@ func TestRoundsService_Delegates(t *testing.T) {
}`)
})

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{{
responseStruct, response, err := client.Rounds.Validators(context.Background(), 12345)
testGeneralError(t, "Rounds.Validators", err)
testResponseUrl(t, "Rounds.Validators", response, "/rounds/12345/validators")
testResponseStruct(t, "Rounds.Validators", responseStruct, &GetValidators{
Data: []RoundValidator{{
PublicKey: "03ffc17c5528d490b045a9b710c754e00a536d05d9b0b78a9baa0533a246dcd98c",
Votes: "156947252547993",
}},
})
}



// TestRoundsService_All tests the All method.
func TestRoundsService_All(t *testing.T) {
client, mux, _, teardown := setupTest()
Expand Down Expand Up @@ -92,7 +90,7 @@ func TestRoundsService_All(t *testing.T) {
Count: 100,
First: "/rounds?limit=100&page=1",
Last: "/rounds?limit=100&page=230",
Next: nil,
Next: nil,
PageCount: 230,
Previous: nil,
Self: "/rounds?limit=100&page=1",
Expand Down Expand Up @@ -154,4 +152,3 @@ func TestRoundsService_Show(t *testing.T) {
},
})
}

72 changes: 72 additions & 0 deletions client/validators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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"
)

// ValidatorsService handles communication with the validators related
// methods of the Ark Core API - Version 2.
type ValidatorsService Service

// Get all accounts.
func (s *ValidatorsService) List(ctx context.Context, query *Pagination) (*Validators, *http.Response, error) {
var responseStruct *Validators
resp, err := s.client.SendRequest(ctx, "GET", "validators", query, nil, &responseStruct, "api")

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get a validator by the given ID. (address, publicKey and username are valid)
func (s *ValidatorsService) Get(ctx context.Context, id string) (*GetValidator, *http.Response, error) {
uri := fmt.Sprintf("validators/%v", id)

var responseStruct *GetValidator
resp, err := s.client.SendRequest(ctx, "GET", uri, nil, nil, &responseStruct, "api")

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get all blocks for the given validator.
func (s *ValidatorsService) Blocks(ctx context.Context, id string, query *Pagination) (*GetValidatorBlocks, *http.Response, error) {
uri := fmt.Sprintf("validators/%v/blocks", id)

var responseStruct *GetValidatorBlocks
resp, err := s.client.SendRequest(ctx, "GET", uri, query, nil, &responseStruct, "api")

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}

// Get all voters for the given validator.
func (s *ValidatorsService) Voters(ctx context.Context, id string, query *Pagination) (*GetValidatorVoters, *http.Response, error) {
uri := fmt.Sprintf("validators/%v/voters", id)

var responseStruct *GetValidatorVoters
resp, err := s.client.SendRequest(ctx, "GET", uri, query, nil, &responseStruct, "api")

if err != nil {
return nil, resp, err
}

return responseStruct, resp, err
}
Loading
Loading