Skip to content

Commit 9550f04

Browse files
committed
Borrow UtxoIndexProxy async methods
Make the proxy methods take &self instead of consuming the wrapper on every async call. The blocking task still gets its own Arc clone, but callers no longer need to treat the proxy as single-use.
1 parent 16641dc commit 9550f04

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

  • indexes/utxoindex/src/core/api

indexes/utxoindex/src/core/api/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,29 @@ impl UtxoIndexProxy {
6666
Self { inner }
6767
}
6868

69-
pub async fn get_circulating_supply(self) -> StoreResult<u64> {
70-
spawn_blocking(move || self.inner.read().get_circulating_supply()).await.unwrap()
69+
pub async fn get_circulating_supply(&self) -> StoreResult<u64> {
70+
let inner = Arc::clone(&self.inner);
71+
spawn_blocking(move || inner.read().get_circulating_supply()).await.unwrap()
7172
}
7273

73-
pub async fn get_utxos_by_script_public_keys(self, script_public_keys: ScriptPublicKeys) -> StoreResult<UtxoSetByScriptPublicKey> {
74-
spawn_blocking(move || self.inner.read().get_utxos_by_script_public_keys(script_public_keys)).await.unwrap()
74+
pub async fn get_utxos_by_script_public_keys(
75+
&self,
76+
script_public_keys: ScriptPublicKeys,
77+
) -> StoreResult<UtxoSetByScriptPublicKey> {
78+
let inner = Arc::clone(&self.inner);
79+
spawn_blocking(move || inner.read().get_utxos_by_script_public_keys(script_public_keys)).await.unwrap()
7580
}
7681

7782
pub async fn get_balance_by_script_public_keys(
78-
self,
83+
&self,
7984
script_public_keys: ScriptPublicKeys,
8085
) -> StoreResult<BalanceByScriptPublicKey> {
81-
spawn_blocking(move || self.inner.read().get_balance_by_script_public_keys(script_public_keys)).await.unwrap()
86+
let inner = Arc::clone(&self.inner);
87+
spawn_blocking(move || inner.read().get_balance_by_script_public_keys(script_public_keys)).await.unwrap()
8288
}
8389

84-
pub async fn update(self, utxo_diff: Arc<UtxoDiff>, tips: Arc<Vec<Hash>>) -> UtxoIndexResult<UtxoChanges> {
85-
spawn_blocking(move || self.inner.write().update(utxo_diff, tips)).await.unwrap()
90+
pub async fn update(&self, utxo_diff: Arc<UtxoDiff>, tips: Arc<Vec<Hash>>) -> UtxoIndexResult<UtxoChanges> {
91+
let inner = Arc::clone(&self.inner);
92+
spawn_blocking(move || inner.write().update(utxo_diff, tips)).await.unwrap()
8693
}
8794
}

0 commit comments

Comments
 (0)