proposal

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatePending   = "pending"
	StateActive    = "active"
	StateCancelled = "canceled"
	StateFailed    = "failed"
	StateSucceeded = "succeeded"
	StateDefeated  = "defeated"
)

Variables

View Source
var (
	OrderByVotes = Order{
		Field:     "votes",
		Direction: DirectionDesc,
	}
	OrderByStates = Order{
		Field:     "array_position(array ['active','pending','succeeded','failed','defeated','canceled'], state)",
		Direction: DirectionAsc,
	}
	OrderByCreated = Order{
		Field:     "created",
		Direction: DirectionAsc,
	}
)

Functions

This section is empty.

Types

type AuthorsFilter

type AuthorsFilter struct {
	List []string
}

func (AuthorsFilter) Apply

func (f AuthorsFilter) Apply(db *gorm.DB) *gorm.DB

type CategoriesFilter

type CategoriesFilter struct {
	Category string
}

func (CategoriesFilter) Apply

func (f CategoriesFilter) Apply(db *gorm.DB) *gorm.DB

type Choices

type Choices []string

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

func NewConsumer

func NewConsumer(nc *nats.Conn, s *Service) (*Consumer, error)

func (*Consumer) Start

func (c *Consumer) Start(ctx context.Context) error

type DaoIDsFilter

type DaoIDsFilter struct {
	DaoIDs []string
}

func (DaoIDsFilter) Apply

func (f DaoIDsFilter) Apply(db *gorm.DB) *gorm.DB

type DaoProvider

type DaoProvider interface {
	GetIDByOriginalID(string) (uuid.UUID, error)
}

type DataProvider

type DataProvider interface {
	Create(Proposal) error
	Update(proposal Proposal) error
	GetByID(string) (*Proposal, error)
	GetAvailableForVoting(time.Duration) ([]*Proposal, error)
	GetByFilters(filters []Filter) (ProposalList, error)
	GetTop(filters []Filter) (ProposalList, error)
	UpdateVotes(list []ResolvedAddress) error
}

type Direction

type Direction string
const (
	DirectionAsc  Direction = "asc"
	DirectionDesc Direction = "desc"
)

type EnsResolver

type EnsResolver interface {
	AddRequests(list []string)
}

type EventRegistered

type EventRegistered interface {
	EventExist(_ context.Context, id, t, event string) (bool, error)
	RegisterEvent(_ context.Context, id, t, event string) error
}

type Filter

type Filter interface {
	Apply(*gorm.DB) *gorm.DB
}

type Order

type Order struct {
	Field     string
	Direction Direction
}

type OrderFilter

type OrderFilter struct {
	Orders []Order
}

func (OrderFilter) Apply

func (f OrderFilter) Apply(db *gorm.DB) *gorm.DB

type PageFilter

type PageFilter struct {
	Offset int
	Limit  int
}

func (PageFilter) Apply

func (f PageFilter) Apply(db *gorm.DB) *gorm.DB

type Proposal

