keeper

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: LGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrevRegisteredSmartContract = sdkerrors.Register(types.ModuleName, 2000, "You cannot register a smart contract that was previously registered")
	ErrFeeDistribution             = sdkerrors.Register(types.ModuleName, 2001, "There was an error sending fees from the fee collector to NFT")
	ErrContractDeployments         = sdkerrors.Register(types.ModuleName, 2004, "There was an error deploying a contract from the CSR module")
	ErrMethodCall                  = sdkerrors.Register(types.ModuleName, 2005, "There was an error calling a method on a smart contract from the module account")
	ErrRegisterInvalidContract     = sdkerrors.Register(types.ModuleName, 2007, "Register/update must have a valid smart contract address entered")
	ErrNonexistentAcct             = sdkerrors.Register(types.ModuleName, 2008, "The recipient of a register event must be an EOA that exists")
	ErrNonexistentCSR              = sdkerrors.Register(types.ModuleName, 2009, "The CSR that was queried does not currently exist")
	ErrNFTNotFound                 = sdkerrors.Register(types.ModuleName, 2010, "The NFT that was queried does not currently exist")
	ErrDuplicateNFTID              = sdkerrors.Register(types.ModuleName, 2011, "There cannot be duplicate NFT IDs passed into a register event")
)

x/csr module sentinel errors

View Source
var DefaultGasLimit uint64 = 30000000

Default gas limit for eth txs from the module account

View Source
var (
	TurnstileContract abi.ABI = contracts.TurnstileContract.ABI
)

Functions

func BytesToUInt64

func BytesToUInt64(bz []byte) uint64

Converts a []byte into a uint64

func UInt64ToBytes

func UInt64ToBytes(number uint64) []byte

Converts a uint64 to a []byte

Types

type Hooks

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

Hooks wrapper struct for fees keeper

func (Hooks) PostTxProcessing

func (h Hooks) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error

The PostTxProcessing hook implements EvmHooks.PostTxProcessing. The EVM hook allows users to utilize the Turnstile smart contract to register and assign smart contracts to a CSR NFT + distribute transaction fees for contracts that are already registered to some NFT. After each successful EVM transaction, the PostTxProcessing hook will check if any of the events emitted in the tx originate from the Turnstile address. If some event does exist, the event handler will process and update state accordingly. At the very end of the hook, the hook will check if the To address in the tx belongs to any NFT currently in state. If so, the fees will be split and distributed to the Turnstile Address / NFT.

type Keeper

type Keeper struct {
	FeeCollectorName string
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey sdk.StoreKey,
	ps paramtypes.Subspace,
	accountKeeper types.AccountKeeper,
	evmKeeper types.EVMKeeper,
	bankKeeper types.BankKeeper,
	FeeCollectorName string,
) Keeper

func (Keeper) CSRByContract

CSRByContract returns the CSR associated with a given smart contracted address passed into the request. This will return nil if the smart contract address does not match up to any CSR

func (Keeper) CSRByNFT

CSRByNFT returns the CSR associated with a given NFT ID passed into the request. This will return nil if the NFT does not match up to any CSR

func (Keeper) CSRs

CSRs returns all of the CSRs in the CSR module with optional pagination

func (Keeper) CallEVM

func (k Keeper) CallEVM(
	ctx sdk.Context,
	from common.Address,
	to *common.Address,
	amount *big.Int,
	data []byte,
	commit bool,
) (*evmtypes.MsgEthereumTxResponse, error)

CallEVM performs a EVM transaction given the from address, the to address, amount to be sent, data and whether to commit the tx in the EVM keeper.

func (Keeper) CallMethod

func (k Keeper) CallMethod(
	ctx sdk.Context,
	method string,
	contract evmtypes.CompiledContract,
	from common.Address,
	contractAddr *common.Address,
	amount *big.Int,
	args ...interface{},
) (*evmtypes.MsgEthereumTxResponse, error)

CallMethod is a function to interact with a contract once it is deployed. It inputs the method name on the smart contract, the compiled smart contract, the address from which the tx will be made, the contract address, the amount to be supplied in msg.value, and finally an arbitrary number of arguments that should be supplied to the function method.

func (Keeper) DeployContract

func (k Keeper) DeployContract(
	ctx sdk.Context,
	contract evmtypes.CompiledContract,
	args ...interface{},
) (common.Address, error)

DeployContract will deploy an arbitrary smart-contract. It takes the compiled contract object as well as an arbitrary number of arguments which will be supplied to the contructor. All contracts deployed are deployed by the module account.

func (Keeper) DeployTurnstile

func (k Keeper) DeployTurnstile(
	ctx sdk.Context,
) (common.Address, error)

DeployTurnstile will deploy the Turnstile smart contract from the csr module account. This will allow the CSR module to interact with the CSR NFTs in a permissionless way.

func (Keeper) GetCSR

func (k Keeper) GetCSR(ctx sdk.Context, nftId uint64) (*types.CSR, bool)

Returns a CSR object given an NFT ID. If the ID is invalid, i.e. it does not exist, then GetCSR will return (nil, false). Otherwise (csr, true).

func (Keeper) GetDefaultParams

func (k Keeper) GetDefaultParams() types.Params

func (Keeper) GetNFTByContract

func (k Keeper) GetNFTByContract(ctx sdk.Context, address string) (uint64, bool)

Returns the NFT ID associated with a smart contract address. If the smart contract address entered does belong to some NFT, then it will return (id, true), otherwise (0, false).

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams get all parameters as types.Params

func (Keeper) GetTurnstile

func (k Keeper) GetTurnstile(ctx sdk.Context) (common.Address, bool)

Retrieves the deployed Turnstile Address from state if found.

func (Keeper) Hooks

func (k Keeper) Hooks() Hooks

Hooks return the wrapper hooks struct for the Keeper

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

func (Keeper) Params

Params returns the CSR module parameters

func (Keeper) RegisterEvent

func (k Keeper) RegisterEvent(ctx sdk.Context, data []byte) error

Register events occur in the Turnstile Contract when a user is attempting to create a new NFT with a smart contract that was just deployed. This event handler will unpack the event data, validate that the smart contract address, check that the receiver address is not null, and validate that this NFT is new. Only register can create new NFTs. Returns an error if the register event fails.

func (Keeper) SetCSR

func (k Keeper) SetCSR(ctx sdk.Context, csr types.CSR)

Set CSR will place a new or updated CSR into the store with the key being the NFT ID and the value being the marshalled CSR object (bytes). Additionally, every single smart contract address entered will get mapped to its NFT ID for easy reads and writes later.

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams set the params

func (Keeper) SetTurnstile

func (k Keeper) SetTurnstile(ctx sdk.Context, turnstile common.Address)

Sets the deployed Turnstile Address to state.

func (Keeper) Turnstile

Turnstile returns the turnstile address that was deployed by the module account. This function does not take in any request params.

func (Keeper) UpdateEvent

func (k Keeper) UpdateEvent(ctx sdk.Context, data []byte) error

Update events occur in the Turnstile contract when a user is attempting to assign their newly deployed smart contract to an existing NFT. This event handler will unpack the data, validate that the smart contract to be assigned is valid, check that NFT id exists, and append the smart contract to the NFT id entered. Update is permissionless in the sense that you do not have to be the owner of the NFT to be able to add new smart contracts to it.

func (Keeper) ValidateContract

func (k Keeper) ValidateContract(ctx sdk.Context, contract common.Address) error

ValidateContract checks if the smart contract can be registered to a CSR. It checks if the address is a smart contract address, whether the smart contract has code, and whether the contract is already assigned to some other NFT.

Jump to

Keyboard shortcuts

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