Skip to content

Commit

Permalink
Add detailed error context for query_type_script
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm committed Jul 24, 2023
1 parent 9062bfa commit 8676c5a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/rpc-client/src/ckb_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,27 @@ impl CKBClient {
#[instrument(skip_all)]
pub async fn query_type_script(
&self,
_contract: &str,
contract: &str,
cell_dep: CellDep,
) -> Result<gw_jsonrpc_types::blockchain::Script> {
let tx_hash = &cell_dep.out_point.tx_hash;
let tx = self.get_transaction(tx_hash).await?;
let type_script = tx
.transaction
.context("transaction not found")?
.with_context(|| {
format!("transaction not found, contract={contract}, tx_hash={tx_hash}")
})?
.inner
.outputs
.get(cell_dep.out_point.index.value() as usize)
.cloned()
.context("output index not found")?
.with_context(|| {
format!("output index not found, contract={contract}, cell_dep={cell_dep:?}")
})?
.type_
.context("type script not found")?;
.with_context(|| {
format!("type script not found, contract={contract}, cell_dep={cell_dep:?}")
})?;
Ok(type_script.into())
}
}

0 comments on commit 8676c5a

Please sign in to comment.