isc

package
v2.0.3-0...-34c6bb6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package isc defines fundamental types that are used in Wasp.

Index

Constants

View Source
const ChainIDLength = iotago.AddressLen
View Source
const GasCoinTargetValue = iotaclient.DefaultGasBudget * 5

GasCoinTargetValue is the target value for topping up the gas coin. After each VM run, the gas coin will be topped up taking funds from the common account.

View Source
const HnameLength = 4
View Source
const HnameNil = Hname(0)

HnameNil is the value used to represent a non-existent Hname.

View Source
const (
	Million = 1_000_000
)
View Source
const RequestIDDigestLen = 6
View Source
const RequestRefKeyLen = iotago.AddressLen + 32
View Source
const VMCoreErrorContractID = math.MaxUint32

VMCoreErrorContractID defines that all errors with a MaxUint32 contract id will be considered as core errors.

View Source
const VMErrorMessageLimit = math.MaxUint16

Variables

This section is empty.

Functions

func AddressFromAgentID

func AddressFromAgentID(a AgentID) (*cryptolib.Address, bool)

AddressFromAgentID returns the L1 address of the AgentID, if applicable.

func ArgAt

func ArgAt[T any](results CallResults, index int) (r T, _ error)

func ContractStateSubrealm

func ContractStateSubrealm(chainState kv.KVStore, contract Hname) kv.KVStore

func ContractStateSubrealmR

func ContractStateSubrealmR(chainState kv.KVStoreReader, contract Hname) kv.KVStoreReader

func DecodeDryRunTransaction

func DecodeDryRunTransaction(dryRunRes *iotajsonrpc.DryRunTransactionBlockResponse) (*Assets, *EstimationRequest, *cryptolib.Address, error)

DecodeDryRunTransaction The intention of this parser is to make the use of the gas estimation easier. We only accept the transactionBytes and select all needed inputs. The upside is that a user can pass an unsigned transaction to estimate. The downside is that any time we change create_and_send_request in the move contract, we need to update this logic. I don't expect it to change often if ever, so that seems to be a straight forward way.

func EVMCallDataFromTx

func EVMCallDataFromTx(tx *types.Transaction) *ethereum.CallMsg

func GetErrorIDFromMessageFormat

func GetErrorIDFromMessageFormat(messageFormat string) uint16

func IsOffledgerKind

func IsOffledgerKind(b byte) bool

func MustArgAt

func MustArgAt[T any](results CallResults, index int) T

func MustOptionalArgAt

func MustOptionalArgAt[T any](results CallResults, index int, def T) T

func MustOptionalResAt

func MustOptionalResAt[T any](results CallResults, index int, def T) T

func MustResAt

func MustResAt[T any](results CallResults, index int) T

func OptionalArgAt

func OptionalArgAt[T any](results CallResults, index int, def T) (T, error)

func OptionalResAt

func OptionalResAt[T any](results CallResults, index int, def T) (T, error)

func RequestGasPrice

func RequestGasPrice(req Request) *big.Int

RequestGasPrice returns: for ISC request: nil, for EVM tx: the gas price set in the EVM tx (full decimals), or 0 if gas price is unset

func RequestHash

func RequestHash(req Request) hashing.HashValue

func ResAt

func ResAt[T any](results CallResults, index int) (T, error)

func VMErrorIs

func VMErrorIs(err error, expected VMErrorBase) bool

VMErrorIs returns true if the error includes a VMErrorCode in its chain that matches the given code

func VMErrorMustBe

func VMErrorMustBe(err error, expected VMErrorBase)

VMErrorMustBe panics unless the error includes a VMErrorCode in its chain that matches the given code

Types

type AddressAgentID

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

AddressAgentID is an AgentID backed by a L1 address

func NewAddressAgentID

func NewAddressAgentID(addr *cryptolib.Address) *AddressAgentID

func (*AddressAgentID) Address

func (a *AddressAgentID) Address() *cryptolib.Address

func (*AddressAgentID) Bytes

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

func (*AddressAgentID) Equals

func (a *AddressAgentID) Equals(other AgentID) bool

func (*AddressAgentID) Kind

func (a *AddressAgentID) Kind() AgentIDKind

func (*AddressAgentID) String

func (a *AddressAgentID) String() string

type AgentID

type AgentID interface {
	Bytes() []byte
	Equals(other AgentID) bool
	Kind() AgentIDKind
	String() string
}

AgentID represents any entity that can hold assets on L2 and/or call contracts.

func AgentIDFromBytes

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

func AgentIDFromString

func AgentIDFromString(s string) (AgentID, error)

AgentIDFromString parses the human-readable string representation

type AgentIDKind

type AgentIDKind byte
const (
	AgentIDKindNil AgentIDKind = iota
	AgentIDKindAddress
	AgentIDKindContract
	AgentIDKindEthereumAddress

	AgentIDIsNil AgentIDKind = 0x80
)

type AgentIDWithL1Address

type AgentIDWithL1Address interface {
	AgentID
	Address() *cryptolib.Address
}

AgentIDWithL1Address is an AgentID backed by an L1 address (either AddressAgentID or ContractAgentID).

type Assets

type Assets struct {
	// Coins is a set of coin balances
	Coins CoinBalances `json:"coins" swagger:"required"`
	// Objects is a set of non-Coin object IDs (e.g. NFTs)
	Objects ObjectSet `json:"objects" swagger:"required"`
}

func AssetsFromAssetsBagWithBalances

func AssetsFromAssetsBagWithBalances(assetsBag *iscmove.AssetsBagWithBalances) (*Assets, error)

func AssetsFromBytes

func AssetsFromBytes(b []byte) (*Assets, error)

func AssetsFromISCMove

