iscp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0, BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package 'iscp' defines fundamental types used in the Wasp.

The core types are mostly based on the fundamental data types of Goshimmer

Index

Constants

View Source
const FuncInit = "init"

FuncInit is a name of the init function for any smart contract

View Source
const HnameLength = 4
View Source
const RequestIDDigestLen = 6

Variables

View Source
var (
	ErrInternalWrongTypeEntryPoint = xerrors.New("internal error: wrong type of the entry point")
	ErrWrongTypeEntryPoint         = xerrors.New("wrong type of the entry point")
)
View Source
var (
	EntryPointInit = Hn(FuncInit)
)

well known hnames

Functions

func OID

func ShortRequestIDs

func ShortRequestIDs(ids []RequestID) []string

Types

type AgentID

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

AgentID represents address on the ledger with optional hname If address is and alias address and hname is != 0 the agent id is interpreted as ad contract id

var NilAgentID AgentID

func AgentIDFromBytes

func AgentIDFromBytes(data []byte) (*AgentID, error)

func AgentIDFromMarshalUtil

func AgentIDFromMarshalUtil(mu *marshalutil.MarshalUtil) (*AgentID, error)

func NewAgentID

func NewAgentID(addr ledgerstate.Address, hname Hname) *AgentID

NewAgentID makes new AgentID

func NewAgentIDFromBase58EncodedString

func NewAgentIDFromBase58EncodedString(s string) (*AgentID, error)

func NewAgentIDFromString

func NewAgentIDFromString(s string) (*AgentID, error)

NewAgentIDFromString parses the human-readable string representation

func NewRandomAgentID

func NewRandomAgentID() *AgentID

NewRandomAgentID creates random AgentID

func (*AgentID) Address

func (a *AgentID) Address() ledgerstate.Address

func (*AgentID) Base58

func (a *AgentID) Base58() string

func (*AgentID) Bytes

func (a *AgentID) Bytes() []byte

func (*AgentID) Clone

func (a *AgentID) Clone() *AgentID

func (*AgentID) Equals

func (a *AgentID) Equals(a1 *AgentID) bool

func (*AgentID) Hname

func (a *AgentID) Hname() Hname

func (*AgentID) IsNil

func (a *AgentID) IsNil() bool

func (*AgentID) String

func (a *AgentID) String() string

String human readable string

type BLS

type BLS interface {
	ValidSignature(data []byte, pubKey []byte, signature []byte) bool
	AddressFromPublicKey(pubKey []byte) (ledgerstate.Address, error)
	AggregateBLSSignatures(pubKeysBin [][]byte, sigsBin [][]byte) ([]byte, []byte, error)
}

type Base58

type Base58 interface {
	Decode(s string) ([]byte, error)
	Encode(data []byte) string
}

type ChainID

type ChainID struct {
	*ledgerstate.AliasAddress
}

ChainID represents the global identifier of the chain It is wrapped AliasAddress, an address without a private key behind

func ChainIDFromAddress

func ChainIDFromAddress(addr ledgerstate.Address) (*ChainID, error)

ChainIDFromAddress creates a chainIDD from alias address. Returns and error if not an alias address type

func ChainIDFromBase58

func ChainIDFromBase58(b58 string) (*ChainID, error)

ChainIDFromBase58 constructor decodes base58 string to the ChainID

func ChainIDFromBytes

func ChainIDFromBytes(data []byte) (*ChainID, error)

ChainIDFromBytes reconstructs a ChainID from its binary representation.

func ChainIDFromMarshalUtil

func ChainIDFromMarshalUtil(mu *marshalutil.MarshalUtil) (*ChainID, error)

func NewChainID

func NewChainID(addr *ledgerstate.AliasAddress) *ChainID

NewChainID creates new chain ID from alias address

func RandomChainID

func RandomChainID(seed ...[]byte) *ChainID

RandomChainID creates a random chain ID.

func (*ChainID) AsAddress

func (chid *ChainID) AsAddress() ledgerstate.Address

func (*ChainID) AsAliasAddress

func (chid *ChainID) AsAliasAddress() *ledgerstate.AliasAddress

func (*ChainID) Base58

func (chid *ChainID) Base58() string

func (*ChainID) Clone

func (chid *ChainID) Clone() (ret *ChainID)

func (*ChainID) Equals

func (chid *ChainID) Equals(chid1 *ChainID) bool

func (*ChainID) Read

func (chid *ChainID) Read(r io.Reader) error

func (*ChainID) String

func (chid *ChainID) String() string

String human readable form (base58 encoding)

func (*ChainID) Write

func (chid *ChainID) Write(w io.Writer) error

type ED25519

type ED25519 interface {
	ValidSignature(data []byte, pubKey []byte, signature []byte) bool
	AddressFromPublicKey(pubKey []byte) (ledgerstate.Address, error)
}

type Hashing

type Hashing interface {
	Blake2b(data []byte) hashing.HashValue
	Sha3(data []byte) hashing.HashValue
	Hname(name string) Hname
}

