Skip to content
Snippets Groups Projects
Commit 46170ce1 authored by Éloïs's avatar Éloïs
Browse files

[feat] bca: add req BalancesOfScripts

parent d7a74ce1
No related branches found
No related tags found
No related merge requests found
...@@ -92,5 +92,8 @@ pub(super) async fn execute_req_type( ...@@ -92,5 +92,8 @@ pub(super) async fn execute_req_type(
)) ))
} }
BcaReqTypeV0::CurrentUd => current_ud::exec_req_current_ud(bca_executor).await, BcaReqTypeV0::CurrentUd => current_ud::exec_req_current_ud(bca_executor).await,
BcaReqTypeV0::BalancesOfScripts(scripts) => {
balances::exec_req_balances_of_scripts(bca_executor, scripts).await
}
} }
} }
...@@ -37,3 +37,25 @@ pub(super) async fn exec_req_balances_of_pubkeys( ...@@ -37,3 +37,25 @@ pub(super) async fn exec_req_balances_of_pubkeys(
.await??, .await??,
)) ))
} }
pub(super) async fn exec_req_balances_of_scripts(
bca_executor: &BcaExecutor,
scripts: ArrayVec<[WalletScriptV10; 16]>,
) -> Result<BcaRespTypeV0, ExecReqTypeError> {
let dbs_reader = bca_executor.dbs_reader();
Ok(BcaRespTypeV0::Balances(
bca_executor
.dbs_pool
.execute(move |_| {
scripts
.into_iter()
.map(|script| {
dbs_reader
.get_account_balance(&script)
.map(|balance_opt| balance_opt.map(|balance| balance.0))
})
.collect::<Result<ArrayVec<_>, _>>()
})
.await??,
))
}
...@@ -78,6 +78,7 @@ pub enum BcaReqTypeV0 { ...@@ -78,6 +78,7 @@ pub enum BcaReqTypeV0 {
SendTxs(Txs), SendTxs(Txs),
Identities(ArrayVec<[PublicKey; 16]>), Identities(ArrayVec<[PublicKey; 16]>),
CurrentUd, CurrentUd,
BalancesOfScripts(ArrayVec<[WalletScriptV10; 16]>),
} }
// Request types helpers // Request types helpers
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment