-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c3b95d
commit ab5a1e6
Showing
6 changed files
with
117 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package responses | ||
|
||
import ( | ||
"main/pkg/types" | ||
"main/pkg/utils" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// cosmos/gov/v1beta1/proposals?pagination.limit=1000&pagination.offset=0 | ||
|
||
type V1ProposalMessage struct { | ||
Content ProposalContent `json:"content"` | ||
} | ||
|
||
type V1Proposal struct { | ||
ProposalID string `json:"id"` | ||
Status string `json:"status"` | ||
VotingEndTime time.Time `json:"voting_end_time"` | ||
Messages []V1ProposalMessage `json:"messages"` | ||
|
||
Title string `json:"title"` | ||
Summary string `json:"summary"` | ||
} | ||
|
||
func (p V1Proposal) ToProposal() types.Proposal { | ||
// Some chains (namely, Quicksilver) do not have title and description fields, | ||
// instead they have content.title and content.description per each message. | ||
// Others (namely, Kujira) have title and summary text. | ||
// This should work for all of them. | ||
title := p.Title | ||
if title == "" { | ||
titles := utils.Map(p.Messages, func(m V1ProposalMessage) string { | ||
return m.Content.Title | ||
}) | ||
|
||
title = strings.Join(titles, ", ") | ||
} | ||
|
||
description := p.Summary | ||
if description == "" { | ||
descriptions := utils.Map(p.Messages, func(m V1ProposalMessage) string { | ||
return m.Content.Description | ||
}) | ||
|
||
description = strings.Join(descriptions, ", ") | ||
} | ||
|
||
return types.Proposal{ | ||
ID: p.ProposalID, | ||
Title: title, | ||
Description: description, | ||
EndTime: p.VotingEndTime, | ||
} | ||
} | ||
|
||
type V1ProposalsRPCResponse struct { | ||
Code int64 `json:"code"` | ||
Message string `json:"message"` | ||
Proposals []V1Proposal `json:"proposals"` | ||
} |
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,35 @@ | ||
package responses | ||
|
||
import ( | ||
"main/pkg/types" | ||
"time" | ||
) | ||
|
||
// cosmos/gov/v1beta1/proposals?pagination.limit=1000&pagination.offset=0 | ||
|
||
type V1beta1Proposal struct { | ||
ProposalID string `json:"proposal_id"` | ||
Status string `json:"status"` | ||
Content *ProposalContent `json:"content"` | ||
VotingEndTime time.Time `json:"voting_end_time"` | ||
} | ||
|
||
type ProposalContent struct { | ||
Title string `json:"title"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type V1Beta1ProposalsRPCResponse struct { | ||
Code int64 `json:"code"` | ||
Message string `json:"message"` | ||
Proposals []V1beta1Proposal `json:"proposals"` | ||
} | ||
|
||
func (p V1beta1Proposal) ToProposal() types.Proposal { | ||
return types.Proposal{ | ||
ID: p.ProposalID, | ||
Title: p.Content.Title, | ||
Description: p.Content.Description, | ||
EndTime: p.VotingEndTime, | ||
} | ||
} |
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,17 @@ | ||
package types | ||
|
||
import ( | ||
"main/pkg/utils" | ||
"time" | ||
) | ||
|
||
type Proposal struct { | ||
ID string | ||
Title string | ||
Description string | ||
EndTime time.Time | ||
} | ||
|
||
func (p Proposal) GetTimeLeft() string { | ||
return utils.FormatDuration(time.Until(p.EndTime).Round(time.Second)) | ||
} |
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