hello @dragoljub_duric ,
I updated the code, it works now. I’m able to fetch the bitcoin headers.
but I still get this error some times. (CanisterError, \\"IC0536: Management canister has no method 'bitcoin_get_block_headers'\\")
do you think, this error is due to calling management canister frequently in a short period of time?
If you are using Regtest the call should fail, because we do not have a Regtest Bitcoin canister (we only have Mainnet and Testnet). But since your request is passing, I guess you do not call with network = Regtest.
In that case, I will need more code in order to try to find the cause of this behavior.
pub(crate) async fn get_best_from_rpc() -> Result<(u32, BlockHash)> {
let url = get_url();
let hash = rpc::get_best_block_hash(&url).await?;
let header = rpc::get_block_header(&url, hash).await?;
log!(
INFO,
"printing after the line header, here is header: {:?}",
header
);
ic_cdk::println!("Am I getting printed?");
ic_cdk::println!("Header: {:?}", header);
Ok((header.height.try_into().expect("usize to u32"), hash))
}
@dragoljub_duric
This code if from ord_canister by omnity network. I’m modifying the code for running in my localhost with regtest mode for testing the application.
No, it is not possible.
If you are using ic_cdk::api::management_canister::bitcoin::BitcoinNetwork as I pointed out above, you should choose between Testnet and Mainnet.
As I’m running a bitcoin node locally, DFX already fetch the blocks from that node.
I’m running a server that uploads bitcoin blocks to the canister for filtering runes.
Skipping the block header check, might not cause that much issue, right?