runtime

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 21 Imported by: 54

README

Cadence Runtime

Usage

  • go run ./cmd <filename>

Development

Update the parser
  • antlr -listener -visitor -Dlanguage=Go -package parser parser/Cadence.g4

Documentation

Index

Constants

View Source
const (
	IdentifierLocationPrefix  = ast.IdentifierLocationPrefix
	StringLocationPrefix      = ast.StringLocationPrefix
	AddressLocationPrefix     = ast.AddressLocationPrefix
	TransactionLocationPrefix = "t"
	ScriptLocationPrefix      = "s"
)
View Source
const BlockHashLength = 32

Variables

This section is empty.

Functions

func CodeToHashValue added in v0.2.0

func CodeToHashValue(code []byte) *interpreter.ArrayValue

func FormatErrorMessage

func FormatErrorMessage(message string, useColor bool) string

func PrettyPrintError

func PrettyPrintError(err error, filename string, code string, useColor bool) string

Types

type Address

type Address = common.Address

type AddressLocation

type AddressLocation = ast.AddressLocation

type BlockHash added in v0.3.0

type BlockHash [BlockHashLength]byte

type BlockValue

type BlockValue struct {
	Height    interpreter.UInt64Value
	ID        *interpreter.ArrayValue
	Timestamp interpreter.Fix64Value
}

func NewBlockValue added in v0.2.0

func NewBlockValue(height uint64, id [stdlib.BlockIDSize]byte, timestamp time.Time) BlockValue

func (BlockValue) Copy

func (v BlockValue) Copy() interpreter.Value

func (BlockValue) DynamicType

func (BlockValue) GetMember

func (BlockValue) GetOwner

func (BlockValue) GetOwner() *common.Address

func (BlockValue) IDAsByteArray added in v0.2.0

func (v BlockValue) IDAsByteArray() [stdlib.BlockIDSize]byte

func (BlockValue) IsModified added in v0.3.0

func (BlockValue) IsModified() bool

func (BlockValue) IsValue

func (BlockValue) IsValue()

func (BlockValue) SetMember

func (BlockValue) SetModified added in v0.3.0

func (BlockValue) SetModified(_ bool)

func (BlockValue) SetOwner

func (BlockValue) SetOwner(_ *common.Address)

func (BlockValue) String

func (v BlockValue) String() string

type ComputationLimitExceededError added in v0.2.0

type ComputationLimitExceededError struct {
	Limit uint64
}

func (ComputationLimitExceededError) Error added in v0.2.0

type EmptyRuntimeInterface

type EmptyRuntimeInterface struct{}

func (*EmptyRuntimeInterface) AddAccountKey

func (i *EmptyRuntimeInterface) AddAccountKey(_ Address, _ []byte) error

func (*EmptyRuntimeInterface) CacheProgram added in v0.2.0

func (i *EmptyRuntimeInterface) CacheProgram(_ Location, _ *ast.Program) error

func (*EmptyRuntimeInterface) CreateAccount

func (i *EmptyRuntimeInterface) CreateAccount(_ Address) (address Address, err error)

func (*EmptyRuntimeInterface) DecodeArgument added in v0.2.0

func (i *EmptyRuntimeInterface) DecodeArgument(_ []byte, _ cadence.Type) (cadence.Value, error)

func (*EmptyRuntimeInterface) EmitEvent

func (i *EmptyRuntimeInterface) EmitEvent(_ cadence.Event)

func (*EmptyRuntimeInterface) GenerateUUID

func (i *EmptyRuntimeInterface) GenerateUUID() uint64

func (*EmptyRuntimeInterface) GetBlockAtHeight added in v0.3.0

func (i *EmptyRuntimeInterface) GetBlockAtHeight(_ uint64) (hash BlockHash, timestamp int64, exists bool, err error)

func (*EmptyRuntimeInterface) GetCachedProgram added in v0.2.0

func (i *EmptyRuntimeInterface) GetCachedProgram(_ Location) (*ast.Program, error)

func (*EmptyRuntimeInterface) GetComputationLimit added in v0.2.0

func (i *EmptyRuntimeInterface) GetComputationLimit() uint64

func (*EmptyRuntimeInterface) GetCurrentBlockHeight added in v0.3.0

func (i *EmptyRuntimeInterface) GetCurrentBlockHeight() uint64

func (*EmptyRuntimeInterface) GetSigningAccounts

func (i *EmptyRuntimeInterface) GetSigningAccounts() []Address

func (*EmptyRuntimeInterface) GetValue

func (i *EmptyRuntimeInterface) GetValue(_, _ []byte) (value []byte, err error)

func (*EmptyRuntimeInterface) Log

func (i *EmptyRuntimeInterface) Log(_ string)

func (*EmptyRuntimeInterface) RemoveAccountKey

