cadence

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 6 Imported by: 327

README

Cadence

Introduction

Cadence is a resource-oriented programming language that introduces new features to smart contract programming that help developers ensure that their code is safe, secure, clear, and approachable.

Some of these features are:

  • Type safety and a strong static type system
  • Resource-oriented programming, a new paradigm that pairs linear types with object capabilities to create a secure and declarative model for digital ownership by ensuring that resources (and their associated assets) can only exist in one location at a time, cannot be copied, and cannot be accidentally lost or deleted
  • Built-in pre-conditions and post-conditions for functions and transactions
  • The utilization of capability-based security, which enforces access control by requiring that access to objects is restricted to only the owner and those who have a valid reference to the object

Getting Started

To get started writing Cadence, try it out in the Playground.

If you want to develop locally, install the Flow Command Line Client, which provides the Flow emulator and the Visual Studio Code extension. The emulator is a lightweight tool that emulates the behaviour of the real Flow network. The Visual Studio Code extension enables the development, deployment of, and interaction with Cadence contracts

Documentation

To read more about Cadence, have a look at the language reference on the Flow documentation site or in this repository.

Documentation

Index

Constants

View Source
const AddressLength = 8

Variables

This section is empty.

Functions

func CastToArray

func CastToArray(value Value) ([]interface{}, error)

func CastToInt

func CastToInt(value Value) (int, error)

func CastToString

func CastToString(value Value) (string, error)

func CastToUInt16

func CastToUInt16(value Value) (uint16, error)

func CastToUInt8

func CastToUInt8(value Value) (uint8, error)

func Fuzz

func Fuzz(data []byte) int

Types

type Address

type Address [AddressLength]byte

func BytesToAddress

func BytesToAddress(b []byte) Address

func NewAddress

func NewAddress(b [AddressLength]byte) Address

func (Address) Bytes

func (v Address) Bytes() []byte

func (Address) Hex

func (v Address) Hex() string

func (Address) String

func (v Address) String() string

func (Address) ToGoValue

func (v Address) ToGoValue() interface{}

func (Address) Type

func (Address) Type() Type

type AddressType

type AddressType struct{}

func (AddressType) ID

func (AddressType) ID() string

type AnyResourceType

type AnyResourceType struct{}

func (AnyResourceType) ID

func (AnyResourceType) ID() string

type AnyStructType

type AnyStructType struct{}

func (AnyStructType) ID

func (AnyStructType) ID() string

type AnyType

type AnyType struct{}

func (AnyType) ID

func (AnyType) ID() string

type Array

type Array struct {
	Values []Value
	// contains filtered or unexported fields
}

func NewArray

func NewArray(values []Value) Array

func (Array) ToGoValue

func (v Array) ToGoValue() interface{}

func (Array) Type

func (v Array) Type() Type

type ArrayType

type ArrayType interface {
	Element() Type
}

type Bool

type Bool bool

func NewBool

func NewBool(b bool) Bool

func (Bool) ToGoValue

func (v Bool) ToGoValue() interface{}

func (Bool) Type

func (Bool) Type() Type

type BoolType

type BoolType struct{}

func (BoolType) ID

func (BoolType) ID() string

type Bytes

type Bytes []byte

func NewBytes

func NewBytes(b []byte) Bytes

func (Bytes) ToGoValue

func (v Bytes) ToGoValue() interface{}

func (Bytes) Type

func (Bytes) Type() Type

type BytesType

type BytesType struct{}

func (BytesType) ID

func (BytesType) ID() string

type CompositeType

type CompositeType interface {
	Type

	CompositeIdentifier() string
	CompositeFields() []Field
	CompositeInitializers() [][]Parameter
	// contains filtered or unexported methods
}

type ConstantSizedArrayType

type ConstantSizedArrayType struct {
	Size        uint
	ElementType Type
}

func (ConstantSizedArrayType) Element

func (v ConstantSizedArrayType) Element() Type

func (ConstantSizedArrayType) ID

type Dictionary

type Dictionary struct {
	Pairs []KeyValuePair
	// contains filtered or unexported fields
}

func NewDictionary

func NewDictionary(pairs []KeyValuePair) Dictionary

func (Dictionary) ToGoValue

func (v Dictionary) ToGoValue() interface{}

func (Dictionary) Type

func (v Dictionary) Type() Type

type DictionaryType

type DictionaryType struct {
	KeyType     Type
	ElementType Type
}

func (DictionaryType) ID

func (t DictionaryType) ID() string

type Event

type Event struct {
	EventType EventType
	Fields    []Value
}

func NewEvent

func NewEvent(fields []Value) Event

func (Event) ToGoValue

func (v Event) ToGoValue() interface{}

func (Event) Type

func (v Event) Type() Type

func (Event) WithType

func (v Event) WithType(typ EventType) Event

type EventPointer

type EventPointer struct {
	TypeName string
}

func (EventPointer) ID

func (t EventPointer) ID() string

type EventType

type EventType struct {
	TypeID      string
	Identifier  string
	Fields      []Field
	Initializer []Parameter
}

func (EventType) CompositeFields

func (t EventType) CompositeFields() []Field

func (EventType) CompositeIdentifier

func (t EventType) CompositeIdentifier() string

func (EventType) CompositeInitializers

func (t EventType) CompositeInitializers() [][]Parameter

func (EventType) ID

func (t EventType) ID() string

type Field

type Field struct {
	Identifier string
	Type       Type
}

type Fix64

type Fix64 int64

func NewFix64

func NewFix64(i int64) Fix64

func (Fix64) ToGoValue

func (v Fix64) ToGoValue() interface{}

func (Fix64) Type

func (Fix64) Type() Type

type Fix64Type

type Fix64Type struct{}

func (Fix64Type) ID

func (Fix64Type) ID() string

type Function

type Function struct {
	Identifier string
	Parameters []Parameter
	ReturnType Type
	// contains filtered or unexported fields
}

func (Function) ID

func (t Function) ID() string

func (Function) WithID

func (t Function) WithID(id string) Function

type Int

type Int struct {
	Value *big.Int
}

func NewInt

func NewInt(i int) Int

func NewIntFromBig

func NewIntFromBig(i *big.Int) Int

func (Int) Big

func (v Int) Big() *big.Int

func (Int) Int

func (v Int) Int() int

func (Int) ToGoValue

func (v Int) ToGoValue() interface{}

func (Int) Type

func (Int) Type() Type

type Int128

type Int128 struct {
	Value *big.Int
}

func NewInt128

func NewInt128(i int) Int128

func NewInt128FromBig

func NewInt128FromBig(i *big.Int) Int128

func (Int128) Big

func (v Int128) Big() *big.Int

func (Int128) Int

func (v Int128) Int() int

func (Int128) ToGoValue

func (v Int128) ToGoValue() interface{}

func (Int128) Type

func (Int128) Type() Type

type Int128Type

type Int128Type struct{}

func (Int128Type) ID

func (Int128Type) ID() string

type Int16

type Int16 int16

func NewInt16

func NewInt16(v int16) Int16

func (Int16) ToGoValue

func (v Int16) ToGoValue() interface{}

func (Int16) Type

func (Int16) Type() Type

type Int16Type

type Int16Type struct{}

func (Int16Type) ID

func (Int16Type) ID() string

type Int256

type Int256 struct {
	Value *big.Int
}

func NewInt256

func NewInt256(i int) Int256

func NewInt256FromBig

func NewInt256FromBig(i *big.Int) Int256

func (Int256) Big

func (v Int256) Big() *big.Int

func (Int256) Int

func (v Int256) Int() int

func (Int256) ToGoValue

func (v Int256) ToGoValue() interface{}

func (Int256) Type

func (Int256) Type() Type

type Int256Type

type Int256Type struct{}

func (Int256Type) ID

func (Int256Type) ID() string

type Int32

type Int32 int32

func NewInt32

func NewInt32(v int32) Int32

func (Int32) ToGoValue

func (v Int32) ToGoValue() interface{}

func (Int32) Type

func (Int32) Type() Type

type Int32Type

type Int32Type struct{}

func (Int32Type) ID

func (Int32Type) ID() string

type Int64

type Int64 int64

func NewInt64

func NewInt64(i int64) Int64

func (Int64) ToGoValue

func (v Int64) ToGoValue() interface{}

func (Int64) Type

func (Int64) Type() Type

type Int64Type

type Int64Type struct{}

func (Int64Type) ID

func (Int64Type) ID() string

type Int8

type Int8 int8

func NewInt8

func NewInt8(v int8) Int8

func (Int8) ToGoValue

func (v Int8) ToGoValue() interface{}

func (Int8) Type

func (Int8) Type() Type

type Int8Type

type Int8Type struct{}

func (Int8Type) ID

func (Int8Type) ID() string

type IntType

type IntType struct{}

func (IntType) ID

