Skip to content

Commit

Permalink
fix: prefetch and resolver for utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Aug 6, 2023
1 parent cbc4431 commit 427f027
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
16 changes: 6 additions & 10 deletions src/rgb/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ pub async fn prefetch_resolver_utxos(
limit: Option<u32>,
) {
use std::collections::HashSet;

let esplora_client: EsploraBlockchain =
EsploraBlockchain::new(&explorer.explorer_url, 1).with_concurrency(6);

Expand Down Expand Up @@ -346,26 +345,23 @@ pub async fn prefetch_resolver_utxos(
}

related_txs.into_iter().for_each(|tx| {
let index = tx
.vout
.clone()
.into_iter()
.position(|txout| txout.scriptpubkey == script);
if let Some(index) = index {
let index = index;
for (index, vout) in tx.vout.iter().enumerate() {
if vout.scriptpubkey != script {
continue;
}

let status = match tx.status.block_height {
Some(height) => MiningStatus::Blockchain(height),
_ => MiningStatus::Mempool,
};
let outpoint = Outpoint::new(
rgbstd::Txid::from_str(&tx.txid.to_hex()).expect("invalid transactionID parse"),
bp::Txid::from_str(&tx.txid.to_hex()).expect("invalid outpoint parse"),
index as u32,
);
let new_utxo = Utxo {
outpoint,
status,
amount: tx.vout[index].value,
amount: vout.value,
derivation: derive.clone(),
};
utxos.insert(new_utxo);
Expand Down
14 changes: 6 additions & 8 deletions src/rgb/resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ impl rgb::Resolver for ExplorerResolver {
}

related_txs.into_iter().for_each(|tx| {
let index = tx
.vout
.clone()
.into_iter()
.position(|txout| txout.scriptpubkey == script);
if let Some(index) = index {
let index = index;
for (index, vout) in tx.vout.iter().enumerate() {
if vout.scriptpubkey != script {
continue;
}

let status = match tx.status.block_height {
Some(height) => MiningStatus::Blockchain(height),
_ => MiningStatus::Mempool,
Expand All @@ -97,7 +95,7 @@ impl rgb::Resolver for ExplorerResolver {
let new_utxo = Utxo {
outpoint,
status,
amount: tx.vout[index].value,
amount: vout.value,
derivation: derive.clone(),
};
utxos.insert(new_utxo);
Expand Down
12 changes: 2 additions & 10 deletions tests/rgb/integration/consig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ pub async fn allow_save_read_remove_transfers() -> Result<()> {
.into_iter()
.find(|x| x.consig_id == transfer.consig_id)
{
let expected_status = match consig_status.status {
TxStatus::Mempool => true,
_ => false,
};
assert!(expected_status);
matches!(consig_status.status, TxStatus::Mempool);

if is_issuer {
assert_eq!(consig_status.ty, TransferType::Sended);
Expand All @@ -153,11 +149,7 @@ pub async fn allow_save_read_remove_transfers() -> Result<()> {
.into_iter()
.find(|x| x.consig_id == transfer.consig_id)
{
let expected_status = match consig_status.status {
TxStatus::Block(_) => true,
_ => false,
};
assert!(expected_status);
matches!(consig_status.status, TxStatus::Block(_));
}
}

Expand Down

0 comments on commit 427f027

Please sign in to comment.