contracts

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// StoreKindPublicName is a human-readable name for public store kind.
	StoreKindPublicName = "public"

	// StoreKindConfidentialName is a human-readable name for confidential store kind.
	StoreKindConfidentialName = "confidential"
)
View Source
const (
	// ABIOasisV1 is the custom Oasis SDK-specific ABI (v1).
	ABIOasisV1 = ABI(1)
)
View Source
const ModuleName = "contracts"

ModuleName is the contracts module name.

View Source
const (
	// PublicKeyTransaction is the transaction public key kind.
	PublicKeyTransaction = PublicKeyKind(1)
)

Variables

This section is empty.

Functions

func CompressCode

func CompressCode(code []byte) []byte

CompressCode performs code compression using Snappy.

func DecodeEvent

func DecodeEvent(event *types.Event) ([]client.DecodedEvent, error)

DecodeEvent decodes a contract event.

func NewCallTx

func NewCallTx(fee *types.Fee, body *Call) *types.Transaction

NewCallTx generates a new contracts.Call transaction.

func NewChangeUpgradePolicyTx added in v0.3.0

func NewChangeUpgradePolicyTx(fee *types.Fee, body *ChangeUpgradePolicy) *types.Transaction

NewChangeUpgradePolicyTx generates a new contracts.ChangeUpgradePolicy transaction.

func NewInstantiateTx

func NewInstantiateTx(fee *types.Fee, body *Instantiate) *types.Transaction

NewInstantiateTx generates a new contracts.Instantiate transaction.

func NewUpgradeTx added in v0.3.0

func NewUpgradeTx(fee *types.Fee, body *Upgrade) *types.Transaction

NewUpgradeTx generates a new contracts.Upgrade transaction.

func NewUploadTx

func NewUploadTx(fee *types.Fee, body *Upload) *types.Transaction

NewUploadTx generates a new contracts.Upload transaction.

Types

type ABI

type ABI uint8

ABI is the ABI that the given contract should conform to.

func (ABI) String

func (a ABI) String() string

String returns a string representation of an ABI.

type Call

type Call struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// Data are the arguments to contract's instantiation function.
	Data []byte `json:"data"`
	// Tokens that should be sent to the contract as part of the call.
	Tokens []types.BaseUnits `json:"tokens"`
}

Call is the body of the contracts.Call call.

type CallResult

type CallResult []byte

CallResult is the result of the contracts.Call call.

type ChangeUpgradePolicy added in v0.3.0

type ChangeUpgradePolicy struct {
	// ID is the unique instance identifier.
	ID InstanceID `json:"id"`
	// UpgradesPolicy is the updated upgrade policy.
	UpgradesPolicy Policy `json:"upgrades_policy"`
}

ChangeUpgradePolicy is the body of the contracts.ChangeUpgradePolicy call.

type Code

type Code struct {
	// ID is the unique code identifier.
	ID CodeID `json:"id"`
	// Hash is the code hash.
	Hash hash.Hash `json:"hash"`
	// ABI.
	ABI ABI `json:"abi"`
	// ABI sub-version.
	ABISubVersion uint32 `json:"abi_sv,omitempty"`
	// Uploader is the code uploader address.
	Uploader types.Address `json:"uploader"`
	// InstantiatePolicy is the policy on who is allowed to instantiate this code.
	InstantiatePolicy Policy `json:"instantiate_policy"`
}

Code is stored code information.

type CodeID

type CodeID uint64

CodeID is the unique stored code identifier.

type CodeQuery

type CodeQuery struct {
	// ID is the code identifier.
	ID CodeID `json:"id"`
}

CodeQuery is the body of the contracts.Code query.

type CodeStorageQuery added in v0.3.0

type CodeStorageQuery struct {
	// ID is the code identifier.
	ID CodeID `json:"id"`
}

CodeStorageQuery is the body of the contracts.CodeStorage query.

type CodeStorageQueryResult added in v0.3.0

type CodeStorageQueryResult struct {
	// Code is the stored contract code.
	Code []byte `json:"code"`
}

CodeStorageQueryResult is the result of the contracts.CodeStorage query.

type CustomQuery

type CustomQuery struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// Data are the query method arguments.
	Data []byte `json:"data"`
}

CustomQuery is the body of the contracts.Custom query.

type CustomQueryResult

type CustomQueryResult []byte

CustomQueryResult is the result of the contracts.Custom query.

type Event

type Event struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// Data is the cbor serialized event data.
	Data []byte `json:"data,omitempty"`
}

Event is an event emitted by a contract.

type GasCosts

