mirror of
https://github.com/transatoshi-mw/grin-explorer.git
synced 2025-10-21 21:43:40 +00:00
remove search by outputs feature
This commit is contained in:
23
src/data.rs
23
src/data.rs
@@ -133,29 +133,6 @@ impl Kernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Output data
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct Output {
|
|
||||||
pub height: String,
|
|
||||||
pub commit: String,
|
|
||||||
pub out_type: String,
|
|
||||||
pub status: String,
|
|
||||||
pub raw_data: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Output {
|
|
||||||
pub fn new() -> Output {
|
|
||||||
Output {
|
|
||||||
height: String::new(),
|
|
||||||
commit: String::new(),
|
|
||||||
out_type: String::new(),
|
|
||||||
status: String::new(),
|
|
||||||
raw_data: String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Transactions data
|
// Transactions data
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Transactions {
|
pub struct Transactions {
|
||||||
|
45
src/main.rs
45
src/main.rs
@@ -19,7 +19,6 @@ use crate::data::Dashboard;
|
|||||||
use crate::data::Block;
|
use crate::data::Block;
|
||||||
use crate::data::Transactions;
|
use crate::data::Transactions;
|
||||||
use crate::data::Kernel;
|
use crate::data::Kernel;
|
||||||
use crate::data::Output;
|
|
||||||
use crate::requests::CONFIG;
|
use crate::requests::CONFIG;
|
||||||
|
|
||||||
|
|
||||||
@@ -150,33 +149,11 @@ async fn kernel(excess: &str) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Rendering page for a specified output.
|
|
||||||
#[get("/output/<commit>")]
|
|
||||||
async fn output(commit: &str) -> Template {
|
|
||||||
let mut output = Output::new();
|
|
||||||
|
|
||||||
let _ = requests::get_output(&commit, &mut output).await;
|
|
||||||
|
|
||||||
if output.commit.is_empty() == false {
|
|
||||||
return Template::render("output", context! {
|
|
||||||
route: "output",
|
|
||||||
cg_api: CONFIG.coingecko_api.clone(),
|
|
||||||
output,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return Template::render("error", context! {
|
|
||||||
route: "error",
|
|
||||||
cg_api: CONFIG.coingecko_api.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Handling search request.
|
// Handling search request.
|
||||||
// Using Option<&str> to match '/search' query without input params.
|
// Using Option<&str> to match '/search' query without input params.
|
||||||
// https://github.com/rwf2/Rocket/issues/608
|
// https://github.com/rwf2/Rocket/issues/608
|
||||||
#[get("/search?<input>")]
|
#[get("/search?<input>")]
|
||||||
pub async fn search(input: Option<&str>) -> Either<Template, Redirect> {
|
fn search(input: Option<&str>) -> Either<Template, Redirect> {
|
||||||
// Unwrap Option and forward to Search page if no parameters
|
// Unwrap Option and forward to Search page if no parameters
|
||||||
let input = match input {
|
let input = match input {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
@@ -197,23 +174,9 @@ pub async fn search(input: Option<&str>) -> Either<Template, Redirect> {
|
|||||||
} else if input.len() == 64 {
|
} else if input.len() == 64 {
|
||||||
return Either::Right(Redirect::to(uri!(block_header_by_hash(input))));
|
return Either::Right(Redirect::to(uri!(block_header_by_hash(input))));
|
||||||
|
|
||||||
// Kernel or Output
|
// Kernel
|
||||||
} else if input.len() == 66 {
|
} else if input.len() == 66 {
|
||||||
// First search for Kernel
|
return Either::Right(Redirect::to(uri!(kernel(input))));
|
||||||
let mut kernel = Kernel::new();
|
|
||||||
|
|
||||||
let _ = requests::get_kernel(&input, &mut kernel).await;
|
|
||||||
|
|
||||||
if kernel.excess.is_empty() == false {
|
|
||||||
return Either::Left(Template::render("kernel", context! {
|
|
||||||
route: "kernel",
|
|
||||||
cg_api: CONFIG.coingecko_api.clone(),
|
|
||||||
kernel,
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
// If Kernel not found, then search for Output
|
|
||||||
return Either::Right(Redirect::to(uri!(output(input))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,7 +646,7 @@ async fn main() {
|
|||||||
block_weight, block_details_by_height, block_header_by_hash,
|
block_weight, block_details_by_height, block_header_by_hash,
|
||||||
soft_supply, production_cost, reward_ratio, breakeven_cost,
|
soft_supply, production_cost, reward_ratio, breakeven_cost,
|
||||||
last_block_age, block_list_by_height, block_list_index, search, kernel,
|
last_block_age, block_list_by_height, block_list_index, search, kernel,
|
||||||
output, api_owner, api_foreign])
|
api_owner, api_foreign])
|
||||||
.mount("/static", FileServer::from("static"))
|
.mount("/static", FileServer::from("static"))
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
.launch()
|
.launch()
|
||||||
|
@@ -17,7 +17,6 @@ use crate::data::Block;
|
|||||||
use crate::data::Transactions;
|
use crate::data::Transactions;
|
||||||
use crate::data::ExplorerConfig;
|
use crate::data::ExplorerConfig;
|
||||||
use crate::data::Kernel;
|
use crate::data::Kernel;
|
||||||
use crate::data::Output;
|
|
||||||
|
|
||||||
|
|
||||||
// Static explorer config structure
|
// Static explorer config structure
|
||||||
@@ -448,41 +447,6 @@ pub async fn get_kernel(excess: &str, kernel: &mut Kernel) -> Result<(), anyhow:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Collecting block kernels for transactions stats.
|
// Collecting block kernels for transactions stats.
|
||||||
pub async fn get_block_kernels(height: &String, blocks: &mut Vec<Block>)
|
pub async fn get_block_kernels(height: &String, blocks: &mut Vec<Block>)
|
||||||
-> Result<(), anyhow::Error> {
|
-> Result<(), anyhow::Error> {
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
<div class="value-text"><i class="bi bi-dot"></i> Block Number</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Block Number</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Block Hash</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Block Hash</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Kernel</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Kernel</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Unspent Output</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -1,52 +0,0 @@
|
|||||||
{% extends "base" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<code>
|
|
||||||
|
|
||||||
<div class="card border-start-0 border-end-0 rounded-0">
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="d-flex justify-content-between">
|
|
||||||
<div class="darkorange-text"><i class="bi bi-card-text"></i> OUTPUT</div>
|
|
||||||
{% if output.status == "Unconfirmed" %}
|
|
||||||
<span class="badge text-bg-warning px-2 py-2">UNCONFIRMED</span>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
<div class="d-flex justify-content-between">
|
|
||||||
<div class="value-text">Commitment </div>
|
|
||||||
<div class="value-text text-break text-end">{{ output.commit }}</div>
|
|
||||||
</div>
|
|
||||||
{% if output.status != "Unconfirmed" %}
|
|
||||||
<br>
|
|
||||||
<div class="d-flex justify-content-between">
|
|
||||||
<div class="value-text">Block Height </div>
|
|
||||||
<div class="value-text text-end">
|
|
||||||
<a class="text-decoration-none" href="/block/{{ output.height }}">
|
|
||||||
{{ output.height }} <i class="bi bi-box-arrow-up-right"></i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<br>
|
|
||||||
<div class="d-flex justify-content-between">
|
|
||||||
<div class="value-text">Type </div>
|
|
||||||
<div class="value-text text-end">{{ output.out_type }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if output.status != "Unconfirmed" %}
|
|
||||||
<div class="card border-top-0 border-start-0 border-end-0 rounded-0">
|
|
||||||
<div class="card-body" align="left">
|
|
||||||
<div class="darkorange-text"><i class="bi bi-layout-text-sidebar-reverse"></i> RAW DATA</div>
|
|
||||||
<br>
|
|
||||||
<div class="value-text">{{ output.raw_data }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
</code>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@@ -21,7 +21,6 @@
|
|||||||
<div class="value-text"><i class="bi bi-dot"></i> Block Number</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Block Number</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Block Hash</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Block Hash</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Kernel</div>
|
<div class="value-text"><i class="bi bi-dot"></i> Kernel</div>
|
||||||
<div class="value-text"><i class="bi bi-dot"></i> Unspent Output</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user