Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to execute cosmos message with options #91

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
beer-1 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading