util

package
v0.35.12 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: AGPL-3.0 Imports: 34 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PayloadFileVersionV1 uint16 = 0x01
)

Variables

This section is empty.

Functions

func CreatePayloadFile added in v0.35.4

func CreatePayloadFile(
	logger zerolog.Logger,
	payloadFile string,
	payloads []*ledger.Payload,
	owners map[string]struct{},
	inputPayloadsFromPartialState bool,
) (int, error)

func IsPayloadFilePartialState added in v0.35.4

func IsPayloadFilePartialState(payloadFile string) (bool, error)

func IsServiceLevelAddress

func IsServiceLevelAddress(address common.Address) bool

IsServiceLevelAddress returns true if the given address is the service level address. Which means it's not an actual account but instead holds service lever registers.

func PayloadsAndAccountsFromEmulatorSnapshot added in v0.35.4

func PayloadsAndAccountsFromEmulatorSnapshot(db *sql.DB) (
	[]*ledger.Payload,
	map[flow.RegisterID]PayloadMetaInfo,
	[]common.Address,
	error,
)

func PayloadsFromEmulatorSnapshot added in v0.35.4

func PayloadsFromEmulatorSnapshot(snapshotPath string) ([]*ledger.Payload, error)

func ReadPayloadFile added in v0.35.4

func ReadPayloadFile(logger zerolog.Logger, payloadFile string) (bool, []*ledger.Payload, error)

func SortPayloadsByAddress added in v0.35.4

func SortPayloadsByAddress(payloads []*ledger.Payload, nWorkers int) []*ledger.Payload

Types

type AccountsAtreeLedger

type AccountsAtreeLedger struct {
	Accounts environment.Accounts
}

func NewAccountsAtreeLedger

func NewAccountsAtreeLedger(accounts environment.Accounts) *AccountsAtreeLedger

func (*AccountsAtreeLedger) AllocateStorageIndex

func (a *AccountsAtreeLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)

AllocateStorageIndex allocates new storage index under the owner accounts to store a new register

func (*AccountsAtreeLedger) GetValue

func (a *AccountsAtreeLedger) GetValue(owner, key []byte) ([]byte, error)

func (*AccountsAtreeLedger) SetValue

func (a *AccountsAtreeLedger) SetValue(owner, key, value []byte) error

func (*AccountsAtreeLedger) ValueExists

func (a *AccountsAtreeLedger) ValueExists(owner, key []byte) (exists bool, err error)

type GerOrLoadProgramListenerFunc added in v0.35.4

type GerOrLoadProgramListenerFunc func(
	location runtime.Location,
	program *interpreter.Program,
	err error,
)

type GetContractCodeFunc added in v0.35.4

type GetContractCodeFunc func(location common.AddressLocation) ([]byte, error)

type GetContractNamesFunc added in v0.35.4

type GetContractNamesFunc func(address flow.Address) ([]string, error)

type GetOrLoadProgramFunc added in v0.35.4

type GetOrLoadProgramFunc func(
	location runtime.Location,
	load func() (*interpreter.Program, error),
) (
	*interpreter.Program,
	error,
)

func NewProgramsGetOrLoadProgramFunc added in v0.35.4

func NewProgramsGetOrLoadProgramFunc(
	nestedTransactionPreparer state.NestedTransactionPreparer,
	accounts environment.Accounts,
) (GetOrLoadProgramFunc, error)

type MigrationRuntimeInterface

type MigrationRuntimeInterface struct {
	GetContractCodeFunc          GetContractCodeFunc
	GetContractNamesFunc         GetContractNamesFunc
	GetOrLoadProgramFunc         GetOrLoadProgramFunc
	GetOrLoadProgramListenerFunc GerOrLoadProgramListenerFunc
}

MigrationRuntimeInterface is a runtime interface that can be used in migrations. It only allows parsing and checking of contracts.

func NewMigrationRuntimeInterface added in v0.35.4

func NewMigrationRuntimeInterface(
	getCodeFunc GetContractCodeFunc,
	getContractNamesFunc GetContractNamesFunc,
	getOrLoadProgramFunc GetOrLoadProgramFunc,
	getOrLoadProgramListenerFunc GerOrLoadProgramListenerFunc,
) *MigrationRuntimeInterface

func (*MigrationRuntimeInterface) AccountKeysCount

func (m *MigrationRuntimeInterface) AccountKeysCount(_ runtime.Address) (uint64, error)

func (*MigrationRuntimeInterface) AddAccountKey

func (*MigrationRuntimeInterface) AddEncodedAccountKey

func (m *MigrationRuntimeInterface) AddEncodedAccountKey(_ runtime.Address, _ []byte) error

func (*MigrationRuntimeInterface) AllocateStorageIndex

func (m *MigrationRuntimeInterface) AllocateStorageIndex(_ []byte) (atree.StorageIndex, error)

func (*MigrationRuntimeInterface) BLSAggregatePublicKeys

func (m *MigrationRuntimeInterface) BLSAggregatePublicKeys(_ []*runtime.PublicKey) (*runtime.PublicKey, error)

func (*MigrationRuntimeInterface) BLSAggregateSignatures

func (m *MigrationRuntimeInterface) BLSAggregateSignatures(_ [][]byte) ([]byte, error)

func (*MigrationRuntimeInterface) BLSVerifyPOP

func (m *MigrationRuntimeInterface) BLSVerifyPOP(_ *runtime.PublicKey, _ []byte) (bool, error)

func (*MigrationRuntimeInterface) ComputationUsed

func (m *MigrationRuntimeInterface) ComputationUsed() (uint64, error)

func (*MigrationRuntimeInterface) CreateAccount

func (m *MigrationRuntimeInterface) CreateAccount(_ runtime.Address) (address runtime.Address, err error)

func (*MigrationRuntimeInterface) DecodeArgument

func (m *MigrationRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error)

func (*MigrationRuntimeInterface) EmitEvent

func (m *MigrationRuntimeInterface) EmitEvent(_ cadence.Event) error

func (*MigrationRuntimeInterface) GenerateAccountID

func (m *MigrationRuntimeInterface) GenerateAccountID(_ common.Address) (uint64, error)

func (*MigrationRuntimeInterface) GenerateUUID

func (m *MigrationRuntimeInterface) GenerateUUID() (uint64, error)

func (*MigrationRuntimeInterface) GetAccountAvailableBalance

func (m *MigrationRuntimeInterface) GetAccountAvailableBalance(_ common.Address) (value uint64, err error)

func (*MigrationRuntimeInterface) GetAccountBalance

func (m *MigrationRuntimeInterface) GetAccountBalance(_ common.Address) (value uint64, err error)

func (*MigrationRuntimeInterface) GetAccountContractCode

func (m *MigrationRuntimeInterface) GetAccountContractCode(
	location common.AddressLocation,
) (code []byte, err error)

func (*MigrationRuntimeInterface) GetAccountContractNames

func (m *MigrationRuntimeInterface) GetAccountContractNames(_ runtime.Address) ([]string, error)

func (*MigrationRuntimeInterface) GetAccountKey

func (*MigrationRuntimeInterface) GetBlockAtHeight

func (m *MigrationRuntimeInterface) GetBlockAtHeight(_ uint64) (block runtime.Block, exists bool, err error)

func (*MigrationRuntimeInterface) GetCode

func (m *MigrationRuntimeInterface) GetCode(location runtime.Location) ([]byte, error)

func (*MigrationRuntimeInterface) GetComputationLimit

func (m *MigrationRuntimeInterface) GetComputationLimit() uint64

func (*MigrationRuntimeInterface) GetCurrentBlockHeight

func (m *MigrationRuntimeInterface) GetCurrentBlockHeight() (uint64, error)

func (*MigrationRuntimeInterface) GetInterpreterSharedState

func (m *MigrationRuntimeInterface) GetInterpreterSharedState() *interpreter.SharedState

func (*MigrationRuntimeInterface) GetOrLoadProgram

func (m *MigrationRuntimeInterface) GetOrLoadProgram(
	location runtime.Location,
	load func() (*interpreter.Program, error),
) (
	program *interpreter.Program,
	err error,
)

func (*MigrationRuntimeInterface) GetSigningAccounts

func (m *MigrationRuntimeInterface) GetSigningAccounts() ([]runtime.Address, error)

