Commit 46170ce1 authored by Éloïs's avatar Éloïs
Browse files

[feat] bca: add req BalancesOfScripts

parent d7a74ce1
......@@ -92,5 +92,8 @@ pub(super) async fn execute_req_type(
))
}
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(
.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 {
SendTxs(Txs),
Identities(ArrayVec<[PublicKey; 16]>),
CurrentUd,
BalancesOfScripts(ArrayVec<[WalletScriptV10; 16]>),
}
// Request types helpers
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment