When interacting with Bitcoin canisters, you can choose between two types of inter-canister calls:
- Bounded-wait: Most functions in this crate use bounded-wait calls because they are primarily used for reading state. This is the default behavior for most helper functions.
- Unbounded-wait: Required for functions that involve state changes or longer processing times. The
bitcoin_send_transaction function is the only one in this crate that uses unbounded-wait by default.
If you need to override the default behavior (e.g., performing an unbounded-wait call for a read operation like bitcoin_get_utxos), you can use the ic_cdk::call::Call struct directly.
use ic_cdk_bitcoin_canister::{cost_get_utxos, get_bitcoin_canister_id, GetUtxosRequest, GetUtxosResponse, Network};
use ic_cdk::call::Call;
async fn example() -> ic_cdk::call::CallResult<GetUtxosResponse> {
let arg = GetUtxosRequest {
address: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq".to_string(),
network: Network::Mainnet.into(),
filter: None,
};
let canister_id = get_bitcoin_canister_id(Network::from(arg.network));
let cycles = cost_get_utxos(&arg);
let res: GetUtxosResponse = Call::unbounded_wait(canister_id, "bitcoin_get_utxos")
.with_arg(&arg)
.with_cycles(cycles)
.await?
.candid()?;
Ok(res)
}