wasmlib

package
v0.5.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FnAccountID              = int32(-1)
	FnAllowance              = int32(-2)
	FnBalance                = int32(-3)
	FnBalances               = int32(-4)
	FnBlockContext           = int32(-5)
	FnCall                   = int32(-6)
	FnCaller                 = int32(-7)
	FnChainID                = int32(-8)
	FnChainOwnerID           = int32(-9)
	FnContract               = int32(-10)
	FnDeployContract         = int32(-11)
	FnEntropy                = int32(-12)
	FnEstimateStorageDeposit = int32(-13)
	FnEvent                  = int32(-14)
	FnLog                    = int32(-15)
	FnMinted                 = int32(-16)
	FnPanic                  = int32(-17)
	FnParams                 = int32(-18)
	FnPost                   = int32(-19)
	FnRequest                = int32(-20)
	FnRequestID              = int32(-21)
	FnRequestSender          = int32(-22)
	FnResults                = int32(-23)
	FnSend                   = int32(-24)
	FnStateAnchor            = int32(-25)
	FnTimestamp              = int32(-26)
	FnTrace                  = int32(-27)
	FnTransferAllowed        = int32(-28)
	FnUtilsBech32Decode      = int32(-29)
	FnUtilsBech32Encode      = int32(-30)
	FnUtilsBlsAddress        = int32(-31)
	FnUtilsBlsAggregate      = int32(-32)
	FnUtilsBlsValid          = int32(-33)
	FnUtilsEd25519Address    = int32(-34)
	FnUtilsEd25519Valid      = int32(-35)
	FnUtilsHashBlake2b       = int32(-36)
	FnUtilsHashName          = int32(-37)
	FnUtilsHashSha3          = int32(-38)
)

Variables

This section is empty.

Functions

func ExportName

func ExportName(index int32, name string)

func FuncError

func FuncError(ctx ScFuncContext)

func Log

func Log(text string)

func NewCallParamsProxy

func NewCallParamsProxy(v *ScView) wasmtypes.Proxy

func NewCallResultsProxy

func NewCallResultsProxy(v *ScView, resultsProxy *wasmtypes.Proxy)

func NewParamsProxy

func NewParamsProxy() wasmtypes.Proxy

func NewResultsProxy added in v1.0.3

func NewResultsProxy() wasmtypes.Proxy

func NewStateProxy

func NewStateProxy() wasmtypes.Proxy

func Panic

func Panic(text string)

func Sandbox

func Sandbox(funcNr int32, params []byte) []byte

func StateDelete

func StateDelete(key []byte)

func StateExists

func StateExists(key []byte) bool

func StateGet

func StateGet(key []byte) []byte

func StateSet

func StateSet(key, value []byte)

func Trace

func Trace(text string)

func ViewError

func ViewError(ctx ScViewContext)

Types

type EventDecoder added in v0.3.0

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

func NewEventDecoder added in v0.3.0

func NewEventDecoder(msg []string) *EventDecoder

func (*EventDecoder) Decode added in v0.3.0

func (d *EventDecoder) Decode() string

func (*EventDecoder) Timestamp added in v0.3.0

func (d *EventDecoder) Timestamp() uint64

type EventEncoder

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

func NewEventEncoder

func NewEventEncoder(eventName string) *EventEncoder

func (*EventEncoder) Emit

func (e *EventEncoder) Emit()

func (*EventEncoder) Encode

func (e *EventEncoder) Encode(value string)

type IEventHandlers added in v1.0.3

type IEventHandlers interface {
	CallHandler(topic string, params []string)
}

type ScAssets

type ScAssets struct {
	BaseTokens   uint64
	NativeTokens TokenAmounts
	NftIDs       map[wasmtypes.ScNftID]bool
}

func NewScAssets added in v0.3.0

func NewScAssets(buf []byte) *ScAssets

func (*ScAssets) Balances

func (a *ScAssets) Balances() ScBalances

func (*ScAssets) Bytes

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

func (*ScAssets) IsEmpty added in v0.3.0

func (a *ScAssets) IsEmpty() bool

func (*ScAssets) TokenIDs added in v0.3.0

