Skip to content

Commit

Permalink
ScriptAggregationId height u32 -> bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Nov 22, 2024
1 parent e0f557a commit cb2658f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/api/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn get_latest_aggregation(
.services
.script_aggregation
.by_id
.list(Some((hid, u32::MAX)), SortOrder::Descending)?
.list(Some((hid, [0xffu8; 4])), SortOrder::Descending)?
.take(1)
.take_while(|item| match item {
Ok(((v, _), _)) => v == &hid,
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn index_script(services: &Arc<Services>, ctx: &Context, txs: &[Transaction]) ->
let repo = &services.script_aggregation;
let latest = repo
.by_id
.list(Some((aggregation.hid, u32::MAX)), SortOrder::Descending)?
.list(Some((aggregation.hid, [0xffu8; 4])), SortOrder::Descending)?
.take(1)
.take_while(|item| match item {
Ok(((hid, _), _)) => &aggregation.hid == hid,
Expand All @@ -342,7 +342,7 @@ fn index_script(services: &Arc<Services>, ctx: &Context, txs: &[Transaction]) ->
aggregation.amount.unspent = aggregation.amount.tx_in - aggregation.amount.tx_out;

repo.by_id
.put(&(aggregation.hid, ctx.block.height), &aggregation)?;
.put(&(aggregation.hid, ctx.block.height.to_be_bytes()), &aggregation)?;

record.insert(aggregation.hid, aggregation);
}
Expand Down Expand Up @@ -404,7 +404,7 @@ fn invalidate_script(services: &Arc<Services>, ctx: &Context, txs: &[Transaction
services
.script_aggregation
.by_id
.delete(&(hid, block.height))?
.delete(&(hid, block.height.to_be_bytes()))?
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/model/script_aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};

use super::BlockContext;

pub type ScriptAggregationId = ([u8; 32], u32); // (hid, block.height)
pub type ScriptAggregationId = ([u8; 32], [u8; 4]); // (hid, block.height)

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ScriptAggregation {
Expand Down

0 comments on commit cb2658f

Please sign in to comment.