type GasCosts struct {
	TxUpload              uint64 `json:"tx_upload"`
	TxUploadPerByte       uint64 `json:"tx_upload_per_byte"`
	TxInstantiate         uint64 `json:"tx_instantiate"`
	TxCall                uint64 `json:"tx_call"`
	TxUpgrade             uint64 `json:"tx_upgrade"`
	TxChangeUpgradePolicy uint64 `json:"tx_change_upgrade_policy"`

	SubcallDispatch uint64 `json:"subcall_dispatch"`

	WASMPublicStorageGetBase          uint64 `json:"wasm_public_storage_get_base"`
	WASMPublicStorageInsertBase       uint64 `json:"wasm_public_storage_insert_base"`
	WASMPublicStorageRemoveBase       uint64 `json:"wasm_public_storage_remove_base"`
	WASMPublicStorageKeyByte          uint64 `json:"wasm_public_storage_key_byte"`
	WASMPublicStorageValueByte        uint64 `json:"wasm_public_storage_value_byte"`
	WASMConfidentialStorageGetBase    uint64 `json:"wasm_confidential_storage_get_base"`
	WASMConfidentialStorageInsertBase uint64 `json:"wasm_confidential_storage_insert_base"`
	WASMConfidentialStorageRemoveBase uint64 `json:"wasm_confidential_storage_remove_base"`
	WASMConfidentialStorageKeyByte    uint64 `json:"wasm_confidential_storage_key_byte"`
	WASMConfidentialStorageValueByte  uint64 `json:"wasm_confidential_storage_value_byte"`
	WASMEnvQueryBase                  uint64 `json:"wasm_env_query_base"`

	WASMCryptoECDSARecover             uint64 `json:"wasm_crypto_ecdsa_recover"`
	WASMCryptoSignatureVerifyEd25519   uint64 `json:"wasm_crypto_signature_verify_ed25519"`
	WASMCryptoSignatureVerifySecp256k1 uint64 `json:"wasm_crypto_signature_verify_secp256k1"`
	WASMCryptoSignatureVerifySr25519   uint64 `json:"wasm_crypto_signature_verify_sr25519"`
	WASMCryptoX25519DeriveSymmetric    uint64 `json:"wasm_crypto_x25519_derive_symmetric"`
	WASMCryptoDeoxysIIBase             uint64 `json:"wasm_crypto_deoxysii_base"`
	WASMCryptoDeoxysIIByte             uint64 `json:"wasm_crypto_deoxysii_byte"`
	WASMCryptoRandomBytesBase          uint64 `json:"wasm_crypto_random_bytes_base"`
	WASMCryptoRandomBytesByte          uint64 `json:"wasm_crypto_random_bytes_byte"`
}

GasCosts are the contracts module gas costs.

type Instance

type Instance struct {
	// ID is the unique instance identifier.
	ID InstanceID `json:"id"`
	// CodeID is the identifier of code used by the instance.
	CodeID CodeID `json:"code_id"`
	// Creator is the instance creator address.
	Creator types.Address `json:"creator"`
	// UpgradesPolicy is the policy on who is allowed to upgrade this instance.
	UpgradesPolicy Policy `json:"upgrades_policy"`
}

Instance is deployed code instance information.

type InstanceID

type InstanceID uint64

InstanceID is the unique deployed code instance identifier.

func (*InstanceID) Address

func (i *InstanceID) Address() types.Address

Address returns address for the InstanceID.

type InstanceQuery

type InstanceQuery struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
}

InstanceQuery is the body of the contracts.Instance query.

type InstanceRawStorageQuery added in v0.3.0

