compute

package
v1.4.1-beta.9 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: AGPL-3.0 Imports: 26 Imported by: 0

README

Wasm Module

This should be a brief overview of the functionality

Configuration

You can add the following section to config/app.toml. Below is shown with defaults:

[wasm]
# This is the maximum sdk gas (wasm and storage) that we allow for any x/compute "smart" queries
query_gas_limit = 300000
# This is the number of wasm vm instances we keep cached in memory for speed-up
contract-memory-enclave-cache-size = 0

Events

A number of events are returned to allow good indexing of the transactions from smart contracts.

Every call to Instantiate or Execute will be tagged with the info on the contract that was executed and who executed it. It should look something like this (with different addresses). The module is always wasm, and code_id is only present when Instantiating a contract, so you can subscribe to new instances, it is omitted on Execute. There is also an action tag which is auto-added by the Cosmos SDK and has a value of either store-code, instantiate or execute depending on which message was sent:

{
  "Type": "message",
  "Attr": [
    {
      "key": "module",
      "value": "wasm"
    },
    {
      "key": "action",
      "value": "instantiate"
    },
    {
      "key": "signer",
      "value": "secret1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"
    },
    {
      "key": "code_id",
      "value": "1"
    },
    {
      "key": "contract_address",
      "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
    }
  ]
}

If any funds were transferred to the contract as part of the message, or if the contract released funds as part of it's executions, it will receive the typical events associated with sending tokens from bank. In this case, we instantiate the contract and provide a initial balance in the same MsgInstantiateContract. We see the following events in addition to the above one:

[
  {
    "Type": "transfer",
    "Attr": [
      {
        "key": "recipient",
        "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
      },
      {
        "key": "sender",
        "value": "secret1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv"
      },
      {
        "key": "amount",
        "value": "100000denom"
      }
    ]
  }
]

Finally, the contract itself can emit a "custom event" on Execute only (not on Init). There is one event per contract, so if one contract calls a second contract, you may receive one event for the original contract and one for the re-invoked contract. All attributes from the contract are passed through verbatim, and we add a contract_address attribute that contains the actual contract that emitted that event. Here is an example from the escrow contract successfully releasing funds to the destination address:

{
  "Type": "wasm",
  "Attr": [
    {
      "key": "contract_address",
      "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
    },
    {
      "key": "action",
      "value": "release"
    },
    {
      "key": "destination",
      "value": "secret14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
    }
  ]
}
Pulling this all together

We will invoke an escrow contract to release to the designated beneficiary. The escrow was previously loaded with 100000denom (from the above example). In this transaction, we send 5000denom along with the MsgExecuteContract and the contract releases the entire funds (105000denom) to the beneficiary.

We will see all the following events, where you should be able to reconstruct the actions (remember there are two events for each transfer). We see (1) the initial transfer of funds to the contract, (2) the contract custom event that it released funds (3) the transfer of funds from the contract to the beneficiary and (4) the generic x/compute event stating that the contract was executed (which always appears, while 2 is optional and has information as reliable as the contract):

[
  {
    "Type": "transfer",
    "Attr": [
      {
        "key": "recipient",
        "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
      },
      {
        "key": "sender",
        "value": "secret1zm074khx32hqy20hlshlsd423n07pwlu9cpt37"
      },
      {
        "key": "amount",
        "value": "5000denom"
      }
    ]
  },
  {
    "Type": "wasm",
    "Attr": [
      {
        "key": "contract_address",
        "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
      },
      {
        "key": "action",
        "value": "release"
      },
      {
        "key": "destination",
        "value": "secret14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
      }
    ]
  },
  {
    "Type": "transfer",
    "Attr": [
      {
        "key": "recipient",
        "value": "secret14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
      },
      {
        "key": "sender",
        "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
      },
      {
        "key": "amount",
        "value": "105000denom"
      }
    ]
  },
  {
    "Type": "message",
    "Attr": [
      {
        "key": "module",
        "value": "wasm"
      },
      {
        "key": "action",
        "value": "execute"
      },
      {
        "key": "signer",
        "value": "secret1zm074khx32hqy20hlshlsd423n07pwlu9cpt37"
      },
      {
        "key": "contract_address",
        "value": "secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg"
      }
    ]
  }
]

