types

package
Version: v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2020 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package types defines the data structures and regular expressions that helps to unmarshal commits history string into data to be shared with the outside world.

Index

Constants

View Source
const (
	// DefaultRepo is the default github repository name where Politea Votes
	// are stored.
	DefaultRepo = "mainnet"

	// DefaultRepoOwner is the owner of the default github repository where
	// Politeia votes are stored.
	DefaultRepoOwner = "hdfchain"

	// DefaultVotesCommitMsg defines the message of the commits that holds
	// the votes data for the various proposal token(s).
	DefaultVotesCommitMsg = "Flush vote journals"

	// CmdDateFormat defines the date format of the time returned by git commandline
	// interface. Time format is known as RFC2822.
	CmdDateFormat = "Mon Jan 2 15:04:05 2006 -0700"
)

Variables

View Source
var ErrGitVersion = errors.New("invalid git version found. A minimum of v" +
	minGitVersion.String() + " was expected")

ErrGitVersion is the default error returned if an invalid git version was found.

Functions

func ClearProposalToken

func ClearProposalToken()

ClearProposalToken deletes the current proposal token value.

func CustomUnmashaller

func CustomUnmashaller(h *History, str string, since ...time.Time) error

CustomUnmashaller unmarshals the string argument passed. Its not in a JSON format. History unmarshalling happens ONLY for the set proposal token and for all proposal tokens available if otherwise (not set).

func GetProposalToken

func GetProposalToken() string

GetProposalToken returns the current proposal token value set.

func IsGitVersionSupported

func IsGitVersionSupported(parsedStr string) error

IsGitVersionSupported checks if the git version in the parse string is supported. An error is returned if otherwise.

func IsMatching

func IsMatching(parent, matchRegex string) bool

IsMatching returns boolean true if the matchRegex can be matched in the parent string.

func ReplaceAny

func ReplaceAny(parent, regex, with string) string

ReplaceAny replaces the all occurence of "regex" in string "parent" with replacement "with" for all the possible occurences.

func ReplaceJournalSelection

func ReplaceJournalSelection(parent, with string) string

ReplaceJournalSelection uses journalSelection regex expression to replace the journal action in the provided parent string using the provided replacement.

func RetrieveAllPatchSelection

func RetrieveAllPatchSelection(parent string) string

RetrieveAllPatchSelection uses patchSelection regex expression to fetch all individual matching lines from the provided parent string.

func RetrieveCMDAuthor

func RetrieveCMDAuthor(parent string) (string, error)

RetrieveCMDAuthor uses cmdAuthorSelection regex expression to retrieve the Author value in the provided parent string.

func RetrieveCMDCommit

func RetrieveCMDCommit(parent string) (string, error)

RetrieveCMDCommit uses cmdCommitSelection to retrieve the commit SHA value from the provided parent string.

func RetrieveCMDDate

func RetrieveCMDDate(parent string) (time.Time, error)

RetrieveCMDDate uses cmdDateSelection regex expression to retrieve the Date value in the provided parent string. The fetched date string is converted into a time.Time objected using "Mon Jan 2 15:04:05 2006 -0700" date format.

func RetrieveProposalToken

func RetrieveProposalToken(parent string) (string, error)

RetrieveProposalToken uses the anyTokenSelection regex to build a regex expression used to select the proposal token from the parent string.

func SetProposalToken

func SetProposalToken(token string) error

SetProposalToken sets the current proposal token string whose data is being unmarshalled.

func SplitCommitDiff

func SplitCommitDiff(parent string) []string

SplitCommitDiff uses the commitDiff separating string to split the string into an array.

func ToBitcast

func ToBitcast(in string) bitCast

ToBitcast casts the vote Id bitCast type.

func VotesJSONSignature

func VotesJSONSignature() string

VotesJSONSignature defines a part of the json string signature that matches the commit patch string required. The matched commit patch string contains the needed votes data.

Types

type CastVoteData

type CastVoteData struct {
	*PiVote `json:"castvote"`
}

CastVoteData defines the struct of a cast vote and the reciept response.

type File

type File struct {
	Token     string
	VotesInfo Votes
}

File defines the votes cast for a single token in a commit. A commit can votes cast for several commits joined together.

type History

type History struct {
	Author    string
	CommitSHA string
	Date      time.Time
	Patch     []*File
}

History defines the standard single commit history contents to be shared with the outside world.

type PiRegExp

type PiRegExp string

PiRegExp helps defines the various regex expression supported. It also helps to easily compile them.

type PiVote

type PiVote struct {
	// Token     string  `json:"token"`
	Ticket  string  `json:"ticket"`
	VoteBit bitCast `json:"votebit"`
}

PiVote defines the ticket hash and vote bit type details about a vote.

type Votes

type Votes []CastVoteData

Votes defines a slice type of votes cast data.

func (*Votes) UnmarshalJSON

func (v *Votes) UnmarshalJSON(b []byte) error

UnmarshalJSON defines the default unmarshaller for Votes.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL