stdlib

package
v0.9.2-leo-debug Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const BlockIDSize = 32
View Source
const HashSize = 32

Variables

View Source
var AccountCodeUpdatedEventType = newFlowEventType(
	"AccountCodeUpdated",
	AccountEventAddressParameter,
	AccountEventCodeHashParameter,
	AccountEventContractsParameter,
)
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 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: (func() *int {
			var count = 1
			return &count
		})(),
	},
	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{}
	},
	[]string{
		sema.ArgumentLabelNotRequired,
		"message",
	},
)
View Source
var BuiltinTypes = StandardLibraryTypes{}
View Source
var CryptoChecker = func() *sema.Checker {

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

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

	location := ast.IdentifierLocation("Crypto")

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

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

	return checker
}()
View Source
var FlowBuiltInTypes = StandardLibraryTypes{
	StandardLibraryType{
		Name: "Block",
		Type: &BlockType{},
		Kind: common.DeclarationKindType,
	},
}
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}
	},
	nil,
)
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,
		})
	},
	nil,
)
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,
	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 BlockType

type BlockType struct{}

func (*BlockType) Equal

func (*BlockType) Equal(other sema.Type) bool

func (*BlockType) GetMembers added in v0.7.0

func (t *BlockType) GetMembers() map[string]sema.MemberResolver

func (*BlockType) ID

func (*BlockType) ID() sema.TypeID

func (*BlockType) IsEquatable added in v0.7.0

func (*BlockType) IsEquatable() bool

func (*BlockType) IsInvalidType

func (*BlockType) IsInvalidType() bool

func (*BlockType) IsResourceType

func (*BlockType) IsResourceType() bool

func (*BlockType) IsStorable added in v0.5.0

func (*BlockType) IsStorable(_ map[*sema.Member]bool) bool

func (*BlockType) IsType

func (*BlockType) IsType()

func (*BlockType) QualifiedString

func (*BlockType) QualifiedString() string

func (*BlockType) Resolve

func (t *BlockType) Resolve(_ map[*sema.TypeParameter]sema.Type) sema.Type

func (*BlockType) RewriteWithRestrictedTypes added in v0.8.0

func (t *BlockType) RewriteWithRestrictedTypes() (sema.Type, bool)

func (*BlockType) String

func (*BlockType) String() string

func (*BlockType) TypeAnnotationState

func (*BlockType) TypeAnnotationState() sema.TypeAnnotationState

func (*BlockType) Unify

func (t *BlockType) Unify(_ sema.Type, _ map[*sema.TypeParameter]sema.Type, _ func(err error), _ ast.Range) bool

type CryptoSignatureVerifier added in v0.5.0

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

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.

type FlowLocation added in v0.5.0

type FlowLocation struct{}

func (FlowLocation) ID added in v0.5.0

func (l FlowLocation) ID() ast.LocationID

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
}

func NewStandardLibraryFunction

func NewStandardLibraryFunction(
	name string,
	functionType sema.InvokableType,
	function interpreter.HostFunction,
	argumentLabels []string,
) StandardLibraryFunction

func (StandardLibraryFunction) ValueDeclarationArgumentLabels

func (f StandardLibraryFunction) ValueDeclarationArgumentLabels() []string

func (StandardLibraryFunction) ValueDeclarationIsConstant

func (StandardLibraryFunction) ValueDeclarationIsConstant() bool

func (StandardLibraryFunction) ValueDeclarationKind

func (StandardLibraryFunction) ValueDeclarationKind() common.DeclarationKind

func (StandardLibraryFunction) ValueDeclarationPosition

func (StandardLibraryFunction) ValueDeclarationPosition() ast.Position

func (StandardLibraryFunction) ValueDeclarationType

func (f StandardLibraryFunction) ValueDeclarationType() sema.Type

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) ToValueDeclarations

func (functions StandardLibraryFunctions) ToValueDeclarations() map[string]sema.ValueDeclaration

func (StandardLibraryFunctions) ToValues

func (functions StandardLibraryFunctions) ToValues() map[string]interpreter.Value

type StandardLibraryType

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

func (StandardLibraryType) TypeDeclarationKind

func (t StandardLibraryType) TypeDeclarationKind() common.DeclarationKind

func (StandardLibraryType) TypeDeclarationPosition

func (StandardLibraryType) TypeDeclarationPosition() ast.Position

func (StandardLibraryType) TypeDeclarationType

func (t StandardLibraryType) TypeDeclarationType() sema.Type

type StandardLibraryTypes

type StandardLibraryTypes []StandardLibraryType

func (StandardLibraryTypes) ToTypeDeclarations

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

type StandardLibraryValue

type StandardLibraryValue struct {
	Name       string
	Type       sema.Type
	Kind       common.DeclarationKind
	IsConstant bool
}

func (StandardLibraryValue) ValueDeclarationArgumentLabels

func (StandardLibraryValue) ValueDeclarationArgumentLabels() []string

func (StandardLibraryValue) ValueDeclarationIsConstant

func (v StandardLibraryValue) ValueDeclarationIsConstant() bool

func (StandardLibraryValue) ValueDeclarationKind

func (v StandardLibraryValue) ValueDeclarationKind() common.DeclarationKind

func (StandardLibraryValue) ValueDeclarationPosition

func (StandardLibraryValue) ValueDeclarationPosition() ast.Position

func (StandardLibraryValue) ValueDeclarationType

func (v StandardLibraryValue) ValueDeclarationType() sema.Type

type StandardLibraryValues

type StandardLibraryValues []StandardLibraryValue

func (StandardLibraryValues) ToValueDeclarations

func (functions StandardLibraryValues) ToValueDeclarations() map[string]sema.ValueDeclaration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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