stdlib

package
v0.13.1-no-contract-up... Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 13 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.VariableSizedType{
			Type: &sema.UInt8Type{},
		},
	),
}
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),
	},
	func(invocation interpreter.Invocation) trampoline.Trampoline {
		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.LocationRange,
			})
		}
		return trampoline.Done{}
	},
)
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",
	&sema.FunctionType{
		Parameters: []*sema.Parameter{
			{
				Label:      sema.ArgumentLabelNotRequired,
				Identifier: "value",
				TypeAnnotation: sema.NewTypeAnnotation(
					sema.AnyStructType,
				),
			},
		},
		ReturnTypeAnnotation: sema.NewTypeAnnotation(
			sema.VoidType,
		),
	},
	func(invocation interpreter.Invocation) trampoline.Trampoline {
		fmt.Printf("%v\n", invocation.Arguments[0])
		result := interpreter.VoidValue{}
		return trampoline.Done{Result: result}
	},
)
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,
		),
	},
	func(invocation interpreter.Invocation) trampoline.Trampoline {
		message := invocation.Arguments[0].(*interpreter.StringValue)
		panic(PanicError{
			Message:       message.Str,
			LocationRange: invocation.LocationRange,
		})
	},
)
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,
	signatureVerifier CryptoSignatureVerifier,
	hasher CryptoHasher,
	invocationRange ast.Range,
) (
	*interpreter.CompositeValue,
	error,
)

Types

type AssertionError

type AssertionError struct {
	Message string
	interpreter.LocationRange
}

func (AssertionError) Error

func (e AssertionError) Error() string

type CryptoHasher added in v0.10.0

type CryptoHasher interface {
	Hash(
		data []byte,
		hashAlgorithm string,
	) ([]byte, error)
}

type CryptoSignatureVerifier added in v0.5.0

type CryptoSignatureVerifier interface {
	VerifySignature(
		signature []byte,
		tag string,
		signedData []byte,
		publicKey []byte,
		signatureAlgorithm string,
		hashAlgorithm string,
	) (bool, error)
}

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.InvokableType
	Function       interpreter.HostFunctionValue
	ArgumentLabels []string
	Available      func(common.Location) bool
}

func NewStandardLibraryFunction

func NewStandardLibraryFunction(
	name string,
	functionType sema.InvokableType,
	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) 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.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
	Value     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) 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.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