func (*MigrationRuntimeInterface) GetStorageCapacity

func (m *MigrationRuntimeInterface) GetStorageCapacity(_ runtime.Address) (value uint64, err error)

func (*MigrationRuntimeInterface) GetStorageUsed

func (m *MigrationRuntimeInterface) GetStorageUsed(_ runtime.Address) (value uint64, err error)

func (*MigrationRuntimeInterface) GetValue

func (m *MigrationRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error)

func (*MigrationRuntimeInterface) Hash

func (*MigrationRuntimeInterface) ImplementationDebugLog

func (m *MigrationRuntimeInterface) ImplementationDebugLog(_ string) error

func (*MigrationRuntimeInterface) InteractionUsed

func (m *MigrationRuntimeInterface) InteractionUsed() (uint64, error)

func (*MigrationRuntimeInterface) MemoryUsed

func (m *MigrationRuntimeInterface) MemoryUsed() (uint64, error)

func (*MigrationRuntimeInterface) MeterComputation

func (m *MigrationRuntimeInterface) MeterComputation(_ common.ComputationKind, _ uint) error

func (*MigrationRuntimeInterface) MeterMemory

func (*MigrationRuntimeInterface) ProgramLog

func (m *MigrationRuntimeInterface) ProgramLog(_ string) error

func (*MigrationRuntimeInterface) ReadRandom

func (m *MigrationRuntimeInterface) ReadRandom([]byte) error

func (*MigrationRuntimeInterface) RecordTrace

func (*MigrationRuntimeInterface) RemoveAccountContractCode

func (m *MigrationRuntimeInterface) RemoveAccountContractCode(common.AddressLocation) (err error)

func (*MigrationRuntimeInterface) ResolveLocation

func (m *MigrationRuntimeInterface) ResolveLocation(
	identifiers []runtime.Identifier,
	location runtime.Location,
) ([]runtime.ResolvedLocation, error)

func (*MigrationRuntimeInterface) ResourceOwnerChanged

func (*MigrationRuntimeInterface) RevokeAccountKey

func (m *MigrationRuntimeInterface) RevokeAccountKey(_ runtime.Address, _ int) (*runtime.AccountKey, error)

func (*MigrationRuntimeInterface) RevokeEncodedAccountKey

func (m *MigrationRuntimeInterface) RevokeEncodedAccountKey(_ runtime.Address, _ int) (publicKey []byte, err error)

func (*MigrationRuntimeInterface) SetComputationUsed

func (m *MigrationRuntimeInterface) SetComputationUsed(_ uint64) error

func (*MigrationRuntimeInterface) SetInterpreterSharedState

func (m *MigrationRuntimeInterface) SetInterpreterSharedState(_ *interpreter.SharedState)

func (*MigrationRuntimeInterface) SetValue

func (m *MigrationRuntimeInterface) SetValue(_, _, _ []byte) (err error)

func (*MigrationRuntimeInterface) UpdateAccountContractCode

func (m *MigrationRuntimeInterface) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) (err error)

func (*MigrationRuntimeInterface) ValidatePublicKey

func (m *MigrationRuntimeInterface) ValidatePublicKey(_ *runtime.PublicKey) error

func (*MigrationRuntimeInterface) ValueExists

func (m *MigrationRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error)

func (*MigrationRuntimeInterface) VerifySignature

func (m *MigrationRuntimeInterface) VerifySignature(
	_ []byte,
	_ string,
	_ []byte,
	_ []byte,
	_ runtime.SignatureAlgorithm,
	_ runtime.HashAlgorithm,
) (bool, error)

type NopMeter

type NopMeter struct{}

NopMeter is a meter that does nothing. It can be used in migrations.

func (NopMeter) ComputationAvailable

func (n NopMeter) ComputationAvailable(_ common.ComputationKind, _ uint) bool

func (NopMeter) ComputationIntensities

func (n NopMeter) ComputationIntensities() meter.MeteredComputationIntensities

func (NopMeter) ComputationUsed

func (n NopMeter) ComputationUsed() (uint64, error)

func (NopMeter) InteractionUsed

func (n NopMeter) InteractionUsed() (uint64, error)