func AssetsFromISCMove(assets *iscmove.Assets) (*Assets, error)

func NewAssets

func NewAssets(baseTokens coin.Value) *Assets

func NewEmptyAssets

func NewEmptyAssets() *Assets

func (*Assets) Add

func (a *Assets) Add(b *Assets) *Assets

func (*Assets) AddBaseTokens

func (a *Assets) AddBaseTokens(amount coin.Value) *Assets

func (*Assets) AddCoin

func (a *Assets) AddCoin(coinType coin.Type, amount coin.Value) *Assets

func (*Assets) AddObject

func (a *Assets) AddObject(obj IotaObject) *Assets

func (*Assets) AsAssetsBagWithBalances

func (a *Assets) AsAssetsBagWithBalances(b *iscmove.AssetsBag) *iscmove.AssetsBagWithBalances

func (*Assets) AsISCMove

func (a *Assets) AsISCMove() *iscmove.Assets

func (*Assets) BaseTokens

func (a *Assets) BaseTokens() coin.Value

func (*Assets) Bytes

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

func (*Assets) Clone

func (a *Assets) Clone() *Assets

func (*Assets) CoinBalance

func (a *Assets) CoinBalance(coinType coin.Type) coin.Value

func (*Assets) Equals

func (a *Assets) Equals(b *Assets) bool

func (*Assets) IsEmpty

func (a *Assets) IsEmpty() bool

func (*Assets) SetBaseTokens

func (a *Assets) SetBaseTokens(amount coin.Value) *Assets

func (*Assets) Size

func (a *Assets) Size() int

Size returns the number of coins and objects in the assets

func (*Assets) Spend

func (a *Assets) Spend(toSpend *Assets) bool

Spend subtracts assets from the current set, mutating the receiver. If the budget is not enough, returns false and leaves receiver untouched.

func (*Assets) String

func (a *Assets) String() string

type Authorize

type Authorize interface {
	RequireCaller(agentID AgentID)
	RequireCallerAnyOf(agentID []AgentID)
	RequireCallerIsChainAdmin()
}

type BLS

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

type Balance

type Balance interface {
	// BalanceBaseTokens returns number of base tokens in the balance of the smart contract
	BaseTokensBalance() (bts coin.Value, remainder *big.Int)
	// CoinBalance returns the balance of the given coin
	CoinBalance(p coin.Type) coin.Value
	// CoinBalances returns the balance of all coins owned by the smart contract
	CoinBalances() CoinBalances
	// OwnedObjects returns the ids of objects owned by the smart contract
	OwnedObjects() []IotaObject
	// returns whether a given user owns a given amount of tokens
	HasInAccount(AgentID, *Assets) bool
}

type CallArguments

type CallArguments [][]byte

func CallArgumentsFromBytes

func CallArgumentsFromBytes(b []byte) (CallArguments, error)

func NewCallArguments

func NewCallArguments(args ...[]byte) CallArguments

func (CallArguments) At

func (c CallArguments) At(index int) ([]byte, error)

func (CallArguments) Bytes

func (c CallArguments) Bytes() []byte

func (CallArguments) Clone

func (c CallArguments) Clone() CallArguments

func (CallArguments) Equals

func (c CallArguments) Equals(other CallArguments) bool

func (CallArguments) Length

func (c CallArguments) Length() int

func (CallArguments) MarshalJSON

func (c CallArguments) MarshalJSON() ([]byte, error)

func (CallArguments) MustAt

func (c CallArguments) MustAt(index int) []byte

func (CallArguments) OrNil

func (c CallArguments) OrNil(index int) []byte

func (CallArguments) String

func (c CallArguments) String() string

func (*CallArguments) UnmarshalJSON

func (c *CallArguments) UnmarshalJSON(data []byte) error

type CallResults

type CallResults = CallArguments

type CallTarget

type CallTarget struct {
	Contract   Hname `json:"contract"`
	EntryPoint Hname `json:"entryPoint"`
}

CallTarget the target representation of the request

func NewCallTarget

func NewCallTarget(contract, entryPoint Hname) CallTarget

func (CallTarget) Equals

func (t CallTarget) Equals(otherTarget CallTarget) bool

type Calldata

type Calldata interface {
	// Assets returns the attached assets for the on-ledger request, empty for off-ledger.
	// Attached assets are deposited in the sender's L2 account by default.
	Assets() *Assets
	// Allowance returns the assets that the sender allows to be debited
	// from their L2 account and transferred to the target contract
	// Returns error if there was an error decoding the allowance from the on-ledger request.
	Allowance() (*Assets, error)
	Message() Message
	GasBudget() (gas uint64, isEVM bool)
	ID() RequestID
	SenderAccount() AgentID
	EVMCallMsg() *ethereum.CallMsg
}

type ChainID

type ChainID iotago.ObjectID

ChainID is the anchor ObjectID

func ChainIDFromAddress

func ChainIDFromAddress(addr *cryptolib.Address) ChainID

func ChainIDFromBytes

func ChainIDFromBytes(data []byte) (ret ChainID, err error)

ChainIDFromBytes reconstructs a ChainID from its binary representation.

func ChainIDFromKey

func ChainIDFromKey(key ChainIDKey) ChainID

func ChainIDFromObjectID

func ChainIDFromObjectID(addr iotago.ObjectID) ChainID

func ChainIDFromString

func ChainIDFromString(hexAddress string) (ChainID, error)

func EmptyChainID

func EmptyChainID() ChainID

EmptyChainID returns an empty ChainID.

func (ChainID) AsAddress

func (id ChainID) AsAddress() *cryptolib.Address

func (ChainID) AsObjectID

func (id ChainID) AsObjectID() iotago.ObjectID

