Skip to content

Commit

Permalink
XC-253: Handle UtxosFilterInRequest::min_confirmation in Bitcoin cani…
Browse files Browse the repository at this point in the history
…ster mock
  • Loading branch information
lpahlavi committed Dec 3, 2024
1 parent 38ec6a7 commit f3c2cc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 14 additions & 9 deletions rs/bitcoin/ckbtc/minter/src/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,27 @@ fn cdk_network(network: Network) -> BitcoinNetwork {
fn cdk_get_utxos_request(
request: GetUtxosRequest,
) -> ic_cdk::api::management_canister::bitcoin::GetUtxosRequest {
use ic_btc_interface::NetworkInRequest::{
mainnet, regtest, testnet, Mainnet, Regtest, Testnet,
};
ic_cdk::api::management_canister::bitcoin::GetUtxosRequest {
address: request.address,
network: match request.network {
Mainnet | mainnet => BitcoinNetwork::Mainnet,
Testnet | testnet => BitcoinNetwork::Testnet,
Regtest | regtest => BitcoinNetwork::Regtest,
},
filter: request.filter.map(|filter| match filter {
UtxosFilterInRequest::MinConfirmations(confirmations)
| UtxosFilterInRequest::min_confirmations(confirmations) => {
UtxoFilter::MinConfirmations(confirmations)
}
UtxosFilterInRequest::Page(bytes) | UtxosFilterInRequest::page(bytes) => {
UtxoFilter::Page(bytes.into_vec())
}
}),
filter: request.filter.map(cdk_utxo_filter),
}
}

fn cdk_utxo_filter(filter: UtxosFilterInRequest) -> UtxoFilter {
use UtxosFilterInRequest::{min_confirmations, page, MinConfirmations, Page};
match filter {
MinConfirmations(confirmations) | min_confirmations(confirmations) => {
UtxoFilter::MinConfirmations(confirmations)
}
Page(bytes) | page(bytes) => UtxoFilter::Page(bytes.into_vec()),
}
}

Expand Down
12 changes: 8 additions & 4 deletions rs/bitcoin/mock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ fn bitcoin_get_utxos(utxos_request: GetUtxosRequest) -> GetUtxosResponse {
.cloned()
.collect::<Vec<Utxo>>();

if let Some(UtxosFilterInRequest::MinConfirmations(min_confirmations)) =
utxos_request.filter
{
utxos.retain(|u| s.tip_height + 1 >= u.height + min_confirmations);
match utxos_request.filter {
Some(UtxosFilterInRequest::MinConfirmations(min_confirmations))
| Some(UtxosFilterInRequest::min_confirmations(min_confirmations)) => {
utxos.retain(|u| s.tip_height + 1 >= u.height + min_confirmations)
}
// Some(UtxosFilterInRequest::Page(_))
// None => {}
_ => {}
}

GetUtxosResponse {
Expand Down

0 comments on commit f3c2cc5

Please sign in to comment.