Skip to content

Commit

Permalink
More misc masp indexer client fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jun 28, 2024
1 parent f4977cc commit 0a439b5
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions crates/sdk/src/masp/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,21 @@ impl MaspClient for IndexerMaspClient {
use serde::Deserialize;

#[derive(Deserialize)]
struct TransactionBatch {
struct TransactionSlot {
// masp_tx_index: u64,
bytes: Vec<u8>,
index: u32,
}

#[derive(Deserialize)]
struct Transaction {
batch: Vec<TransactionSlot>,
block_index: u32,
block_height: u64,
}

#[derive(Deserialize)]
struct TxResponse {
txs: Vec<TransactionBatch>,
txs: Vec<Transaction>,
}

if from > to {
Expand All @@ -361,7 +367,7 @@ impl MaspClient for IndexerMaspClient {
const MAX_RANGE_THRES: u64 = 30;
let mut fetch_iter = progress.fetch(from..=to);

while from <= to {
loop {
let from_height = from;
let off = (to - from).min(MAX_RANGE_THRES);
let to_height = from + off;
Expand Down Expand Up @@ -404,26 +410,32 @@ impl MaspClient for IndexerMaspClient {

let mut last_height = None;

for TransactionBatch {
bytes,
index,
for Transaction {
batch,
block_index,
block_height,
} in payload.txs
{
type MaspTxBatch =
Vec<masp_primitives::transaction::Transaction>;
let mut extracted_masp_txs = Vec::with_capacity(batch.len());

for TransactionSlot { bytes } in batch {
type MaspTx = masp_primitives::transaction::Transaction;

extracted_masp_txs.push(
MaspTx::try_from_slice(&bytes).map_err(|err| {
Error::Other(format!(
"Could not deserialize the masp txs borsh \
data at height {block_height} and index \
{block_index}: {err}"
))
})?,
);
}

let extracted_masp_txs = MaspTxBatch::try_from_slice(&bytes)
.map_err(|err| {
Error::Other(format!(
"Could not deserialize the masp txs borsh data at \
height {block_height} and index {index}: {err}"
))
})?;
tx_sender.send((
IndexedTx {
height: BlockHeight(block_height),
index: TxIndex(index),
index: TxIndex(block_index),
},
extracted_masp_txs,
));
Expand All @@ -434,6 +446,10 @@ impl MaspClient for IndexerMaspClient {
_ = fetch_iter.next();
}
}

if from >= to {
break;
}
}

// NB: a hack to drain the iterator in case
Expand Down Expand Up @@ -493,8 +509,9 @@ impl MaspClient for IndexerMaspClient {
#[derive(Deserialize)]
struct Note {
// is_fee_unshielding: bool,
// masp_tx_index: u64,
note_position: usize,
index: u32,
block_index: u32,
block_height: u64,
}

Expand Down Expand Up @@ -526,13 +543,13 @@ impl MaspClient for IndexerMaspClient {
.into_iter()
.map(
|Note {
index,
block_index,
block_height,
note_position,
}| {
(
IndexedTx {
index: TxIndex(index),
index: TxIndex(block_index),
height: BlockHeight(block_height),
},
note_position,
Expand Down

0 comments on commit 0a439b5

Please sign in to comment.