type Hname

type Hname uint32

Hname is 4 bytes of blake2b hash of any string interpreted as little-endian uint32. 0 and not ^0 are reserved values and the iscp.Hn ensures it is not returned

func Hn

func Hn(name string) (ret Hname)

Hn create hname from arbitrary string.

func HnameFromBytes

func HnameFromBytes(data []byte) (ret Hname, err error)

func HnameFromMarshalUtil

func HnameFromMarshalUtil(mu *marshalutil.MarshalUtil) (ret Hname, err error)

HnameFromBytes constructor, unmarshalling

func HnameFromString

func HnameFromString(s string) (Hname, error)

func (Hname) Bytes

func (hn Hname) Bytes() []byte

func (Hname) Clone

func (hn Hname) Clone() Hname

func (*Hname) Read

func (hn *Hname) Read(r io.Reader) error

func (*Hname) ReadFromMarshalUtil

func (hn *Hname) ReadFromMarshalUtil(mu *marshalutil.MarshalUtil) error

func (Hname) String

func (hn Hname) String() string

func (*Hname) Write

func (hn *Hname) Write(w io.Writer) error

func (*Hname) WriteToMarshalUtil

func (hn *Hname) WriteToMarshalUtil(mu *marshalutil.MarshalUtil)

type InMemoryBlobCache

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

InMemoryBlobCache is supposed to be used as BlobCache in tests through factory method NewInMemoryBlobCache NOTE: Implements registry.BlobCache

func NewInMemoryBlobCache

func NewInMemoryBlobCache() *InMemoryBlobCache

NewInMemoryBlobCache is a factory method for inMemoryBlobCache

func (*InMemoryBlobCache) GetBlob

func (d *InMemoryBlobCache) GetBlob(h hashing.HashValue) ([]byte, bool, error)

func (*InMemoryBlobCache) HasBlob

func (d *InMemoryBlobCache) HasBlob(h hashing.HashValue) (bool, error)

func (*InMemoryBlobCache) PutBlob

func (d *InMemoryBlobCache) PutBlob(data []byte, ttl ...time.Duration) (hashing.HashValue, error)

type LogInterface

type LogInterface interface {
	Infof(format string, param ...interface{})
	Debugf(format string, param ...interface{})
	Panicf(format string, param ...interface{})
}

type Request

type Request interface {
	// index == 0 for off ledger requests
	ID() RequestID
	// is request on transaction of not
	IsOffLedger() bool
	// true or false for on-ledger requests, always true for off-ledger
	IsFeePrepaid() bool
	// arguments of the call with the flag if they are ready. No arguments mean empty dictionary and true
	Params() (dict.Dict, bool)
	// account of the sender
	SenderAccount() *AgentID
	// address of the sender for all requests,
	SenderAddress() ledgerstate.Address
	// returns contract/entry point pair
	Target() (Hname, Hname)
	// Timestamp returns a request TX timestamp, if such TX exist, otherwise zero is returned.
	Timestamp() time.Time
	// Bytes returns binary representation of the request
	Bytes() []byte
	// Hash returns the hash of the request (used for consensus)
	Hash() [32]byte
}

region Request ////////////////////////////////////////////////////// Request has two main implementations - RequestOnLedger - RequestOffLedger

type RequestID

type RequestID ledgerstate.OutputID

region RequestID ///////////////////////////////////////////////////////////////

func NewRequestID

func NewRequestID(txid ledgerstate.TransactionID, index uint16) RequestID

func RequestIDFromBase58

func RequestIDFromBase58(b58 string) (ret RequestID, err error)

func RequestIDFromBytes

func RequestIDFromBytes(data []byte) (RequestID, error)

func RequestIDFromMarshalUtil

func RequestIDFromMarshalUtil(mu *marshalutil.MarshalUtil) (RequestID, error)

func TakeRequestIDs

func TakeRequestIDs(reqs ...Request) []RequestID

func (RequestID) Base58

func (rid RequestID) Base58() string

Base58 returns a base58 encoded version of the request id.

func (RequestID) Bytes

func (rid RequestID) Bytes() []byte

func (RequestID) LookupDigest

func (rid RequestID) LookupDigest() RequestLookupDigest

func (RequestID) OutputID

func (rid RequestID) OutputID() ledgerstate.OutputID

func (RequestID) Short

func (rid RequestID) Short() string

func (RequestID) String

func (rid RequestID) String() string

type RequestLookupDigest

type RequestLookupDigest [RequestIDDigestLen + 2]byte

RequestLookupDigest is shortened version of the request id. It is guaranteed to be uniques within one block, however it may collide globally. Used for quick checking for most requests if it was never seen

type Sandbox