func (a *ScAssets) TokenIDs() []*wasmtypes.ScTokenID

type ScBalances

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

func (*ScBalances) Balance

func (b *ScBalances) Balance(tokenID *wasmtypes.ScTokenID) wasmtypes.ScBigInt

func (*ScBalances) BaseTokens added in v0.3.0

func (b *ScBalances) BaseTokens() uint64

func (*ScBalances) Bytes added in v0.3.0

func (b *ScBalances) Bytes() []byte

func (*ScBalances) IsEmpty added in v0.3.0

func (b *ScBalances) IsEmpty() bool

func (*ScBalances) NftIDs added in v0.3.0

func (b *ScBalances) NftIDs() map[wasmtypes.ScNftID]bool

func (*ScBalances) TokenIDs added in v0.3.0

func (b *ScBalances) TokenIDs() []*wasmtypes.ScTokenID

type ScDict

type ScDict struct {
	ScImmutableDict
}

func NewScDict

func NewScDict() *ScDict

func NewScDictFromBytes

func NewScDictFromBytes(buf []byte) *ScDict

func (*ScDict) AsProxy

func (d *ScDict) AsProxy() wasmtypes.Proxy

func (*ScDict) Bytes

func (d *ScDict) Bytes() []byte

func (*ScDict) Delete

func (d *ScDict) Delete(key []byte)

func (*ScDict) Immutable

func (d *ScDict) Immutable() *ScImmutableDict

func (*ScDict) Set

func (d *ScDict) Set(key, value []byte)

type ScExportMap

type ScExportMap struct {
	Names []string
	Funcs []ScFuncContextFunction
	Views []ScViewContextFunction
}

func (*ScExportMap) Dispatch added in v1.0.3

func (m *ScExportMap) Dispatch(index int32)

general entrypoint for the host to call any SC function the host will pass the index of one of the entry points that was provided by on_load during SC initialization

func (*ScExportMap) Export added in v0.3.6

func (m *ScExportMap) Export()

constructs the symbol export context for the on_load function

type ScFunc

type ScFunc struct {
	ScView
	// contains filtered or unexported fields
}

func NewScFunc

func NewScFunc(ctx ScFuncCallContext, hContract, hFunction wasmtypes.ScHname) *ScFunc

func (*ScFunc) Allowance added in v0.3.0

func (f *ScFunc) Allowance(allowance *ScTransfer) *ScFunc

Allowance defines the assets that the SC is allowed to take out of the caller account on the chain. Note that that does not mean that the SC will take them all. The SC needs to be able to take them explicitly. Otherwise the assets will stay in the caller’s account.

func (*ScFunc) AllowanceBaseTokens added in v0.3.0

func (f *ScFunc) AllowanceBaseTokens(amount uint64) *ScFunc

func (*ScFunc) Call

func (f *ScFunc) Call()

func (*ScFunc) Delay

func (f *ScFunc) Delay(seconds uint32) *ScFunc

func (*ScFunc) OfContract

func (f *ScFunc) OfContract(hContract wasmtypes.ScHname) *ScFunc

func (*ScFunc) Post

func (f *ScFunc) Post()

func (*ScFunc) PostToChain

func (f *ScFunc) PostToChain(chainID wasmtypes.ScChainID)

func (*ScFunc) Transfer

func (f *ScFunc) Transfer(transfer *ScTransfer) *ScFunc

Transfer defines the assets that are transferred from the caller’s L1 address to his L2 account. The SC cannot touch these unless explicitly allowed. Transfer only comes into play with on-ledger requests. Off-ledger requests cannot do a transfer.

func (*ScFunc) TransferBaseTokens added in v0.3.0

func (f *ScFunc) TransferBaseTokens(amount uint64) *ScFunc

type ScFuncCallContext

type ScFuncCallContext interface {
	ScViewCallContext
	FnPost(req *wasmrequests.PostRequest) []byte
	InitFuncCallContext()
}

type ScFuncContext

type ScFuncContext struct {
	ScSandboxFunc
}

smart contract func sandbox interface

func (ScFuncContext) Host

func (ctx ScFuncContext) Host() ScHost

func (ScFuncContext) InitFuncCallContext

func (ctx ScFuncContext) InitFuncCallContext()

func (ScFuncContext) InitViewCallContext

func (ctx ScFuncContext) InitViewCallContext(hContract wasmtypes.ScHname) wasmtypes.ScHname

type ScFuncContextFunction

type ScFuncContextFunction func(ScFuncContext)

type ScHost

type ScHost interface {
	ExportName(index int32, name string)
	Sandbox(funcNr int32, params []byte) []byte
	StateDelete(key []byte)
	StateExists(key []byte) bool
	StateGet(key []byte) []byte
	StateSet(key, value []byte)
}

func ConnectHost

func ConnectHost(h ScHost) ScHost

type ScImmutableDict

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

func (*ScImmutableDict) Exists

func (d *ScImmutableDict) Exists(key []byte) bool

func (*ScImmutableDict) Get

func (d *ScImmutableDict) Get(key []byte) []byte

type ScImmutableState

type ScImmutableState struct{}

func (ScImmutableState) Exists

func (d ScImmutableState) Exists(key []byte) bool

func (ScImmutableState) Get

func (d ScImmutableState) Get(key []byte) []byte

type ScInitFunc

type ScInitFunc struct {
	ScView
}

func NewScInitFunc

func NewScInitFunc(ctx ScFuncCallContext, hContract, hFunction wasmtypes.ScHname) *ScInitFunc

func (*ScInitFunc) Call

func (f *ScInitFunc) Call()

func (*ScInitFunc) OfContract

func (f *ScInitFunc) OfContract(hContract wasmtypes.ScHname) *ScInitFunc

func (*ScInitFunc) Params

func (f *ScInitFunc) Params() []interface{}

type ScSandbox

type ScSandbox struct{}

func (ScSandbox) AccountID

func (s ScSandbox) AccountID() wasmtypes.ScAgentID

retrieve the agent id of this contract account

func (ScSandbox) Balance

func (s ScSandbox) Balance(tokenID wasmtypes.ScTokenID) uint64

func (ScSandbox) Balances

func (s ScSandbox) Balances() *ScBalances

access the current balances for all assets

func (ScSandbox) ChainOwnerID

func (s ScSandbox) ChainOwnerID() wasmtypes.ScAgentID

retrieve the agent id of the owner of the chain this contract lives on

func (ScSandbox) Contract

func (s ScSandbox) Contract() wasmtypes.ScHname

retrieve the hname of this contract

func (ScSandbox) CurrentChainID added in v0.3.0

func (s ScSandbox) CurrentChainID() wasmtypes.ScChainID

retrieve the chain id of the chain this contract lives on

func (ScSandbox) FnCall added in v1.0.3

func (s ScSandbox) FnCall(req *wasmrequests.CallRequest) []byte

func (ScSandbox) FnChainID added in v1.0.3

func (s ScSandbox) FnChainID() wasmtypes.ScChainID

func (ScSandbox) Log

func (s ScSandbox) Log(text string)

logs informational text message

func (ScSandbox) Panic

func (s ScSandbox) Panic(text string)

logs error text message and then panics

func (ScSandbox) Params

func (s ScSandbox) Params() *ScImmutableDict

retrieve parameters passed to the smart contract function that was called

func (ScSandbox) RawState

func (s ScSandbox) RawState() ScImmutableState

func (ScSandbox) Require

func (s ScSandbox) Require(cond bool, msg string)

panics if condition is not satisfied

func (ScSandbox) Results

func (s ScSandbox) Results(results wasmtypes.Proxy)

func (ScSandbox) Timestamp

func (s ScSandbox) Timestamp() uint64

deterministic timestamp in nanosecond fixed at the moment of calling the smart contract

func (ScSandbox) Trace

func (s ScSandbox) Trace(text string)

logs debugging trace text message

func (ScSandbox) Utility

func (s ScSandbox) Utility() ScSandboxUtils

access diverse utility functions

type ScSandboxFunc

type ScSandboxFunc struct {
	ScSandbox
}

