diff --git a/lib/ain-ocean/src/api/address.rs b/lib/ain-ocean/src/api/address.rs index 0e4dcd35fa..e41ff07373 100644 --- a/lib/ain-ocean/src/api/address.rs +++ b/lib/ain-ocean/src/api/address.rs @@ -458,14 +458,17 @@ async fn list_transaction_unspent( msg: format!("Invalid height: {}", height), })?; let txid = Txid::from_str(txid)?; - let n = n.parse::()?; - Ok::<([u8; 4], Txid, usize), Error>((height, txid, n)) + let decoded_n = hex::decode(n)?; + let n = decoded_n.try_into().map_err(|_| Error::Other { + msg: format!("Invalid txno: {}", n) + })?; + Ok::<([u8; 4], Txid, [u8; 8]), Error>((height, txid, n)) }) .transpose()? .unwrap_or(( - [0u8, 0u8, 0u8, 0u8], + [0u8; 4], Txid::from_byte_array([0x00u8; 32]), - usize::default(), + [0u8; 8], )); let res = ctx diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index fbc140fc0f..1824e285f4 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -160,7 +160,7 @@ fn index_script_unspent_vin( vin: &VinStandard, ctx: &Context, ) -> Result<()> { - let key = (ctx.block.height.to_be_bytes(), vin.txid, vin.vout); + let key = (ctx.block.height.to_be_bytes(), vin.txid, vin.vout.to_be_bytes()); let id = services.script_unspent.by_key.get(&key)?; if let Some(id) = id { services.script_unspent.by_id.delete(&id)?; @@ -255,8 +255,8 @@ 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.to_be_bytes(), tx.txid, vout.n); + let id = (hid, block.height.to_be_bytes(), tx.txid, vout.n.to_be_bytes()); + let key = (block.height.to_be_bytes(), tx.txid, vout.n.to_be_bytes()); services.script_unspent.by_key.put(&key, &id)?; services.script_unspent.by_id.put(&id, &script_unspent)?; Ok(()) @@ -458,12 +458,12 @@ fn invalidate_script_unspent_vin( hid, transaction.block.height.to_be_bytes(), transaction.txid, - vout.n, + vout.n.to_be_bytes(), ); let key = ( transaction.block.height.to_be_bytes(), transaction.txid, - vout.n, + vout.n.to_be_bytes(), ); services.script_unspent.by_key.put(&key, &id)?; @@ -496,8 +496,8 @@ fn invalidate_script_unspent_vout( vout: &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); + let id = (hid, ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n.to_be_bytes()); + let key = (ctx.block.height.to_be_bytes(), ctx.tx.txid, vout.n.to_be_bytes()); services.script_unspent.by_id.delete(&id)?; services.script_unspent.by_key.delete(&key)?; diff --git a/lib/ain-ocean/src/model/script_unspent.rs b/lib/ain-ocean/src/model/script_unspent.rs index c088751976..0bf270cd8b 100644 --- a/lib/ain-ocean/src/model/script_unspent.rs +++ b/lib/ain-ocean/src/model/script_unspent.rs @@ -3,8 +3,8 @@ 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 = ([u8; 4], Txid, usize); // block.height + txid + vout_index, ps: key is required in index_script_unspent_vin +pub type ScriptUnspentId = ([u8; 32], [u8; 4], Txid, [u8; 8]); // hid + block.height + txid + vout_index +pub type ScriptUnspentKey = ([u8; 4], Txid, [u8; 8]); // block.height + txid + vout_index, ps: key is required in index_script_unspent_vin #[derive(Debug, Serialize, Deserialize)] pub struct ScriptUnspent {