models

package
v0.0.0-...-1350c8b Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EarlyVote   string = "earlyVote"
	Streak             = "streak"
	WinningVote        = "winningVote"
)
View Source
const COUNT_CATEGORIES_DEFAULT_SQL = `` /* 139-byte string literal not displayed */
View Source
const COUNT_CATEGORIES_SEARCH_SQL = `` /* 145-byte string literal not displayed */
View Source
const DEFAULT_SEARCH_SQL = `
	SELECT id, name, body, logo, category
		FROM communities
    WHERE is_featured = 'true'
		AND category IS NOT NULL
`
View Source
const HOMEPAGE_SQL = `` /* 450-byte string literal not displayed */
View Source
const INSERT_COMMUNITY_SQL = `` /* 566-byte string literal not displayed */
View Source
const SEARCH_COMMUNITIES_SQL = `` /* 152-byte string literal not displayed */
View Source
const UPDATE_COMMUNITY_SQL = `` /* 937-byte string literal not displayed */

Variables

View Source
var USER_TYPES = UserTypes{"member", "author", "admin"}

Functions

func AddEarlyVoteAchievement

func AddEarlyVoteAchievement(db *s.Database, v *Vote) error

func AddWinningVoteAchievement

func AddWinningVoteAchievement(db *s.Database, votes []*VoteWithBalance, p ProposalResults) error

func CreateUserNFTRecord

func CreateUserNFTRecord(db *s.Database, v *VoteWithBalance) error

func DoesNFTExist

func DoesNFTExist(db *s.Database, v *VoteWithBalance) (bool, error)

func EnsureRoleForCommunity

func EnsureRoleForCommunity(db *s.Database, addr string, communityId int, userType string) error

func EnsureValidRole

func EnsureValidRole(userType string) bool

func GetActiveStrategiesForCommunity

func GetActiveStrategiesForCommunity(db *s.Database, communityId int) ([]string, error)

func GetCategoryCount

func GetCategoryCount(db *s.Database, search string) (map[string]int, error)

func GrantAdminRolesToAddress

func GrantAdminRolesToAddress(db *s.Database, communityId int, addr string) error

func GrantAuthorRolesToAddress

func GrantAuthorRolesToAddress(db *s.Database, communityId int, addr string) error

func GrantRolesToCommunityCreator

func GrantRolesToCommunityCreator(db *s.Database, addr string, communityId int) error

func IsNFTStrategy

func IsNFTStrategy(name string) bool

func ValidateVoteMessage

func ValidateVoteMessage(message string, proposal Proposal) error

Types

type Balance

type Balance struct {
	ID                      string    `json:"id"`
	Addr                    string    `json:"addr"`
	PrimaryAccountBalance   uint64    `json:"primaryAccountBalance"`
	SecondaryAddress        string    `json:"secondaryAddress"`
	SecondaryAccountBalance uint64    `json:"secondaryAccountBalance"`
	StakingBalance          uint64    `json:"stakingBalance"`
	ScriptResult            string    `json:"scriptResult"`
	Stakes                  []string  `json:"stakes"`
	BlockHeight             uint64    `json:"blockHeight"`
	Proposal_id             int       `json:"proposal_id"`
	NFTCount                int       `json:"nftCount"`
	CreatedAt               time.Time `json:"createdAt"`
}

func (*Balance) CreateBalance

func (b *Balance) CreateBalance(db *s.Database) error

func (*Balance) GetBalanceByAddressAndBlockHeight

func (b *Balance) GetBalanceByAddressAndBlockHeight(db *s.Database) error

type Community