func (ScSandboxFunc) Allowance added in v0.3.0

func (s ScSandboxFunc) Allowance() *ScBalances

access the allowance assets

func (ScSandboxFunc) Call

func (s ScSandboxFunc) Call(hContract, hFunction wasmtypes.ScHname, params *ScDict, allowance *ScTransfer) *ScImmutableDict

calls a smart contract function

func (ScSandboxFunc) Caller

func (s ScSandboxFunc) Caller() wasmtypes.ScAgentID

retrieve the agent id of the caller of the smart contract

func (ScSandboxFunc) DeployContract

func (s ScSandboxFunc) DeployContract(programHash wasmtypes.ScHash, name, description string, initParams *ScDict)

deploys a smart contract

func (ScSandboxFunc) Entropy

func (s ScSandboxFunc) Entropy() wasmtypes.ScHash

returns random entropy data for current request.

func (ScSandboxFunc) EstimateStorageDeposit added in v0.3.0

func (s ScSandboxFunc) EstimateStorageDeposit(fn *ScFunc) uint64

func (ScSandboxFunc) Event

func (s ScSandboxFunc) Event(msg string)

signals an event on the node that external entities can subscribe to

func (ScSandboxFunc) FnPost added in v1.0.3

func (s ScSandboxFunc) FnPost(req *wasmrequests.PostRequest) []byte

func (ScSandboxFunc) Minted

func (s ScSandboxFunc) Minted() ScBalances

retrieve the assets that were minted in this transaction

func (ScSandboxFunc) Post

func (s ScSandboxFunc) Post(chainID wasmtypes.ScChainID, hContract, hFunction wasmtypes.ScHname, params *ScDict, allowance, transfer ScTransfer, delay uint32)

Post (delayed) posts a SC function request

func (ScSandboxFunc) Random

func (s ScSandboxFunc) Random(max uint64) (rnd uint64)

generates a random value from 0 to max (exclusive max) using a deterministic RNG

func (ScSandboxFunc) RawState

func (s ScSandboxFunc) RawState() ScState

func (ScSandboxFunc) RequestID

func (s ScSandboxFunc) RequestID() wasmtypes.ScRequestID

retrieve the request id of this transaction

func (ScSandboxFunc) RequestSender added in v0.3.0

func (s ScSandboxFunc) RequestSender() wasmtypes.ScAgentID

retrieve the request sender of this transaction

func (ScSandboxFunc) Send

func (s ScSandboxFunc) Send(address wasmtypes.ScAddress, transfer *ScTransfer)

Send transfers SC assets to the specified address

func (ScSandboxFunc) TransferAllowed added in v0.3.0

func (s ScSandboxFunc) TransferAllowed(agentID wasmtypes.ScAgentID, transfer *ScTransfer)

TransferAllowed transfers allowed assets from caller to the specified account

type ScSandboxUtils

type ScSandboxUtils struct{}

func (ScSandboxUtils) Bech32Decode added in v0.3.0

func (u ScSandboxUtils) Bech32Decode(value string) wasmtypes.ScAddress

Bech32Decode decodes the specified bech32-encoded string value to its original address

func (ScSandboxUtils) Bech32Encode added in v0.3.0

func (u ScSandboxUtils) Bech32Encode(addr wasmtypes.ScAddress) string

Bech32Encode encodes the specified address to a bech32-encoded string

func (ScSandboxUtils) BlsAddressFromPubKey

func (u ScSandboxUtils) BlsAddressFromPubKey(pubKey []byte) wasmtypes.ScAddress

func (ScSandboxUtils) BlsAggregateSignatures

func (u ScSandboxUtils) BlsAggregateSignatures(pubKeys, sigs [][]byte) ([]byte, []byte)

func (ScSandboxUtils) BlsValidSignature

func (u ScSandboxUtils) BlsValidSignature(data, pubKey, signature []byte) bool

func (ScSandboxUtils) Ed25519AddressFromPubKey

func (u ScSandboxUtils) Ed25519AddressFromPubKey(pubKey []byte) wasmtypes.ScAddress

func (ScSandboxUtils) Ed25519ValidSignature

