Skip to content

Commit

Permalink
fix script_unspent_vin key
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Oct 28, 2024
1 parent d5ec03f commit 32428fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -265,7 +266,7 @@ fn index_script_unspent_vout(services: &Arc<Services>, 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(())
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/model/script_unspent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 32428fb

Please sign in to comment.