-
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.
feat: add Neutron votes fetching (#66)
* feat: add Neutron votes fetching * chore: add config example
- Loading branch information
1 parent
38bc617
commit 770e864
Showing
8 changed files
with
98 additions
and
38 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
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,44 @@ | ||
package responses | ||
|
||
import ( | ||
"main/pkg/types" | ||
) | ||
|
||
type Vote struct { | ||
Voter string `json:"voter"` | ||
Vote string `json:"vote"` | ||
} | ||
|
||
func (v Vote) GetOption() string { | ||
options := map[string]string{ | ||
"yes": "Yes", | ||
"no": "No", | ||
"abstain": "Abstain", | ||
} | ||
|
||
if option, ok := options[v.Vote]; ok { | ||
return option | ||
} | ||
|
||
return v.Vote | ||
} | ||
|
||
type VoteResponse struct { | ||
Data struct { | ||
Vote *Vote `json:"vote"` | ||
} `json:"data"` | ||
} | ||
|
||
func (v VoteResponse) ToVote(proposalID string) *types.Vote { | ||
if v.Data.Vote == nil { | ||
return nil | ||
} | ||
|
||
return &types.Vote{ | ||
ProposalID: proposalID, | ||
Voter: v.Data.Vote.Voter, | ||
Options: []types.VoteOption{ | ||
{Option: v.Data.Vote.GetOption(), Weight: 1}, | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,23 @@ | ||
package neutron | ||
|
||
import "main/pkg/types" | ||
import ( | ||
"fmt" | ||
"main/pkg/fetchers/neutron/responses" | ||
"main/pkg/types" | ||
) | ||
|
||
func (fetcher *Fetcher) GetVote(proposal, voter string) (*types.Vote, *types.QueryError) { | ||
// TODO: fix | ||
return nil, nil | ||
query := fmt.Sprintf( | ||
"{\"get_vote\":{\"proposal_id\":%s,\"voter\":\"%s\"}}", | ||
proposal, | ||
voter, | ||
) | ||
|
||
var vote responses.VoteResponse | ||
if err := fetcher.GetSmartContractState(query, &vote); err != nil { | ||
return nil, err | ||
} | ||
|
||
voteParsed := vote.ToVote(proposal) | ||
return voteParsed, nil | ||
} |
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