func (ChainID) Bytes

func (id ChainID) Bytes() []byte

func (ChainID) Empty

func (id ChainID) Empty() bool

func (ChainID) Equals

func (id ChainID) Equals(other ChainID) bool

func (ChainID) Key

func (id ChainID) Key() ChainIDKey

func (ChainID) ShortString

func (id ChainID) ShortString() string

func (ChainID) String

func (id ChainID) String() string

type ChainIDKey

type ChainIDKey string

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

type ChainInfo

type ChainInfo struct {
	ChainID         ChainID
	ChainAdmin      AgentID
	GasFeePolicy    *gas.FeePolicy
	GasLimits       *gas.Limits
	BlockKeepAmount int32

	PublicURL string
	Metadata  *PublicChainMetadata
}

ChainInfo is an API structure containing the main parameters of the chain

func ChainInfoFromBytes

func ChainInfoFromBytes(b []byte) (*ChainInfo, error)

func (*ChainInfo) Bytes

func (c *ChainInfo) Bytes() []byte

type CoinBalances

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

func CoinBalancesFromBytes

func CoinBalancesFromBytes(b []byte) (CoinBalances, error)

func NewCoinBalances

func NewCoinBalances() CoinBalances

func (CoinBalances) Add

func (c CoinBalances) Add(coinType coin.Type, amount coin.Value) CoinBalances

func (CoinBalances) AddBaseTokens

func (c CoinBalances) AddBaseTokens(amount coin.Value) CoinBalances

func (CoinBalances) BaseTokens

func (c CoinBalances) BaseTokens() coin.Value

func (CoinBalances) Bytes

func (c CoinBalances) Bytes() []byte

func (CoinBalances) Clone

func (c CoinBalances) Clone() CoinBalances

func (CoinBalances) Equals

func (c CoinBalances) Equals(b CoinBalances) bool

func (CoinBalances) Get

func (c CoinBalances) Get(coinType coin.Type) coin.Value

func (CoinBalances) IsEmpty

func (c CoinBalances) IsEmpty() bool

func (CoinBalances) Iterate

func (c CoinBalances) Iterate() iter.Seq2[coin.Type, coin.Value]

Iterate returns a deterministic iterator

func (CoinBalances) NativeTokens

func (c CoinBalances) NativeTokens() CoinBalances

func (CoinBalances) Set

func (c CoinBalances) Set(coinType coin.Type, amount coin.Value) CoinBalances

func (CoinBalances) Size

func (c CoinBalances) Size() int

func (CoinBalances) String

func (c CoinBalances) String() string

func (CoinBalances) Sub

func (c CoinBalances) Sub(coinType coin.Type, amount coin.Value) CoinBalances

func (CoinBalances) ToAssets

func (c CoinBalances) ToAssets() *Assets

type ContractAgentID

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

ContractAgentID is an AgentID formed by a contract Hname.

func NewContractAgentID

func NewContractAgentID(hname Hname) *ContractAgentID

func (*ContractAgentID) Address

func (a *ContractAgentID) Address() *cryptolib.Address

func (*ContractAgentID) Bytes

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

func (*ContractAgentID) BytesWithoutChainID

func (a *ContractAgentID) BytesWithoutChainID() []byte

func (*ContractAgentID) Equals

func (a *ContractAgentID) Equals(other AgentID) bool

func (*ContractAgentID) Hname

func (a *ContractAgentID) Hname() Hname

func (*ContractAgentID) Kind

func (a *ContractAgentID) Kind() AgentIDKind

func (*ContractAgentID) String

func (a *ContractAgentID) String() string

type ContractIdentity

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

func ContractIdentityFromEVMAddress

func ContractIdentityFromEVMAddress(addr common.Address) ContractIdentity

func ContractIdentityFromHname

func ContractIdentityFromHname(hn Hname) ContractIdentity

func EmptyContractIdentity

func EmptyContractIdentity() ContractIdentity

func (*ContractIdentity) AgentID

func (c *ContractIdentity) AgentID(chainID ChainID) AgentID

func (*ContractIdentity) EVMAddress

func (c *ContractIdentity) EVMAddress() (common.Address, error)

func (*ContractIdentity) Empty

func (c *ContractIdentity) Empty() bool

func (*ContractIdentity) Hname

func (c *ContractIdentity) Hname() (Hname, error)

func (*ContractIdentity) MarshalBCS

func (c *ContractIdentity) MarshalBCS(e *bcs.Encoder) error

func (*ContractIdentity) String

func (c *ContractIdentity) String() string

func (*ContractIdentity) UnmarshalBCS

func (c *ContractIdentity) UnmarshalBCS(d *bcs.Decoder) error

type ControlAddresses

type ControlAddresses struct {
	AnchorOwner     *cryptolib.Address
	ChainAdmin      AgentID
	SinceBlockIndex uint32
}

type CoreCallbackFunc

type CoreCallbackFunc func(contractPartition kv.KVStore, gasBurned uint64, vmError *VMError)

type ED25519

type ED25519 interface {
	AddressFromPublicKey(pubKey []byte) (*cryptolib.Address, error)
}

type EstimationRequest

type EstimationRequest struct {
	Message      iscmove.Message
	AllowanceBCS []byte
	GasBudget    json.Number
}

type EthereumAddressAgentID

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

EthereumAddressAgentID is an AgentID formed by an Ethereum address

func NewEthereumAddressAgentID

func NewEthereumAddressAgentID(eth common.Address) *EthereumAddressAgentID

func (*EthereumAddressAgentID) Bytes

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

func (*EthereumAddressAgentID) Equals

func (a *EthereumAddressAgentID) Equals(other AgentID) bool

