Skip to content

Commit

Permalink
feat: update dynamic caller contract to use interface detection and
Browse files Browse the repository at this point in the history
update contracts depending cosmwasm
  • Loading branch information
loloicci committed Sep 29, 2022
1 parent e931134 commit 64c9263
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/burner/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/call-number/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/call-number/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
schemars = "0.8.1"
serde = { version = "1.0.125", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.24" }
wasmer-types = { version = "1.0.2", features = ["enable-serde"] }

[dev-dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
1 change: 1 addition & 0 deletions contracts/crypto-verify/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/dynamic-callee-contract/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/dynamic-callee-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
schemars = "0.8.1"
serde = { version = "1.0.125", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.24" }
wasmer-types = { version = "1.0.2", features = ["enable-serde"] }

[dev-dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
1 change: 1 addition & 0 deletions contracts/dynamic-caller-contract/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/dynamic-caller-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cosmwasm-storage = { path = "../../packages/storage", features = ["iterator"] }
schemars = "0.8.1"
serde = { version = "1.0.125", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.24" }
wasmer-types = { version = "1.0.2", features = ["enable-serde"] }

[dev-dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
28 changes: 27 additions & 1 deletion contracts/dynamic-caller-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl Callee for CalleeContract {
fn do_panic(&self) {
panic!()
}

fn validate_interface(&self, _deps: Deps) -> cosmwasm_std::StdResult<()> {
Ok(())
}
}

// Note, you can use StdResult in some functions where you do not
Expand Down Expand Up @@ -96,11 +100,13 @@ pub fn execute(
ExecuteMsg::Ping { ping_num } => try_ping(deps, ping_num),
ExecuteMsg::TryReEntrancy {} => try_re_entrancy(deps, env),
ExecuteMsg::DoPanic {} => try_do_panic(deps, env),
ExecuteMsg::ValidateInterface {} => try_validate_interface(deps.as_ref(), env),
ExecuteMsg::ValidateInterfaceErr {} => try_validate_interface_err(deps.as_ref(), env),
}
}

pub fn try_ping(deps: DepsMut, ping_num: Uint128) -> Result<Response, ContractError> {
let address = from_slice(&deps.storage.get(b"dynamic_callee_contract").unwrap())?;
let address: Addr = from_slice(&deps.storage.get(b"dynamic_callee_contract").unwrap())?;
let contract = CalleeContract { address };
let pong_ret = contract.pong(ping_num.u128() as u64);
let struct_ret = contract.pong_with_struct(ExampleStruct {
Expand Down Expand Up @@ -144,6 +150,26 @@ pub fn try_do_panic(deps: DepsMut, _env: Env) -> Result<Response, ContractError>
Ok(Response::default())
}

pub fn try_validate_interface(deps: Deps, _env: Env) -> Result<Response, ContractError> {
let address = from_slice(&deps.storage.get(b"dynamic_callee_contract").unwrap())?;
let contract = CalleeContract { address };
contract.validate_interface(deps)?;
Ok(Response::default())
}

// should error
pub fn try_validate_interface_err(deps: Deps, _env: Env) -> Result<Response, ContractError> {
let address = from_slice(&deps.storage.get(b"dynamic_callee_contract").unwrap())?;
let err_interface: Vec<wasmer_types::ExportType<wasmer_types::FunctionType>> =
vec![wasmer_types::ExportType::new(
"not_exist",
([wasmer_types::Type::I32], [wasmer_types::Type::I32]).into(),
)];
deps.api
.validate_dynamic_link_interface(&address, &err_interface)?;
Ok(Response::default())
}

#[callable_point]
fn should_never_be_called(_deps: Deps, _env: Env) {}

Expand Down
2 changes: 2 additions & 0 deletions contracts/dynamic-caller-contract/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum ExecuteMsg {
Ping { ping_num: Uint128 },
TryReEntrancy {},
DoPanic {},
ValidateInterface {},
ValidateInterfaceErr {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down
1 change: 1 addition & 0 deletions contracts/hackatom/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/ibc-reflect-send/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/ibc-reflect/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/number/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/queue/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/reflect/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/staking/Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/voting-with-uuid/Cargo.lock

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

0 comments on commit 64c9263

Please sign in to comment.