cache

package
v0.9.0-beta9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EOSTokenContract = eos.AccountName("eosio.token")

Variables

This section is empty.

Functions

func AssetToProtoAccountBalance

func AssetToProtoAccountBalance(asset *OwnedAsset) *pbtokenmeta.AccountBalance

func SortTokensByHolderCount

func SortTokensByHolderCount(tokens []*pbtokenmeta.Token, order SortingOrder) []*pbtokenmeta.Token

func SortTokensByMarketCap

func SortTokensByMarketCap(tokens []*pbtokenmeta.Token, order SortingOrder) []*pbtokenmeta.Token

TODO: implement me

func SortTokensBySymbolAlpha

func SortTokensBySymbolAlpha(tokens []*pbtokenmeta.Token, order SortingOrder) []*pbtokenmeta.Token

Types

type AccountBalanceOption

type AccountBalanceOption int
const (
	EOSIncludeStakedAccOpt AccountBalanceOption = iota
)

type Block

type Block struct {
	Id  string `json:"id"`
	Num uint64 `json:"num"`
}

type Cache

type Cache interface {
	Tokens() []*pbtokenmeta.Token
	IsTokenContract(contract eos.AccountName) bool
	TokenContract(contract eos.AccountName, code eos.SymbolCode) *pbtokenmeta.Token
	AccountBalances(account eos.AccountName, opts ...AccountBalanceOption) []*OwnedAsset
	TokenBalances(contract eos.AccountName, opts ...TokenBalanceOption) []*OwnedAsset
	Apply(mutationsBatch *MutationsBatch, processedBlock bstream.BlockRef) []error
	SaveToFile() error
	AtBlockRef() bstream.BlockRef
	SetHeadBlockTime(t time.Time)
	GetHeadBlockTime() time.Time
}

type DefaultCache

type DefaultCache struct {
	// eosio.token -> [WAX, EOS]
	TokensInContract map[eos.AccountName][]*pbtokenmeta.Token `json:"tokens_in_contract"`

	// tokencontract-centric: eosio.token -> eoscanadadad -> [23 WAX, 22 EOS]
	Balances map[eos.AccountName]map[eos.AccountName][]*OwnedAsset `json:"balances"`

	AtBlock *Block `json:"at_block"`

	EOSStake      map[eos.AccountName]*EOSStake `json:"eos_stake"`
	HeadBlockTime time.Time
	// contains filtered or unexported fields
}

func LoadDefaultCacheFromFile

func LoadDefaultCacheFromFile(filename string) (*DefaultCache, error)

func NewDefaultCache

func NewDefaultCache(cacheFilePath string) *DefaultCache

func NewDefaultCacheWithData

func NewDefaultCacheWithData(tokensInContract []*pbtokenmeta.Token, tokenBalances []*pbtokenmeta.AccountBalance, stakedEntries []*EOSStakeEntry, startBlock bstream.BlockRef, cacheFilePath string) *DefaultCache

func (*DefaultCache) AccountBalances

func (c *DefaultCache) AccountBalances(account eos.AccountName, opts ...AccountBalanceOption) (ownedAssets []*OwnedAsset)

func (*DefaultCache) Apply

func (c *DefaultCache) Apply(mutationsBatch *MutationsBatch, processedBlock bstream.BlockRef) (errors []error)

func (*DefaultCache) AtBlockRef

func (c *DefaultCache) AtBlockRef() bstream.BlockRef

func (*DefaultCache) GetHeadBlockTime

func (c *DefaultCache) GetHeadBlockTime() time.Time

func (*DefaultCache) IsTokenContract

func (c *DefaultCache) IsTokenContract(contract eos.AccountName) bool

func (*DefaultCache) SaveToFile

func (c *DefaultCache) SaveToFile() error

func (*DefaultCache) SetHeadBlockTime

func (c *DefaultCache) SetHeadBlockTime(t time.Time)

func (*DefaultCache) TokenBalances

func (c *DefaultCache) TokenBalances(contract eos.AccountName, opts ...TokenBalanceOption) (tokenBalances []*OwnedAsset)

func (*DefaultCache) TokenContract

func (c *DefaultCache) TokenContract(contract eos.AccountName, code eos.SymbolCode) *pbtokenmeta.Token

func (*DefaultCache) Tokens

func (c *DefaultCache) Tokens() (tokens []*pbtokenmeta.Token)

type EOSStake

type EOSStake struct {
	TotalNet eos.Int64                          `json:"total_net"`
	TotalCpu eos.Int64                          `json:"total_cpu"`
	Entries  map[eos.AccountName]*EOSStakeEntry `json:"stake_entries"`
}

type EOSStakeEntry

type EOSStakeEntry struct {
	To   eos.AccountName `json:"to"`
	From eos.AccountName `json:"from"`
	Net  eos.Int64       `json:"net"`
	Cpu  eos.Int64       `json:"cpu"`
}

type Mutation

type Mutation struct {
	Type MutationType
	Args []interface{}
}

type MutationType

type MutationType int
const (
	SetBalanceMutation MutationType = iota
	RemoveBalanceMutation
	SetTokenMutation
	SetStakeMutation
	SetContractMutation
)

type MutationsBatch

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

func (*MutationsBatch) Mutations

func (m *MutationsBatch) Mutations() []*Mutation

func (*MutationsBatch) RemoveBalance

func (m *MutationsBatch) RemoveBalance(bal *pbtokenmeta.AccountBalance)

TODO THIS IS NEVER CALLED, so holders do not decrement.. RemoveBalance removes a 0-value and decrements holders

func (*MutationsBatch) SetBalance

func (m *MutationsBatch) SetBalance(bal *pbtokenmeta.AccountBalance)

func (*MutationsBatch) SetContract

func (m *MutationsBatch) SetContract(contractName eos.AccountName)

func (*MutationsBatch) SetStake

func (m *MutationsBatch) SetStake(stake *EOSStakeEntry)

func (*MutationsBatch) SetToken

func (m *MutationsBatch) SetToken(token *pbtokenmeta.Token)

SetToken should be called when you change maximumSupply or Supply. It ignores the `holders` attribute from token param

type OwnedAsset

type OwnedAsset struct {
	Owner eos.AccountName    // ex: eoscanadadad
	Asset *eos.ExtendedAsset // ex: 1.23 EOS (eosio.token)
}

func ProtoEOSAccountBalanceToOwnedAsset

func ProtoEOSAccountBalanceToOwnedAsset(bal *pbtokenmeta.AccountBalance) *OwnedAsset

func SortOwnedAssetByAccountAlpha

func SortOwnedAssetByAccountAlpha(assets []*OwnedAsset, order SortingOrder) []*OwnedAsset

func SortOwnedAssetBySymbolAlpha

func SortOwnedAssetBySymbolAlpha(assets []*OwnedAsset, order SortingOrder) []*OwnedAsset

func SortOwnedAssetByTokenAmount

func SortOwnedAssetByTokenAmount(assets []*OwnedAsset, order SortingOrder) []*OwnedAsset

func SortOwnedAssetByTokenMarketValue

func SortOwnedAssetByTokenMarketValue(assets []*OwnedAsset, order SortingOrder) []*OwnedAsset

type OwnedAssetSorter

type OwnedAssetSorter func([]*OwnedAsset, SortingOrder) []*OwnedAsset

type SortingOrder

type SortingOrder int32
const (
	ASC SortingOrder = iota
	DESC
)

type TokenBalanceOption

type TokenBalanceOption int
const (
	EOSIncludeStakedTokOpt TokenBalanceOption = iota
)

Jump to

Keyboard shortcuts

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