func (*EthereumAddressAgentID) EthAddress

func (a *EthereumAddressAgentID) EthAddress() common.Address

func (*EthereumAddressAgentID) Kind

func (*EthereumAddressAgentID) String

func (a *EthereumAddressAgentID) String() string

type Event

type Event struct {
	ContractID Hname  `json:"contractID"`
	Topic      string `json:"topic"`
	Timestamp  uint64 `json:"timestamp"`
	Payload    []byte `json:"payload"`
}

func EventFromBytes

func EventFromBytes(data []byte) (*Event, error)

func (*Event) Bytes

func (e *Event) Bytes() []byte

type Expiration

type Expiration struct {
	Time          time.Time
	ReturnAddress *cryptolib.Address
}

type Gas

type Gas interface {
	Burn(burnCode gas.BurnCode, par ...uint64)
	Budget() uint64
	Burned() uint64
	EstimateGasMode() bool
}

type Hashing

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

type Helpers

type Helpers interface {
	Requiref(cond bool, format string, args ...any)
	RequireNoError(err error, str ...string)
}

type Hname

type Hname uint32

Hname is calculated as the first 4 bytes of the BLAKE2b hash of a string, interpreted as a little-endian uint32.

func ContractIDFromEventBytes

func ContractIDFromEventBytes(eventBytes []byte) (Hname, error)

ContractIDFromEventBytes is used by blocklog to filter out specific events per contract For performance reasons it is working directly with the event bytes.

func Hn

func Hn(name string) (ret Hname)

Hn calculates the hname for the given string. For any given string s, it is guaranteed that Hn(s) != HnameNil.

func HnameFromAgentID

func HnameFromAgentID(a AgentID) Hname

HnameFromAgentID returns the hname of the AgentID, or HnameNil if not applicable.

func HnameFromBytes

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

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) IsNil

func (hn Hname) IsNil() bool

func (Hname) String

func (hn Hname) String() string

type IRC30NativeTokenMetadata

type IRC30NativeTokenMetadata struct {
	Standard string `json:"standard"`
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals uint8  `json:"decimals"`
}

IRC30NativeTokenMetadata represents the Native Token metadata according to IRC30. See: https://github.com/iotaledger/tips/blob/main/tips/TIP-0030/tip-0030.md Right now, only required properties are included. Optional parameters such as description or logo/Url can be added later

func IRC30NativeTokenMetadataFromBytes

func IRC30NativeTokenMetadataFromBytes(b []byte) (*IRC30NativeTokenMetadata, error)

func NewIRC30NativeTokenMetadata

func NewIRC30NativeTokenMetadata(name, symbol string, decimals uint8) *IRC30NativeTokenMetadata

func (*IRC30NativeTokenMetadata) Bytes

func (m *IRC30NativeTokenMetadata) Bytes() []byte

type ImpersonatedOffLedgerRequest

type ImpersonatedOffLedgerRequest interface {
	WithSenderAddress(senderAddress *cryptolib.Address) OffLedgerRequest
}

type ImpersonatedOffLedgerRequestData

type ImpersonatedOffLedgerRequestData struct {
	OffLedgerRequestData
	// contains filtered or unexported fields
}

func (*ImpersonatedOffLedgerRequestData) SenderAccount

func (r *ImpersonatedOffLedgerRequestData) SenderAccount() AgentID

func (*ImpersonatedOffLedgerRequestData) WithSenderAddress

func (r *ImpersonatedOffLedgerRequestData) WithSenderAddress(senderAddress *cryptolib.Address) OffLedgerRequest

type IotaObject

type IotaObject struct {
	ID   iotago.ObjectID
	Type iotago.ObjectType
}

IotaObject represents a non-coin object originally created on L1

func NewIotaObject

func NewIotaObject(id iotago.ObjectID, t iotago.ObjectType) IotaObject

type JSONTokenScheme

type JSONTokenScheme struct {
	Type          int    `json:"type"`
	MintedSupply  string `json:"mintedTokens"`
	MeltedTokens  string `json:"meltedTokens"`
	MaximumSupply string `json:"maximumSupply"`
}

JSONTokenScheme is for now a 1:1 copy of the Stardusts version

type LogInterface

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

type Message

type Message struct {
	Target CallTarget    `json:"target"`
	Params CallArguments `json:"params"`
}

func NewMessage

func NewMessage(contract Hname, ep Hname, params ...CallArguments) Message

func NewMessageFromNames

func NewMessageFromNames(contract string, ep string, params ...CallArguments) Message

func (Message) AsISCMove

func (m Message) AsISCMove() *iscmove.Message

func (Message) Clone

func (m Message) Clone() Message

func (Message) Equals

func (m Message) Equals(other Message) bool

func (Message) String

func (m Message) String() string

type NilAgentID

type NilAgentID struct{}

func (*NilAgentID) Bytes

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

func (*NilAgentID) Equals

func (a *NilAgentID) Equals(other AgentID) bool

func (*NilAgentID) Kind

func (a *NilAgentID) Kind() AgentIDKind

func (*NilAgentID) String

func (a *NilAgentID) String() string

type ObjectSet

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

func NewObjectSet

func NewObjectSet(objs ...IotaObject) ObjectSet

func (ObjectSet) Add

func (o ObjectSet) Add(obj IotaObject)

func (ObjectSet) AddAll

func (o ObjectSet) AddAll(obj []IotaObject)

func (ObjectSet) Clone

func (o ObjectSet) Clone() ObjectSet

func (ObjectSet) Equals

func (o ObjectSet) Equals(b ObjectSet) bool

func (ObjectSet) Has

func (o ObjectSet) Has(id iotago.ObjectID) bool

func (ObjectSet) IsEmpty

