From cb2658f164adebb4938e67ceac4e5a301a05e19a Mon Sep 17 00:00:00 2001 From: canonbrother Date: Fri, 22 Nov 2024 11:06:45 +0800 Subject: [PATCH] ScriptAggregationId height u32 -> bytes --- lib/ain-ocean/src/api/address.rs | 2 +- lib/ain-ocean/src/indexer/mod.rs | 6 +++--- lib/ain-ocean/src/model/script_aggregation.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ain-ocean/src/api/address.rs b/lib/ain-ocean/src/api/address.rs index 6e98e80c46..0e4dcd35fa 100644 --- a/lib/ain-ocean/src/api/address.rs +++ b/lib/ain-ocean/src/api/address.rs @@ -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, diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index 725ec86808..fbc140fc0f 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -317,7 +317,7 @@ fn index_script(services: &Arc, 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, @@ -342,7 +342,7 @@ fn index_script(services: &Arc, 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); } @@ -404,7 +404,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction services .script_aggregation .by_id - .delete(&(hid, block.height))? + .delete(&(hid, block.height.to_be_bytes()))? } Ok(()) diff --git a/lib/ain-ocean/src/model/script_aggregation.rs b/lib/ain-ocean/src/model/script_aggregation.rs index 7623c1b47b..8e1f882c7b 100644 --- a/lib/ain-ocean/src/model/script_aggregation.rs +++ b/lib/ain-ocean/src/model/script_aggregation.rs @@ -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 {