func (IntType) ID() string

type KeyValuePair

type KeyValuePair struct {
	Key   Value
	Value Value
}

type MetaType added in v0.4.0

type MetaType struct{}

func (MetaType) ID added in v0.4.0

func (MetaType) ID() string

type Optional

type Optional struct {
	Value Value
}

func NewOptional

func NewOptional(value Value) Optional

func (Optional) ToGoValue

func (o Optional) ToGoValue() interface{}

func (Optional) Type

func (Optional) Type() Type

type OptionalType

type OptionalType struct {
	Type Type
}

func (OptionalType) ID

func (t OptionalType) ID() string

type Parameter

type Parameter struct {
	Label      string
	Identifier string
	Type       Type
}

type Resource

type Resource struct {
	ResourceType ResourceType
	Fields       []Value
}

func NewResource

func NewResource(fields []Value) Resource

func (Resource) ToGoValue

func (v Resource) ToGoValue() interface{}

func (Resource) Type

func (v Resource) Type() Type

func (Resource) WithType

func (v Resource) WithType(typ ResourceType) Resource

type ResourcePointer

type ResourcePointer struct {
	TypeName string
}

func (ResourcePointer) ID

func (t ResourcePointer) ID() string

type ResourceType

type ResourceType struct {
	TypeID       string
	Identifier   string
	Fields       []Field
	Initializers [][]Parameter
}

func (ResourceType) CompositeFields

func (t ResourceType) CompositeFields() []Field

func (ResourceType) CompositeIdentifier

func (t ResourceType) CompositeIdentifier() string

func (ResourceType) CompositeInitializers

func (t ResourceType) CompositeInitializers() [][]Parameter

func (ResourceType) ID

func (t ResourceType) ID() string

type String

type String string

func NewString

func NewString(s string) String

func (String) ToGoValue

func (v String) ToGoValue() interface{}

func (String) Type

func (String) Type() Type

type StringType

type StringType struct{}

func (StringType) ID

func (StringType) ID() string

type Struct

type Struct struct {
	StructType StructType
	Fields     []Value
}

func NewStruct

func NewStruct(fields []Value) Struct

func (Struct) ToGoValue

func (v Struct) ToGoValue() interface{}

func (Struct) Type

func (v Struct) Type() Type

func (Struct) WithType

func (v Struct) WithType(typ StructType) Struct

type StructPointer

type StructPointer struct {
	TypeName string
}

func (StructPointer) ID

func (t StructPointer) ID() string

type StructType

type StructType struct {
	TypeID       string
	Identifier   string
	Fields       []Field
	Initializers [][]Parameter
}

func (StructType) CompositeFields

func (t StructType) CompositeFields() []Field

func (StructType) CompositeIdentifier

func (t StructType) CompositeIdentifier() string

func (StructType) CompositeInitializers

func (t StructType) CompositeInitializers() [][]Parameter

func (StructType) ID

func (t StructType) ID() string

type Type

type Type interface {
	ID() string
	// contains filtered or unexported methods
}

type UFix64

type UFix64 uint64

func NewUFix64

func NewUFix64(i uint64) UFix64

func (UFix64) ToGoValue

func (v UFix64) ToGoValue() interface{}

func (UFix64) Type

func (UFix64) Type() Type

type UFix64Type

type UFix64Type struct{}

func (UFix64Type) ID

func (UFix64Type) ID() string

type UInt

type UInt struct {
	Value *big.Int
}

func NewUInt

func NewUInt(i uint) UInt

func NewUIntFromBig

func NewUIntFromBig(i *big.Int) UInt

func (UInt) Big

func (v UInt) Big() *big.Int

func (UInt) Int

func (v UInt) Int() int

func (UInt) ToGoValue

func (v UInt) ToGoValue() interface{}

func (UInt) Type

func (UInt) Type() Type

type UInt128

type UInt128 struct {
	Value *big.Int
}

func NewUInt128

func NewUInt128(i uint) UInt128

func NewUInt128FromBig

func NewUInt128FromBig(i *big.Int) UInt128

func (UInt128) Big

func (v UInt128) Big() *big.Int

func (UInt128) Int

func (v UInt128) Int() int

func (UInt128) ToGoValue

func (v UInt128) ToGoValue() interface{}

func (UInt128) Type

func (UInt128) Type() Type

type UInt128Type

type UInt128Type struct{}

func (UInt128Type) ID

func (UInt128Type) ID() string

type UInt16

type UInt16 uint16

