Skip to content

Commit

Permalink
feat: add missing api endpoints (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored and faustbrian committed Sep 15, 2019
1 parent 21d4e4d commit da072b1
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 18 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Expand Up @@ -35,6 +35,7 @@ type Client struct {
Delegates *DelegatesService
Node *NodeService
Peers *PeersService
Rounds *RoundsService
Transactions *TransactionsService
Votes *VotesService
Wallets *WalletsService
Expand All @@ -58,6 +59,7 @@ func NewClient(httpClient *http.Client) *Client {
c.Delegates = (*DelegatesService)(&c.common)
c.Node = (*NodeService)(&c.common)
c.Peers = (*PeersService)(&c.common)
c.Rounds = (*RoundsService)(&c.common)
c.Transactions = (*TransactionsService)(&c.common)
c.Votes = (*VotesService)(&c.common)
c.Wallets = (*WalletsService)(&c.common)
Expand Down
32 changes: 32 additions & 0 deletions client/rounds.go
@@ -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
}
17 changes: 17 additions & 0 deletions client/rounds_responses.go
@@ -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"`
}
44 changes: 44 additions & 0 deletions client/rounds_test.go
@@ -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",
}},
})
}
12 changes: 12 additions & 0 deletions client/transactions.go
Expand Up @@ -104,3 +104,15 @@ func (s *TransactionsService) Types(ctx context.Context) (*TransactionTypes, *ht

return responseStruct, resp, err
}

// Get a list of static transaction fees.
func (s *TransactionsService) Fees(ctx context.Context) (*TransactionFees, *http.Response, error) {
var responseStruct *TransactionFees
resp, err := s.client.SendRequest(ctx, "GET", "transactions/fees", nil, nil, &responseStruct)

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

return responseStruct, resp, err
}
4 changes: 4 additions & 0 deletions client/transactions_responses.go
Expand Up @@ -44,6 +44,10 @@ type TransactionTypes struct {
Data map[string]byte `json:"data,omitempty"`
}

type TransactionFees struct {
Data map[string]FlexToshi `json:"data,omitempty"`
}

type Timestamp struct {
Epoch int32 `json:"epoch,omitempty"`
Unix int32 `json:"unix,omitempty"`
Expand Down
77 changes: 59 additions & 18 deletions client/transactions_test.go
Expand Up @@ -413,15 +413,15 @@ func TestTransactionsService_Types(t *testing.T) {
fmt.Fprint(writer,
`{
"data": {
"TRANSFER": 0,
"SECOND_SIGNATURE": 1,
"DELEGATE_REGISTRATION": 2,
"VOTE": 3,
"MULTI_SIGNATURE": 4,
"IPFS": 5,
"TIMELOCK_TRANSFER": 6,
"MULTI_PAYMENT": 7,
"DELEGATE_RESIGNATION": 8
"Transfer": 0,
"SecondSignature": 1,
"DelegateRegistration": 2,
"Vote": 3,
"MultiSignature": 4,
"Ipfs": 5,
"TimelockTransfer": 6,
"MultiPayment": 7,
"DelegateResignation": 8
}
}`)
})
Expand All @@ -431,15 +431,56 @@ func TestTransactionsService_Types(t *testing.T) {
testResponseUrl(t, "Transactions.Types", response, "/api/transactions/types")
testResponseStruct(t, "Transactions.Types", responseStruct, &TransactionTypes{
Data: map[string]byte{
"TRANSFER": 0,
"SECOND_SIGNATURE": 1,
"DELEGATE_REGISTRATION": 2,
"VOTE": 3,
"MULTI_SIGNATURE": 4,
"IPFS": 5,
"TIMELOCK_TRANSFER": 6,
"MULTI_PAYMENT": 7,
"DELEGATE_RESIGNATION": 8,
"Transfer": 0,
"SecondSignature": 1,
"DelegateRegistration": 2,
"Vote": 3,
"MultiSignature": 4,
"Ipfs": 5,
"TimelockTransfer": 6,
"MultiPayment": 7,
"DelegateResignation": 8,
},
})
}

// Get a list of static transaction fees.
func TestTransactionsService_Fees(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/transactions/fees", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
fmt.Fprint(writer,
`{
"data": {
"transfer": 10000000,
"secondSignature": 500000000,
"delegateRegistration": 2500000000,
"vote": 100000000,
"multiSignature": 500000000,
"ipfs": 0,
"timelockTransfer": 0,
"multiPayment": 0,
"delegateResignation": 2500000000
}
}`)
})

responseStruct, response, err := client.Transactions.Fees(context.Background())
testGeneralError(t, "Transactions.Fees", err)
testResponseUrl(t, "Transactions.Fees", response, "/api/transactions/fees")
testResponseStruct(t, "Transactions.Fees", responseStruct, &TransactionFees{
Data: map[string]FlexToshi{
"transfer": 10000000,
"secondSignature": 500000000,
"delegateRegistration": 2500000000,
"vote": 100000000,
"multiSignature": 500000000,
"ipfs": 0,
"timelockTransfer": 0,
"multiPayment": 0,
"delegateResignation": 2500000000,
},
})
}

0 comments on commit da072b1

Please sign in to comment.