Skip to content

Commit

Permalink
execute cosmos message during evm session
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 27, 2024
1 parent 873b1fd commit d787121
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 707 deletions.
64 changes: 11 additions & 53 deletions x/evm/contracts/counter/Counter.go

Large diffs are not rendered by default.

30 changes: 11 additions & 19 deletions x/evm/contracts/counter/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,19 @@ contract Counter is IIBCAsyncCallback {
return COSMOS_CONTRACT.query_cosmos(path, req);
}

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

if (call_revert) {
revert("revert reason dummy value for test");
}
}

function execute_cosmos_with_options(
function execute_cosmos(
string memory exec_msg,
bool allow_failure,
uint64 callback_id
bool try_catch
) 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);
if (try_catch) {
try COSMOS_CONTRACT.execute_cosmos(exec_msg) {
// do nothing
} catch {
// do nothing
}
} else {
COSMOS_CONTRACT.execute_cosmos(exec_msg);
}
}

function get_blockhash(uint64 n) external view returns (bytes32) {
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: 1 addition & 28 deletions x/evm/contracts/i_cosmos/ICosmos.go

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

30 changes: 0 additions & 30 deletions x/evm/contracts/i_cosmos/ICosmos.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,6 @@ 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 queries.
//
// example)
Expand Down
Loading

0 comments on commit d787121

Please sign in to comment.