func (i *EmptyRuntimeInterface) RemoveAccountKey(_ Address, _ int) (publicKey []byte, err error)

func (*EmptyRuntimeInterface) ResolveImport

func (i *EmptyRuntimeInterface) ResolveImport(_ Location) ([]byte, error)

func (*EmptyRuntimeInterface) SetValue

func (i *EmptyRuntimeInterface) SetValue(_, _, _ []byte) error

func (*EmptyRuntimeInterface) UnsafeRandom added in v0.5.0

func (i *EmptyRuntimeInterface) UnsafeRandom() uint64

func (*EmptyRuntimeInterface) UpdateAccountCode

func (i *EmptyRuntimeInterface) UpdateAccountCode(_ Address, _ []byte) error

func (*EmptyRuntimeInterface) ValueExists

func (i *EmptyRuntimeInterface) ValueExists(_, _ []byte) (exists bool, err error)

func (*EmptyRuntimeInterface) VerifySignature added in v0.5.0

func (i *EmptyRuntimeInterface) VerifySignature(
	_ []byte,
	_ string,
	_ []byte,
	_ []byte,
	_ string,
	_ string,
) bool

type Error

type Error struct {
	Err error
}

Error is the containing type for all errors produced by the runtime.

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type FileLocation

type FileLocation string

func (FileLocation) ID

func (l FileLocation) ID() ast.LocationID

func (FileLocation) String

func (l FileLocation) String() string

type HighLevelStorage added in v0.6.0

type HighLevelStorage interface {
	Interface

	// HighLevelStorageEnabled should return true
	// if the functions of HighLevelStorage should be called,
	// e.g. SetCadenceValue
	HighLevelStorageEnabled() bool

	// SetCadenceValue sets a value for the given key in the storage, owned by the given account.
	SetCadenceValue(owner Address, key string, value cadence.Value) (err error)
}

type ImportResolver

type ImportResolver = func(location Location) (program *ast.Program, e error)

type Interface

type Interface interface {
	// ResolveImport resolves an import of a program.
	ResolveImport(Location) ([]byte, error)
	// GetCachedProgram attempts to get a parsed program from a cache.
	GetCachedProgram(Location) (*ast.Program, error)
	// CacheProgram adds a parsed program to a cache.
	CacheProgram(Location, *ast.Program) error
	// GetValue gets a value for the given key in the storage, owned by the given account.
	GetValue(owner, key []byte) (value []byte, err error)
	// SetValue sets a value for the given key in the storage, owned by the given account.
	SetValue(owner, key, value []byte) (err error)
	// CreateAccount creates a new account.
	CreateAccount(payer Address) (address Address, err error)
	// AddAccountKey appends a key to an account.
	AddAccountKey(address Address, publicKey []byte) error
	// RemoveAccountKey removes a key from an account by index.
	RemoveAccountKey(address Address, index int) (publicKey []byte, err error)
	// UpdateAccountCode updates the code associated with an account.
	UpdateAccountCode(address Address, code []byte) (err error)
	// GetSigningAccounts returns the signing accounts.
	GetSigningAccounts() []Address
	// Log logs a string.
	Log(string)
	// EmitEvent is called when an event is emitted by the runtime.
	EmitEvent(cadence.Event)
	// ValueExists returns true if the given key exists in the storage, owned by the given account.
	ValueExists(owner, key []byte) (exists bool, err error)
	// GenerateUUID is called to generate a UUID.
	GenerateUUID() uint64
	// GetComputationLimit returns the computation limit. A value <= 0 means there is no limit
	GetComputationLimit() uint64
	// DecodeArgument decodes a transaction argument against the given type.
	DecodeArgument(argument []byte, argumentType cadence.Type) (cadence.Value, error)
	// GetCurrentBlockHeight returns the current block height.
	GetCurrentBlockHeight() uint64
	// GetBlockAtHeight returns the block at the given height.
	GetBlockAtHeight(height uint64) (hash BlockHash, timestamp int64, exists bool, err error)
	// UnsafeRandom returns a random uint64, where the process of random number derivation is not cryptographically
	// secure.
	UnsafeRandom() uint64
	// VerifySignature returns true if the given signature was produced by signing the given tag + data
	// using the given public key, signature algorithm, and hash algorithm.
	VerifySignature(
		signature []byte,
		tag string,
		signedData []byte,
		publicKey []byte,
		signatureAlgorithm string,
		hashAlgorithm string,
	) bool
}

type InvalidEntryPointArgumentError added in v0.5.0

type InvalidEntryPointArgumentError struct {
	Index int
	Err   error
}

func (*InvalidEntryPointArgumentError) Error added in v0.5.0

func (*InvalidEntryPointArgumentError) Unwrap added in v0.5.0

type InvalidEntryPointParameterCountError added in v0.5.0

type InvalidEntryPointParameterCountError struct {
	Expected int
	Actual   int
}

