stdlib

package
v0.20.0-beta10 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 11 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",
	&sema.FunctionType{
		Parameters: []*sema.Parameter{
			{
				Label:          sema.ArgumentLabelNotRequired,
				Identifier:     "condition",
				TypeAnnotation: sema.NewTypeAnnotation(sema.BoolType),
			},
			{
				Identifier:     "message",
				TypeAnnotation: sema.NewTypeAnnotation(sema.StringType),
			},
		},
		ReturnTypeAnnotation: sema.NewTypeAnnotation(
			sema.VoidType,
		),
		RequiredArgumentCount: sema.RequiredArgumentCount(1),
	},
	assertFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		result := invocation.Arguments[0].(interpreter.BoolValue)
		if !result {
			var message string
			if len(invocation.Arguments) > 1 {
				message = invocation.Arguments[1].(*interpreter.StringValue).Str
			}
			panic(AssertionError{
				Message:       message,
				LocationRange: invocation.GetLocationRange(),
			})
		}
		return interpreter.VoidValue{}
	},
)
View Source
var CreatePublicKeyFunction = NewStandardLibraryFunction(
	sema.PublicKeyTypeName,
	&sema.FunctionType{
		Parameters: []*sema.Parameter{
			{
				Identifier:     sema.PublicKeyPublicKeyField,
				TypeAnnotation: sema.NewTypeAnnotation(&sema.VariableSizedType{Type: sema.UInt8Type}),
			},
			{
				Identifier:     sema.PublicKeySignAlgoField,
				TypeAnnotation: sema.NewTypeAnnotation(sema.SignatureAlgorithmType),
			},
		},
		ReturnTypeAnnotation: sema.NewTypeAnnotation(sema.PublicKeyType),
	},
	createPublicKeyFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		publicKey := invocation.Arguments[0].(*interpreter.ArrayValue)
		signAlgo := invocation.Arguments[1].(*interpreter.CompositeValue)

		inter := invocation.Interpreter

		return interpreter.NewPublicKeyValue(
			inter,
			invocation.GetLocationRange,
			publicKey,
			signAlgo,
			inter.PublicKeyValidationHandler,
		)
	},
)
View Source
var CryptoChecker = func() *sema.Checker {

	code := internal.MustAssetString("contracts/crypto.cdc")

	program, err := parser2.ParseProgram(code)
	if err != nil {
		panic(err)
	}

	location := common.IdentifierLocation("Crypto")

	var checker *sema.Checker
	checker, err = sema.NewChecker(
		program,
		location,
		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 HashType = &sema.ConstantSizedType{
	Size: HashSize,
	Type: sema.UInt8Type,
}
View Source
var LogFunction = NewStandardLibraryFunction(
	"log",
	LogFunctionType,
	logFunctionDocString,
	func(invocation interpreter.Invocation) interpreter.Value {
		println(invocation.Arguments[0].String())
		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 {
		message := invocation.Arguments[0].(*interpreter.StringValue)
		panic(PanicError{
			Message:       message.Str,
			LocationRange: invocation.GetLocationRange(),
		})
	},
)
View Source
var TypeIDsType = &sema.VariableSizedType{
	Type: sema.StringType,
}

Functions

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

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) ID added in v0.5.0

func (FlowLocation) MarshalJSON added in v0.12.0

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

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(qualifiedIdentifier string) common.TypeID

type PanicError

type PanicError struct {
	Message string
	interpreter.LocationRange
}

func (PanicError) Error

func (e PanicError) Error() string

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 BuiltinValues added in v0.14.0

func BuiltinValues() StandardLibraryValues

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