Skip to content

Commit

Permalink
Get contract address from tx response events
Browse files Browse the repository at this point in the history
  • Loading branch information
stiiifff committed Nov 7, 2024
1 parent 510c60a commit 6872fc4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions local-interchain/rust/localic-std/src/modules/cosmwasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn get_contract_address(rb: &ChainRequestBuilder, tx_hash: &str) -> Result<S
}

fn get_contract(rb: &ChainRequestBuilder, tx_hash: &str) -> Result<String, LocalError> {
let res = rb.query_tx_hash(tx_hash);
let mut res = rb.query_tx_hash(tx_hash);

let code = res["code"].as_i64().unwrap_or_default();
if code != 0 {
Expand All @@ -298,7 +298,13 @@ fn get_contract(rb: &ChainRequestBuilder, tx_hash: &str) -> Result<String, Local
});
}

for event in res["logs"][0]["events"].as_array().iter() {
let mut tx_logs = res["logs"].take();
let events = tx_logs
.as_array_mut()
.and_then(|logs| logs.first_mut())
.map_or_else(|| res["events"].take(), |log| log["events"].take());

for event in events.as_array().into_iter() {
for attr in event.iter() {
for attr_values in attr["attributes"].as_array().iter() {
for attr in attr_values.iter() {
Expand Down

0 comments on commit 6872fc4

Please sign in to comment.