func (NopMeter) MemoryUsed

func (n NopMeter) MemoryUsed() (uint64, error)

func (NopMeter) MeterComputation

func (n NopMeter) MeterComputation(_ common.ComputationKind, _ uint) error

func (NopMeter) MeterEmittedEvent

func (n NopMeter) MeterEmittedEvent(_ uint64) error

func (NopMeter) MeterMemory

func (n NopMeter) MeterMemory(_ common.MemoryUsage) error

func (NopMeter) TotalEmittedEventBytes

func (n NopMeter) TotalEmittedEventBytes() uint64

type PayloadAccountGroup

type PayloadAccountGroup struct {
	Address  flow.Address
	Payloads []*ledger.Payload
}

PayloadAccountGroup is a grouping of payloads by account

type PayloadAccountGrouping

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

PayloadAccountGrouping is a grouping of payloads by account.

func GroupPayloadsByAccount

func GroupPayloadsByAccount(
	log zerolog.Logger,
	payloads []*ledger.Payload,
	nWorkers int,
) *PayloadAccountGrouping

GroupPayloadsByAccount takes a list of payloads and groups them by account. it uses nWorkers to sort the payloads by address and find the start and end indexes of each account.

func (*PayloadAccountGrouping) AllPayloadsCount

func (g *PayloadAccountGrouping) AllPayloadsCount() int

AllPayloadsCount the number of payloads

func (*PayloadAccountGrouping) Len

func (g *PayloadAccountGrouping) Len() int

Len returns the number of accounts

func (*PayloadAccountGrouping) Next

Next returns the next account group. If there is no more account group, it returns nil. The zero address is used for global Payloads and is not an actual account.

type PayloadMetaInfo added in v0.35.4

type PayloadMetaInfo struct {
	Height, Version uint64
}

type PayloadsLedger added in v0.35.4

type PayloadsLedger struct {
	Payloads map[flow.RegisterID]*ledger.Payload

	AllocateStorageIndexFunc func(owner []byte) (atree.StorageIndex, error)
}

PayloadsLedger is a simple read/write in-memory atree.Ledger implementation

func NewPayloadsLedger added in v0.35.4

func NewPayloadsLedger(payloads map[flow.RegisterID]*ledger.Payload) *PayloadsLedger

func (*PayloadsLedger) AllocateStorageIndex added in v0.35.4

func (p *PayloadsLedger) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)

func (*PayloadsLedger) GetValue added in v0.35.4

func (p *PayloadsLedger) GetValue(owner, key []byte) (value []byte, err error)

func (*PayloadsLedger) SetValue added in v0.35.4

func (p *PayloadsLedger) SetValue(owner, key, value []byte) (err error)

func (*PayloadsLedger) ValueExists added in v0.35.4

func (p *PayloadsLedger) ValueExists(owner, key []byte) (exists bool, err error)

type TopN added in v0.35.8

type TopN[T any] struct {
	Tree   []T
	N      int
	IsLess func(T, T) bool
}

TopN keeps track of the top N elements. Use Add to add elements to the list.

func NewTopN added in v0.35.8

func NewTopN[T any](n int, isLess func(T, T) bool) *TopN[T]

func (*TopN[T]) Add added in v0.35.8

func (h *TopN[T]) Add(value T) (popped T, didPop bool)

Add tries to add a value to the list. If the list is full, it will return the smallest value and true. If the list is not full, it will return the zero value and false.

func (*TopN[T]) Len added in v0.35.8

func (h *TopN[T]) Len() int

func (*TopN[T]) Less added in v0.35.8

func (h *TopN[T]) Less(i, j int) bool

func (*TopN[T]) Pop added in v0.35.8

func (h *TopN[T]) Pop() interface{}

func (*TopN[T]) Push added in v0.35.8

func (h *TopN[T]) Push(x interface{})

func (*TopN[T]) Swap added in v0.35.8

func (h *TopN[T]) Swap(i, j int)

type Trace added in v0.35.12

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

func NewTrace added in v0.35.12

func NewTrace(value string) *Trace

func (*Trace) Append added in v0.35.12

func (t *Trace) Append(value string) *Trace

func (*Trace) String added in v0.35.12

func (t *Trace) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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