flow

package
v0.0.0-...-360f37a Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

View Source
const AddressLength uint = 8
View Source
const IdentifierLength uint = 32
View Source
const PublicKeyLength uint = 65

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address        Address
	PublicKeys     []PublicKey
	PublicKeyCount uint64
	SequenceNumber uint64
}

type Address

type Address [AddressLength]byte

func HexToAddress

func HexToAddress(address string) Address

type Block

type Block struct {
	Header             *Header
	Collections        []*Collection
	TransactionResults []*TransactionResult
}

func GenesisBlock

func GenesisBlock() *Block

type CadenceRuntime

type CadenceRuntime struct {
	runtime.Runtime
}

type Collection

type Collection struct {
	Transactions []*Transaction
}
type Header struct {
	ChainID     string
	ParentID    Identifier
	Height      uint64
	PayloadHash Identifier
	Timestamp   time.Time
	View        uint64
	ParentView  uint64
}

func (*Header) ID

func (header *Header) ID() Identifier

type Identifier

type Identifier [IdentifierLength]byte

func (Identifier) Bytes

func (i Identifier) Bytes() []byte

type JSRuntime

type JSRuntime struct {
	// contains filtered or unexported fields
}

func NewJSRuntime

func NewJSRuntime(runtime js.Value) *JSRuntime

func (*JSRuntime) AccountKeysCount

func (j *JSRuntime) AccountKeysCount(address common.Address) (uint64, error)

func (*JSRuntime) AddAccountKey

func (j *JSRuntime) AddAccountKey(address common.Address, publicKey *runtime.PublicKey, hashAlgo runtime.HashAlgorithm, weight int) (*runtime.AccountKey, error)

AddAccountKey appends a key to an account.

func (*JSRuntime) AllocateStorageIndex

func (j *JSRuntime) AllocateStorageIndex(owner []byte) (atree.StorageIndex, error)

AllocateStorageIndex allocates a new storage index under the given account.

func (*JSRuntime) BLSAggregatePublicKeys

func (j *JSRuntime) BLSAggregatePublicKeys(publicKeys []*runtime.PublicKey) (*runtime.PublicKey, error)

BLSAggregatePublicKeys aggregate multiple BLS public keys into one.

func (*JSRuntime) BLSAggregateSignatures

func (j *JSRuntime) BLSAggregateSignatures(signatures [][]byte) ([]byte, error)

BLSAggregateSignatures aggregate multiple BLS signatures into one.

func (*JSRuntime) BLSVerifyPOP

func (j *JSRuntime) BLSVerifyPOP(publicKey *runtime.PublicKey, signature []byte) (bool, error)

BLSVerifyPOP verifies a proof of possession (PoP) for the receiver public key.

func (*JSRuntime) ComputationUsed

func (j *JSRuntime) ComputationUsed() (uint64, error)

ComputationUsed returns the total computation used in the current runtime.

func (*JSRuntime) CreateAccount

func (j *JSRuntime) CreateAccount(payer common.Address) (address common.Address, err error)

CreateAccount creates a new account.

func (*JSRuntime) DecodeArgument

func (j *JSRuntime) DecodeArgument(argument []byte, argumentType cadence.Type) (cadence.Value, error)

DecodeArgument decodes a transaction/script argument against the given type.

func (*JSRuntime) EmitEvent

func (j *JSRuntime) EmitEvent(event cadence.Event) error

EmitEvent is called when an event is emitted by the runtime.

func (*JSRuntime) GenerateAccountID

func (j *JSRuntime) GenerateAccountID(address common.Address) (uint64, error)

GenerateAccountID generates a new, *non-zero*, unique ID for the given account.

func (*JSRuntime) GenerateUUID

func (j *JSRuntime) GenerateUUID() (uint64, error)

GenerateUUID is called to generate a UUID.

func (*JSRuntime) GetAccountAvailableBalance

func (j *JSRuntime) GetAccountAvailableBalance(address common.Address) (value uint64, err error)

GetAccountAvailableBalance gets accounts default flow token balance - balance that is reserved for storage.

func (*JSRuntime) GetAccountBalance

func (j *JSRuntime) GetAccountBalance(address common.Address) (value uint64, err error)

GetAccountBalance gets accounts default flow token balance.

func (*JSRuntime) GetAccountContractCode

func (j *JSRuntime) GetAccountContractCode(location common.AddressLocation) (code []byte, err error)

GetAccountContractCode returns the code associated with an account contract.

