go-piparser is tool that parses Politeia proposals votes data stored in github. It adds a timestamp field obtained from the commit history. The tool makes use of the git commandline interface to clone and query the politeia votes data. Github repository updates are fetched at intervals of 1hr after setting up the environment. politeia doc
Check out the full doc at godoc.org or code navigation on sourcegraph.com
- Requirement
- Installation
- Import go-piparser
- Initialize the Parser instance
- Fetch the Proposal's Votes
- Fetch new updates via a trigger channel
- Full Sample Program
- Test Client
-
git - The tool requires a functional git commandline installation. To install git visit here
- A git version of
v1.5.1
released on April 4th 2007 or one after is needed.
- A git version of
-
go - Golang installation is needed.
- go1.11 or one after is required.
go get -u github.com/dmigwi/go-piparser/proposals
import "github.com/dmigwi/go-piparser/proposals"
repoOwner := ""
repoName := ""
cloneDir := "/path/to/root/clone/directory"
parser, err := proposals.NewParser(repoOwner, repoName, cloneDir)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
repoOwner
- defines the owner of the repository where the Politeia votes are to be queries from. If not set, it defaults todecred-proposals
repoName
- defines the name of the repository holding the Politeia votes. If not set, it defaults tomainnet
.cloneDir
- defines the directory where the said repository will be cloned into. If not set, a tmp folder is created and set.
// Decred Integration for IDAX Exchange Proposal token.
// https://proposals.decred.org/proposals/60adb9c0946482492889e85e9bce05c309665b3438dd85cb1a837df31fbf57fb
proposalToken := "60adb9c0946482492889e85e9bce05c309665b3438dd85cb1a837df31fbf57fb"
// ProposalHistory returns votes data only associated with the set proposal token.
data, err := parser.ProposalHistory(proposalToken)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
...
- The one hour interval at which the update signal is sent starts to count immediately
after the
proposals.NewParser(repoOwner, repoName, cloneDir)
is invoked.
// Updates trigger signal is sent hourly after which retrieval of the newly
// fetched updates can commence.
proposalUpdatesSignal := parser.UpdateSignal()
for range proposalUpdatesSignal{
// set the since time value
since, err := time.Parse(time.RFC3339,"2019-03-05T00:59:18Z")
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
// Fetch the proposal updates since 2019-03-05T00:59:18Z.
data, err = parser.ProposalHistorySince(proposalToken, since)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
}
package main
import (
"log"
"github.com/dmigwi/go-piparser/proposals"
)
func main() {
cloneDir := "/path/to/root/clone/directory"
// Set the Proposal token
proposalToken := "60adb9c0946482492889e85e9bce05c309665b3438dd85cb1a837df31fbf57fb"
// Create a new Parser instance
parser, err := proposals.NewParser("", "", cloneDir)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
// Retrieve the proposal token's votes data.
data, err := parser.ProposalHistory(proposalToken)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
...
// Retrieve proposal updates after they happen.
proposalUpdatesSignal := parser.UpdateSignal()
for range proposalUpdatesSignal{
// set the since time value
since, err := time.Parse(time.RFC3339,"2019-03-05T00:59:18Z")
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
// Fetch the proposal updates since 2019-03-05T00:59:18Z.
data, err = parser.ProposalHistorySince(proposalToken, since)
if err != nil {
log.Fatalf("unexpected error occured: %v", err)
}
...
}
}
Find a complete test go-piparser implementation here