type Community struct {
	ID                       int         `json:"id,omitempty"`
	Name                     string      `json:"name,omitempty"`
	Category                 *string     `json:"category,omitempty"              validate:"required"`
	Category_count           *int        `json:"categoryCount,omitempty"`
	Body                     *string     `json:"body,omitempty"`
	Strategies               *[]Strategy `json:"strategies,omitempty"`
	Strategy                 *string     `json:"strategy,omitempty"`
	Banner_img_url           *string     `json:"bannerImgUrl,omitempty"`
	Website_url              *string     `json:"websiteUrl,omitempty"`
	Twitter_url              *string     `json:"twitterUrl,omitempty"`
	Github_url               *string     `json:"githubUrl,omitempty"`
	Discord_url              *string     `json:"discordUrl,omitempty"`
	Instagram_url            *string     `json:"instagramUrl,omitempty"`
	Terms_and_conditions_url *string     `json:"termsAndConditionsUrl,omitempty"`
	Only_authors_to_submit   *bool       `json:"onlyAuthorsToSubmit,omitempty"`
	Proposal_validation      *string     `json:"proposalValidation,omitempty"`
	Proposal_threshold       *string     `json:"proposalThreshold,omitempty"`
	Slug                     *string     `json:"slug,omitempty"                  validate:"required"`
	Is_featured              *bool       `json:"isFeatured,omitempty"`

	Total *int `json:"total,omitempty"` // for search only

	Contract_name *string `json:"contractName,omitempty"`
	Contract_addr *string `json:"contractAddr,omitempty"`
	Contract_type *string `json:"contractType,omitempty"`
	Public_path   *string `json:"publicPath,omitempty"`

	Timestamp            string                  `json:"timestamp"             validate:"required"`
	Composite_signatures *[]s.CompositeSignature `json:"compositeSignatures"`
	Creator_addr         string                  `json:"creatorAddr"           validate:"required"`
	Signing_addr         *string                 `json:"signingAddr,omitempty"`
	Voucher              *shared.Voucher         `json:"voucher,omitempty"`
	Created_at           *time.Time              `json:"createdAt,omitempty"`
	Cid                  *string                 `json:"cid,omitempty"`
}

func GetCommunities

func GetCommunities(db *s.Database, pageParams shared.PageParams) ([]*Community, int, error)

func GetDefaultCommunities

func GetDefaultCommunities(
	db *s.Database,
	params shared.PageParams,
	filters []string,
	isSearch bool,
) ([]*Community, int, error)

func SearchForCommunity

func SearchForCommunity(
	db *s.Database,
	query string,
	filters []string,
	params shared.PageParams,
) ([]*Community, int, error)

func (*Community) CanUpdateCommunity

func (c *Community) CanUpdateCommunity(db *s.Database, addr string) error

func (*Community) CreateCommunity

func (c *Community) CreateCommunity(db *s.Database) error

func (*Community) GetCommunity

func (c *Community) GetCommunity(db *s.Database) error

func (*Community) GetCommunityByProposalId

func (c *Community) GetCommunityByProposalId(db *s.Database, proposalId int) error

func (*Community) GetStrategy

func (c *Community) GetStrategy(name string) (Strategy, error)

func (*Community) UpdateCommunity

func (c *Community) UpdateCommunity(db *s.Database, p *UpdateCommunityRequestPayload) error

type CommunityType

type CommunityType struct {
	Key         string `json:"key"                   validate:"required"`
	Name        string `json:"name"                  validate:"required"`
	Description string `json:"description,omitempty"`
}

func GetCommunityTypes

func GetCommunityTypes(db *s.Database) ([]*CommunityType, error)

type CommunityUser

type CommunityUser struct {
	Community_id int    `json:"communityId" validate:"required"`
	Addr         string `json:"addr" validate:"required"`
	User_type    string `json:"userType" validate:"required"`
}

func GetAllRolesForUserInCommunity

func GetAllRolesForUserInCommunity(db *s.Database, addr string, communityId int) ([]CommunityUser, error)

func GetUsersForCommunityByType

func GetUsersForCommunityByType(
	db *s.Database,
	communityId int,
	user_type string,
	pageParams shared.PageParams,
) ([]CommunityUser, int, error)

func (*CommunityUser) CreateCommunityUser

func (u *CommunityUser) CreateCommunityUser(db *s.Database) error

func (*CommunityUser) GetCommunityUser

func (u *CommunityUser) GetCommunityUser(db *s.Database) error

func (*CommunityUser) Remove