func (u ScSandboxUtils) Ed25519ValidSignature(data, pubKey, signature []byte) bool

func (ScSandboxUtils) HashBlake2b

func (u ScSandboxUtils) HashBlake2b(value []byte) wasmtypes.ScHash

hashes the specified value bytes using blake2b hashing and returns the resulting 32-byte hash

func (ScSandboxUtils) HashName added in v1.0.3

func (u ScSandboxUtils) HashName(value string) wasmtypes.ScHname

hashes the specified value bytes using blake2b hashing and returns the resulting 32-byte hash

func (ScSandboxUtils) HashSha3

func (u ScSandboxUtils) HashSha3(value []byte) wasmtypes.ScHash

hashes the specified value bytes using sha3 hashing and returns the resulting 32-byte hash

func (ScSandboxUtils) String

func (u ScSandboxUtils) String(value int64) string

converts an integer to its string representation

type ScSandboxView

type ScSandboxView struct {
	ScSandbox
}

func (ScSandboxView) Call

func (s ScSandboxView) Call(hContract, hFunction wasmtypes.ScHname, params *ScDict) *ScImmutableDict

calls a smart contract view

type ScState

type ScState struct {
	ScImmutableState
}

func (ScState) Bytes added in v1.0.3

func (d ScState) Bytes() []byte

func (ScState) Delete

func (d ScState) Delete(key []byte)

func (ScState) Immutable

func (d ScState) Immutable() ScImmutableState

func (ScState) Set

func (d ScState) Set(key, value []byte)

type ScTransfer added in v0.3.0

type ScTransfer struct {
	ScBalances
}

func NewScTransfer

func NewScTransfer() *ScTransfer

create a new transfer object ready to add token transfers

func NewScTransferBaseTokens added in v0.3.0

func NewScTransferBaseTokens(amount uint64) *ScTransfer

create a new transfer object and initialize it with the specified amount of base tokens

func NewScTransferFromBalances added in v0.3.0

func NewScTransferFromBalances(balances *ScBalances) *ScTransfer

create a new transfer object from a balances object

func NewScTransferNFT added in v0.3.0

func NewScTransferNFT(nftID *wasmtypes.ScNftID) *ScTransfer

create a new transfer object and initialize it with the specified NFT

func NewScTransferTokens added in v0.3.0

func NewScTransferTokens(tokenID *wasmtypes.ScTokenID, amount wasmtypes.ScBigInt) *ScTransfer

create a new transfer object and initialize it with the specified token transfer

func (*ScTransfer) AddNFT added in v0.3.0

func (t *ScTransfer) AddNFT(nftID *wasmtypes.ScNftID)

func (*ScTransfer) Bytes added in v0.3.0

func (t *ScTransfer) Bytes() []byte

func (*ScTransfer) Set added in v0.3.0

func (t *ScTransfer) Set(tokenID *wasmtypes.ScTokenID, amount wasmtypes.ScBigInt)

set the specified tokenID amount in the transfers object note that this will overwrite any previous amount for the specified tokenID

type ScView

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

func NewScView

func NewScView(ctx ScViewCallContext, hContract, hFunction wasmtypes.ScHname) *ScView

func (*ScView) Call

func (v *ScView) Call()

func (*ScView) OfContract

func (v *ScView) OfContract(hContract wasmtypes.ScHname) *ScView

type ScViewCallContext

type ScViewCallContext interface {
	FnCall(req *wasmrequests.CallRequest) []byte
	FnChainID() wasmtypes.ScChainID
	InitViewCallContext(hContract wasmtypes.ScHname) wasmtypes.ScHname
}

type ScViewContext

type ScViewContext struct {
	ScSandboxView
}

smart contract view sandbox interface

func (ScViewContext) InitViewCallContext

func (ctx ScViewContext) InitViewCallContext(hContract wasmtypes.ScHname) wasmtypes.ScHname

type ScViewContextFunction

type ScViewContextFunction func(ScViewContext)

type TokenAmounts added in v0.3.0

type TokenAmounts map[wasmtypes.ScTokenID]wasmtypes.ScBigInt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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