return back search by unspent output feature

This commit is contained in:
aglkm
2024-06-20 15:16:34 +03:00
parent 9f3446ddf2
commit 4aaf39cf5f
6 changed files with 163 additions and 16 deletions

View File

@@ -17,6 +17,7 @@ use crate::data::Block;
use crate::data::Transactions;
use crate::data::ExplorerConfig;
use crate::data::Kernel;
use crate::data::Output;
// Static explorer config structure
@@ -419,6 +420,41 @@ pub async fn get_block_header(hash: &str, height: &mut String)
}
// Get output.
pub async fn get_output(commit: &str, output: &mut Output) -> Result<(), anyhow::Error> {
// First check whether output is broadcasted but not confirmed yet (in mempool)
let mut resp = call("get_unconfirmed_transactions", "[]", "1", "foreign").await?;
if resp["result"]["Ok"].is_null() == false {
for tx in resp["result"]["Ok"].as_array().unwrap() {
for out in tx["tx"]["body"]["outputs"].as_array().unwrap() {
if out["commit"].as_str().unwrap() == commit {
// Only Plain outputs in the mempool
output.out_type = "Plain".to_string();
output.commit = out["commit"].as_str().unwrap().to_string();
output.status = "Unconfirmed".to_string();
// Found it, no need to continue
return Ok(());
}
}
}
}
let params = &format!("[[\"{}\"], null, null, true, true]", commit)[..];
resp = call("get_outputs", params, "1", "foreign").await?;
if resp["result"]["Ok"][0].is_null() == false {
output.height = resp["result"]["Ok"][0]["block_height"].to_string();
output.commit = resp["result"]["Ok"][0]["commit"].as_str().unwrap().to_string();
output.out_type = resp["result"]["Ok"][0]["output_type"].as_str().unwrap().to_string();
output.raw_data = serde_json::to_string_pretty(&resp).unwrap()
}
Ok(())
}
// Get kernel.
pub async fn get_kernel(excess: &str, kernel: &mut Kernel) -> Result<(), anyhow::Error> {
// First check whether kernel is broadcasted but not confirmed yet (in mempool)