func (u *CommunityUser) Remove(db *s.Database) error

type CommunityUserPayload

type CommunityUserPayload struct {
	CommunityUser
	Signing_addr         string                  `json:"signingAddr"`
	Timestamp            string                  `json:"timestamp"`
	Composite_signatures *[]s.CompositeSignature `json:"compositeSignatures"`
	Voucher              *s.Voucher              `json:"voucher"`
}

type CommunityUserType

type CommunityUserType struct {
	Community_id int    `json:"communityId" validate:"required"`
	Addr         string `json:"addr" validate:"required"`
	Is_admin     bool   `json:"isAdmin" validate:"required"`
	Is_author    bool   `json:"isAuthor" validate:"required"`
	Is_member    bool   `json:"isMember" validate:"required"`
}

func GetUsersForCommunity

func GetUsersForCommunity(db *s.Database, communityId int, pageParams shared.PageParams) ([]CommunityUserType, int, error)

type CreateCommunityRequestPayload

type CreateCommunityRequestPayload struct {
	Community

	Additional_authors *[]string `json:"additionalAuthors,omitempty"`
	Additional_admins  *[]string `json:"additionalAdmins,omitempty"`
}

type LeaderboardPayload

type LeaderboardPayload struct {
	Users       []LeaderboardUser `json:"users"`
	CurrentUser LeaderboardUser   `json:"currentUser"`
}

func GetCommunityLeaderboard

func GetCommunityLeaderboard(
	db *s.Database,
	communityId int,
	addr string,
	pageParams shared.PageParams,
) (LeaderboardPayload, int, error)

type LeaderboardUser

type LeaderboardUser struct {
	Addr  string `json:"addr" validate:"required"`
	Score int    `json:"score,omitempty"`
	Index int    `json:"index,omitempty"`
}

type List

type List struct {
	ID           int        `json:"id"`
	Community_id int        `json:"communityId"`
	Addresses    []string   `json:"addresses,omitempty" validate:"required"`
	List_type    *string    `json:"listType,omitempty"`
	Cid          *string    `json:"cid,omitempty"`
	Created_at   *time.Time `json:"createdAt,omitempty"`
}

func GetListForCommunityByType

func GetListForCommunityByType(db *s.Database, communityId int, listType string) (List, error)

func GetListsForCommunity

func GetListsForCommunity(db *s.Database, communityId int) ([]List, error)

func (*List) AddAddresses

func (l *List) AddAddresses(addresses []string)

func (*List) CreateList

func (l *List) CreateList(db *s.Database) error

func (*List) GetListById

func (l *List) GetListById(db *s.Database) error

func (*List) RemoveAddresses

func (l *List) RemoveAddresses(toRemove []string)

func (*List) UpdateList

func (l *List) UpdateList(db *s.Database) error

type ListPayload

type ListPayload struct {
	List
	s.TimestampSignaturePayload
}

type ListUpdatePayload

type ListUpdatePayload struct {
	ID        int      `json:"id"`
	Addresses []string `json:"addresses,omitempty" validate:"required"`
	s.TimestampSignaturePayload
}

type NFT

type NFT struct {
	ID             interface{} `json:"id"`
	Contract_addr  string      `json:"contract_addr"`
	Created_at     time.Time   `json:"created_at"`
	Float_event_id uint64      `json:"event_id,omitempty"`
}

func GetUserNFTs

func GetUserNFTs(db *s.Database, vote *VoteWithBalance) ([]*NFT, error)

type Proposal

