Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add node/fees endpoint #47

Merged
merged 2 commits into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ func (s *NodeService) Configuration(ctx context.Context) (*GetNodeConfiguration,

return responseStruct, resp, err
}

// Get the node fee statistics.
func (s *NodeService) Fees(ctx context.Context, days int) (*GetNodeFees, *http.Response, error) {
var responseStruct *GetNodeFees
resp, err := s.client.SendRequest(ctx, "GET", "node/fees", FeesRequest{ days }, nil, &responseStruct)

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

return responseStruct, resp, err
}
12 changes: 12 additions & 0 deletions client/node_requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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 FeesRequest struct {
Days int `url:"days"`
}
35 changes: 19 additions & 16 deletions client/node_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type GetNodeConfiguration struct {
Data NodeConfiguration `json:"data,omitempty"`
}

type GetNodeFees struct {
Data NodeFees `json:"data,omitempty"`
}

type NodeStatus struct {
Synced bool `json:"synced,omitempty"`
Now int64 `json:"now,omitempty"`
Expand All @@ -33,16 +37,17 @@ type NodeSyncing struct {
}

type NodeConfiguration struct {
Nethash string `json:"nethash,omitempty"`
Token string `json:"token,omitempty"`
Symbol string `json:"symbol,omitempty"`
Explorer string `json:"explorer,omitempty"`
Version int16 `json:"version,omitempty"`
Ports map[string]string `json:"ports,omitempty"`
Constants NodeConstants `json:"constants,omitempty"`
FeeStatistics []FeeStatistic `json:"feeStatistics,omitempty"`
Nethash string `json:"nethash,omitempty"`
Token string `json:"token,omitempty"`
Symbol string `json:"symbol,omitempty"`
Explorer string `json:"explorer,omitempty"`
Version int16 `json:"version,omitempty"`
Ports map[string]string `json:"ports,omitempty"`
Constants NodeConstants `json:"constants,omitempty"`
}

type NodeFees []FeeStatistic

type NodeConstantsBlock struct {
Version byte `json:"version,omitempty"`
MaxTransactions byte `json:"maxTransactions,omitempty"`
Expand All @@ -60,15 +65,13 @@ type NodeConstants struct {
DynamicOffsets DynamicFeeOffsets `json:"dynamicOffsets,omitempty"`
}

type Fees struct {
MinFee int64 `json:"minFee,omitempty"`
MaxFee int64 `json:"maxFee,omitempty"`
MvgFee int64 `json:"avgFee,omitempty"`
}

type FeeStatistic struct {
Type int16 `json:"type,omitempty"`
Fees Fees `json:"fees,omitempty"`
Type int16 `json:"type,omitempty"`
MinFee int64 `json:"min,omitempty"`
MaxFee int64 `json:"max,omitempty"`
AvgFee int64 `json:"avg,omitempty"`
SumFee int64 `json:"sum,omitempty"`
MdnFee int64 `json:"median,omitempty"`
}

type FeeTypes struct {
Expand Down
117 changes: 68 additions & 49 deletions client/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,7 @@ func TestNodeService_Configuration(t *testing.T) {
"multiPayment": 500,
"delegateResignation": 500
}
},
"feeStatistics": [
{
"type": 0,
"fees": {
"minFee": 10000000,
"maxFee": 10000000,
"avgFee": 10000000
}
},
{
"type": 1,
"fees": {
"minFee": 500000000,
"maxFee": 500000000,
"avgFee": 500000000
}
},
{
"type": 3,
"fees": {
"minFee": 100000000,
"maxFee": 100000000,
"avgFee": 100000000
}
}
]
}
}
}`)
})
Expand Down Expand Up @@ -207,28 +181,73 @@ func TestNodeService_Configuration(t *testing.T) {
DelegateResignation: 500,
},
},
FeeStatistics: []FeeStatistic{{
Type: 0,
Fees: Fees{
MinFee: 10000000,
MaxFee: 10000000,
MvgFee: 10000000,
},
}, {
Type: 1,
Fees: Fees{
MinFee: 500000000,
MaxFee: 500000000,
MvgFee: 500000000,
},
}, {
Type: 3,
Fees: Fees{
MinFee: 100000000,
MaxFee: 100000000,
MvgFee: 100000000,
},
}},
},
})
}

// Get the node fee statistics.
func TestNodeService_Fees(t *testing.T) {
client, mux, _, teardown := setupTest()
defer teardown()

mux.HandleFunc("/node/fees", func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
fmt.Fprint(writer,
`{
"data": [
{
"type": 0,
"min": 10000000,
"max": 10000000,
"avg": 10000000,
"sum": 10000000,
"median": 10000000
},
{
"type": 1,
"min": 500000000,
"max": 500000000,
"avg": 500000000,
"sum": 500000000,
"median": 500000000
},
{
"type": 3,
"min": 100000000,
"max": 100000000,
"avg": 100000000,
"sum": 100000000,
"median": 100000000
}
]
}`)
})

responseStruct, response, err := client.Node.Fees(context.Background(), 7)
testGeneralError(t, "Node.Fees", err)
testResponseUrl(t, "Node.Fees", response, "/api/node/fees?days=7")
testResponseStruct(t, "Node.Fees", responseStruct, &GetNodeFees{
Data: []FeeStatistic{{
Type: 0,
MinFee: 10000000,
MaxFee: 10000000,
AvgFee: 10000000,
SumFee: 10000000,
MdnFee: 10000000,
}, {
Type: 1,
MinFee: 500000000,
MaxFee: 500000000,
AvgFee: 500000000,
SumFee: 500000000,
MdnFee: 500000000,
}, {
Type: 3,
MinFee: 100000000,
MaxFee: 100000000,
AvgFee: 100000000,
SumFee: 100000000,
MdnFee: 100000000,
}},
})
}