func (InvalidEntryPointParameterCountError) Error added in v0.5.0

type InvalidEntryPointTypeError added in v0.5.0

type InvalidEntryPointTypeError struct {
	Type sema.Type
}

func (*InvalidEntryPointTypeError) Error added in v0.5.0

type InvalidTransactionAuthorizerCountError added in v0.2.0

type InvalidTransactionAuthorizerCountError struct {
	Expected int
	Actual   int
}

func (InvalidTransactionAuthorizerCountError) Error added in v0.2.0

type InvalidTransactionCountError

type InvalidTransactionCountError struct {
	Count int
}

func (InvalidTransactionCountError) Error

type InvalidTypeAssignmentError added in v0.2.0

type InvalidTypeAssignmentError struct {
	Value interpreter.Value
	Type  sema.Type
	Err   error
}

func (*InvalidTypeAssignmentError) Error added in v0.2.0

func (*InvalidTypeAssignmentError) Unwrap added in v0.2.0

func (e *InvalidTypeAssignmentError) Unwrap() error

type Location

type Location = ast.Location

type LocationID

type LocationID = ast.LocationID

type Metrics added in v0.2.0

type Metrics interface {
	ProgramParsed(location ast.Location, duration time.Duration)
	ProgramChecked(location ast.Location, duration time.Duration)
	ProgramInterpreted(location ast.Location, duration time.Duration)
	ValueEncoded(duration time.Duration)
	ValueDecoded(duration time.Duration)
}

type MissingEntryPointError added in v0.5.0

type MissingEntryPointError struct {
	Expected string
}

func (*MissingEntryPointError) Error added in v0.5.0

func (e *MissingEntryPointError) Error() string

type Option added in v0.5.0

type Option func(Runtime)

type REPL

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

func NewREPL

func NewREPL(onError func(error), onResult func(interpreter.Value)) (*REPL, error)

func (*REPL) Accept

func (r *REPL) Accept(code string) (inputIsComplete bool)

func (*REPL) Suggestions

func (r *REPL) Suggestions() (result []REPLSuggestion)

type REPLLocation

type REPLLocation struct{}

func (REPLLocation) ID

func (l REPLLocation) ID() LocationID

func (REPLLocation) String

func (l REPLLocation) String() string

type REPLSuggestion added in v0.2.0

type REPLSuggestion struct {
	Name, Description string
}

type Runtime

type Runtime interface {
	// ExecuteScript executes the given script.
	//
	// This function returns an error if the program has errors (e.g syntax errors, type errors),
	// or if the execution fails.
	ExecuteScript(script []byte, arguments [][]byte, runtimeInterface Interface, location Location) (cadence.Value, error)

	// ExecuteTransaction executes the given transaction.
	//
	// This function returns an error if the program has errors (e.g syntax errors, type errors),
	// or if the execution fails.
	ExecuteTransaction(script []byte, arguments [][]byte, runtimeInterface Interface, location Location) error

	// ParseAndCheckProgram parses and checks the given code without executing the program.
	//
	// This function returns an error if the program contains any syntax or semantic errors.
	ParseAndCheckProgram(code []byte, runtimeInterface Interface, location Location) error
}

Runtime is a runtime capable of executing Cadence.

func NewInterpreterRuntime

func NewInterpreterRuntime(options ...Option) Runtime

NewInterpreterRuntime returns a interpreter-based version of the Flow runtime.

type ScriptLocation

type ScriptLocation []byte

func (ScriptLocation) ID

func (l ScriptLocation) ID() ast.LocationID

func (ScriptLocation) String

func (l ScriptLocation) String() string

type ScriptParameterTypeNotStorableError added in v0.8.0

type ScriptParameterTypeNotStorableError struct {
	Type sema.Type
}

func (*ScriptParameterTypeNotStorableError) Error added in v0.8.0

type ScriptReturnTypeNotStorableError added in v0.8.0

type ScriptReturnTypeNotStorableError struct {
	Type sema.Type
}

func (*ScriptReturnTypeNotStorableError) Error added in v0.8.0

type StringLocation

type StringLocation = ast.StringLocation

type TransactionLocation

type TransactionLocation []byte

func (TransactionLocation) ID

func (TransactionLocation) String

func (l TransactionLocation) String() string

type TransactionParameterTypeNotStorableError added in v0.8.0

type TransactionParameterTypeNotStorableError struct {
	Type sema.Type
}

func (*TransactionParameterTypeNotStorableError) Error added in v0.8.0

Directories

Path Synopsis
cmd
minifier
* Cadence - The resource-oriented smart contract programming language * * Copyright 2019-2020 Dapper Labs, Inc.
* Cadence - The resource-oriented smart contract programming language * * Copyright 2019-2020 Dapper Labs, Inc.
tests

Jump to

Keyboard shortcuts

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