func (o ObjectSet) IsEmpty() bool

func (ObjectSet) Iterate

func (o ObjectSet) Iterate() iter.Seq[IotaObject]

Iterate returns a deterministic iterator

func (ObjectSet) KeysSorted

func (o ObjectSet) KeysSorted() []iotago.ObjectID

func (ObjectSet) Size

func (o ObjectSet) Size() int

func (ObjectSet) Sorted

func (o ObjectSet) Sorted() []IotaObject

type OffLedgerRequest

type OffLedgerRequest interface {
	Request
	ChainID() ChainID
	Nonce() uint64
	VerifySignature() error
	GasPrice() *big.Int
}

func NewEVMOffLedgerCallRequest

func NewEVMOffLedgerCallRequest(chainID ChainID, callMsg ethereum.CallMsg) OffLedgerRequest

func NewEVMOffLedgerTxRequest

func NewEVMOffLedgerTxRequest(chainID ChainID, tx *types.Transaction) (OffLedgerRequest, error)

type OffLedgerRequestData

type OffLedgerRequestData struct {
	OffLedgerRequestDataEssence
	// contains filtered or unexported fields
}

OffLedgerRequestData implements OffLedgerRequest

func (*OffLedgerRequestData) Allowance

func (req *OffLedgerRequestData) Allowance() (*Assets, error)

Allowance from the sender's account to the target smart contract. Nil mean no Allowance

func (*OffLedgerRequestData) Assets

func (req *OffLedgerRequestData) Assets() *Assets

Assets is attached assets to the UTXO. Nil for off-ledger

func (*OffLedgerRequestData) Bytes

func (req *OffLedgerRequestData) Bytes() []byte

func (*OffLedgerRequestData) ChainID

func (req *OffLedgerRequestData) ChainID() ChainID

func (*OffLedgerRequestData) EVMCallMsg

func (req *OffLedgerRequestData) EVMCallMsg() *ethereum.CallMsg

func (*OffLedgerRequestData) Expiry

func (req *OffLedgerRequestData) Expiry() (time.Time, *cryptolib.Address)

func (*OffLedgerRequestData) GasBudget

func (req *OffLedgerRequestData) GasBudget() (gasBudget uint64, isEVM bool)

func (*OffLedgerRequestData) GasPrice

func (req *OffLedgerRequestData) GasPrice() *big.Int

func (*OffLedgerRequestData) ID

func (req *OffLedgerRequestData) ID() (requestID RequestID)

ID returns request id for this request index part of request id is always 0 for off ledger requests note that request needs to have been signed before this value is considered valid

func (*OffLedgerRequestData) IsOffLedger

func (req *OffLedgerRequestData) IsOffLedger() bool

func (*OffLedgerRequestData) Message

func (req *OffLedgerRequestData) Message() Message

func (*OffLedgerRequestData) Nonce

func (req *OffLedgerRequestData) Nonce() uint64

Nonce incremental nonce used for replay protection

func (*OffLedgerRequestData) ReturnAmount

func (req *OffLedgerRequestData) ReturnAmount() (uint64, bool)

func (*OffLedgerRequestData) SenderAccount

func (req *OffLedgerRequestData) SenderAccount() AgentID

func (*OffLedgerRequestData) String

func (req *OffLedgerRequestData) String() string

func (*OffLedgerRequestData) TimeLock

func (req *OffLedgerRequestData) TimeLock() time.Time

func (*OffLedgerRequestData) Timestamp

func (req *OffLedgerRequestData) Timestamp() time.Time

func (*OffLedgerRequestData) VerifySignature

func (req *OffLedgerRequestData) VerifySignature() error

VerifySignature verifies essence signature

type OffLedgerRequestDataEssence

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

OffLedgerRequestDataEssence implements UnsignedOffLedgerRequest

func (*OffLedgerRequestDataEssence) Bytes

func (req *OffLedgerRequestDataEssence) Bytes() []byte

func (*OffLedgerRequestDataEssence) Sign

func (*OffLedgerRequestDataEssence) WithAllowance

func (req *OffLedgerRequestDataEssence) WithAllowance(allowance *Assets) UnsignedOffLedgerRequest

func (*OffLedgerRequestDataEssence) WithGasBudget

func (req *OffLedgerRequestDataEssence) WithGasBudget(gasBudget uint64) UnsignedOffLedgerRequest

func (*OffLedgerRequestDataEssence) WithNonce

func (*OffLedgerRequestDataEssence) WithSender

WithSender can be used to estimate gas, without a signature

type OnLedgerRequest

type OnLedgerRequest interface {
	Request
	RequestRef() iotago.ObjectRef
	AssetsBag() *iscmove.AssetsBagWithBalances
}

func OnLedgerFromMoveRequest

func OnLedgerFromMoveRequest(request *iscmove.RefWithObject[iscmove.Request], anchorAddress *cryptolib.Address) (OnLedgerRequest, error)

type OnLedgerRequestData

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

func (*OnLedgerRequestData) Allowance

func (req *OnLedgerRequestData) Allowance() (*Assets, error)

func (*OnLedgerRequestData) Assets

func (req *OnLedgerRequestData) Assets() *Assets

func (*OnLedgerRequestData) AssetsBag

func (*OnLedgerRequestData) Bytes

func (req *OnLedgerRequestData) Bytes() []byte

func (*OnLedgerRequestData) EVMCallMsg

func (req *OnLedgerRequestData) EVMCallMsg() *ethereum.CallMsg

func (*OnLedgerRequestData) GasBudget

func (req *OnLedgerRequestData) GasBudget() (gasBudget uint64, isEVM bool)

func (*OnLedgerRequestData) ID

