Documentation
¶
Index ¶
- type ContractKeeper
- func (k ContractKeeper) IBCOnAcknowledgementPacketCallback(ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, ...) error
- func (k ContractKeeper) IBCOnTimeoutPacketCallback(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, ...) error
- func (k ContractKeeper) IBCReceivePacketCallback(ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement, ...) error
- func (k ContractKeeper) IBCSendPacketCallback(cachedCtx sdk.Context, sourcePort string, sourceChannel string, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContractKeeper ¶
type ContractKeeper struct {
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper(authKeeper types.AccountKeeper, evmKeeper types.EVMKeeper, erc20Keeper types.ERC20Keeper) ContractKeeper
NewKeeper creates and initializes a new ContractKeeper instance.
The ContractKeeper manages cross-chain contract execution and handles IBC packet callbacks for smart contract interactions.
func (ContractKeeper) IBCOnAcknowledgementPacketCallback ¶
func (k ContractKeeper) IBCOnAcknowledgementPacketCallback( ctx sdk.Context, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, contractAddress, packetSenderAddress string, version string, ) error
IBCOnAcknowledgementPacketCallback handles IBC packet acknowledgement callbacks for cross-chain contract execution. This function is triggered when an IBC packet receives an acknowledgement from the destination chain, allowing contracts to react to successful or failed packet delivery.
The function performs the following operations: 1. Unmarshals and validates the IBC packet data 2. Extracts callback data from the packet (source-side callback) 3. Validates that no calldata is present (acknowledgement callbacks should not contain calldata) 4. Verifies the target contract exists and contains code 5. Calls the contract's onPacketAcknowledgement function with packet details 6. Manages gas consumption and validates gas limits
Returns:
- error: Returns nil on success, or an error if any step fails including:
- Packet data unmarshaling errors
- Invalid callback data or unexpected calldata presence
- Address parsing failures
- Contract validation failures (non-existent or no code)
- ABI loading errors
- EVM execution errors
- Gas limit exceeded errors
Contract Requirements:
- Must implement onPacketAcknowledgement(string calldata sourceChannel, string calldata sourcePort, uint64 sequence, bytes calldata data, bytes calldata acknowledgement) function
- Should handle both successful and failed acknowledgements appropriately
func (ContractKeeper) IBCOnTimeoutPacketCallback ¶
func (k ContractKeeper) IBCOnTimeoutPacketCallback( ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, contractAddress, packetSenderAddress string, version string, ) error
IBCOnTimeoutPacketCallback handles IBC packet timeout callbacks for cross-chain contract execution. This function is triggered when an IBC packet times out without receiving an acknowledgement, allowing contracts to handle timeout scenarios and perform cleanup or rollback operations.
The function performs the following operations: 1. Unmarshals and validates the IBC packet data 2. Extracts callback data from the packet (source-side callback) 3. Validates that no calldata is present (timeout callbacks should not contain calldata) 4. Sets up a cached context with proper gas metering for EVM execution 5. Verifies the target contract exists and contains code 6. Calls the contract's onPacketTimeout function with packet details 7. Manages gas consumption and validates gas limits 8. Commits the cached context changes back to the original context
Returns:
- error: Returns nil on success, or an error if any step fails including:
- Packet data unmarshaling errors
- Invalid callback data or unexpected calldata presence
- Address parsing failures
- Contract validation failures (non-existent or no code)
- ABI loading errors
- EVM execution errors
- Gas limit exceeded errors
Contract Requirements:
- Must implement onPacketTimeout(string calldata sourceChannel, string calldata sourcePort, uint64 sequence, bytes calldata data) function
- Should handle timeout scenarios appropriately (e.g., refunds, state rollbacks)
func (ContractKeeper) IBCReceivePacketCallback ¶
func (k ContractKeeper) IBCReceivePacketCallback( ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement, contractAddress string, version string, ) error
IBCReceivePacketCallback handles IBC packet callbacks for cross-chain contract execution. This function processes incoming IBC packets that contain callback data and executes the specified contract with the transferred tokens.
The function performs the following operations: 1. Unmarshals and validates the IBC packet data 2. Extracts callback data from the packet 3. Generates an isolated address for security 4. Validates the receiver address matches the isolated address 5. Verifies the target contract exists and contains code 6. Sets up ERC20 token allowance for the contract 7. Executes the callback function on the target contract 8. Validates that all tokens were successfully transferred to the contract
Returns:
- error: Returns nil on success, or an error if any step fails including:
- Packet data unmarshaling errors
- Invalid callback data
- Address validation failures
- Contract validation failures (non-existent or no code)
- Token pair registration errors
- EVM execution errors
- Gas limit exceeded errors
- Token transfer validation failures
Security Notes:
- Uses isolated addresses to prevent unauthorized access
- Validates contract existence to prevent fund loss
- Enforces gas limits to prevent DoS attacks
- Requires contracts to implement proper token transfer logic
- Validates final token balances to ensure successful transfers
func (ContractKeeper) IBCSendPacketCallback ¶
func (k ContractKeeper) IBCSendPacketCallback( cachedCtx sdk.Context, sourcePort string, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, packetData []byte, contractAddress, packetSenderAddress string, version string, ) error
IBCSendPacketCallback handles IBC packet send callbacks for cross-chain operations.
IMPORTANT: This callback is currently not supported and always returns nil. The rationale is that contracts can implement custom logic before the send packet operation is called, making this callback redundant or potentially conflicting with contract-defined behavior.