type Sandbox interface {
	SandboxBase

	// State k/v store of the current call (in the context of the smart contract)
	State() kv.KVStore
	// Request return the request in the context of which the smart contract is called
	Request() Request
	// Balance return number of tokens of specific color in the balance of the smart contract
	Balance(col colored.Color) uint64
	// Call calls the entry point of the contract with parameters and transfer.
	// If the entry point is full entry point, transfer tokens are moved between caller's and
	// target contract's accounts (if enough). If the entry point is view, 'transfer' has no effect
	Call(target, entryPoint Hname, params dict.Dict, transfer colored.Balances) (dict.Dict, error)
	// Caller is the agentID of the caller.
	Caller() *AgentID
	// DeployContract deploys contract on the same chain. 'initParams' are passed to the 'init' entry point
	DeployContract(programHash hashing.HashValue, name string, description string, initParams dict.Dict) error
	// Event publishes "vmmsg" message through Publisher on nanomsg. It also logs locally, but it is not the same thing
	Event(msg string)
	// GetEntropy 32 random bytes based on the hash of the current state transaction
	GetEntropy() hashing.HashValue // 32 bytes of deterministic and unpredictably random data
	// IncomingTransfer return colored balances transferred by the call. They are already accounted into the Balances()
	IncomingTransfer() colored.Balances
	// Minted represents new colored tokens which has been minted in the request transaction
	// Note that the minted tokens can be sent to any addresses, not necessarily the chain address
	Minted() colored.Balances
	// Send one generic method for sending assets with ledgerstate.ExtendedLockedOutput
	// replaces TransferToAddress and Post1Request
	Send(target ledgerstate.Address, tokens colored.Balances, metadata *SendMetadata, options ...SendOptions) bool
	// Internal for use in native hardcoded contracts
	BlockContext(construct func(sandbox Sandbox) interface{}, onClose func(interface{})) interface{}
	// properties of the anchor output
	StateAnchor() StateAnchor
}

Sandbox is an interface given to the processor to access the VMContext and virtual state, transaction builder and request parameters through it.

type SandboxBase

type SandboxBase interface {
	// AccountID returns the agentID of the current contract
	AccountID() *AgentID
	// Params returns the parameters of the current call
	Params() dict.Dict
	// Balances returns the colored balances owned by the contract
	Balances() colored.Balances
	// ChainID returns the chain ID
	ChainID() *ChainID
	// ChainOwnerID returns the AgentID of the current owner of the chain
	ChainOwnerID() *AgentID
	// Contract returns the Hname of the contract in the current chain
	Contract() Hname
	// ContractCreator returns the agentID that deployed the contract
	ContractCreator() *AgentID
	// GetTimestamp returns the timestamp of the current state
	GetTimestamp() int64
	// Log returns a logger that ouputs on the local machine. It includes Panicf method
	Log() LogInterface
	// Utils provides access to common necessary functionality
	Utils() Utils
}

SandboxBase is the common interface of Sandbox and SandboxView

type SandboxView

type SandboxView interface {
	SandboxBase

	// State immutable k/v store of the current call (in the context of the smart contract)
	State() kv.KVStoreReader
	// Call calls another contract. Only calls view entry points
	Call(contractHname Hname, entryPoint Hname, params dict.Dict) (dict.Dict, error)
}

SandboxView is an interface for read only call

type SendMetadata

type SendMetadata struct {
	TargetContract Hname
	EntryPoint     Hname
	Args           dict.Dict
}

RequestMetadata represents content of the data payload of the output

type SendOptions

type SendOptions struct {
	TimeLock         uint32 // unix seconds
	FallbackAddress  ledgerstate.Address
	FallbackDeadline uint32 // unix seconds
}

func (*SendOptions) ToGoshimmerSendOptions

func (opt *SendOptions) ToGoshimmerSendOptions() *sendoptions.SendFundsOptions

type StateAnchor

type StateAnchor interface {
	StateAddress() ledgerstate.Address
	GoverningAddress() ledgerstate.Address
	StateIndex() uint32
	StateHash() hashing.HashValue
	OutputID() ledgerstate.OutputID
}

properties of the anchor output/transaction in the current context

type Utils

type Utils interface {
	Base58() Base58
	Hashing() Hashing
	ED25519() ED25519
	BLS() BLS
}

Utils implement various utilities which are faster on host side than on wasm VM Implement deterministic stateless computations

type VMProcessor

type VMProcessor interface {
	GetEntryPoint(code Hname) (VMProcessorEntryPoint, bool)
	GetDefaultEntryPoint() VMProcessorEntryPoint // return EP which can only be called with Sandbox
	GetDescription() string
}

VMProcessor is a abstract interface to the VM processor instance.

type VMProcessorEntryPoint

type VMProcessorEntryPoint interface {
	Call(ctx interface{}) (dict.Dict, error)
	IsView() bool
}

VMProcessorEntryPoint is an abstract interface by which VM is called by passing the Sandbox interface

Directories

Path Synopsis
package coreutil provides functions to describe interface of the core contract in a compact way
package coreutil provides functions to describe interface of the core contract in a compact way
Package requestargs implements special encoding of the dict.Dict which allows optimized transfer of big data through SC request.
Package requestargs implements special encoding of the dict.Dict which allows optimized transfer of big data through SC request.

Jump to

Keyboard shortcuts

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