type Proposal struct {
	ID            string `gorm:"primary_key"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
	Ipfs          string
	Author        string
	Created       int
	DaoOriginalID string `gorm:"-"`
	DaoID         uuid.UUID
	Network       string
	Symbol        string
	Type          string
	Strategies    Strategies `gorm:"serializer:json"`
	Title         string
	Body          string
	Discussion    string
	Choices       Choices `gorm:"serializer:json"`
	Start         int
	End           int
	Quorum        float64
	Privacy       string
	Snapshot      string
	State         State
	OriginalState string
	Link          string
	App           string
	Scores        Scores `gorm:"serializer:json"`
	ScoresState   string
	ScoresTotal   float32
	ScoresUpdated int
	Votes         int
	Timeline      Timeline `gorm:"serializer:json"`
	EnsName       string
	Spam          bool
}

Proposal model todo: check queries to the DB and add indexes

func (*Proposal) CalculateState

func (p *Proposal) CalculateState() State

func (*Proposal) Deleted

func (p *Proposal) Deleted() bool

func (*Proposal) InProgress

func (p *Proposal) InProgress() bool

func (*Proposal) IsBasic

func (p *Proposal) IsBasic() bool

func (*Proposal) IsVotedAgainst

func (p *Proposal) IsVotedAgainst() bool

func (*Proposal) Pending

func (p *Proposal) Pending() bool

func (*Proposal) QuorumReached

func (p *Proposal) QuorumReached() bool

func (*Proposal) QuorumSpecified

func (p *Proposal) QuorumSpecified() bool

type ProposalIDsFilter

type ProposalIDsFilter struct {
	ProposalIDs []string
}

func (ProposalIDsFilter) Apply

func (f ProposalIDsFilter) Apply(db *gorm.DB) *gorm.DB

type ProposalList

type ProposalList struct {
	Proposals  []Proposal
	TotalCount int64
}

type Publisher

type Publisher interface {
	PublishJSON(ctx context.Context, subject string, obj any) error
}

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo(db *gorm.DB) *Repo

func (*Repo) Create

func (r *Repo) Create(p Proposal) error

Create creates one proposal object todo: check creating error/unique and others

func (*Repo) GetAvailableForVoting

func (r *Repo) GetAvailableForVoting(window time.Duration) ([]*Proposal, error)

todo: think about limits, add pagination or cursor

func (*Repo) GetByFilters

func (r *Repo) GetByFilters(filters []Filter) (ProposalList, error)

todo: add order by

func (*Repo) GetByID

func (r *Repo) GetByID(id string) (*Proposal, error)

func (*Repo) GetCountByFilters added in v0.1.8

func (r *Repo) GetCountByFilters(filters []Filter) (int64, error)

func (*Repo) GetEarliestByDaoID

func (r *Repo) GetEarliestByDaoID(daoID uuid.UUID) (*Proposal, error)

func (*Repo) GetTop

func (r *Repo) GetTop(filters []Filter) (ProposalList, error)

func (*Repo) Update

func (r *Repo) Update(p Proposal) error

Update single proposal object in database todo: think about updating fields to default value(boolean, string etc)

func (*Repo) UpdateVotes

func (r *Repo) UpdateVotes(list []ResolvedAddress) error

type ResolvedAddress

type ResolvedAddress struct {
	Address string
	Name    string
}

type Scores

type Scores []float32

type Server

type Server struct {
	storagepb.UnimplementedProposalServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(sp *Service) *Server

type Service

type Service struct {
	// contains filtered or unexported fields
}

todo: convert types to interfaces for unit testing

func NewService

func NewService(
	r DataProvider,
	p Publisher,
	er EventRegistered,
	dp DaoProvider,
	ensResolver EnsResolver,
) (*Service, error)

func (*Service) GetByFilters

func (s *Service) GetByFilters(filters []Filter) (ProposalList, error)

func (*Service) GetByID

func (s *Service) GetByID(id string) (*Proposal, error)

func (*Service) GetTop

func (s *Service) GetTop(limit, offset int) (ProposalList, error)

func (*Service) HandleDeleted

func (s *Service) HandleDeleted(ctx context.Context, pro Proposal) error

func (*Service) HandleProposal

func (s *Service) HandleProposal(ctx context.Context, pro Proposal) error

func (*Service) HandleProposalTimeline

func (s *Service) HandleProposalTimeline(_ context.Context, id string, tl Timeline) error

func (*Service) HandleResolvedAddresses

func (s *Service) HandleResolvedAddresses(ctx context.Context, list []ResolvedAddress) error

type SkipCanceled

type SkipCanceled struct {
}

func (SkipCanceled) Apply

func (f SkipCanceled) Apply(db *gorm.DB) *gorm.DB

type SkipSpamFilter

type SkipSpamFilter struct{}

func (SkipSpamFilter) Apply

func (f SkipSpamFilter) Apply(db *gorm.DB) *gorm.DB

type State

type State string

type Strategies

type Strategies []Strategy

type Strategy

type Strategy struct {
	Name    string
	Network string
	Params  map[string]interface{}
}

type Timeline

type Timeline []TimelineItem

func (*Timeline) ActualizeTimeline

func (t *Timeline) ActualizeTimeline() Timeline

func (*Timeline) AddNonUniqueAction

func (t *Timeline) AddNonUniqueAction(createdAt time.Time, action TimelineAction)

func (*Timeline) AddUniqueAction

func (t *Timeline) AddUniqueAction(createdAt time.Time, action TimelineAction) (isNew bool)

func (*Timeline) ContainsAction

func (t *Timeline) ContainsAction(action TimelineAction) bool

func (*Timeline) LastAction

func (t *Timeline) LastAction() TimelineAction

func (*Timeline) Sort

func (t *Timeline) Sort()

type TimelineAction

type TimelineAction string
const (
	None                        TimelineAction = ""
	ProposalCreated             TimelineAction = "proposal.created"
	ProposalUpdated             TimelineAction = "proposal.updated"
	ProposalVotingStartsSoon    TimelineAction = "proposal.voting.starts_soon"
	ProposalVotingEndsSoon      TimelineAction = "proposal.voting.ends_soon"
	ProposalVotingStarted       TimelineAction = "proposal.voting.started"
	ProposalVotingQuorumReached TimelineAction = "proposal.voting.quorum_reached"
	ProposalVotingEnded         TimelineAction = "proposal.voting.ended"
)

func (TimelineAction) Equals

func (a TimelineAction) Equals(action TimelineAction) bool

type TimelineItem

type TimelineItem struct {
	CreatedAt time.Time      `json:"created_at"`
	Action    TimelineAction `json:"action"`
}

type TitleFilter

type TitleFilter struct {
	Title string
}

func (TitleFilter) Apply

func (f TitleFilter) Apply(db *gorm.DB) *gorm.DB

type TopWorker

type TopWorker struct {
	// contains filtered or unexported fields
}

func NewTopWorker

func NewTopWorker(s *Service) *TopWorker

func (*TopWorker) Start

func (w *TopWorker) Start(ctx context.Context) error

type VotingWorker

type VotingWorker struct {
	// contains filtered or unexported fields
}

func NewVotingWorker

func NewVotingWorker(s *Service) *VotingWorker

func (*VotingWorker) Start

func (w *VotingWorker) Start(ctx context.Context) error

Jump to

Keyboard shortcuts

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