func (req *OnLedgerRequestData) ID() RequestID

func (*OnLedgerRequestData) IsOffLedger

func (req *OnLedgerRequestData) IsOffLedger() bool

func (*OnLedgerRequestData) Message

func (req *OnLedgerRequestData) Message() Message

func (*OnLedgerRequestData) RequestID

func (req *OnLedgerRequestData) RequestID() iotago.ObjectID

func (*OnLedgerRequestData) RequestRef

func (req *OnLedgerRequestData) RequestRef() iotago.ObjectRef

func (*OnLedgerRequestData) SenderAccount

func (req *OnLedgerRequestData) SenderAccount() AgentID

func (*OnLedgerRequestData) SenderAddress

func (req *OnLedgerRequestData) SenderAddress() *cryptolib.Address

func (*OnLedgerRequestData) String

func (req *OnLedgerRequestData) String() string

type Privileged

type Privileged interface {
	GasBurnEnable(enable bool)
	GasBurnEnabled() bool
	OnWriteReceipt(CoreCallbackFunc)
	CallOnBehalfOf(caller AgentID, msg Message, allowance *Assets) CallArguments
	SendOnBehalfOf(caller ContractIdentity, metadata RequestParameters)

	// only called from EVM
	MustMoveBetweenAccounts(fromAgentID, toAgentID AgentID, assets *Assets)
	DebitFromAccount(AgentID, *big.Int)
	CreditToAccount(AgentID, *big.Int)
}

Privileged is a sub-interface for core contracts. Should not be called by VM plugins

type ProcessorEntryPoint

type ProcessorEntryPoint interface {
	VMProcessorEntryPoint
	Name() string
	Hname() Hname
}

type PublicChainMetadata

type PublicChainMetadata struct {
	EVMJsonRPCURL   string
	EVMWebSocketURL string
	Name            string
	Description     string
	Website         string
}

func PublicChainMetadataFromBytes

func PublicChainMetadataFromBytes(data []byte) (*PublicChainMetadata, error)

func (*PublicChainMetadata) Bytes

func (m *PublicChainMetadata) Bytes() []byte

type Receipt

type Receipt struct {
	Request       []byte             `json:"request"`
	Error         *UnresolvedVMError `json:"error"`
	GasBudget     uint64             `json:"gasBudget"`
	GasBurned     uint64             `json:"gasBurned"`
	GasFeeCharged coin.Value         `json:"gasFeeCharged"`
	SDCharged     coin.Value         `json:"storageDepositCharged"`
	BlockIndex    uint32             `json:"blockIndex"`
	RequestIndex  uint16             `json:"requestIndex"`
	ResolvedError string             `json:"resolvedError"`
	GasBurnLog    *gas.BurnLog       `json:"-"`
}

Receipt represents a blocklog.RequestReceipt with a resolved error string

func (Receipt) DeserializedRequest

func (r Receipt) DeserializedRequest() Request

func (Receipt) String

func (r Receipt) String() string

type Request

type Request interface {
	Calldata

	Bytes() []byte
	IsOffLedger() bool
	String() string
}

Request wraps any data which can be potentially be interpreted as a request

func RequestFromBytes

func RequestFromBytes(data []byte) (Request, error)

type RequestID

type RequestID iotago.ObjectID

func RequestIDFromBytes

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

func RequestIDFromEVMTxHash

func RequestIDFromEVMTxHash(txHash common.Hash) RequestID

func RequestIDFromString

func RequestIDFromString(s string) (ret RequestID, err error)

func (*RequestID) AsIotaAddress

func (rid *RequestID) AsIotaAddress() iotago.Address

func (*RequestID) AsIotaObjectID

func (rid *RequestID) AsIotaObjectID() iotago.ObjectID

func (RequestID) Bytes

func (rid RequestID) Bytes() []byte

func (RequestID) Equals

func (rid RequestID) Equals(other RequestID) bool

func (RequestID) LookupDigest

func (rid RequestID) LookupDigest() RequestLookupDigest

func (RequestID) Short

func (rid RequestID) Short() string

func (RequestID) String

func (rid RequestID) String() string

type RequestKind

type RequestKind byte

type RequestLookupDigest

type RequestLookupDigest [RequestIDDigestLen + 2]byte

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

type RequestMetadata

type RequestMetadata struct {
	SenderContract ContractIdentity `json:"senderContract"`
	Message        Message          `json:"message"`
	// AllowanceBCS is either empty or a BCS-encoded iscmove.Allowance.
	AllowanceBCS []byte `json:"allowanceBcs"`
	// gas budget
	GasBudget uint64 `json:"gasBudget"`
}

func RequestMetadataFromBytes

func RequestMetadataFromBytes(data []byte) (*RequestMetadata, error)

func (*RequestMetadata) Bytes

func (meta *RequestMetadata) Bytes() []byte

type RequestParameters

type RequestParameters struct {
	// TargetAddress is the target address. It may represent another chain or L1 address
	TargetAddress *cryptolib.Address
	// Assets attached to the request, always taken from the caller's account.
	// It expected to contain base tokens at least the amount required for storage deposit
	// It depends on the context how it is handled when base tokens are not enough for storage deposit
	Assets *Assets
}

RequestParameters represents parameters of the on-ledger request. The request is build from these parameters

type RequestRef

type RequestRef struct {
	ID   RequestID
	Hash hashing.HashValue
}

func RequestRefFromBytes

func RequestRefFromBytes(data []byte) (*RequestRef, error)

func RequestRefFromRequest

func RequestRefFromRequest(req Request) *RequestRef

func RequestRefsFromRequests

func RequestRefsFromRequests(reqs []Request) []*RequestRef

func (*RequestRef) AsKey