func NewUInt16

func NewUInt16(v uint16) UInt16

func (UInt16) ToGoValue

func (v UInt16) ToGoValue() interface{}

func (UInt16) Type

func (UInt16) Type() Type

type UInt16Type

type UInt16Type struct{}

func (UInt16Type) ID

func (UInt16Type) ID() string

type UInt256

type UInt256 struct {
	Value *big.Int
}

func NewUInt256

func NewUInt256(i uint) UInt256

func NewUInt256FromBig

func NewUInt256FromBig(i *big.Int) UInt256

func (UInt256) Big

func (v UInt256) Big() *big.Int

func (UInt256) Int

func (v UInt256) Int() int

func (UInt256) ToGoValue

func (v UInt256) ToGoValue() interface{}

func (UInt256) Type

func (UInt256) Type() Type

type UInt256Type

type UInt256Type struct{}

func (UInt256Type) ID

func (UInt256Type) ID() string

type UInt32

type UInt32 uint32

func NewUInt32

func NewUInt32(v uint32) UInt32

func (UInt32) ToGoValue

func (v UInt32) ToGoValue() interface{}

func (UInt32) Type

func (UInt32) Type() Type

type UInt32Type

type UInt32Type struct{}

func (UInt32Type) ID

func (UInt32Type) ID() string

type UInt64

type UInt64 uint64

func NewUInt64

func NewUInt64(v uint64) UInt64

func (UInt64) ToGoValue

func (v UInt64) ToGoValue() interface{}

func (UInt64) Type

func (UInt64) Type() Type

type UInt64Type

type UInt64Type struct{}

func (UInt64Type) ID

func (UInt64Type) ID() string

type UInt8

type UInt8 uint8

func NewUInt8

func NewUInt8(v uint8) UInt8

func (UInt8) ToGoValue

func (v UInt8) ToGoValue() interface{}

func (UInt8) Type

func (UInt8) Type() Type

type UInt8Type

type UInt8Type struct{}

func (UInt8Type) ID

func (UInt8Type) ID() string

type UIntType

type UIntType struct{}

func (UIntType) ID

func (UIntType) ID() string

type Value

type Value interface {
	Type() Type
	ToGoValue() interface{}
	// contains filtered or unexported methods
}

func MustConvertValue

func MustConvertValue(value interface{}) Value

MustConvertValue converts a Go value to an ABI value or panics if the value cannot be converted.

func NewValue

func NewValue(value interface{}) (Value, error)

type Variable

type Variable struct {
	Type Type
}

func (Variable) ID

func (Variable) ID() string

TODO:

type VariableSizedArrayType

type VariableSizedArrayType struct {
	ElementType Type
}

func (VariableSizedArrayType) Element

func (v VariableSizedArrayType) Element() Type

func (VariableSizedArrayType) ID

type Void

type Void struct{}

func NewVoid

func NewVoid() Void

func (Void) ToGoValue

func (Void) ToGoValue() interface{}

func (Void) Type

func (Void) Type() Type

type VoidType

type VoidType struct{}

func (VoidType) ID

func (VoidType) ID() string

type Word16

type Word16 uint16

func NewWord16

func NewWord16(v uint16) Word16

func (Word16) ToGoValue

func (v Word16) ToGoValue() interface{}

func (Word16) Type

func (Word16) Type() Type

type Word16Type

type Word16Type struct{}

func (Word16Type) ID

func (Word16Type) ID() string

type Word32

type Word32 uint32

func NewWord32

func NewWord32(v uint32) Word32

func (Word32) ToGoValue

func (v Word32) ToGoValue() interface{}

func (Word32) Type

func (Word32) Type() Type

type Word32Type

type Word32Type struct{}

func (Word32Type) ID

func (Word32Type) ID() string

type Word64

type Word64 uint64

func NewWord64

func NewWord64(v uint64) Word64

func (Word64) ToGoValue

func (v Word64) ToGoValue() interface{}

func (Word64) Type

func (Word64) Type() Type

type Word64Type

type Word64Type struct{}

func (Word64Type) ID

func (Word64Type) ID() string

type Word8

type Word8 uint8

func NewWord8

func NewWord8(v uint8) Word8

func (Word8) ToGoValue

func (v Word8) ToGoValue() interface{}

func (Word8) Type

func (Word8) Type() Type

type Word8Type

type Word8Type struct{}

func (Word8Type) ID

func (Word8Type) ID() string

Jump to

Keyboard shortcuts

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