Documentation
¶
Index ¶
- Constants
- func AllAccounts() (*sqlx.Rows, error)
- func ClearKey(key string) error
- func CreateAccount(account *Account) error
- func CreateDMAnalyticsEvent(twitterID int64, message string) error
- func CreateETHEvent(event *ETHEvent, data interface{}) error
- func CreateMentionAnalyticsEvent(twitterID int64, tweetID string, message string) error
- func CreateOAuthToken(token *OAuthToken) error
- func GetDBSession() *sqlx.DB
- func GetKey(key string) (string, error)
- func RecordFaucetHit(accountID int64, amount *big.Int) error
- func SetKey(key string, value string) error
- func TCRHasUpdatedSinceEventID(id int64) (needsUpdate bool, latestID int64, err error)
- type Account
- func FindAccountByHandle(handle string) (*Account, error)
- func FindAccountByID(id int64) (*Account, error)
- func FindAccountByMultisigAddress(address string) (*Account, error)
- func FindAccountByMultisigFactoryIdentifier(identifier int64) (*Account, error)
- func FindAccountByTwitterID(id int64) (*Account, error)
- func (a *Account) AddToPLCRBalance(ethEventID int64, amount *big.Int) (*Balance, error)
- func (a *Account) AddToWalletBalance(ethEventID int64, amount *big.Int) (*Balance, error)
- func (a *Account) Destroy() error
- func (a *Account) HasCompletedChallenges() (bool, error)
- func (a *Account) MarkActivated() error
- func (a *Account) MarkRegistered() error
- func (a *Account) Save() error
- func (a *Account) SetMultisigAddress(address string) error
- func (a *Account) SetMultisigFactoryIdentifier(identifier int64) error
- func (a *Account) UpdateLastDMAt() error
- type AnalyticsEvent
- type AnalyticsEventType
- type Balance
- type ETHEvent
- type FaucetHit
- type OAuthToken
- type RegistrationChallenge
- type RegistrationChallengeRegistrationQuestion
- type RegistrationQuestion
- type RegistryChallenge
- type RegistryListing
- type RegistryListingWithChallenge
- type TokenAmount
- type Vote
- func CreateVote(account *Account, pollID int64, salt int64, voteVal bool, weight int64) (*Vote, error)
- func FindUnrevealedVotesFromPoll(pollID int64) ([]*Vote, error)
- func FindUnrewardedVotesFromPoll(pollID int64, voteDirection bool) ([]*Vote, error)
- func FindVote(pollID, accountID int64) (*Vote, error)
Constants ¶
const ( LatestListSyncedEventKey = "LatestListSyncedEvent" LatestRegistrySyncedEventKey = "LatestRegistrySyncedEvent" LatestSyncedBlockKey = "LatestSyncedBlock" LatestLoggedBlockKey = "LatestLoggedBlock" LatestSyncedTweetKey = "LatestSyncedTweet" TwitterRequestTokenKey = "TwitterRequestToken" )
const ( // RegistrationChallengeCount is the number of registration challenges // required to be completed before a user is considered registered. RegistrationChallengeCount = 3 )
Variables ¶
This section is empty.
Functions ¶
func AllAccounts ¶
AllAccounts returns a list of all accounts currently in the database
func CreateAccount ¶
CreateAccount creates a new account record in the database from the given account struct.
func CreateDMAnalyticsEvent ¶
CreateDMAnalyticsEvent creates a new event given an account ID (optional, set to 0 if null) and the direct message's text
func CreateETHEvent ¶
CreateETHEvent creates a new event given an Ethereum event name and its associated data
func CreateMentionAnalyticsEvent ¶
CreateMentionAnalyticsEvent creates a new event given an account ID (optional, set to 0 if null), the tweet's text, and its ID.
func CreateOAuthToken ¶
func CreateOAuthToken(token *OAuthToken) error
CreateOAuthToken inserts a new OAuth token into the database
func GetDBSession ¶
GetDBSession returns the current active database connection pool or creates it if it doesn't already exist
func RecordFaucetHit ¶
RecordFaucetHit will create a new hit in the database for the given user
Types ¶
type Account ¶
type Account struct {
ID int64 `db:"id"`
TwitterID int64 `db:"twitter_id"`
TwitterHandle string `db:"twitter_handle"`
MultisigAddress *sql.NullString `db:"multisig_address"`
MultisigFactoryIdentifier *sql.NullInt64 `db:"multisig_factory_identifier"`
PassedRegistrationChallengeAt *time.Time `db:"passed_registration_challenge_at"`
CreatedAt *time.Time `db:"created_at"`
LastDMAt *time.Time `db:"last_dm_at"`
// ActivatedAt is used for the pre-registration phase of the party. After
// pre-registration it can be ignored
ActivatedAt *time.Time `db:"activated_at"`
}
Account represents a twitter account that interacts with our bot. They may or may not be a member on the TCR or a token holder.
func FindAccountByHandle ¶
FindAccountByHandle searches for a given account based on its handle or returns nil if it cannot be found
func FindAccountByID ¶
FindAccountByID searches for an account based on a user ID (not twitter ID)
func FindAccountByMultisigAddress ¶
FindAccountByMultisigAddress returns an account based on the provided multisig address
func FindAccountByMultisigFactoryIdentifier ¶
FindAccountByMultisigFactoryIdentifier searches for a given account based on its factory identifier returns nil if it cannot be found
func FindAccountByTwitterID ¶
FindAccountByTwitterID searches for a given account based on the provided ID or returns nil if it cannot be found
func (*Account) AddToPLCRBalance ¶
func (*Account) AddToWalletBalance ¶
func (*Account) HasCompletedChallenges ¶
HasCompletedChallenges returns true if this account has completed all of the required verification challenges (and therefore has a verified account)
func (*Account) MarkActivated ¶
MarkActivated updates the activated_at column with the current timestamp
func (*Account) MarkRegistered ¶
MarkRegistered updates the passed_registration_challenge_at column with the current timestamp
func (*Account) Save ¶
Save updates the account record in the database and returns an error if it occurs
func (*Account) SetMultisigAddress ¶
SetMultisigAddress updates the user's account with the given multisig wallet address
func (*Account) SetMultisigFactoryIdentifier ¶
SetMultisigFactoryIdentifier updates the user's account with the given multisig factory identifier
func (*Account) UpdateLastDMAt ¶
UpdateLastDMAt sets last_dm_at to the current timestamp and updates the db
type AnalyticsEvent ¶
type AnalyticsEvent struct {
ID int64 `db:"id"`
Key AnalyticsEventType `db:"key"`
AccountID sql.NullInt64 `db:"account_id"`
Additionals types.JSONText `db:"additionals"`
CreatedAt *time.Time `db:"created_at"`
}
AnalyticsEvent represents any form of event that we may want to keep track of for product metrics
type AnalyticsEventType ¶
type AnalyticsEventType string
AnalyticsEventType represents the various event types in our analytics table. This reflects the analyitics_event_type enum in postgres.
const ( DMAnalyticsEvent AnalyticsEventType = "dm" MentionAnalyticsEvent AnalyticsEventType = "mention" )
type Balance ¶
type Balance struct {
ID int64 `db:"id"`
AccountID int64 `db:"account_id"`
ETHEventID int64 `db:"eth_event_id"`
PLCRBalance TokenAmount `db:"plcr_balance"`
WalletBalance TokenAmount `db:"wallet_balance"`
}
Balance represents an account's current balance at a given block
func CreateBalance ¶
func CreateBalance(accountID, ethEventID int64, walletBalance, plcrBalance *big.Int) (*Balance, error)
CreateBalance creates a new balance entry in the database
func FindLatestBalance ¶
FindLatestBalance finds the most recently created balance row. This is usually used for syncing with the blockchain, as this row will represent the latest block number that has been synced.
func FindLatestUserBalance ¶
FindLatestUserBalance returns the most recent balance row for the given account ID
func (*Balance) AddToPLCRBalance ¶
AddToPLCRBalance adds the given amount to the user's latest PLCR balance, creates a new balance entry, and returns it.
type ETHEvent ¶
type ETHEvent struct {
ID int64 `db:"id"`
EventType string `db:"event_type"`
Data types.JSONText `db:"data"`
BlockNumber uint64 `db:"block_number"`
TxHash string `db:"tx_hash"`
TxIndex uint `db:"tx_index"`
LogIndex uint `db:"log_index"`
CreatedAt *time.Time `db:"created_at"`
}
func FindETHEventByID ¶
FindETHEventByID returns an ETH event given its ID
func FindETHEventsSinceID ¶
FindETHEventsSinceID returns all events that have occured with IDs greater than the provided number. Since initial syncs have the potential of loading thousands of events, this function will return at most 500 (this number was selected arbitrarily and can be replaced based on performance) and return true on the moreAvailable value, signaling that the user should call the function again to retrieve the next batch of results.
type FaucetHit ¶
type FaucetHit struct {
ID int64 `db:"id"`
AccountID int64 `db:"account_id"`
Amount string `db:"amount"`
Timestamp *time.Time `db:"created_at"`
}
FaucetHit is a record of each time a user hits the faucet
func LatestFaucetHit ¶
LatestFaucetHit returns the record for the latest hit from the given user
type OAuthToken ¶
type OAuthToken struct {
ID int64 `db:"id"`
TwitterHandle string `db:"twitter_handle"`
TwitterID int64 `db:"twitter_id"`
OAuthToken string `db:"oauth_token"`
OAuthTokenSecret string `db:"oauth_token_secret"`
CreatedAt time.Time `db:"created_at"`
}
OAuthToken stores the data required to control the two bots which act as the frontend for our TCR. This table should only have two rows, one for the TCR Bot and one for the VIP bot.
func FindOAuthTokenByHandle ¶
func FindOAuthTokenByHandle(handle string) (*OAuthToken, error)
FindOAuthTokenByHandle returns an OAuth token given a twitter handle
func (*OAuthToken) Save ¶
func (token *OAuthToken) Save() error
Save saves the OAuthToken to the database
type RegistrationChallenge ¶
type RegistrationChallenge struct {
ID int64 `db:"id"`
AccountID int64 `db:"account_id"`
RegistrationQuestionID int64 `db:"registration_question_id"`
SentAt *time.Time `db:"sent_at"`
CompletedAt *time.Time `db:"completed_at"`
}
RegistrationChallenge is a mapping between users and registration questions, facilitating the registration process
func CreateRegistrationChallenge ¶
func CreateRegistrationChallenge(account *Account, question *RegistrationQuestion) (*RegistrationChallenge, error)
CreateRegistrationChallenge stores a new challenge in the database
func (*RegistrationChallenge) MarkCompleted ¶
func (challenge *RegistrationChallenge) MarkCompleted() error
func (*RegistrationChallenge) MarkSent ¶
func (challenge *RegistrationChallenge) MarkSent() error
type RegistrationChallengeRegistrationQuestion ¶
type RegistrationChallengeRegistrationQuestion struct {
RegistrationChallenge
RegistrationQuestion `db:"registration_questions"`
}
RegistrationChallengeRegistrationQuestion is a union between challenges and questions to facilitate joins between the two tables.
func FindIncompleteChallenge ¶
func FindIncompleteChallenge(accountId int64) (*RegistrationChallengeRegistrationQuestion, error)
func FindUnsentChallenge ¶
func FindUnsentChallenge(accountId int64) (*RegistrationChallengeRegistrationQuestion, error)
type RegistrationQuestion ¶
type RegistrationQuestion struct {
ID int64 `db:"id"`
Question string `db:"question"`
Answer string `db:"answer"`
DeletedAt *time.Time `db:"deleted_at"`
}
RegistrationQuestion is a struct representing a row in the registration_questions table
func FetchRandomRegistrationQuestions ¶
func FetchRandomRegistrationQuestions(count uint) ([]RegistrationQuestion, error)
FetchRandomRegistrationQuestions will return `count` number of registration questions from the database
type RegistryChallenge ¶
type RegistryChallenge struct {
PollID int64 `db:"poll_id" json:"poll_id"`
ListingHash string `db:"listing_hash" json:"-"`
ListingID string `db:"listing_id" json:"-"`
ChallengerAccountID sql.NullInt64 `db:"challenger_account_id" json:"-"`
ChallengerAddress string `db:"challenger_address" json:"-"`
CreatedAt *time.Time `db:"created_at" json:"created_at"`
CommitEndsAt *time.Time `db:"commit_ends_at" json:"commit_ends_at"`
RevealEndsAt *time.Time `db:"reveal_ends_at" json:"reveal_ends_at"`
SucceededAt *time.Time `db:"succeeded_at" json:"-"`
FailedAt *time.Time `db:"failed_at" json:"-"`
Listing *RegistryListing `db:"registry_listing" json:"-"`
}
RegistryChallenge represents a challenge on a RegistryListing
func FindActiveChallenges ¶
func FindActiveChallenges() ([]*RegistryChallenge, error)
FindActiveChallenges returns a list of challenges current in progress
func FindRegistryChallengeByPollID ¶
func FindRegistryChallengeByPollID(pollID int64) (*RegistryChallenge, error)
FindRegistryChallengeByPollID finds a challenge given its poll ID (also known as a challenge ID)
func (*RegistryChallenge) Create ¶
func (challenge *RegistryChallenge) Create() error
Create inserts the registry challenge into the database
func (*RegistryChallenge) Save ¶
func (challenge *RegistryChallenge) Save() error
Save updates the registry challenge's row in the database
type RegistryListing ¶
type RegistryListing struct {
ID string `db:"id" json:"-"`
ListingHash string `db:"listing_hash" json:"listing_hash"`
TwitterHandle string `db:"twitter_handle" json:"twitter_handle"`
Deposit string `db:"deposit" json:"deposit"`
ApplicationCreatedAt *time.Time `db:"application_created_at" json:"application_created_at"`
ApplicationEndedAt *time.Time `db:"application_ended_at" json:"application_ended_at"`
WhitelistedAt *time.Time `db:"whitelisted_at" json:"whitelisted_at"`
RemovedAt *time.Time `db:"removed_at" json:"-"`
}
RegistryListing represents an application for a listing in the registry (which may later be whitelisted)
func FindLatestRegistryListingByHash ¶
func FindLatestRegistryListingByHash(listingHash [32]byte) (*RegistryListing, error)
FindLatestRegistryListingByHash finds a registry listing by its listing hash
func FindUnchallengedApplications ¶
func FindUnchallengedApplications() ([]*RegistryListing, error)
FindUnchallengedApplications returns a list of listings that are currently applying to be on the TCR and do not have an active challenge against them.
func FindUnchallengedWhitelistedListings ¶
func FindUnchallengedWhitelistedListings() ([]*RegistryListing, error)
FindUnchallengedWhitelistedListings returns a list of registry listings that have been whitelisted but do not have an active challenge against them
func FindWhitelistedRegistryListings ¶
func FindWhitelistedRegistryListings() ([]*RegistryListing, error)
FindWhitelistedRegistryListings returns a slice of all currently whitelisted listings
func (*RegistryListing) Create ¶
func (listing *RegistryListing) Create() error
Create inserts the registry challenge into the database
func (*RegistryListing) Save ¶
func (listing *RegistryListing) Save() error
Save updates the registry listing in the database based on its current state
type RegistryListingWithChallenge ¶
type RegistryListingWithChallenge struct {
RegistryListing
RegistryChallenge `db:"registry_challenge" json:"challenge"`
}
func FindChallengedRegistryListings ¶
func FindChallengedRegistryListings() ([]*RegistryListingWithChallenge, error)
FindChallengedRegistryListings returns a list of registry listings (in the application and whitelisted stages) that are under active challenge
type TokenAmount ¶
TokenAmount represents a big.Int stored in a postgres VARCHAR column
func (*TokenAmount) Scan ¶
func (t *TokenAmount) Scan(src interface{}) error
type Vote ¶
type Vote struct {
PollID int64 `db:"poll_id"`
AccountID int64 `db:"account_id"`
Salt int64 `db:"salt"`
Vote bool `db:"vote"`
Weight int64 `db:"weight"`
Revealed *time.Time `db:"revealed_at"`
RewardClaimedAt *time.Time `db:"reward_claimed_at"`
CreatedAt *time.Time `db:"created_at"`
}
Vote represents a vote submitted to the PLCR contract. It is mostly used for stats and a temporary store of salts which are used in the reveal phase
func CreateVote ¶
func CreateVote(account *Account, pollID int64, salt int64, voteVal bool, weight int64) (*Vote, error)
CreateVote instantiates a new Vote struct and persists it to the database
func FindUnrevealedVotesFromPoll ¶
FindUnrevealedVotesFromPoll returns all unrevealed votes associated with a given poll ID
func FindUnrewardedVotesFromPoll ¶
FindUnrewardedVotesFromPoll returns all votes which have yet to reveal their rewards for a given poll and vote direction
func (*Vote) MarkRevealed ¶
MarkRevealed sets the revealed_at column of the vote to the current timestamp
func (*Vote) MarkRewardClaimed ¶
MarkRewardClaimed sets the reward_claimed_at column of the vote to the current timestamp