Skip to content

Commit

Permalink
Revert "fix: execute cosmos message during evm session (#123)" (#145)
Browse files Browse the repository at this point in the history
* Revert "fix: execute cosmos message during evm session (#123)"

This reverts commit 43d4784.

* keep bug fix

* use same sol version
  • Loading branch information
beer-1 authored Jan 21, 2025
1 parent 4eccfea commit 39d0fc7
Show file tree
Hide file tree
Showing 31 changed files with 751 additions and 267 deletions.
121 changes: 82 additions & 39 deletions x/evm/contracts/counter/Counter.go

Large diffs are not rendered by default.

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

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

constructor() payable {}
Expand Down Expand Up @@ -47,19 +47,27 @@ contract Counter is IIBCAsyncCallback {
return COSMOS_CONTRACT.query_cosmos(path, req);
}

function execute_cosmos(
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(
string memory exec_msg,
bool try_catch
bool allow_failure,
uint64 callback_id
) external {
if (try_catch) {
try COSMOS_CONTRACT.execute_cosmos(exec_msg) {
emit execute_reverted(false);
} catch {
emit execute_reverted(true);
}
} else {
COSMOS_CONTRACT.execute_cosmos(exec_msg);
}
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) {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/contracts/erc165/ERC165.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.25;

import {IERC165} from "../i_erc165/IERC165.sol";

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_registry/ERC20Registry.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_wrapper/ERC20Wrapper.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/contracts/erc721/ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.20;
pragma solidity ^0.8.25;

import {IERC721, IERC721Metadata, IERC721Errors, IERC721Receiver} from "../i_erc721/IERC721.sol";
import {IERC165, ERC165} from "../erc165/ERC165.sol";
Expand Down
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.

31 changes: 31 additions & 0 deletions x/evm/contracts/i_cosmos/ICosmos.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface ICosmos {
) external returns (address erc20_address);

// record a cosmos message to be executed after the current message execution.
// - if execution fails, whole transaction will be reverted.
//
// `msg` format (json string):
// {
Expand All @@ -60,6 +61,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 queries.
//
// example)
Expand Down
Loading

0 comments on commit 39d0fc7

Please sign in to comment.