-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor tally querying and types (#59)
* chore: refactor tally querying and types * chore: moved types * chore: add tally test * chore: fix linting
- Loading branch information
1 parent
ab5a1e6
commit 1eb2212
Showing
13 changed files
with
437 additions
and
331 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
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,49 @@ | ||
package cosmos | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"main/pkg/fetchers/cosmos/responses" | ||
"main/pkg/types" | ||
"main/pkg/utils" | ||
) | ||
|
||
func (rpc *RPC) GetAllV1Proposals() ([]types.Proposal, *types.QueryError) { | ||
proposals := []types.Proposal{} | ||
offset := 0 | ||
|
||
for { | ||
url := fmt.Sprintf( | ||
// 2 is for PROPOSAL_STATUS_VOTING_PERIOD | ||
"/cosmos/gov/v1/proposals?pagination.limit=%d&pagination.offset=%d&proposal_status=2", | ||
PaginationLimit, | ||
offset, | ||
) | ||
|
||
var batchProposals responses.V1ProposalsRPCResponse | ||
if errs := rpc.Get(url, &batchProposals); len(errs) > 0 { | ||
return nil, &types.QueryError{ | ||
QueryError: nil, | ||
NodeErrors: errs, | ||
} | ||
} | ||
|
||
if batchProposals.Message != "" { | ||
return nil, &types.QueryError{ | ||
QueryError: errors.New(batchProposals.Message), | ||
} | ||
} | ||
|
||
parsedProposals := utils.Map(batchProposals.Proposals, func(p responses.V1Proposal) types.Proposal { | ||
return p.ToProposal() | ||
}) | ||
proposals = append(proposals, parsedProposals...) | ||
if len(batchProposals.Proposals) < PaginationLimit { | ||
break | ||
} | ||
|
||
offset += PaginationLimit | ||
} | ||
|
||
return proposals, nil | ||
} |
Oops, something went wrong.