func (*JSRuntime) GetAccountContractNames

func (j *JSRuntime) GetAccountContractNames(address common.Address) ([]string, error)

GetAccountContractNames returns the names of all contracts deployed in an account.

func (*JSRuntime) GetAccountKey

func (j *JSRuntime) GetAccountKey(address common.Address, index int) (*runtime.AccountKey, error)

GetAccountKey retrieves a key from an account by index.

func (*JSRuntime) GetBlockAtHeight

func (j *JSRuntime) GetBlockAtHeight(height uint64) (runtime.Block, bool, error)

GetBlockAtHeight returns the block at the given height.

func (*JSRuntime) GetCode

func (j *JSRuntime) GetCode(location runtime.Location) ([]byte, error)

GetCode returns the code at a given location

func (*JSRuntime) GetCurrentBlockHeight

func (j *JSRuntime) GetCurrentBlockHeight() (uint64, error)

GetCurrentBlockHeight returns the current block height.

func (*JSRuntime) GetInterpreterSharedState

func (j *JSRuntime) GetInterpreterSharedState() *interpreter.SharedState

GetInterpreterSharedState gets the shared state of all interpreters. May return nil if none is available or use is not applicable.

func (*JSRuntime) GetOrLoadProgram

func (j *JSRuntime) GetOrLoadProgram(
	location runtime.Location,
	load func() (*interpreter.Program, error),
) (*interpreter.Program, error)

GetOrLoadProgram returns the program for the given location, if available, or sets the program by calling the given load function.

For implementations:

  • Perform a lookup for the location and return the program if it exists.
  • If the program does not exist, call load, and store the result, *EVEN IF loading failed* (program is nil / error is non-nil)!
  • During execution of a high-level program (e.g. script, transaction, etc.), this function MUST always return the *same* program, i.e. it may NOT return a different program, an elaboration in the program that is not annotating the AST in the program; or a program/elaboration and then nothing in a subsequent call.
  • This function MUST also return exactly what was previously returned from load, *EVEN IF loading failed* (program is nil / error is non-nil), and it may NOT return something different
  • Do NOT implement this as a cache!

func (*JSRuntime) GetSigningAccounts

func (j *JSRuntime) GetSigningAccounts() ([]common.Address, error)

GetSigningAccounts returns the signing accounts.

func (*JSRuntime) GetStorageCapacity

func (j *JSRuntime) GetStorageCapacity(address common.Address) (value uint64, err error)

GetStorageCapacity gets storage capacity in bytes on the address.

func (*JSRuntime) GetStorageUsed

func (j *JSRuntime) GetStorageUsed(address common.Address) (value uint64, err error)

GetStorageUsed gets storage used in bytes by the address at the moment of the function call.

func (*JSRuntime) GetValue

func (j *JSRuntime) GetValue(owner, key []byte) (value []byte, err error)

GetValue gets a value for the given key in the storage, owned by the given account.

func (*JSRuntime) Hash

func (j *JSRuntime) Hash(data []byte, tag string, hashAlgorithm runtime.HashAlgorithm) ([]byte, error)

Hash returns the digest of hashing the given data with using the given hash algorithm

func (*JSRuntime) ImplementationDebugLog

func (j *JSRuntime) ImplementationDebugLog(message string) error

ImplementationDebugLog logs implementation log statements on a debug-level

func (*JSRuntime) InteractionUsed

func (j *JSRuntime) InteractionUsed() (uint64, error)

InteractionUsed returns the total storage interaction used in the current runtime.

func (*JSRuntime) MemoryUsed

func (j *JSRuntime) MemoryUsed() (uint64, error)

MemoryUsed returns the total memory (estimate) used in the current runtime.

func (*JSRuntime) MeterComputation

func (j *JSRuntime) MeterComputation(operationType common.ComputationKind, intensity uint) error

MeterComputation is a callback method for metering computation, it returns error when computation passes the limit (set by the environment)

func (*JSRuntime) MeterMemory

func (j *JSRuntime) MeterMemory(usage common.MemoryUsage) error

func (*JSRuntime) ProgramLog

func (j *JSRuntime) ProgramLog(log string) error

ProgramLog logs program logs.

func (*JSRuntime) ReadRandom

func (j *JSRuntime) ReadRandom(r []byte) error

ReadRandom reads pseudo-random bytes into the input slice, using distributed randomness.

func (*JSRuntime) RecordTrace

func (j *JSRuntime) RecordTrace(operation string, location runtime.Location, duration time.Duration, attrs []attribute.KeyValue)

