Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocean: api address get account history #2967

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
script activity uses find_tx_vout
  • Loading branch information
canonbrother committed Jul 15, 2024
commit abefbb9a3da61a0764abf6b9243416b2157a9191
43 changes: 6 additions & 37 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
@@ -182,43 +182,12 @@ fn index_script_activity(services: &Arc<Services>, block: &Block<Transaction>) -
continue;
}
let vin = vin_standard.unwrap();
let tx_vout = if tx.txid == vin.txid {
let vout = tx.vout.iter().find(|vout| vout.n == vin.vout);
if let Some(vout) = vout {
let value =
Decimal::from_f64(vout.value).ok_or(Error::DecimalConversionError)?;
let tx_vout = TransactionVout {
id: format!("{}{:x}", tx.txid, vin.vout),
txid: tx.txid,
n: vout.n,
value: format!("{:.8}", value),
token_id: vout.token_id,
script: TransactionVoutScript {
r#type: vout.script_pub_key.r#type.clone(),
hex: vout.script_pub_key.hex.clone(),
},
};
Some(tx_vout)
} else {
None
}
} else {
None
};

let vout = if let Some(tx_vout) = tx_vout {
tx_vout
} else {
let tx_vout = services.transaction.vout_by_id.get(&(vin.txid, vin.vout))?;
if tx_vout.is_none() {
return Err(Error::NotFoundIndex(
IndexAction::Index,
"TransactionVout".to_string(),
format!("{}-{}", vin.txid, vin.vout),
));
}
tx_vout.unwrap()
};
let vout = find_tx_vout(services, block, &vin)?;
if vout.is_none() {
log::error!("attempting to sync: {:?} but type: TransactionVout with id:{}-{} cannot be found in the index", IndexAction::Index, vin.txid, vin.vout);
continue;
}
let vout = vout.unwrap();

let id = (block.height, ScriptActivityType::Vin, vin.txid, vin.vout);
let hid = as_sha256(vout.script.hex.clone()); // as key