core

package
v0.0.0-...-0c3fea9 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogChanMaxSize = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseProposal

type BaseProposal struct {
	ID          uint64
	Type        ProposalType
	Strategy    ProposalStrategy
	Proposer    string
	Title       string
	Desc        string
	BlockNumber uint64

	// totalVotes is total votes for this proposal
	// attention: some users may not vote for this proposal
	TotalVotes uint64

	// passVotes record user address for passed vote
	PassVotes []string

	RejectVotes []string
	Status      ProposalStatus
}

type Client

type Client interface {
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

	SubscribeFilterLogs(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)
}

type Guardian

type Guardian struct {
	Ctx    context.Context
	Client Client
	Logger *logrus.Logger
	DB     storage.Storage
	Config *repo.Config

	// Subscribe log
	FromBlock *big.Int
	ToBlock   *big.Int
	Addresses []common.Address
	Topics    [][]common.Hash

	LogChan chan types.Log
	LogSub  ethereum.Subscription
	// contains filtered or unexported fields
}

func NewGuardian

func NewGuardian(ctx context.Context, config *repo.Config, client Client) (*Guardian, error)

func (*Guardian) Start

func (g *Guardian) Start() error

func (*Guardian) Stop

func (g *Guardian) Stop() error

type MockClient

type MockClient struct {
}

func (*MockClient) FilterLogs

func (mc *MockClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)

func (*MockClient) SubscribeFilterLogs

func (mc *MockClient) SubscribeFilterLogs(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)

type MockSubscription

type MockSubscription struct {
}

func (*MockSubscription) Err

func (ms *MockSubscription) Err() <-chan error

func (*MockSubscription) Unsubscribe

func (ms *MockSubscription) Unsubscribe()

type NodeProposal

type NodeProposal struct {
	BaseProposal
	DownloadUrls []string
	CheckHash    string
}

type ProposalStatus

type ProposalStatus uint8
const (
	Voting ProposalStatus = iota
	Approved
	Rejected
)

type ProposalStrategy

type ProposalStrategy uint8
const (
	// SimpleStrategy means proposal is approved if pass votes is greater than half of total votes
	SimpleStrategy ProposalStrategy = iota
)

type ProposalType

type ProposalType uint8
const (
	// CouncilElect is a proposal for elect the council
	CouncilElect ProposalType = iota

	// NodeUpgrade is a proposal for update or upgrade the node
	NodeUpgrade

	// NodeAdd is a proposal for adding a new node
	NodeAdd

	// NodeRemove is a proposal for removing a node
	NodeRemove
)

Jump to

Keyboard shortcuts

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