tokenstate

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttachSectorsData

type AttachSectorsData struct {
	TokenID  types.TokenID
	SectorID []byte
}

AttachSectorsData include information about token sector and storing it.

type Event

type Event struct {
	EventTopUp                 *EventTopUp                 `json:"event_top_up"`
	EventTokenDownload         *EventTokenDownload         `json:"event_token_download"`
	EventAddSectors            *EventAddSectors            `json:"event_add_sectors"`
	EventRemoveSpecificSectors *EventRemoveSpecificSectors `json:"event_remove_specific_sectors"`
	EventRemoveAllSectors      *EventRemoveAllSectors      `json:"event_remove_sectors"`
	EventAttachSectors         *EventAttachSectors         `json:"event_attach_sectors"`
	Time                       time.Time                   `json:"time"`
}

Event include state events.

type EventAddSectors

type EventAddSectors struct {
	TokenID    types.TokenID `json:"token_id"`
	SectorsIDs [][]byte      `json:"sectors_ids"`
}

EventAddSectors represent adding sectors to token.

type EventAttachSectors

type EventAttachSectors struct {
	TokensSectors []AttachSectorsData `json:"tokens_sectors"`
}

EventAttachSectors represent attaching sector to contract.

type EventRemoveAllSectors

type EventRemoveAllSectors struct {
	TokenID    types.TokenID `json:"token_id"`
	SectorsIDs [][]byte      `json:"sectors_ids"`
}

EventRemoveAllSectors represent force removing sectors from token.

type EventRemoveSpecificSectors

type EventRemoveSpecificSectors struct {
	TokenID    types.TokenID `json:"token_id"`
	SectorsIDs [][]byte      `json:"sectors_ids"`
}

EventRemoveSpecificSectors represent removing specified sectors from token.

type EventTokenDownload

type EventTokenDownload struct {
	TokenID        types.TokenID `json:"token_id"`
	DownloadBytes  int64         `json:"download_bytes"`
	SectorAccesses int64         `json:"sector_accesses"`
}

EventTokenDownload change of state when downloading.

type EventTopUp

type EventTopUp struct {
	TokenID        types.TokenID   `json:"token_id"`
	ResourceType   types.Specifier `json:"resource_type"`
	ResourceAmount int64           `json:"resource_amount"`
}

EventTopUp change of state when token replenishment.

type State

type State struct {
	Tokens map[types.TokenID]TokenRecord `json:"tokens"`
	// contains filtered or unexported fields
}

State representation of token storage state.

func NewState

func NewState(dir string) (*State, error)

NewState create new state.

func (*State) Apply

func (s *State) Apply(e *Event)

Apply handle state events.

func (*State) Close

func (s *State) Close() error

Close DB connection.

func (*State) EnoughStorageResource

func (s *State) EnoughStorageResource(id types.TokenID, sectorsNum int64, now time.Time) (enoughResource bool)

EnoughStorageResource checks if there is enough storage resource to store existing sectors and new ones for one second. if the resource is less, it will return false.

func (*State) GetLimitedSectors

func (s *State) GetLimitedSectors(tokenID types.TokenID, pageID string, limit int) ([]crypto.Hash, string, error)

GetLimitedSectors return paginated sectors.

func (*State) GetSectors

func (s *State) GetSectors(tokenID types.TokenID) ([]crypto.Hash, error)

GetSectors return sectors IDs from database by token ID.

func (*State) HasSectors

func (s *State) HasSectors(tokenID types.TokenID, sectorIDs []crypto.Hash) ([]crypto.Hash, bool, error)

HasSectors checks if all sectors exist and returns a list of existing ones. It also removes duplicates from the list.

func (*State) LoadHistory

func (s *State) LoadHistory(r io.Reader) error

LoadHistory load history in state.

func (*State) NonexistentSectors

func (s *State) NonexistentSectors(tokenID types.TokenID, sectorIDs []crypto.Hash) ([]crypto.Hash, error)

NonexistentSectors returns a list of only nonexistent sectors from sectorIDs. It also removes duplicates from the list.

type TokenRecord

type TokenRecord struct {
	DownloadBytes  int64            `json:"download_bytes"`
	UploadBytes    int64            `json:"upload_bytes"`
	SectorAccesses int64            `json:"sector_accesses"`
	TokenInfo      tokenStorageInfo `json:"token_info"`
}

TokenRecord include information about token record.

Jump to

Keyboard shortcuts

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