cache

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EOSTokenContract = zsw.AccountName("zswhq.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 zsw.AccountName) bool
	TokenContract(contract zsw.AccountName, code zsw.SymbolCode) *pbtokenmeta.Token
	AccountBalances(account zsw.AccountName, opts ...AccountBalanceOption) []*OwnedAsset
	TokenBalances(contract zsw.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 {
	// zswhq.token -> [WAX, EOS]
	TokensInContract map[zsw.AccountName][]*pbtokenmeta.Token `json:"tokens_in_contract"`

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

	AtBlock *Block `json:"at_block"`

	EOSStake      map[zsw.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 zsw.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 zsw.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 zsw.AccountName, opts ...TokenBalanceOption) (tokenBalances []*OwnedAsset)

func (*DefaultCache) TokenContract

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

func (*DefaultCache) Tokens

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

type EOSStake

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

type EOSStakeEntry

type EOSStakeEntry struct {
	To   zsw.AccountName `json:"to"`
	From zsw.AccountName `json:"from"`
	Net  zsw.Int64       `json:"net"`
	Cpu  zsw.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 zsw.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 zsw.AccountName    // ex: eoscanadadad
	Asset *zsw.ExtendedAsset // ex: 1.23 EOS (zswhq.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