From 32428fbeeb917b90f604ec6f24b3d1d18e70b3a7 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Mon, 28 Oct 2024 13:35:06 +0800 Subject: [PATCH] fix script_unspent_vin key --- lib/ain-ocean/src/indexer/mod.rs | 13 ++++++++++--- lib/ain-ocean/src/model/script_unspent.rs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index 5eeb3fedf44..050033d0bd0 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -170,10 +170,11 @@ fn index_script_unspent_vin( vin: &VinStandard, ctx: &Context, ) -> Result<()> { - let key = (ctx.block.height, vin.txid, vin.vout); + let key = (ctx.block.height.to_be_bytes(), vin.txid, vin.vout); let id = services.script_unspent.by_key.get(&key)?; if let Some(id) = id { services.script_unspent.by_id.delete(&id)?; + services.script_unspent.by_key.delete(&key)?; } Ok(()) } @@ -265,7 +266,7 @@ fn index_script_unspent_vout(services: &Arc, vout: &Vout, ctx: &Contex }; let id = (hid, block.height.to_be_bytes(), tx.txid, vout.n); - let key = (block.height, tx.txid, vout.n); + let key = (block.height.to_be_bytes(), tx.txid, vout.n); services.script_unspent.by_key.put(&key, &id)?; services.script_unspent.by_id.put(&id, &script_unspent)?; Ok(()) @@ -469,7 +470,11 @@ fn invalidate_script_unspent_vin( transaction.txid, vout.n, ); - let key = (transaction.block.height, transaction.txid, vout.n); + let key = ( + transaction.block.height.to_be_bytes(), + transaction.txid, + vout.n, + ); services.script_unspent.by_key.put(&key, &id)?; services.script_unspent.by_id.put(&id, &script_unspent)?; @@ -502,7 +507,9 @@ fn invalidate_script_unspent_vout( ) -> Result<()> { let hid = as_sha256(&vout.script_pub_key.hex); let id = (hid, ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n); + let key = (ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n); services.script_unspent.by_id.delete(&id)?; + services.script_unspent.by_key.delete(&key)?; Ok(()) } diff --git a/lib/ain-ocean/src/model/script_unspent.rs b/lib/ain-ocean/src/model/script_unspent.rs index 3546b438957..c0887519768 100644 --- a/lib/ain-ocean/src/model/script_unspent.rs +++ b/lib/ain-ocean/src/model/script_unspent.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use super::BlockContext; pub type ScriptUnspentId = ([u8; 32], [u8; 4], Txid, usize); // hid + block.height + txid + vout_index -pub type ScriptUnspentKey = (u32, Txid, usize); // block.height + txid + vout_index +pub type ScriptUnspentKey = ([u8; 4], Txid, usize); // block.height + txid + vout_index, ps: key is required in index_script_unspent_vin #[derive(Debug, Serialize, Deserialize)] pub struct ScriptUnspent {