type InstanceRawStorageQuery struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`

	// StoreKind is type of store to query.
	StoreKind StoreKind `json:"store_kind"`

	// Limit is the maximum number of items per page.
	Limit uint64 `json:"limit,omitempty"`

	// Offset is the number of skipped items.
	Offset uint64 `json:"offset,omitempty"`
}

InstanceRawStorageQuery is the body of the contracts.InstanceRawStorage query.

type InstanceRawStorageQueryResult added in v0.3.0

type InstanceRawStorageQueryResult struct {
	// Items is a list of key-value pairs in contract's public store.
	Items []InstanceStorageKeyValue `json:"items"`
}

InstanceRawStorageQueryResult is the result of the contracts.InstanceRawStorage query.

type InstanceStorageKeyValue added in v0.3.0

type InstanceStorageKeyValue struct {
	Key   []byte
	Value []byte
	// contains filtered or unexported fields
}

InstanceStorageKeyValue is used as a tuple type for the contract storage.

type InstanceStorageQuery

type InstanceStorageQuery struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// Key is the storage key.
	Key []byte `json:"key"`
}

InstanceStorageQuery is the body of the contracts.InstanceStorage query.

type InstanceStorageQueryResult

type InstanceStorageQueryResult struct {
	// Value is the storage value or nil if key doesn't exist.
	Value []byte `json:"value"`
}

InstanceStorageQueryResult is the result of the contracts.InstanceStorage query.

type Instantiate

type Instantiate struct {
	// CodeID is the identifier of code used by the instance.
	CodeID CodeID `json:"code_id"`
	// UpgradesPolicy is the policy on who is allowed to upgrade this instance.
	UpgradesPolicy Policy `json:"upgrades_policy"`
	// Data are the arguments to contract's instantiation function.
	Data []byte `json:"data"`
	// Tokens that should be sent to the contract as part of the instantiate call.
	Tokens []types.BaseUnits `json:"tokens"`
}

Instantiate is the body of the contracts.Instantiate call.

type InstantiateResult

type InstantiateResult struct {
	// ID is the assigned instance identifier.
	ID InstanceID `json:"id"`
}

InstantiateResult is the result of the contracts.Instantiate call.

type Parameters

type Parameters struct {
	MaxCodeSize    uint32 `json:"max_code_size"`
	MaxStackSize   uint32 `json:"max_stack_size"`
	MaxMemoryPages uint32 `json:"max_memory_pages"`

	MaxWASMFunctions uint32 `json:"max_wasm_functions"`
	MaxWASMLocals    uint32 `json:"max_wasm_locals"`

	MaxSubcallDepth uint16 `json:"max_subcall_depth"`
	MaxSubcallCount uint16 `json:"max_subcall_count"`

	MaxResultSizeBytes                       uint32 `json:"max_result_size_bytes"`
	MaxQuerySizeBytes                        uint32 `json:"max_query_size_bytes"`
	MaxStorageKeySizeBytes                   uint32 `json:"max_storage_key_size_bytes"`
	MaxStorageValueSizeBytes                 uint32 `json:"max_storage_value_size_bytes"`
	MaxCryptoSignatureVerifyMessageSizeBytes uint32 `json:"max_crypto_signature_verify_message_size_bytes"`

	GasCosts GasCosts `json:"gas_costs"`
}

Parameters are the parameters for the contracts module.

type Policy

type Policy struct {
	Nobody   *struct{}      `json:"nobody,omitempty"`
	Address  *types.Address `json:"address,omitempty"`
	Everyone *struct{}      `json:"everyone,omitempty"`
}

Policy is a generic policy that specifies who is allowed to perform an action.

type PublicKeyKind

type PublicKeyKind uint8

PublicKeyKind is the public key kind.

type PublicKeyQuery

type PublicKeyQuery struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// Kind is the public key kind.
	Kind PublicKeyKind `json:"kind"`
}

PublicKeyQuery is the body of the contracts.PublicKey query.

type PublicKeyQueryResult

type PublicKeyQueryResult struct {
	// Key is the public key.
	Key []byte `json:"key"`
	// Checksum of the key manager state.
	Checksum []byte `json:"checksum"`
	// Signature is the Sign(sk, (key || checksum)) from the key manager.
	Signature []byte `json:"signature"`
}

PublicKeyQueryResult is the result of the contracts.PublicKey query.

type StoreKind added in v0.3.0

type StoreKind uint32

StoreKind defines the public or confidential store type for performing queries.

const (
	StoreKindPublic       StoreKind = 0
	StoreKindConfidential StoreKind = 1
)

These constants represent the kinds of store that the queries support.

func (StoreKind) MarshalText added in v0.3.0

func (sk StoreKind) MarshalText() (data []byte, err error)

MarshalText returns human-readable name of StoreKind.

func (*StoreKind) UnmarshalText added in v0.3.0

func (sk *StoreKind) UnmarshalText(s []byte) error

UnmarshalText converts human-readable name of store kind to StoreKind.

type Upgrade

type Upgrade struct {
	// ID is the instance identifier.
	ID InstanceID `json:"id"`
	// CodeID is the identifier of updated code to be used by the instance.
	CodeID CodeID `json:"code_id"`
	// Data are the arguments to contract's instantiation function.
	Data []byte `json:"data"`
	// Tokens that should be sent to the contract as part of the upgrade call.
	Tokens []types.BaseUnits `json:"tokens"`
}

Upgrade is the body of the contracts.Upgrade call.

type Upload

type Upload struct {
	// ABI.
	ABI ABI `json:"abi"`
	// InstantiatePolicy is the policy on Who is allowed to instantiate this code.
	InstantiatePolicy Policy `json:"instantiate_policy"`
	// Code is the compressed compiled contract code.
	Code []byte `json:"code"`
}

Upload is the body of the contracts.Upload call.

type UploadResult

type UploadResult struct {
	// ID is the assigned code identifier.
	ID CodeID `json:"id"`
}

UploadResult is the result of the contracts.Upload call.

type V1

type V1 interface {
	client.EventDecoder

	// Upload generates a contracts.Upload transaction.
	Upload(abi ABI, instantiatePolicy Policy, code []byte) *client.TransactionBuilder

	// InstantiateRaw generates a contracts.Instantiate transaction.
	//
	// This method allows specifying an arbitrary data payload. If the contract is using the Oasis
	// ABI you can use the regular Call method as convenience since it will perform the CBOR
	// serialization automatically.
	InstantiateRaw(codeID CodeID, upgradesPolicy Policy, data []byte, tokens []types.BaseUnits) *client.TransactionBuilder

	// Instantiate generates a contracts.Instantiate transaction.
	//
	// This method will encode the specified data using CBOR as defined by the Oasis ABI.
	Instantiate(codeID CodeID, upgradesPolicy Policy, data interface{}, tokens []types.BaseUnits) *client.TransactionBuilder

	// CallRaw generates a contracts.Call transaction.
	//
	// This method allows specifying an arbitrary data payload. If the contract is using the Oasis
	// ABI you can use the regular Call method as convenience since it will perform the CBOR
	// serialization automatically.
	CallRaw(id InstanceID, data []byte, tokens []types.BaseUnits) *client.TransactionBuilder

	// Call generates a contracts.Call transaction.
	//
	// This method will encode the specified data using CBOR as defined by the Oasis ABI.
	Call(id InstanceID, data interface{}, tokens []types.BaseUnits) *client.TransactionBuilder

	// UpgradeRaw generates a contracts.Upgrade transaction.
	//
	// This method allows specifying an arbitrary data payload. If the contract is using the Oasis
	// ABI you can use the regular Upgrade method as convenience since it will perform the CBOR
	// serialization automatically.
	UpgradeRaw(id InstanceID, codeID CodeID, data []byte, tokens []types.BaseUnits) *client.TransactionBuilder

	// Upgrade generates a contracts.Upgrade transaction.
	//
	// This method will encode the specified data using CBOR as defined by the Oasis ABI.
	Upgrade(id InstanceID, codeID CodeID, data interface{}, tokens []types.BaseUnits) *client.TransactionBuilder

	// ChangeUpgradePolicy generates a contracts.ChangeUpgradePolicy transaction.
	ChangeUpgradePolicy(id InstanceID, upgradesPolicy Policy) *client.TransactionBuilder

	// Code queries the given code information.
	Code(ctx context.Context, round uint64, id CodeID) (*Code, error)

	// CodeStorage queries the given code's storage.
	CodeStorage(ctx context.Context, round uint64, id CodeID) (*CodeStorageQueryResult, error)

	// Instance queries the given instance information.
	Instance(ctx context.Context, round uint64, id InstanceID) (*Instance, error)

	// InstanceStorage queries the given instance's public storage.
	InstanceStorage(ctx context.Context, round uint64, id InstanceID, key []byte) (*InstanceStorageQueryResult, error)

	// InstanceRawStorage returns the key-value pairs of contract instance storage.
	InstanceRawStorage(ctx context.Context, round uint64, id InstanceID, kind StoreKind, limit, offset uint64) (*InstanceRawStorageQueryResult, error)

	// PublicKey queries the given instance's public key.
	PublicKey(ctx context.Context, round uint64, id InstanceID, kind PublicKeyKind) (*PublicKeyQueryResult, error)

	// CustomRaw queries the given contract for a custom query.
	//
	// This method allows specifying an arbitrary data payload. If the contract is using the Oasis
	// ABI you can use the regular Custom method as convenience since it will perform the CBOR
	// serialization automatically.
	CustomRaw(ctx context.Context, round uint64, id InstanceID, data []byte) ([]byte, error)

	// Custom queries the given contract for a custom query.
	//
	// This method will encode the specified data using CBOR as defined by the Oasis ABI.
	Custom(ctx context.Context, round uint64, id InstanceID, data, rsp interface{}) error

	// Parameters queries the EVM module parameters.
	Parameters(ctx context.Context, round uint64) (*Parameters, error)

	// GetEvents returns events emitted by the contract at the provided round.
	GetEvents(ctx context.Context, instanceID InstanceID, round uint64) ([]*Event, error)
}

V1 is the v1 contracts module interface.

func NewV1

func NewV1(rc client.RuntimeClient) V1

NewV1 generates a V1 client helper for the contracts module.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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