stdlib

package
v0.25.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const FlowLocationPrefix = "flow"
View Source
const HashSize = 32

Variables

View Source
var AccountContractAddedEventType = newFlowEventType(
	"AccountContractAdded",
	AccountEventAddressParameter,
	AccountEventCodeHashParameter,
	AccountEventContractParameter,
)
View Source
var AccountContractRemovedEventType = newFlowEventType(
	"AccountContractRemoved",
	AccountEventAddressParameter,
	AccountEventCodeHashParameter,
	AccountEventContractParameter,
)
View Source
var AccountContractUpdatedEventType = newFlowEventType(
	"AccountContractUpdated",
	AccountEventAddressParameter,
	AccountEventCodeHashParameter,
	AccountEventContractParameter,
)
View Source
var AccountCreatedEventType = newFlowEventType(
	"AccountCreated",
	AccountEventAddressParameter,
)
View Source
var AccountEventAddressParameter = &sema.Parameter{
	Identifier:     "address",
	TypeAnnotation: sema.NewTypeAnnotation(&sema.AddressType{}),
}
View Source
var AccountEventCodeHashParameter = &sema.Parameter{
	Identifier:     "codeHash",
	TypeAnnotation: sema.NewTypeAnnotation(HashType),
}
View Source
var AccountEventContractParameter = &sema.Parameter{
	Identifier:     "contract",
	TypeAnnotation: sema.NewTypeAnnotation(sema.StringType),
}
View Source
var AccountEventContractsParameter = &sema.Parameter{
	Identifier:     "contracts",
	TypeAnnotation: sema.NewTypeAnnotation(TypeIDsType),
}
View Source
var AccountEventPublicKeyParameter = &sema.Parameter{
	Identifier: "publicKey",
	TypeAnnotation: sema.NewTypeAnnotation(
		sema.ByteArrayType,
	),
}
View Source
var AccountKeyAddedEventType = newFlowEventType(
	"AccountKeyAdded",
	AccountEventAddressParameter,
	AccountEventPublicKeyParameter,
)
View Source
var AccountKeyRemovedEventType = newFlowEventType(
	"AccountKeyRemoved",
	AccountEventAddressParameter,
	AccountEventPublicKeyParameter,
)
View Source
var AssertFunction = NewStandardLibraryFunction(
	"assert",
	assertFunctionType,
	assertFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		result, ok := invocation.Arguments[0].(interpreter.BoolValue)
		if !ok {
			panic(errors.NewUnreachableError())
		}

		if !result {
			var message string
			if len(invocation.Arguments) > 1 {
				messageValue, ok := invocation.Arguments[1].(*interpreter.StringValue)
				if !ok {
					panic(errors.NewUnreachableError())
				}
				message = messageValue.Str
			}
			panic(AssertionError{
				Message:       message,
				LocationRange: invocation.GetLocationRange(),
			})
		}
		return interpreter.VoidValue{}
	},
)
View Source
var BuiltinFunctions = StandardLibraryFunctions{
	AssertFunction,
	PanicFunction,
	publicKeyConstructor,
}
View Source
var BuiltinValues = StandardLibraryValues{
	signatureAlgorithmConstructor,
	hashAlgorithmConstructor,
	blsContract,
	rlpContract,
}
View Source
var CryptoChecker = func() *sema.Checker {

	program, err := parser.ParseProgram(contracts.Crypto, nil)
	if err != nil {
		panic(err)
	}

	location := common.IdentifierLocation("Crypto")

	var checker *sema.Checker
	checker, err = sema.NewChecker(
		program,
		location,
		nil,
		false,
		sema.WithPredeclaredValues(BuiltinFunctions.ToSemaValueDeclarations()),
		sema.WithPredeclaredTypes(BuiltinTypes.ToTypeDeclarations()),
	)
	if err != nil {
		panic(err)
	}

	err = checker.Check()
	if err != nil {
		panic(err)
	}

	return checker
}()
View Source
var FlowDefaultPredeclaredTypes = append(
	FlowBuiltInTypes,
	BuiltinTypes...,
).ToTypeDeclarations()
View Source
var HashType = &sema.ConstantSizedType{
	Size: HashSize,
	Type: sema.UInt8Type,
}
View Source
var LogFunction = NewStandardLibraryFunction(
	"log",
	LogFunctionType,
	logFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		fmt.Println(invocation.Arguments[0].MeteredString(invocation.Interpreter, interpreter.SeenReferences{}))
		return interpreter.VoidValue{}
	},
)
View Source
var LogFunctionType = &sema.FunctionType{
	Parameters: []*sema.Parameter{
		{
			Label:      sema.ArgumentLabelNotRequired,
			Identifier: "value",
			TypeAnnotation: sema.NewTypeAnnotation(
				sema.AnyStructType,
			),
		},
	},
	ReturnTypeAnnotation: sema.NewTypeAnnotation(
		sema.VoidType,
	),
}
View Source
var PanicFunction = NewStandardLibraryFunction(
	"panic",
	&sema.FunctionType{
		Parameters: []*sema.Parameter{
			{
				Label:          sema.ArgumentLabelNotRequired,
				Identifier:     "message",
				TypeAnnotation: sema.NewTypeAnnotation(sema.StringType),
			},
		},
		ReturnTypeAnnotation: sema.NewTypeAnnotation(
			sema.NeverType,
		),
	},
	panicFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		messageValue, ok := invocation.Arguments[0].(*interpreter.StringValue)
		if !ok {
			panic(errors.NewUnreachableError())
		}
		message := messageValue.Str

		panic(PanicError{
			Message:       message,
			LocationRange: invocation.GetLocationRange(),
		})
	},
)
View Source
var TypeIDsType = &sema.VariableSizedType{
	Type: sema.StringType,
}

