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

[feat] bca: add req BalancesOfScripts

parent d7a74ce1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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
        }
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -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??,
    ))
}
+1 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ pub enum BcaReqTypeV0 {
    SendTxs(Txs),
    Identities(ArrayVec<[PublicKey; 16]>),
    CurrentUd,
    BalancesOfScripts(ArrayVec<[WalletScriptV10; 16]>),
}

// Request types helpers