A note on this format. This is what we return from our module. However, it seems to me that many events with the same Type get merged together somewhere along the stack, so in this case, you may end up with one "transfer" event with the info for both transfers. Double check when evaluating the event logs, I will document better with more experience, especially when I find out the entire path for the events.

Messages

TODO

CLI

TODO - working, but not the nicest interface (json + bash = bleh). Use to upload, but I suggest to focus on frontend / js tooling

Rest

TODO - main supported interface, under rapid change

Documentation

Overview

autogenerated code using github.com/rigelrozanski/multitool aliases generated for the following subdirectories: ALIASGEN: github.com/scrtlabs/SecretNetwork/x/compute/internal/types ALIASGEN: github.com/scrtlabs/SecretNetwork/x/compute/internal/keeper

Index

Constants

View Source
const (
	ModuleName                    = types.ModuleName
	StoreKey                      = types.StoreKey
	TStoreKey                     = types.TStoreKey
	QuerierRoute                  = types.QuerierRoute
	RouterKey                     = types.RouterKey
	MaxWasmSize                   = types.MaxWasmSize
	MaxLabelSize                  = types.MaxLabelSize
	BuildTagRegexp                = types.BuildTagRegexp
	MaxBuildTagSize               = types.MaxBuildTagSize
	CustomEventType               = types.CustomEventType
	AttributeKeyContractAddr      = types.AttributeKeyContractAddr
	GasMultiplier                 = types.GasMultiplier
	MaxGas                        = types.MaxGas
	QueryListContractByCode       = keeper.QueryListContractByCode
	QueryGetContract              = keeper.QueryGetContract
	QueryGetContractState         = keeper.QueryGetContractState
	QueryGetCode                  = keeper.QueryGetCode
	QueryListCode                 = keeper.QueryListCode
	QueryContractKey              = keeper.QueryContractKey
	QueryContractAddress          = keeper.QueryContractAddress
	QueryMethodContractStateSmart = keeper.QueryMethodContractStateSmart
	DefaultConfigTemplate         = types.DefaultConfigTemplate
)

Variables

View Source
var (
	// functions aliases
	// ConvertToProposals        = types.ConvertToProposals
	// DefaultParams             = types.DefaultParams
	RegisterCodec             = types.RegisterLegacyAminoCodec
	RegisterInterfaces        = types.RegisterInterfaces
	ValidateGenesis           = types.ValidateGenesis
	GetCodeKey                = types.GetCodeKey
	GetContractAddressKey     = types.GetContractAddressKey
	GetContractStorePrefixKey = types.GetContractStorePrefixKey
	NewCodeInfo               = types.NewCodeInfo
	NewAbsoluteTxPosition     = types.NewAbsoluteTxPosition
	NewContractInfo           = types.NewContractInfo
	NewEnv                    = types.NewEnv
	NewWasmCoins              = types.NewWasmCoins
	DefaultWasmConfig         = types.DefaultWasmConfig
	IsEncryptedError          = types.IsEncryptedErrorCode
	ErrContainsQueryError     = types.ErrContainsQueryError
	GetConfig                 = types.GetConfig
	InitGenesis               = keeper.InitGenesis
	ExportGenesis             = keeper.ExportGenesis
	NewMessageHandler         = keeper.NewMessageHandler
	DefaultEncoders           = keeper.DefaultEncoders
	EncodeBankMsg             = keeper.EncodeBankMsg
	NoCustomMsg               = keeper.NoCustomMsg
	EncodeStakingMsg          = keeper.EncodeStakingMsg
	EncodeWasmMsg             = keeper.EncodeWasmMsg
	NewKeeper                 = keeper.NewKeeper
	NewQuerier                = keeper.NewGrpcQuerier
	NewLegacyQuerier          = keeper.NewLegacyQuerier
	DefaultQueryPlugins       = keeper.DefaultQueryPlugins
	BankQuerier               = keeper.BankQuerier
	NoCustomQuerier           = keeper.NoCustomQuerier
	StakingQuerier            = keeper.StakingQuerier
	WasmQuerier               = keeper.WasmQuerier
	MakeTestCodec             = keeper.MakeTestCodec
	CreateTestInput           = keeper.CreateTestInput
	CreateFakeFundedAccount   = keeper.CreateFakeFundedAccount
	TestHandler               = keeper.TestHandler
	PrepareInitSignedTx       = keeper.PrepareInitSignedTx
	PrepareExecSignedTx       = keeper.PrepareExecSignedTx
	NewWasmSnapshotter        = keeper.NewWasmSnapshotter
	ContractFromPortID        = keeper.ContractFromPortID
	NewCountTXDecorator       = keeper.NewCountTXDecorator

	// variable aliases
	ModuleCdc            = types.ModuleCdc
	DefaultCodespace     = types.DefaultCodespace
	ErrCreateFailed      = types.ErrCreateFailed
	ErrAccountExists     = types.ErrAccountExists
	ErrInstantiateFailed = types.ErrInstantiateFailed
	ErrExecuteFailed     = types.ErrExecuteFailed
	ErrGasLimit          = types.ErrGasLimit
	ErrInvalidGenesis    = types.ErrInvalidGenesis
	ErrNotFound          = types.ErrNotFound
	ErrQueryFailed       = types.ErrQueryFailed
	ErrInvalidMsg        = types.ErrInvalidMsg
	KeyLastCodeID        = types.KeyLastCodeID
	KeyLastInstanceID    = types.KeyLastInstanceID
	CodeKeyPrefix        = types.CodeKeyPrefix
	ContractKeyPrefix    = types.ContractKeyPrefix
	ContractStorePrefix  = types.ContractStorePrefix
)