Functions

func FlowDefaultPredeclaredValues added in v0.25.0

func FlowDefaultPredeclaredValues(impls FlowBuiltinImpls) (
	[]sema.ValueDeclaration,
	[]interpreter.ValueDeclaration,
)

func NewCryptoContract added in v0.5.0

func NewCryptoContract(
	inter *interpreter.Interpreter,
	constructor interpreter.FunctionValue,
	invocationRange ast.Range,
) (
	*interpreter.CompositeValue,
	error,
)

func NewHashAlgorithmCase added in v0.18.0

func NewHashAlgorithmCase(inter *interpreter.Interpreter, rawValue uint8) *interpreter.CompositeValue

func NewSignatureAlgorithmCase added in v0.18.0

func NewSignatureAlgorithmCase(inter *interpreter.Interpreter, rawValue uint8) *interpreter.CompositeValue

Types

type AssertionError

type AssertionError struct {
	Message string
	interpreter.LocationRange
}

func (AssertionError) Error

func (e AssertionError) Error() string

func (AssertionError) IsUserError added in v0.25.0

func (AssertionError) IsUserError()

type FlowBuiltinImpls

type FlowBuiltinImpls struct {
	CreateAccount   interpreter.HostFunction
	GetAccount      interpreter.HostFunction
	Log             interpreter.HostFunction
	GetCurrentBlock interpreter.HostFunction
	GetBlock        interpreter.HostFunction
	UnsafeRandom    interpreter.HostFunction
}

FlowBuiltinImpls defines the set of functions needed to implement the Flow built-in functions.

func DefaultFlowBuiltinImpls added in v0.10.0

func DefaultFlowBuiltinImpls() FlowBuiltinImpls

type FlowLocation added in v0.5.0

type FlowLocation struct{}

func (FlowLocation) Description added in v0.25.0

func (l FlowLocation) Description() string

func (FlowLocation) ID added in v0.5.0

func (FlowLocation) MarshalJSON added in v0.12.0

func (l FlowLocation) MarshalJSON() ([]byte, error)

func (FlowLocation) MeteredID added in v0.24.0

func (FlowLocation) QualifiedIdentifier added in v0.10.2

func (l FlowLocation) QualifiedIdentifier(typeID common.TypeID) string

func (FlowLocation) String added in v0.12.0

func (l FlowLocation) String() string

func (FlowLocation) TypeID added in v0.10.2

func (l FlowLocation) TypeID(memoryGauge common.MemoryGauge, qualifiedIdentifier string) common.TypeID

type PanicError

type PanicError struct {
	Message string
	interpreter.LocationRange
}

func (PanicError) Error

func (e PanicError) Error() string

func (PanicError) IsUserError added in v0.25.0

func (PanicError) IsUserError()

type RLPDecodeListError added in v0.23.0

type RLPDecodeListError struct {
	Msg string
	interpreter.LocationRange
}

func (RLPDecodeListError) Error added in v0.23.0

func (e RLPDecodeListError) Error() string

func (RLPDecodeListError) IsUserError added in v0.25.0

func (RLPDecodeListError) IsUserError()

type RLPDecodeStringError added in v0.23.0

type RLPDecodeStringError struct {
	Msg string
	interpreter.LocationRange
}

func (RLPDecodeStringError) Error added in v0.23.0

func (e RLPDecodeStringError) Error() string

func (RLPDecodeStringError) IsUserError added in v0.25.0

func (RLPDecodeStringError) IsUserError()

type StandardLibraryFunction

type StandardLibraryFunction struct {
	Name           string
	Type           *sema.FunctionType
	DocString      string
	Function       *interpreter.HostFunctionValue
	ArgumentLabels []string
	Available      func(common.Location) bool
}

func NewStandardLibraryFunction

func NewStandardLibraryFunction(
	name string,
	functionType *sema.FunctionType,
	docString string,
	function interpreter.HostFunction,
) StandardLibraryFunction

func (StandardLibraryFunction) ValueDeclarationArgumentLabels

func (f StandardLibraryFunction) ValueDeclarationArgumentLabels() []string

func (StandardLibraryFunction) ValueDeclarationAvailable added in v0.12.0