type Proposal struct {
	ID                   int                     `json:"id,omitempty"`
	Name                 string                  `json:"name" validate:"required"`
	Community_id         int                     `json:"communityId"`
	Choices              []s.Choice              `json:"choices" validate:"required"`
	Strategy             *string                 `json:"strategy,omitempty"`
	Max_weight           *float64                `json:"maxWeight,omitempty"`
	Min_balance          *float64                `json:"minBalance,omitempty"`
	Creator_addr         string                  `json:"creatorAddr" validate:"required"`
	Start_time           time.Time               `json:"startTime" validate:"required"`
	Result               *string                 `json:"result,omitempty"`
	End_time             time.Time               `json:"endTime" validate:"required"`
	Created_at           *time.Time              `json:"createdAt,omitempty"`
	Cid                  *string                 `json:"cid,omitempty"`
	Status               *string                 `json:"status,omitempty"`
	Body                 *string                 `json:"body,omitempty" validate:"required"`
	Block_height         *uint64                 `json:"block_height"`
	Total_votes          int                     `json:"total_votes"`
	Timestamp            string                  `json:"timestamp" validate:"required"`
	Composite_signatures *[]s.CompositeSignature `json:"compositeSignatures"`
	Computed_status      *string                 `json:"computedStatus,omitempty"`
	Snapshot_status      *string                 `json:"snapshotStatus,omitempty"`
	Voucher              *shared.Voucher         `json:"voucher,omitempty"`
	Achievements_done    bool                    `json:"achievementsDone"`
}

func GetProposalsForCommunity

func GetProposalsForCommunity(
	db *s.Database,
	communityId int,
	status string,
	params shared.PageParams,
) ([]*Proposal, int, error)

func (*Proposal) CreateProposal

func (p *Proposal) CreateProposal(db *s.Database) error

func (*Proposal) EnforceMaxWeight

func (p *Proposal) EnforceMaxWeight(balance float64) float64

func (*Proposal) GetProposalById

func (p *Proposal) GetProposalById(db *s.Database) error

func (*Proposal) IsLive

func (p *Proposal) IsLive() bool

func (*Proposal) UpdateProposal

func (p *Proposal) UpdateProposal(db *s.Database) error

func (*Proposal) ValidateBalance

func (p *Proposal) ValidateBalance(weight float64) error

Returns an error if the account's balance is insufficient to cast a vote on the proposal.

type ProposalResults

type ProposalResults struct {
	Proposal_id       int                `json:"proposalId" validate:"required"`
	Results           map[string]int     `json:"results" validate:"required"`
	Results_float     map[string]float64 `json:"resultsFloat" validate:"required"`
	Updated_at        time.Time          `json:"updatedAt" validate:"required"`
	Cid               *string            `json:"cid,omitempty"`
	Achievements_done bool               `json:"achievementsDone"`
}

func NewProposalResults

func NewProposalResults(id int, choices []s.Choice) *ProposalResults

func (*ProposalResults) GetLatestProposalResultsById

func (r *ProposalResults) GetLatestProposalResultsById(db *s.Database) error

type Strategy

type Strategy struct {
	Name            *string `json:"name,omitempty"`
	shared.Contract `json:"contract,omitempty"`
}

func MatchStrategyByProposal

func MatchStrategyByProposal(s []Strategy, strategyToMatch string) (Strategy, error)

type UpdateCommunityRequestPayload

type UpdateCommunityRequestPayload struct {
	Name                     *string         `json:"name,omitempty"`
	Category                 *string         `json:"category,omitempty"`
	Body                     *string         `json:"body,omitempty"`
	Strategies               *[]Strategy     `json:"strategies,omitempty"`
	Strategy                 *string         `json:"strategy,omitempty"`
	Banner_img_url           *string         `json:"bannerImgUrl,omitempty"`
	Website_url              *string         `json:"websiteUrl,omitempty"`
	Twitter_url              *string         `json:"twitterUrl,omitempty"`
	Github_url               *string         `json:"githubUrl,omitempty"`
	Discord_url              *string         `json:"discordUrl,omitempty"`
	Instagram_url            *string         `json:"instagramUrl,omitempty"`
	Terms_and_conditions_url *string         `json:"termsAndConditionsUrl,omitempty"`
	Proposal_validation      *string         `json:"proposalValidation,omitempty"`
	Proposal_threshold       *string         `json:"proposalThreshold,omitempty"`
	Only_authors_to_submit   *bool           `json:"onlyAuthorsToSubmit,omitempty"`
	Voucher                  *shared.Voucher `json:"voucher,omitempty"`

	//TODO dup fields in Community struct, make sub struct for both to use
	Contract_name *string  `json:"contractName,omitempty"`
	Contract_addr *string  `json:"contractAddr,omitempty"`
	Contract_type *string  `json:"contractType,omitempty"`
	Public_path   *string  `json:"publicPath,omitempty"`
	Threshold     *float64 `json:"threshold,omitempty"`

	s.TimestampSignaturePayload
}