Functions

func NewHandler

func NewHandler(k Keeper) sdk.Handler

NewHandler returns a handler for "compute" type messages. We still need this legacy handler to pass reply info in the data field as the new grpc handler truncates the data field if there's an error this handler is only used here: https://github.com/scrtlabs/SecretNetwork/blob/d8492253/x/compute/internal/keeper/handler_plugin.go#L574-L582 As a reference point see the x/bank legacy msg handler which just wraps the new grpc handler https://github.com/scrtlabs/cosmos-sdk/blob/67c2d41286/x/bank/handler.go#L10-L30

func ValidateChannelParams

func ValidateChannelParams(channelID string) error

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module for the compute module.

func NewAppModule

func NewAppModule(keeper Keeper) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the compute module.

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

ConsensusVersion implements AppModule/ConsensusVersion.

func (AppModule) EndBlock

EndBlock returns the end blocker for the compute module. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the compute module.

func (AppModule) GenerateGenesisState

func (AppModule) GenerateGenesisState(simState *module.SimulationState)

GenerateGenesisState creates a randomized GenState of the bank module.

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the compute module. It returns no validator updates.

func (AppModule) LegacyQuerierHandler

func (am AppModule) LegacyQuerierHandler(amino *codec.LegacyAmino) sdk.Querier

func (AppModule) ProposalContents

func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent

ProposalContents doesn't return any content functions for governance proposals.

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the compute module's querier route name.

func (AppModule) RandomizedParams

func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange

RandomizedParams creates randomized bank param changes for the simulator.

func (AppModule) RegisterInvariants

func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry)

RegisterInvariants registers the compute module invariants.

func (AppModule) RegisterServices

func (am AppModule) RegisterServices(configurator module.Configurator)

func (AppModule) RegisterStoreDecoder

func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry)

RegisterStoreDecoder registers a decoder for supply module's types

func (AppModule) Route

func (am AppModule) Route() sdk.Route

Route returns the message routing key for the compute module.

func (AppModule) WeightedOperations

func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation

WeightedOperations returns the all the gov module operations with their respective weights.

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the basic application module used by the compute module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the compute module.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd() *cobra.Command

GetQueryCmd returns no root query command for the compute module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd() *cobra.Command

GetTxCmd returns the root tx command for the compute module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the compute module's name.

func (AppModuleBasic) RegisterGRPCGatewayRoutes

func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, serveMux *runtime.ServeMux)

func (AppModuleBasic) RegisterInterfaces

func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)

RegisterInterfaceTypes implements InterfaceModule

func (AppModuleBasic) RegisterLegacyAminoCodec

func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino)

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the compute module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error

ValidateGenesis performs genesis state validation for the compute module.

type BankEncoder

type BankEncoder = keeper.BankEncoder

type Code

type Code = types.Code

type CodeInfo

type CodeInfo = types.CodeInfo