RecordTrace records an opentelemetry trace.

func (*JSRuntime) RemoveAccountContractCode

func (j *JSRuntime) RemoveAccountContractCode(location common.AddressLocation) (err error)

RemoveAccountContractCode removes the code associated with an account contract.

func (*JSRuntime) ResolveLocation

func (j *JSRuntime) ResolveLocation(identifiers []runtime.Identifier, location runtime.Location) ([]runtime.ResolvedLocation, error)

ResolveLocation resolves an import location.

func (*JSRuntime) ResourceOwnerChanged

func (j *JSRuntime) ResourceOwnerChanged(
	interpreter *interpreter.Interpreter,
	resource *interpreter.CompositeValue,
	oldOwner common.Address,
	newOwner common.Address,
)

ResourceOwnerChanged gets called when a resource's owner changed (if enabled)

func (*JSRuntime) RevokeAccountKey

func (j *JSRuntime) RevokeAccountKey(address common.Address, index int) (*runtime.AccountKey, error)

RevokeAccountKey removes a key from an account by index.

func (*JSRuntime) SetInterpreterSharedState

func (j *JSRuntime) SetInterpreterSharedState(state *interpreter.SharedState)

SetInterpreterSharedState sets the shared state of all interpreters.

func (*JSRuntime) SetNetwork

func (j *JSRuntime) SetNetwork(network *Network)

func (*JSRuntime) SetValue

func (j *JSRuntime) SetValue(owner, key, value []byte) (err error)

SetValue sets a value for the given key in the storage, owned by the given account.

func (*JSRuntime) UpdateAccountContractCode

func (j *JSRuntime) UpdateAccountContractCode(location common.AddressLocation, code []byte) (err error)

UpdateAccountContractCode updates the code associated with an account contract.

func (*JSRuntime) ValidatePublicKey

func (j *JSRuntime) ValidatePublicKey(key *runtime.PublicKey) error

ValidatePublicKey verifies the validity of a public key.

func (*JSRuntime) ValueExists

func (j *JSRuntime) ValueExists(owner, key []byte) (exists bool, err error)

ValueExists returns true if the given key exists in the storage, owned by the given account.

func (*JSRuntime) VerifySignature

func (j *JSRuntime) VerifySignature(
	signature []byte,
	tag string,
	signedData []byte,
	publicKey []byte,
	signatureAlgorithm runtime.SignatureAlgorithm,
	hashAlgorithm runtime.HashAlgorithm,
) (bool, error)

VerifySignature returns true if the given signature was produced by signing the given tag + data using the given public key, signature algorithm, and hash algorithm.

type Ledger

type Ledger interface {
	GetValue(owner, key []byte) (value []byte, err error)
	SetValue(owner, key, value []byte) (err error)
}

type LedgerChange

type LedgerChange struct {
	Address []byte
	Key     []byte
	Value   []byte
}

type LedgerKey

type LedgerKey struct {
	Address string
	Key     string
}

type Network

type Network struct {
	Runtime   CadenceRuntime
	JSRuntime *JSRuntime
	Blocks    []*Block
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork(jsRuntime js.Value) *Network

func (*Network) CommitLedgerChange

func (n *Network) CommitLedgerChange(ledgerChange *LedgerChange)

func (*Network) ExecuteAndCommitBlock

func (n *Network) ExecuteAndCommitBlock()

func (*Network) ExecuteTransaction

func (n *Network) ExecuteTransaction(transaction *Transaction)

type ProposalKey

type ProposalKey struct {
	Address        Address
	KeyIndex       uint64
	SequenceNumber uint64
}

type PublicKey

type PublicKey [PublicKeyLength]byte

type Signature

type Signature struct {
	Address     Address
	SignerIndex int
	KeyIndex    uint64
	Signature   []byte
}

type Transaction

type Transaction struct {
	ReferenceBlockID   Identifier
	Script             []byte
	Arguments          [][]byte
	GasLimit           uint64
	ProposalKey        ProposalKey
	Payer              Address
	Authorizers        []Address
	PayloadSignatures  []Signature
	EnvelopeSignatures []Signature
	TransactionResult  TransactionResult
}

func (*Transaction) ID

func (transaction *Transaction) ID() Identifier

type TransactionResult

type TransactionResult struct {
	Status        uint64
	Error         error
	LedgerChanges []*LedgerChange
	Events        []cadence.Event
}

Jump to

Keyboard shortcuts

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