diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index 5eeb3fedf4..f8072fcc78 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,7 @@ 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 +503,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 3546b43895..c088751976 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 {