type UpdateProposalRequestPayload

type UpdateProposalRequestPayload struct {
	Status  string     `json:"status"`
	Voucher *s.Voucher `json:"voucher,omitempty"`

	s.TimestampSignaturePayload
}

type UserAchievements

type UserAchievements = []struct {
	Addr         string
	NumVotes     int
	EarlyVotes   int
	Streaks      int
	WinningVotes int
}

type UserCommunity

type UserCommunity struct {
	Community
	Roles string `json:"roles" validate:"required"`
}

func GetCommunitiesForUser

func GetCommunitiesForUser(db *s.Database, addr string, pageParams shared.PageParams) ([]UserCommunity, int, error)

type UserTypes

type UserTypes []string

type Vote

type Vote struct {
	ID                   int                     `json:"id,omitempty"`
	Proposal_id          int                     `json:"proposalId"`
	Addr                 string                  `json:"addr"                validate:"required"`
	Choice               string                  `json:"choice"              validate:"required"`
	Composite_signatures *[]s.CompositeSignature `json:"compositeSignatures" validate:"required"`
	Created_at           time.Time               `json:"createdAt,omitempty"`
	Cid                  *string                 `json:"cid"`
	Message              string                  `json:"message"`
	Voucher              *shared.Voucher         `json:"voucher,omitempty"`
	IsCancelled          bool                    `json:"isCancelled"`
	IsEarly              bool                    `json:"isEarly"`
	IsWinning            bool                    `json:"isWinning"`
}

func (*Vote) CreateVote

func (v *Vote) CreateVote(db *s.Database) error

func (*Vote) GetVote

func (v *Vote) GetVote(db *s.Database) error

func (*Vote) GetVoteById

func (v *Vote) GetVoteById(db *s.Database) error

func (*Vote) ValidateChoice

func (v *Vote) ValidateChoice(proposal Proposal) error

type VoteWithBalance

type VoteWithBalance struct {
	// Extend Vote
	Vote
	// Balance
	BlockHeight             *uint64  `json:"blockHeight" pg:"block_height"`
	Balance                 *uint64  `json:"balance"`
	PrimaryAccountBalance   *uint64  `json:"primaryAccountBalance"`
	SecondaryAccountBalance *uint64  `json:"secondaryAccountBalance"`
	StakingBalance          *uint64  `json:"stakingBalance"`
	Weight                  *float64 `json:"weight"`

	NFTs []*NFT
}

func GetAllVotesForProposal

func GetAllVotesForProposal(db *s.Database, proposalId int, strategy string) ([]*VoteWithBalance, error)

func GetVotesForAddress

func GetVotesForAddress(
	db *s.Database,
	address string,
	proposalIds *[]int,
	pageParams shared.PageParams,
) ([]*VoteWithBalance, int, error)

func GetVotesForProposal

func GetVotesForProposal(
	db *s.Database,
	proposalId int,
	strategy string,
	pageParams shared.PageParams,
) ([]*VoteWithBalance, int, error)

func (*VoteWithBalance) GetVote

func (vb *VoteWithBalance) GetVote(db *s.Database) error

type VotingStrategy

type VotingStrategy struct {
	Key         string           `json:"key" validate:"required"`
	Name        string           `json:"name" validate:"required"`
	Description string           `json:"description,omitempty"`
	Scripts     []s.CustomScript `json:"scripts,omitempty"`
}

func GetVotingStrategies

func GetVotingStrategies(db *s.Database) ([]*VotingStrategy, error)

type VotingStreak

type VotingStreak struct {
	Proposal_id  uint64
	Addr         string
	Is_cancelled bool
}

Jump to

Keyboard shortcuts

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