func (f StandardLibraryFunction) ValueDeclarationAvailable(location common.Location) bool

func (StandardLibraryFunction) ValueDeclarationDocString added in v0.17.0

func (f StandardLibraryFunction) ValueDeclarationDocString() string

func (StandardLibraryFunction) ValueDeclarationIsConstant

func (StandardLibraryFunction) ValueDeclarationIsConstant() bool

func (StandardLibraryFunction) ValueDeclarationKind

func (StandardLibraryFunction) ValueDeclarationKind() common.DeclarationKind

func (StandardLibraryFunction) ValueDeclarationName added in v0.12.0

func (f StandardLibraryFunction) ValueDeclarationName() string

func (StandardLibraryFunction) ValueDeclarationPosition

func (StandardLibraryFunction) ValueDeclarationPosition() ast.Position

func (StandardLibraryFunction) ValueDeclarationType

func (f StandardLibraryFunction) ValueDeclarationType() sema.Type

func (StandardLibraryFunction) ValueDeclarationValue added in v0.12.0

func (f StandardLibraryFunction) ValueDeclarationValue(_ *interpreter.Interpreter) interpreter.Value

type StandardLibraryFunctions

type StandardLibraryFunctions []StandardLibraryFunction

func FlowBuiltInFunctions

func FlowBuiltInFunctions(impls FlowBuiltinImpls) StandardLibraryFunctions

FlowBuiltInFunctions returns a list of standard library functions, bound to the provided implementation.

func (StandardLibraryFunctions) ToInterpreterValueDeclarations added in v0.12.0

func (functions StandardLibraryFunctions) ToInterpreterValueDeclarations() []interpreter.ValueDeclaration

func (StandardLibraryFunctions) ToSemaValueDeclarations added in v0.12.0

func (functions StandardLibraryFunctions) ToSemaValueDeclarations() []sema.ValueDeclaration

type StandardLibraryType

type StandardLibraryType struct {
	Name string
	Type sema.Type
	Kind common.DeclarationKind
}

func (StandardLibraryType) TypeDeclarationKind

func (t StandardLibraryType) TypeDeclarationKind() common.DeclarationKind

func (StandardLibraryType) TypeDeclarationName added in v0.12.0

func (t StandardLibraryType) TypeDeclarationName() string

func (StandardLibraryType) TypeDeclarationPosition

func (StandardLibraryType) TypeDeclarationPosition() ast.Position

func (StandardLibraryType) TypeDeclarationType

func (t StandardLibraryType) TypeDeclarationType() sema.Type

type StandardLibraryTypes

type StandardLibraryTypes []StandardLibraryType
var BuiltinTypes StandardLibraryTypes
var FlowBuiltInTypes StandardLibraryTypes

func (StandardLibraryTypes) ToTypeDeclarations

func (types StandardLibraryTypes) ToTypeDeclarations() []sema.TypeDeclaration

type StandardLibraryValue

type StandardLibraryValue struct {
	Name         string
	Type         sema.Type
	DocString    string
	ValueFactory func(*interpreter.Interpreter) interpreter.Value
	Kind         common.DeclarationKind
	Available    func(common.Location) bool
}

func (StandardLibraryValue) ValueDeclarationArgumentLabels

func (StandardLibraryValue) ValueDeclarationArgumentLabels() []string

func (StandardLibraryValue) ValueDeclarationAvailable added in v0.12.0

func (v StandardLibraryValue) ValueDeclarationAvailable(location common.Location) bool

func (StandardLibraryValue) ValueDeclarationDocString added in v0.17.0

func (v StandardLibraryValue) ValueDeclarationDocString() string

func (StandardLibraryValue) ValueDeclarationIsConstant

func (v StandardLibraryValue) ValueDeclarationIsConstant() bool

func (StandardLibraryValue) ValueDeclarationKind

func (v StandardLibraryValue) ValueDeclarationKind() common.DeclarationKind

func (StandardLibraryValue) ValueDeclarationName added in v0.12.0

func (v StandardLibraryValue) ValueDeclarationName() string

func (StandardLibraryValue) ValueDeclarationPosition

func (StandardLibraryValue) ValueDeclarationPosition() ast.Position

func (StandardLibraryValue) ValueDeclarationType

func (v StandardLibraryValue) ValueDeclarationType() sema.Type

func (StandardLibraryValue) ValueDeclarationValue added in v0.12.0

func (v StandardLibraryValue) ValueDeclarationValue(interpreter *interpreter.Interpreter) interpreter.Value

type StandardLibraryValues

type StandardLibraryValues []StandardLibraryValue

func (StandardLibraryValues) ToInterpreterValueDeclarations added in v0.12.0

func (values StandardLibraryValues) ToInterpreterValueDeclarations() []interpreter.ValueDeclaration

func (StandardLibraryValues) ToSemaValueDeclarations added in v0.12.0

func (values StandardLibraryValues) ToSemaValueDeclarations() []sema.ValueDeclaration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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