type CodeInfoResponse

type CodeInfoResponse = types.CodeInfoResponse

type Contract

type Contract = types.Contract

type ContractConfirmStateAck

type ContractConfirmStateAck []byte

func (ContractConfirmStateAck) Acknowledgement

func (w ContractConfirmStateAck) Acknowledgement() []byte

func (ContractConfirmStateAck) Success

func (w ContractConfirmStateAck) Success() bool

type ContractInfo

type ContractInfo = types.ContractInfo

type ContractInfoWithAddress

type ContractInfoWithAddress = types.ContractInfoWithAddress

type CreatedAt

type CreatedAt = types.AbsoluteTxPosition

type CustomEncoder

type CustomEncoder = keeper.CustomEncoder

type CustomQuerier

type CustomQuerier = keeper.CustomQuerier

type GenesisState

type GenesisState = types.GenesisState

ProposalType = types.ProposalType

type GovEncoder

type GovEncoder = keeper.GovEncoder

type IBCHandler

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

func (IBCHandler) OnAcknowledgementPacket

func (i IBCHandler) OnAcknowledgementPacket(
	ctx sdk.Context,
	packet channeltypes.Packet,
	acknowledgement []byte,
	relayer sdk.AccAddress,
) error

OnAcknowledgementPacket implements the IBCModule interface

func (IBCHandler) OnChanCloseConfirm

func (i IBCHandler) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error

OnChanCloseConfirm implements the IBCModule interface

func (IBCHandler) OnChanCloseInit

func (i IBCHandler) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error

OnChanCloseInit implements the IBCModule interface

func (IBCHandler) OnChanOpenAck

func (i IBCHandler) OnChanOpenAck(
	ctx sdk.Context,
	portID, channelID string,
	counterpartyChannelID string,
	counterpartyVersion string,
) error

OnChanOpenAck implements the IBCModule interface

func (IBCHandler) OnChanOpenConfirm

func (i IBCHandler) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error

OnChanOpenConfirm implements the IBCModule interface

func (IBCHandler) OnChanOpenInit

func (i IBCHandler) OnChanOpenInit(
	ctx sdk.Context,
	order channeltypes.Order,
	connectionHops []string,
	portID string,
	channelID string,
	chanCap *capabilitytypes.Capability,
	counterParty channeltypes.Counterparty,
	version string,
) error

OnChanOpenInit implements the IBCModule interface

func (IBCHandler) OnChanOpenTry

func (i IBCHandler) OnChanOpenTry(
	ctx sdk.Context,
	order channeltypes.Order,
	connectionHops []string,
	portID, channelID string,
	chanCap *capabilitytypes.Capability,
	counterParty channeltypes.Counterparty,
	counterpartyVersion string,
) (string, error)

OnChanOpenTry implements the IBCModule interface

func (IBCHandler) OnRecvPacket

func (i IBCHandler) OnRecvPacket(
	ctx sdk.Context,
	packet channeltypes.Packet,
	relayer sdk.AccAddress,
) ibcexported.Acknowledgement

OnRecvPacket implements the IBCModule interface

func (IBCHandler) OnTimeoutPacket

func (i IBCHandler) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error

OnTimeoutPacket implements the IBCModule interface

type Keeper

type Keeper = keeper.Keeper

type MessageEncoders

type MessageEncoders = keeper.MessageEncoders

type MessageHandler

type MessageHandler = keeper.SDKMessageHandler

type Model

type Model = types.Model

type MsgExecuteContract

type MsgExecuteContract = types.MsgExecuteContract

type MsgInstantiateContract

type MsgInstantiateContract = types.MsgInstantiateContract

type MsgStoreCode

type MsgStoreCode = types.MsgStoreCode

type QueryHandler

type QueryHandler = keeper.QueryHandler

type QueryPlugins

type QueryPlugins = keeper.QueryPlugins

type StakingEncoder

type StakingEncoder = keeper.StakingEncoder

type WasmConfig

type WasmConfig = types.WasmConfig

type WasmEncoder

type WasmEncoder = keeper.WasmEncoder

Directories

Path Synopsis
client
cli
internal
types
Package types is a reverse proxy.
Package types is a reverse proxy.
legacy
migrations
v1
v2

Jump to

Keyboard shortcuts

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