models

package
v0.0.0-...-c09acad Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LatestListSyncedEventKey     = "LatestListSyncedEvent"
	LatestRegistrySyncedEventKey = "LatestRegistrySyncedEvent"
	LatestSyncedBlockKey         = "LatestSyncedBlock"
	LatestLoggedBlockKey         = "LatestLoggedBlock"
	LatestSyncedTweetKey         = "LatestSyncedTweet"
	TwitterRequestTokenKey       = "TwitterRequestToken"
)
View Source
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

func AllAccounts() (*sqlx.Rows, error)

AllAccounts returns a list of all accounts currently in the database

func ClearKey

func ClearKey(key string) error

ClearKey removes the given key's row from the database

func CreateAccount

func CreateAccount(account *Account) error

CreateAccount creates a new account record in the database from the given account struct.

func CreateDMAnalyticsEvent

func CreateDMAnalyticsEvent(twitterID int64, message string) error

CreateDMAnalyticsEvent creates a new event given an account ID (optional, set to 0 if null) and the direct message's text

func CreateETHEvent

func CreateETHEvent(event *ETHEvent, data interface{}) error

CreateETHEvent creates a new event given an Ethereum event name and its associated data

func CreateMentionAnalyticsEvent

func CreateMentionAnalyticsEvent(twitterID int64, tweetID string, message string) error

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

func GetDBSession() *sqlx.DB

GetDBSession returns the current active database connection pool or creates it if it doesn't already exist

func GetKey

func GetKey(key string) (string, error)

GetKey fetches the given key's value from the database

func RecordFaucetHit

func RecordFaucetHit(accountID int64, amount *big.Int) error

RecordFaucetHit will create a new hit in the database for the given user

func SetKey

func SetKey(key string, value string) error

SetKey updates or inserts a key with the provided value

func TCRHasUpdatedSinceEventID

func TCRHasUpdatedSinceEventID(id int64) (needsUpdate bool, latestID int64, err error)

TCRHasUpdatedSinceEventID returns true or false based on whether or not there are eth events which have updated the state of the tcr since a given event ID

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

func FindAccountByHandle(handle string) (*Account, error)

FindAccountByHandle searches for a given account based on its handle or returns nil if it cannot be found

func FindAccountByID

func FindAccountByID(id int64) (*Account, error)

FindAccountByID searches for an account based on a user ID (not twitter ID)

func FindAccountByMultisigAddress

func FindAccountByMultisigAddress(address string) (*Account, error)

FindAccountByMultisigAddress returns an account based on the provided multisig address

func FindAccountByMultisigFactoryIdentifier

func FindAccountByMultisigFactoryIdentifier(identifier int64) (*Account, error)

FindAccountByMultisigFactoryIdentifier searches for a given account based on its factory identifier returns nil if it cannot be found

func FindAccountByTwitterID

func FindAccountByTwitterID(id int64) (*Account, error)

FindAccountByTwitterID searches for a given account based on the provided ID or returns nil if it cannot be found

func (*Account) AddToPLCRBalance

func (a *Account) AddToPLCRBalance(ethEventID int64, amount *big.Int) (*Balance, error)

func (*Account) AddToWalletBalance

func (a *Account) AddToWalletBalance(ethEventID int64, amount *big.Int) (*Balance, error)

func (*Account) Destroy

func (a *Account) Destroy() error

Destroy will delete all records of the account from the db

func (*Account) HasCompletedChallenges

func (a *Account) HasCompletedChallenges() (bool, error)

HasCompletedChallenges returns true if this account has completed all of the required verification challenges (and therefore has a verified account)

func (*Account) MarkActivated

func (a *Account) MarkActivated() error

MarkActivated updates the activated_at column with the current timestamp

func (*Account) MarkRegistered

func (a *Account) MarkRegistered() error

MarkRegistered updates the passed_registration_challenge_at column with the current timestamp

func (*Account) Save

func (a *Account) Save() error

Save updates the account record in the database and returns an error if it occurs

func (*Account) SetMultisigAddress

func (a *Account) SetMultisigAddress(address string) error

SetMultisigAddress updates the user's account with the given multisig wallet address

func (*Account) SetMultisigFactoryIdentifier

func (a *Account) SetMultisigFactoryIdentifier(identifier int64) error

SetMultisigFactoryIdentifier updates the user's account with the given multisig factory identifier

func (*Account) UpdateLastDMAt

func (a *Account) UpdateLastDMAt() error

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

func FindLatestBalance() (*Balance, error)

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

func FindLatestUserBalance(accountID int64) (*Balance, error)

FindLatestUserBalance returns the most recent balance row for the given account ID

func (*Balance) AddToPLCRBalance

func (b *Balance) AddToPLCRBalance(ethEventID int64, amount *big.Int) (*Balance, error)

AddToPLCRBalance adds the given amount to the user's latest PLCR balance, creates a new balance entry, and returns it.

func (*Balance) AddToWalletBalance

func (b *Balance) AddToWalletBalance(ethEventID int64, amount *big.Int) (*Balance, error)

AddToWalletBalance adds the given amount to the user's latest wallet 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

func FindETHEventByID(id int64) (*ETHEvent, error)

FindETHEventByID returns an ETH event given its ID

func FindETHEventsSinceID

func FindETHEventsSinceID(id int64) (events []*ETHEvent, moreAvailable bool, err error)

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

func LatestFaucetHit(accountID int64) (*FaucetHit, error)

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

type TokenAmount struct {
	Amt *big.Int
}

TokenAmount represents a big.Int stored in a postgres VARCHAR column

func (*TokenAmount) Scan

func (t *TokenAmount) Scan(src interface{}) error

func (TokenAmount) Value

func (t TokenAmount) Value() (driver.Value, 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

func FindUnrevealedVotesFromPoll(pollID int64) ([]*Vote, error)

FindUnrevealedVotesFromPoll returns all unrevealed votes associated with a given poll ID

func FindUnrewardedVotesFromPoll

func FindUnrewardedVotesFromPoll(pollID int64, voteDirection bool) ([]*Vote, error)

FindUnrewardedVotesFromPoll returns all votes which have yet to reveal their rewards for a given poll and vote direction

func FindVote

func FindVote(pollID, accountID int64) (*Vote, error)

FindVote returns a vote for a given poll or account ID

func (*Vote) MarkRevealed

func (v *Vote) MarkRevealed() error

MarkRevealed sets the revealed_at column of the vote to the current timestamp

func (*Vote) MarkRewardClaimed

func (v *Vote) MarkRewardClaimed() error

MarkRewardClaimed sets the reward_claimed_at column of the vote to the current timestamp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL