harvester

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ArbitrumNova string = "arbitrum_nova"
View Source
const Ethereum string = "ethereum"
View Source
const Polkadot string = "polkadot"

Variables

This section is empty.

Functions

func HexToAddress

func HexToAddress(s string) []byte

func Initialise

func Initialise(ctx context.Context, log *zap.SugaredLogger, cfg *config.Config, pool *pgxpool.Pool)

func SubscribeAllWallets

func SubscribeAllWallets(ctx context.Context, harv *Harvester, cfg *config.Config, pool *pgxpool.Pool) error

Types

type Adapter

type Adapter interface {
	GetLastBlockNumber() (uint64, error)
	GetBalance(wallet string, contract string, blockNumber uint64) (*big.Int, error)
	GetLogs(fromBlock, toBlock int64, addresses []common.Address) ([]any, error)
	GetLogsRecursively(fromBlock, toBlock int64, addresses []common.Address, level int) ([]any, error)
	RegisterNewBlockListener(f AdapterListener)
	Run()
	GetInfo() (umid umid.UMID, name string, rpcURL string)
}

type AdapterListener

type AdapterListener func(blockNumber uint64, diffs []*BCDiff, stakes []*BCStake)

type Address

type Address []byte

type BCBlock

type BCBlock struct {
	Hash   string
	Number uint64
}

type BCDiff

type BCDiff struct {
	From   string
	To     string
	Token  string
	Amount *big.Int
}

type BCStake

type BCStake struct {
	From        string
	OdysseyID   umid.UMID
	TokenType   uint8 //0-MOM; 1-DAD
	Amount      *big.Int
	TotalAmount *big.Int
}

type BCType

type BCType string

type Callback

type Callback *func(p any)

type Callbacks

type Callbacks struct {
	Mu   sync.RWMutex
	Data map[string]map[Event]map[Callback]bool
}

func NewCallbacks

func NewCallbacks() *Callbacks

func (*Callbacks) Add

func (c *Callbacks) Add(bcType string, event Event, f Callback)

func (*Callbacks) Remove

func (c *Callbacks) Remove(bcType string, event Event, f Callback)

func (*Callbacks) Trigger

func (c *Callbacks) Trigger(bcType string, event Event, p any)

type Event

type Event string
const BalanceChange Event = "balance_change"
const NewBlock Event = "new_block"

type Harvester

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

func GetInstance

func GetInstance() *Harvester

func NewHarvester

func NewHarvester(db *pgxpool.Pool) *Harvester

func (*Harvester) Init

func (h *Harvester) Init()

func (*Harvester) OnBalanceChange

func (h *Harvester) OnBalanceChange()

func (*Harvester) OnNewBlock

func (h *Harvester) OnNewBlock(bcType string, block *BCBlock)

func (*Harvester) RegisterAdapter

func (h *Harvester) RegisterAdapter(adapter Adapter) error

func (*Harvester) Run

func (h *Harvester) Run() error

func (*Harvester) Subscribe

func (h *Harvester) Subscribe(bcType string, eventName Event, callback Callback)

func (*Harvester) SubscribeForWallet

func (h *Harvester) SubscribeForWallet(bcType string, wallet, callback Callback)

func (*Harvester) SubscribeForWalletAndContract

func (h *Harvester) SubscribeForWalletAndContract(bcType string, wallet string, contract string, callback Callback) error

func (*Harvester) Unsubscribe

func (h *Harvester) Unsubscribe(bcType string, eventName Event, callback Callback)

type IHarvester

type IHarvester interface {
	RegisterAdapter(bcAdapter Adapter) error
	OnBalanceChange()
	Subscribe(bcType string, eventName Event, callback Callback)
	Unsubscribe(bcType string, eventName Event, callback Callback)
	SubscribeForWallet(bcType string, wallet, callback Callback)
	SubscribeForWalletAndContract(bcType string, wallet string, contract string, callback Callback) error
}

type NftEvent

type NftEvent struct {
	From      string
	To        string
	OdysseyID umid.UMID
	Contract  string
}

type RestakeLog

type RestakeLog struct {
	UserWallet        string
	FromOdysseyID     umid.UMID
	ToOdysseyID       umid.UMID
	Amount            *big.Int
	TokenType         uint8
	TotalStakedToFrom *big.Int
	TotalStakedToTo   *big.Int
}

*

*
* @param user User address
* @param odyssey_from Odyssey ID that the user is removing stake
* @param odyssey_to Odyssey ID that the user is staking into
* @param amount Amount that's being restaked
* @param token Token used (MOM or DAD)
* @param total_staked_from Total amount of tokens that remains staked on the `odyssey_from`
* @param total_staked_to Total amount of tokens staked on `odyssey_to`

event Restake(address user, bytes16 odyssey_from, bytes16 odyssey_to, uint256 amount, Token token, uint256 total_staked_from, uint256 total_staked_to);

type StakeEvent

type StakeEvent struct {
	TxHash       string
	LogIndex     string
	Wallet       string
	Kind         uint8
	OdysseyID    umid.UMID
	Amount       *big.Int
	ActivityType string
}

type StakeLog

type StakeLog struct {
	LogIndex     uint
	TxHash       string
	UserWallet   string
	OdysseyID    umid.UMID
	AmountStaked *big.Int
	TokenType    uint8
	TotalStaked  *big.Int
}

*

*
* @param user User address
* @param odyssey Odyssey ID that's being staked
* @param amount_staked Amount being staked
* @param token Token used (MOM or DAD)
* @param total_staked Total being staked by the user on the Odyssey

event Stake(address user, bytes16 odyssey, uint256 amount_staked, Token token, uint256 total_staked);

type Table

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

func NewTable

func NewTable(db *pgxpool.Pool, adapter Adapter, listener func(bcName string, p []*UpdateEvent, s []*StakeEvent)) *Table

func (*Table) AddWalletContract

func (t *Table) AddWalletContract(wallet string, contract string)

func (*Table) Display

func (t *Table) Display()

func (*Table) LoadFromDB

func (t *Table) LoadFromDB() error

func (*Table) ProcessDiffs

func (t *Table) ProcessDiffs(blockNumber uint64, logs []any)

func (*Table) Run

func (t *Table) Run()

func (*Table) SaveToDB

func (t *Table) SaveToDB(events []*UpdateEvent, stakeEvents []*StakeEvent) (err error)

type Table2

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

func NewTable2

func NewTable2(db *pgxpool.Pool, adapter Adapter, listener func(bcName string, p []*UpdateEvent, s []*StakeEvent, n []*NftEvent) error) *Table2

func (*Table2) AddWalletContract

func (t *Table2) AddWalletContract(wallet string, contract string)

func (*Table2) Display

func (t *Table2) Display()

func (*Table2) GetLastCommentByTxHash

func (t *Table2) GetLastCommentByTxHash(txHash string) (string, error)

func (*Table2) LoadFromDB

func (t *Table2) LoadFromDB() error

func (*Table2) ProcessLogs

func (t *Table2) ProcessLogs(blockNumber uint64, logs []any)

func (*Table2) Run

func (t *Table2) Run()

func (*Table2) SaveToDB

func (t *Table2) SaveToDB(events []*UpdateEvent, stakeEvents []*StakeEvent, nftLogs []*TransferNFTLog) (err error)

type TransferERC20Log

type TransferERC20Log struct {
	From     string
	To       string
	Value    *big.Int
	Contract string
}

type TransferNFTLog

type TransferNFTLog struct {
	From     string
	To       string
	TokenID  umid.UMID
	Contract string
}

*

  • @dev Emitted when `tokenId` token is transferred from `from` to `to`.

event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

type UnstakeLog

type UnstakeLog struct {
	LogIndex       uint
	TxHash         string
	UserWallet     string
	OdysseyID      umid.UMID
	AmountUnstaked *big.Int
	TokenType      uint8
	TotalStaked    *big.Int
}

*

*
* @param user User address
* @param odyssey Odyssey ID that's being unstaked
* @param amount_unstaked Amount unstaked
* @param token Token used (MOM or DAD)
* @param total_staked Total remained staked by the user on that Odyssey

event Unstake(address user, bytes16 odyssey, uint256 amount_unstaked, Token token, uint256 total_staked);

type UpdateEvent

type UpdateEvent struct {
	Wallet   string
	Contract string
	Amount   *big.Int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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