Skip to content

Commit

Permalink
Fixed get_producers call.
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed Jan 19, 2022
1 parent 84a69f3 commit d910fac
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

#### Breaking Changes

* Fixed [`Producer`](https://github.com/eoscanada/eos-go/blob/c56c2f318d421cbc9d49d9094ea3732ddb94969a/responses.go#L451) to use more standard `eos-go` types.
* Fixed [ProducersResp](https://github.com/eoscanada/eos-go/blob/c56c2f318d421cbc9d49d9094ea3732ddb94969a/responses.go#L462) to fit with actual EOSIO API.

#### Added

* Add EOSIO Testnet symbol (#165)
* Update ActionResp (#166)

#### Changed

#### Fixed

* Bugfix StringToSymbol (44b6fbd)
* Fixed built-in examples (pointing by default to EOS Nation API nodes) (36114bd)

#### Deprecated

### [**0.10.1**](https://github.com/eoscanada/eos-go/releases/tag/v0.10.1) (January 19th, 2022)

#### Breaking Changes

* Renamed [`BlockTimestampFormat`](https://github.com/eoscanada/eos-go/blob/a1623cc5a2223005a4dc7d4dec972d6119de42ff/types.go#L844) to `blockTimestampFormat` making it private.

#### Added

* Add EOSIO Testnet symbol (#165)
* Update ActionResp (#166)

#### Changed

#### Fixed

* Bugfix StringToSymbol (44b6fbd)
* Fixed built-in examples (pointing by default to EOS Nation API nodes) (36114bd)

#### Deprecated

### [**0.10**](https://github.com/eoscanada/eos-go/releases/tag/v0.10.0) (October 16th, 2021)
Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (api *API) GetProducers(ctx context.Context) (out *ProducersResp, err error
/*
+FC_REFLECT( eosio::chain_apis::read_only::get_producers_params, (json)(lower_bound)(limit) )
+FC_REFLECT( eosio::chain_apis::read_only::get_producers_result, (rows)(total_producer_vote_weight)(more) ); */
err = api.call(ctx, "chain", "get_producers", nil, &out)
err = api.call(ctx, "chain", "get_producers", M{"json": true}, &out)
return
}

Expand Down
34 changes: 34 additions & 0 deletions example_api_get_producers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package eos_test

import (
"context"
"fmt"
"sort"

eos "github.com/eoscanada/eos-go"
)

func ExampleAPI_GetProducers() {
api := eos.New(getAPIURL())

resp, err := api.GetProducers(context.Background())
if err != nil {
panic(fmt.Errorf("get account: %w", err))
}

sort.Slice(resp.Producers, func(i, j int) bool {
if resp.Producers[i].IsActive && !resp.Producers[j].IsActive {
return true
}

return resp.Producers[i].TotalVotes < resp.Producers[j].TotalVotes
})

for _, producer := range resp.Producers {
fmt.Printf("Producer %s (%s) with %.5f votes (last claimed %s)\n", producer.Owner, producer.URL, producer.TotalVotes, producer.LastClaimTime)
}

fmt.Printf("Total Vote Weight: %.4f\n", resp.TotalProducerVoteWeight)
fmt.Printf("More: %s\n", resp.More)
// Output: any
}
25 changes: 16 additions & 9 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,23 +449,28 @@ type Global struct {
}

type Producer struct {
Owner string `json:"owner"`
TotalVotes float64 `json:"total_votes,string"`
ProducerKey string `json:"producer_key"`
IsActive int `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime Float64 `json:"last_claim_time"`
Location int `json:"location"`
Owner Name `json:"owner"`
TotalVotes Float64 `json:"total_votes,string"`
ProducerKey ecc.PublicKey `json:"producer_key"`
IsActive Bool `json:"is_active"`
URL string `json:"url"`
UnpaidBlocks int `json:"unpaid_blocks"`
LastClaimTime JSONTime `json:"last_claim_time"`
Location int `json:"location"`
}

type ProducersResp struct {
Producers []Producer `json:"producers"`
Producers []Producer `json:"rows"`
TotalProducerVoteWeight Float64 `json:"total_producer_vote_weight"`
More Name `json:"more"`
}

type GetActionsRequest struct {
AccountName AccountName `json:"account_name"`
Pos Int64 `json:"pos"`
Offset Int64 `json:"offset"`
}

type ActionResp struct {
GlobalSeq JSONInt64 `json:"global_action_seq"`
AccountSeq JSONInt64 `json:"account_action_seq"`
Expand All @@ -474,10 +479,12 @@ type ActionResp struct {
Trace ActionTrace `json:"action_trace"`
Irreversible bool `json:"irreversible"`
}

type ActionsResp struct {
Actions []ActionResp `json:"actions"`
LastIrreversibleBlock uint32 `json:"last_irreversible_block"`
}

type KeyAccountsResp struct {
AccountNames []string `json:"account_names"`
}
Expand Down

0 comments on commit d910fac

Please sign in to comment.