func (ref *RequestRef) AsKey() RequestRefKey

func (*RequestRef) Bytes

func (ref *RequestRef) Bytes() []byte

func (*RequestRef) IsFor

func (ref *RequestRef) IsFor(req Request) bool

func (*RequestRef) String

func (ref *RequestRef) String() string

type RequestRefKey

type RequestRefKey [RequestRefKeyLen]byte

func (RequestRefKey) String

func (rrk RequestRefKey) String() string

type Sandbox

type Sandbox interface {
	SandboxBase
	Authorize

	// 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() Calldata

	// Call calls the entry point of the contract with parameters and allowance.
	// If the entry point is full entry point, allowance tokens are available to be moved from the caller's
	// accounts (if enough). If the entry point is view, 'allowance' has no effect
	Call(msg Message, allowance *Assets) CallArguments
	// Event emits an event
	Event(topic string, payload []byte)
	// RegisterError registers an error
	RegisterError(messageFormat string) *VMErrorTemplate
	// GetEntropy 32 random bytes based on the hash of the current state transaction
	GetEntropy() hashing.HashValue
	// AllowanceAvailable specifies max remaining (after transfers) budget of assets the smart contract can take
	// from the caller with TransferAllowedFunds. Nil means no allowance left (zero budget)
	AllowanceAvailable() *Assets
	// TransferAllowedFunds moves assets from the caller's account to specified account within the budget set by Allowance.
	// Skipping 'assets' means transfer all Allowance().
	// The TransferAllowedFunds call mutates AllowanceAvailable
	// Returns remaining budget
	TransferAllowedFunds(target AgentID, transfer ...*Assets) *Assets
	// Send sends an on-ledger request (or a regular transaction to any L1 Address)
	Send(metadata RequestParameters)
	// StateIndex returns the index of the current block being produced
	StateIndex() uint32
	// RequestIndex returns the index of the current request in the request batch
	RequestIndex() uint16

	// EVMTracer returns a non-nil tracer if an EVM tx is being traced
	// (e.g. with the debug_traceTransaction JSONRPC method).
	EVMTracer() *tracers.Tracer

	// TakeStateSnapshot takes a snapshot of the state. This is useful to implement the try/catch
	// behavior in Solidity, where the state is reverted after a low level call fails.
	TakeStateSnapshot() int
	RevertToStateSnapshot(int)

	// Privileged is a sub-interface of the sandbox which should not be called by VM plugins
	Privileged() Privileged
}

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 {
	Helpers
	Balance
	// Params returns the parameters of the current call
	Params() CallArguments
	// ChainID returns the chain ID
	ChainID() ChainID
	// ChainAdmin returns the chain admin AgentID (not necessarily the same as "anchor owner")
	ChainAdmin() AgentID
	// ChainInfo returns information and configuration parameters of the chain
	ChainInfo() *ChainInfo
	// Contract returns the Hname of the current contract in the context
	Contract() Hname
	// AccountID returns the agentID of the current contract (i.e. chainID + contract hname)
	AccountID() AgentID
	// Caller is the agentID of the caller.
	Caller() AgentID
	// Timestamp returns the Unix timestamp of the current state in seconds
	Timestamp() time.Time
	// Log returns a logger that outputs on the local machine. It includes Panicf method
	Log() LogInterface
	// Utils provides access to common necessary functionality
	Utils() Utils
	// Gas returns sub-interface for gas related functions. It is stateful but does not modify chain's state
	Gas() Gas
	// GetCoinInfo returns information about a coin known by the chain
	GetCoinInfo(coinType coin.Type) (*parameters.IotaCoinInfo, bool)
	// CallView calls another contract. Only calls view entry points
	CallView(Message) CallArguments
	// StateR returns the immutable k/v store of the current call (in the context of the smart contract)
	StateR() kv.KVStoreReader
	// SchemaVersion returns the schema version of the current state
	SchemaVersion() SchemaVersion
}

SandboxBase is the common interface of Sandbox and SandboxView

type SandboxView

type SandboxView interface {
	SandboxBase
}

SandboxView is an interface for read only call

type SchemaVersion

type SchemaVersion uint32

type SendMetadata

type SendMetadata struct {
	Message   Message
	Allowance *Assets
	GasBudget uint64
}

SendMetadata represents content of the data payload of the request

type SendOptions

type SendOptions struct {
	Timelock   time.Time
	Expiration *Expiration
}

type SimpleTokenScheme

type SimpleTokenScheme struct {
	// The amount of tokens which has been minted.
	MintedTokens *big.Int
	// The amount of tokens which has been melted.
	MeltedTokens *big.Int
	// The maximum supply of tokens controlled.
	MaximumSupply *big.Int
}

func (*SimpleTokenScheme) Clone

type StateAnchor

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

StateAnchor contains properties of the anchor request/transaction in the current context

func NewStateAnchor

func NewStateAnchor(
	anchor *iscmove.AnchorWithRef,
	iscPackage iotago.Address,
) StateAnchor

NewStateAnchor creates a new state anchor. Every time changing the L1 state of the Anchor object, the nodes should create it. a latest StateAnchor, and remember to update the latest ObjectRef of GasCoin "changing the L1 state of the Anchor object" includes the following 'txbuilder' operations * BuildTransactionEssence (update the anchor commitment) * RotationTransaction

func (StateAnchor) Anchor

func (s StateAnchor) Anchor() *iscmove.AnchorWithRef

func (StateAnchor) ChainID

func (s StateAnchor) ChainID() ChainID

func (StateAnchor) Equals

func (s StateAnchor) Equals(input *StateAnchor) bool

func (StateAnchor) GetAssetsBag

