Documentation ¶
Overview ¶
Package 'coretypes' defines fundamental types used in the Wasp.
The core types are mostly based on the fundamental data types of Goshimmer
Index ¶
- Constants
- Variables
- func ReadAgentID(r io.Reader, agentID *AgentID) error
- type AgentID
- func NewAgentIDFromAddress(addr address.Address) AgentID
- func NewAgentIDFromBytes(data []byte) (ret AgentID, err error)
- func NewAgentIDFromContractID(id ContractID) (ret AgentID)
- func NewAgentIDFromSigScheme(sigScheme signaturescheme.SignatureScheme) AgentID
- func NewAgentIDFromString(s string) (ret AgentID, err error)
- func NewRandomAgentID() AgentID
- type BLS
- type Base58
- type BlobCache
- type BlobCacheFull
- type ChainID
- type ColoredBalances
- type ContractID
- type ED25519
- type EntryPoint
- type Hashing
- type Hname
- type LogInterface
- type PostRequestParams
- type Processor
- type RequestID
- func (rid *RequestID) Base58() string
- func (rid *RequestID) Index() uint16
- func (rid *RequestID) MarshalJSON() ([]byte, error)
- func (rid *RequestID) Read(r io.Reader) error
- func (rid *RequestID) Short() string
- func (rid *RequestID) String() string
- func (rid *RequestID) TransactionID() *valuetransaction.ID
- func (rid *RequestID) UnmarshalJSON(b []byte) error
- func (rid *RequestID) Write(w io.Writer) error
- type SCTransactionProperties
- type Sandbox
- type SandboxView
- type Utils
Constants ¶
const AgentIDLength = ContractIDLength // max(ContractIDLength, address.Length)
AgentIDLength is the size of AgentID in bytes
const ChainIDLength = address.Length
ChainIDLength size of the ChainID in bytes
const ContractIDLength = ChainIDLength + HnameLength
ContractIDLength size of the contract ID in bytes
const DefaultTTL = 1 * time.Hour
const FuncInit = "init"
FuncInit is a name of the init function for any smart contract
const HnameLength = 4
const RequestIDLength = valuetransaction.IDLength + 2
RequestIDLength size of the RequestID in bytes
Variables ¶
var ( // NilEntryPointFull represents empty full entry point NilEntryPointFull = nilEntryPoint(false) // NilEntryPointView represents empty view entry point NilEntryPointView = nilEntryPoint(true) )
var EntryPointInit = Hn(FuncInit)
EntryPointInit is a hashed name of the init function
var (
ErrWrongDataLength = errors.New("wrong data length")
)
var ErrWrongTypeEntryPoint = fmt.Errorf("wrong type of entry point")
var NilChainID = ChainID{}
Functions ¶
Types ¶
type AgentID ¶
type AgentID [AgentIDLength]byte
AgentID represents exactly one of two types of entities on the ISCP ledger in one ID:
- It can represent an address on the Tangle (controlled by some private key). In this case it can be interpreted as address.Address type (see MustAddress).
- alternatively, it can represent a smart contract on the ISCP. In this case it can be interpreted as a coretypes.ContractID type (see MustContractID)
Type of ID represented by the AgentID can be recognized with IsAddress call. An attempt to interpret the AgentID in the wrong way invokes panic
func NewAgentIDFromAddress ¶
NewAgentIDFromAddress makes AgentID from address.Address
func NewAgentIDFromBytes ¶
NewAgentIDFromBytes makes an AgentID from binary representation
func NewAgentIDFromContractID ¶
func NewAgentIDFromContractID(id ContractID) (ret AgentID)
NewAgentIDFromContractID makes AgentID from ContractID
func NewAgentIDFromSigScheme ¶
func NewAgentIDFromSigScheme(sigScheme signaturescheme.SignatureScheme) AgentID
NewAgentIDFromSigScheme makes AgentID from signaturescheme.SignatureScheme
func NewAgentIDFromString ¶
NewAgentIDFromString parses the human-readable string representation
func (AgentID) IsAddress ¶
IsAddress checks if agentID represents address. 0 in the place of the contract's hname means it is an address This is based on the assumption that fro coretypes.Hname 0 is a reserved value
func (AgentID) MustAddress ¶
MustAddress takes address or panic if not address
func (AgentID) MustContractID ¶
func (a AgentID) MustContractID() (ret ContractID)
MustContractID takes contract ID or panics if not a contract ID
type BlobCacheFull ¶
type ChainID ¶
ChainID represents the global identifier of the chain
Currently it is an alias for the chain address (type address.Address) In the future it will be refactored as an alias for chain color (type balance.Color)
func NewChainIDFromBase58 ¶
NewChainIDFromBase58 constructor decodes base58 string to the ChainID
func NewChainIDFromBytes ¶
NewChainIDFromBytes reconstructs a ChainID from its binary representation.
type ColoredBalances ¶
type ColoredBalances interface { // Balance is balance of the color or 0 if color is not present Balance(color balance.Color) int64 // Iterate over elements Iterate(func(color balance.Color, balance int64) bool) // IterateDeterministic iterates over elements in the order of lexicographically sorted keys IterateDeterministic(func(color balance.Color, balance int64) bool) // Len number of (non-zero) balances Len() uint16 // Equal returns if balances equal color by color Equal(b1 ColoredBalances) bool // Diff return difference between receiver and parameter color by color Diff(b1 ColoredBalances) ColoredBalances // NonNegative is when all elements >= 0 NonNegative() bool // AddToMap adds balances to the map color by color AddToMap(m map[balance.Color]int64) // TakeOutColor takes out balance with specified color TakeOutColor(col balance.Color) ColoredBalances // String human readable representation of the map String() string }
ColoredBalances is an interface to immutable map of (color code: int64)
New colored balance can be created by cbalances.NewFromMap and cbalances.NewFromBalances
type ContractID ¶
type ContractID [ContractIDLength]byte
ContractID global identifier of the smart contract. It consists of chainID and the hname of the contract on the chain
func NewContractID ¶
func NewContractID(chid ChainID, contractHn Hname) (ret ContractID)
NewContractID creates new ContractID from chainID and contract hname
func NewContractIDFromBase58 ¶
func NewContractIDFromBase58(base58string string) (ret ContractID, err error)
NewContractIDFromBase58 decodes contract ID from base58 string
func NewContractIDFromBytes ¶
func NewContractIDFromBytes(data []byte) (ret ContractID, err error)
NewContractIDFromBytes creates contract ID frm its binary representation
func NewContractIDFromString ¶
func NewContractIDFromString(s string) (ret ContractID, err error)
NewContractIDFromString parses the human-readable string representation of the contract ID
func (ContractID) Base58 ¶
func (scid ContractID) Base58() string
Base58 base58 representation of the binary representation
func (ContractID) ChainID ¶
func (scid ContractID) ChainID() (ret ChainID)
ChainID returns ID of the native chain of the contract
func (ContractID) Hname ¶
func (scid ContractID) Hname() Hname
Hname returns hashed name of the contract, local ID on the chain
func (*ContractID) Short ¶
func (scid *ContractID) Short() string
Short human readable representation in short form
func (*ContractID) String ¶
func (scid *ContractID) String() string
String human readable representation of the contract ID <chainID>::<hanme>
type EntryPoint ¶
type EntryPoint interface { IsView() bool Call(ctx Sandbox) (dict.Dict, error) CallView(ctx SandboxView) (dict.Dict, error) }
EntryPoint is an abstract interface by which VM is called by passing the Sandbox interface
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 coretypes.Hn ensures it is not returned
func HnameFromString ¶
func NewHnameFromBytes ¶
NewHnameFromBytes constructor, unmarshalling
type LogInterface ¶
type PostRequestParams ¶
type PostRequestParams struct { TargetContractID ContractID EntryPoint Hname TimeLock uint32 Params dict.Dict Transfer ColoredBalances }
PostRequestParams is parameters of the PostRequest call
type Processor ¶
type Processor interface { GetEntryPoint(code Hname) (EntryPoint, bool) GetDescription() string }
Processor is a abstract interface to the VM processor instance.
type RequestID ¶
type RequestID [RequestIDLength]byte
RequestID is a global ID of any smart contract request. In ISCP, each request is a section in the smart contract transaction (sctransaction.Transaction). The request ID is a concatenation of the transaction ID and little-endian 2 bytes of uint16 index of the section
func NewRequestID ¶
func NewRequestID(txid valuetransaction.ID, index uint16) (ret RequestID)
NewRequestID a constructor
func NewRequestIDFromBase58 ¶
NewRequestIDFromBase58 a constructor
func NewRequestIDFromBytes ¶
NewRequestIDFromBytes a constructor
func (*RequestID) MarshalJSON ¶
func (*RequestID) TransactionID ¶
func (rid *RequestID) TransactionID() *valuetransaction.ID
TransactionID of the request ID (copy)
func (*RequestID) UnmarshalJSON ¶
type SCTransactionProperties ¶
type SCTransactionProperties interface { // address of the transaction sender. It may be address of the wallet or chain address SenderAddress() *address.Address // is it state transaction, i.e. transaction with the valid state section IsState() bool // is it origin transaction IsOrigin() bool // chain ID of the state section or panic if not a state transaction MustChainID() *ChainID // color of the state section or panic if not a state transaction MustStateColor() *balance.Color // number of minted tokens which are not request tokens NumFreeMintedTokens() int64 // all tokens sent to the address but not included into the requests to that address // (normally 0. Needed for fallback processing otherwise those free tokens will be unaccounted // for and essentially lost FreeTokensForAddress(addr address.Address) ColoredBalances // string representation String() string }
SCTransactionProperties defines interface to the properties of syntactically and semantically valid smart contract transaction.
type Sandbox ¶
type Sandbox interface { // ChainOwnerID AgentID of the current owner of the chain ChainOwnerID() AgentID // ContractCreator agentID which deployed contract ContractCreator() AgentID // ContractID is the ID of the current contract. Take chainID with ctx.ContractID().ChainID() ContractID() ContractID // Caller is the agentID of the caller. Caller() AgentID // Params of the current call Params() dict.Dict // State k/v store of the current call (in the context of the smart contract) State() kv.KVStore // 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 // 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 Hname, entryPoint Hname, params dict.Dict, transfer ColoredBalances) (dict.Dict, error) // RequestID of the request in the context of which is the current call RequestID() RequestID // MintedSupply is number of free minted tokens, i.e. minted tokens which are sent to addresses // other than chain address. It is a proof of how many tokens has been minted with the // color of the transaction (after un-coloring all request tokens) // It may be used in use-cases such as Token Registry. // The color of the supply can be extracted from the RequestID // It is read-only method, it returns same value for all requests and all calls in the context of the transaction MintedSupply() int64 // GetTimestamp return current timestamp of the context GetTimestamp() int64 // GetEntropy 32 random bytes based on the hash of the current state transaction GetEntropy() hashing.HashValue // 32 bytes of deterministic and unpredictably random data // Balances returns colored balances owned by the smart contract Balances() ColoredBalances // IncomingTransfer return colored balances transferred by the call. They are already accounted into the Balances() IncomingTransfer() ColoredBalances // Balance return number of tokens of specific color in the balance of the smart contract Balance(col balance.Color) int64 // TransferToAddress send tokens to the L1 ledger address TransferToAddress(addr address.Address, transfer ColoredBalances) bool // PostRequest sends cross-chain request PostRequest(par PostRequestParams) bool // Log interface provides local logging on the machine. It also includes Panicf methods which logs and panics Log() LogInterface // Event publishes "vmmsg" message through Publisher on nanomsg. It also logs locally, but it is not the same thing Event(msg string) // Utils() Utils }
Sandbox is an interface given to the processor to access the VMContext and virtual state, transaction builder and request parameters through it.
type SandboxView ¶
type SandboxView interface { // ChainOwnerID AgentID of the current owner of the chain ChainOwnerID() AgentID // ContractCreator agentID which deployed contract ContractCreator() AgentID // ContractID is the ID of the current contract ContractID() ContractID // GetTimestamp return timestamp of the current state GetTimestamp() int64 // Params of the current call Params() dict.Dict // 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) // Balances is colored balances owned by the contract Balances() ColoredBalances // Log interface provides local logging on the machine. It includes Panicf method Log() LogInterface // Utils() Utils }
SandboxView is an interface for read only call
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package cbalances implements coretypes.ColoredBalances interface
|
package cbalances implements coretypes.ColoredBalances interface |
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 encodedargs implements special encoding of the dict.Dict which alows optimized transfer of big data through SC request.
|
Package encodedargs implements special encoding of the dict.Dict which alows optimized transfer of big data through SC request. |