Skip to content

Commit

Permalink
fix script_agg indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Dec 16, 2024
1 parent b6c50cd commit 6b0f7fa
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ fn index_script_aggregation_vin(
record: &mut BTreeMap<[u8; 32], ScriptAggregation>,
) {
let hid = as_sha256(&vout.script.hex);
let entry = record.entry(hid).or_insert_with(|| ScriptAggregation {
hid,
block: block.clone(),
script: ScriptAggregationScript {
r#type: vout.script.r#type.clone(),
hex: vout.script.hex.clone(),
},
statistic: ScriptAggregationStatistic::default(),
amount: ScriptAggregationAmount::default(),
});
entry.statistic.tx_out_count += 1;
entry.amount.tx_out += vout.value;
record.entry(hid)
.and_modify(|script| {
script.statistic.tx_out_count += 1;
script.amount.tx_out += vout.value;
})
.or_insert_with(|| ScriptAggregation {
hid,
block: block.clone(),
script: ScriptAggregationScript {
r#type: vout.script.r#type.clone(),
hex: vout.script.hex.clone(),
},
statistic: ScriptAggregationStatistic::default(),
amount: ScriptAggregationAmount::default(),
});
}

fn index_script_unspent_vin(
Expand Down Expand Up @@ -219,18 +222,21 @@ fn index_script_aggregation_vout(
) {
let hid = as_sha256(&vout.script_pub_key.hex);

let entry = record.entry(hid).or_insert_with(|| ScriptAggregation {
hid,
block: block.clone(),
script: ScriptAggregationScript {
r#type: vout.script_pub_key.r#type.clone(),
hex: vout.script_pub_key.hex.clone(),
},
statistic: ScriptAggregationStatistic::default(),
amount: ScriptAggregationAmount::default(),
});
entry.statistic.tx_in_count += 1;
entry.amount.tx_in += vout.value;
record.entry(hid)
.and_modify(|script| {
script.statistic.tx_in_count += 1;
script.amount.tx_in += vout.value;
})
.or_insert_with(|| ScriptAggregation {
hid,
block: block.clone(),
script: ScriptAggregationScript {
r#type: vout.script_pub_key.r#type.clone(),
hex: vout.script_pub_key.hex.clone(),
},
statistic: ScriptAggregationStatistic::default(),
amount: ScriptAggregationAmount::default(),
});
}

fn index_script_unspent_vout(services: &Arc<Services>, vout: &Vout, ctx: &Context) -> Result<()> {
Expand Down Expand Up @@ -354,8 +360,6 @@ fn index_script(services: &Arc<Services>, ctx: &Context, txs: &[Transaction]) ->
&(aggregation.hid, ctx.block.height.to_be_bytes()),
&aggregation,
)?;

record.insert(aggregation.hid, aggregation);
}

log_elapsed(start, format!("Indexed script {:x}", ctx.tx.txid));
Expand Down

0 comments on commit 6b0f7fa

Please sign in to comment.