Skip to content

Golang implementation of the Politeia's proposals votes data parser tool.

License

Notifications You must be signed in to change notification settings

dmigwi/go-piparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-piparser

Build Status ISC License GitHub top language

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

Table of Contents

Requirement

  • 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.
  • go - Golang installation is needed.

    • go1.11 or one after is required.

Installation

    go get -u github.com/dmigwi/go-piparser/proposals

Import go-piparser

    import "github.com/dmigwi/go-piparser/proposals"

Initialize the Parser instance

    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 to decred-proposals
  • repoName - defines the name of the repository holding the Politeia votes. If not set, it defaults to mainnet.
  • cloneDir - defines the directory where the said repository will be cloned into. If not set, a tmp folder is created and set.

Fetch the Proposal's Votes

    // 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)
    }
    
    ...

Fetch new updates via a signal channel

  • 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)
        }
    }

Full Sample Program

    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)
            }

            ...
        }
    }

Test Client

Find a complete test go-piparser implementation here