func (s StateAnchor) GetAssetsBag() *iscmove.AssetsBag

func (StateAnchor) GetObjectID

func (s StateAnchor) GetObjectID() *iotago.ObjectID

func (StateAnchor) GetObjectRef

func (s StateAnchor) GetObjectRef() *iotago.ObjectRef

func (StateAnchor) GetStateIndex

func (s StateAnchor) GetStateIndex() uint32

func (StateAnchor) GetStateMetadata

func (s StateAnchor) GetStateMetadata() []byte

func (StateAnchor) Hash

func (s StateAnchor) Hash() hashing.HashValue

func (*StateAnchor) ISCPackage

func (s *StateAnchor) ISCPackage() iotago.Address

func (*StateAnchor) MarshalBCS

func (s *StateAnchor) MarshalBCS(e *bcs.Encoder) error

func (StateAnchor) Owner

func (s StateAnchor) Owner() *cryptolib.Address

func (StateAnchor) String

func (s StateAnchor) String() string

func (*StateAnchor) UnmarshalBCS

func (s *StateAnchor) UnmarshalBCS(d *bcs.Decoder) error

type UnresolvedVMError

type UnresolvedVMError struct {
	ErrorCode VMErrorCode    `json:"code"`
	Params    []VMErrorParam `json:"params"`
}

func (*UnresolvedVMError) AsGoError

func (e *UnresolvedVMError) AsGoError() error

func (*UnresolvedVMError) Bytes

func (e *UnresolvedVMError) Bytes() []byte

func (*UnresolvedVMError) Code

func (e *UnresolvedVMError) Code() VMErrorCode

func (*UnresolvedVMError) Error

func (e *UnresolvedVMError) Error() string

type UnsignedOffLedgerRequest

type UnsignedOffLedgerRequest interface {
	Bytes() []byte
	WithNonce(nonce uint64) UnsignedOffLedgerRequest
	WithGasBudget(gasBudget uint64) UnsignedOffLedgerRequest
	WithAllowance(allowance *Assets) UnsignedOffLedgerRequest
	WithSender(sender *cryptolib.PublicKey) OffLedgerRequest
	Sign(signer cryptolib.Signer) OffLedgerRequest
}

func NewOffLedgerRequest

func NewOffLedgerRequest(
	chainID ChainID,
	msg Message,
	nonce uint64,
	gasBudget uint64,
) UnsignedOffLedgerRequest

type Utils

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

Utils provides various utilities that are faster on host side than on VM interpreter side.

type VMError

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

func (*VMError) AsGoError

func (e *VMError) AsGoError() error

func (*VMError) AsTemplate

func (e *VMError) AsTemplate() *VMErrorTemplate

func (*VMError) AsUnresolvedError

func (e *VMError) AsUnresolvedError() *UnresolvedVMError

func (*VMError) Bytes

func (e *VMError) Bytes() []byte

func (*VMError) Code

func (e *VMError) Code() VMErrorCode

func (*VMError) Error

func (e *VMError) Error() string

func (*VMError) MessageFormat

func (e *VMError) MessageFormat() string

func (*VMError) Params

func (e *VMError) Params() []VMErrorParam

type VMErrorBase

type VMErrorBase interface {
	error
	Code() VMErrorCode
}

VMErrorBase is the common interface of UnresolvedVMError and VMError

type VMErrorCode

type VMErrorCode struct {
	ContractID Hname
	ID         uint16
}

func NewCoreVMErrorCode

func NewCoreVMErrorCode(id uint16) VMErrorCode

func NewVMErrorCode

func NewVMErrorCode(contractID Hname, id uint16) VMErrorCode

func VMErrorCodeFromBytes

func VMErrorCodeFromBytes(b []byte) (VMErrorCode, error)

func (VMErrorCode) Bytes

func (c VMErrorCode) Bytes() []byte

func (VMErrorCode) String

func (c VMErrorCode) String() string

type VMErrorParam

type VMErrorParam any

type VMErrorTemplate

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

func NewVMErrorTemplate

func NewVMErrorTemplate(code VMErrorCode, messageFormat string) *VMErrorTemplate

func VMErrorTemplateFromBytes

func VMErrorTemplateFromBytes(data []byte) (*VMErrorTemplate, error)

func (*VMErrorTemplate) Bytes

func (e *VMErrorTemplate) Bytes() []byte

func (*VMErrorTemplate) Code

func (e *VMErrorTemplate) Code() VMErrorCode

func (*VMErrorTemplate) Create

func (e *VMErrorTemplate) Create(params ...VMErrorParam) *VMError

func (*VMErrorTemplate) Error

func (e *VMErrorTemplate) Error() string

Error implements the error interface. VMErrorTemplate implements error just in case someone panics with it. VMErrorTemplate by mistake, so that we don't crash the VM because of that.

func (*VMErrorTemplate) MessageFormat

func (e *VMErrorTemplate) MessageFormat() string

type VMProcessor

type VMProcessor interface {
	GetEntryPoint(code Hname) (VMProcessorEntryPoint, bool)
	Entrypoints() map[Hname]ProcessorEntryPoint
}

VMProcessor is an interface to the VM processor instance.

type VMProcessorEntryPoint

type VMProcessorEntryPoint interface {
	Call(ctx SandboxBase) CallArguments
	IsView() bool
}

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

Directories

Path Synopsis
Package assert provides assertion utilities for the IOTA Smart Contract platform.
Package assert provides assertion utilities for the IOTA Smart Contract platform.
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
generator command
Package isctest provides testing utilities and helpers for the ISC (IOTA Smart Contracts) package.
Package isctest provides testing utilities and helpers for the ISC (IOTA Smart Contracts) package.

Jump to

Keyboard shortcuts

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