Skip to content

Commit

Permalink
add option to execute cosmos message with options
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 29, 2024
1 parent 0ff2791 commit dfd0c4d
Show file tree
Hide file tree
Showing 21 changed files with 1,009 additions and 64 deletions.
315 changes: 313 additions & 2 deletions x/evm/contracts/counter/Counter.go

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions x/evm/contracts/counter/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ contract Counter is IIBCAsyncCallback {
uint256 public count;

event increased(uint256 oldCount, uint256 newCount);
event callback_received(uint64 callback_id, bool success);
event recursive_called(uint64 n);

constructor() payable {}

Expand Down Expand Up @@ -37,22 +39,36 @@ contract Counter is IIBCAsyncCallback {
return COSMOS_CONTRACT.query_cosmos(path, req);
}

function execute_cosmos(
string memory exec_msg,
bool call_revert
) external {
function execute_cosmos(string memory exec_msg, bool call_revert) external {
COSMOS_CONTRACT.execute_cosmos(exec_msg);

if (call_revert) {
revert("revert");
}
}

function execute_cosmos_with_options(
string memory exec_msg,
bool allow_failure,
uint64 callback_id
) external {
COSMOS_CONTRACT.execute_cosmos_with_options(
exec_msg,
ICosmos.Options(allow_failure, callback_id)
);
}

function callback(uint64 callback_id, bool success) external {
emit callback_received(callback_id, success);
}

function get_blockhash(uint64 n) external view returns (bytes32) {
return blockhash(n);
}

function recursive(uint64 n) public {
emit recursive_called(n);

if (n == 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion x/evm/contracts/erc20/ERC20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/contracts/erc20_acl/ERC20ACL.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/evm/contracts/erc20_factory/ERC20Factory.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/contracts/erc20_wrapper/ERC20Wrapper.go

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion x/evm/contracts/i_cosmos/ICosmos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 39 additions & 5 deletions x/evm/contracts/i_cosmos/ICosmos.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ ICosmos constant COSMOS_CONTRACT = ICosmos(COSMOS_ADDRESS);

interface ICosmos {
// check if an address is blocked in bank module
function is_blocked_address(address account) external view returns (bool blocked);
function is_blocked_address(
address account
) external view returns (bool blocked);

// check if an address is a module account
function is_module_address(address account) external view returns (bool module);
function is_module_address(
address account
) external view returns (bool module);

// convert an EVM address to a Cosmos address
function to_cosmos_address(
Expand All @@ -34,10 +38,10 @@ interface ICosmos {
string memory denom
) external returns (address erc20_address);

// record a cosmos message to be executed
// after the current message execution.
// record a cosmos message to be executed after the current message execution.
// - if execution fails, whole transaction will be reverted.
//
// msg should be in json string format like:
// `msg` format (json string):
// {
// "@type": "/cosmos.bank.v1beta1.MsgSend",
// "from_address": "init13vhzmdmzsqlxkdzvygue9zjtpzedz7j87c62q4",
Expand All @@ -52,6 +56,36 @@ interface ICosmos {
//
function execute_cosmos(string memory msg) external returns (bool dummy);

// @args
// - `allow_failure`: if `true`, the transaction will not be reverted even if the execution fails.
// - `callback_id`: the callback id to be called after the execution. `0` means no callback.
struct Options {
bool allow_failure;
uint64 callback_id;
}

// record a cosmos message to be executed after the current message execution.
//
// `msg` format (json string):
// {
// "@type": "/cosmos.bank.v1beta1.MsgSend",
// "from_address": "init13vhzmdmzsqlxkdzvygue9zjtpzedz7j87c62q4",
// "to_address": "init1enjh88u7c9s08fgdu28wj6umz94cetjy0hpcxf",
// "amount": [
// {
// "denom": "stake",
// "amount": "100"
// }
// ]
// }
//
// `callback` function signature in the caller contract (see ICosmosCallback.sol):
// - function callback(uint64 callback_id, bool success) external;
function execute_cosmos_with_options(
string memory msg,
Options memory options
) external returns (bool dummy);

// query a whitelisted cosmos querys.
//
// example)
Expand Down
Loading

0 comments on commit dfd0c4d

Please sign in to comment.