diff --git a/src/data.rs b/src/data.rs index d529320..bae2440 100644 --- a/src/data.rs +++ b/src/data.rs @@ -118,6 +118,7 @@ pub struct Kernel { pub excess: String, pub ker_type: String, pub fee: String, + pub status: String, pub raw_data: String, } @@ -128,6 +129,7 @@ impl Kernel { excess: String::new(), ker_type: String::new(), fee: String::new(), + status: String::new(), raw_data: String::new(), } } diff --git a/src/main.rs b/src/main.rs index 97ce2e4..5e74b06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,7 @@ async fn kernel(excess: &str) -> Template { let _ = requests::get_kernel(&excess, &mut kernel).await; - if kernel.height.is_empty() == false { + if kernel.excess.is_empty() == false { return Template::render("kernel", context! { route: "kernel", kernel, diff --git a/src/requests.rs b/src/requests.rs index 00a0864..b6f62dd 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -404,11 +404,31 @@ pub async fn get_block_header(hash: &str, height: &mut String) // Get kernel. -pub async fn get_kernel(excess: &str, kernel: &mut Kernel) - -> Result<(), anyhow::Error> { +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) + 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 ker in tx["tx"]["body"]["kernels"].as_array().unwrap() { + if ker["excess"].as_str().unwrap() == excess { + // Only Plain kernels in the mempool + kernel.ker_type = "Plain".to_string(); + kernel.excess = ker["excess"].as_str().unwrap().to_string(); + kernel.status = "Unconfirmed".to_string(); + kernel.fee = format!("ツ {}", + ker["features"]["Plain"]["fee"] + .to_string().parse::().unwrap() / 1000000000.0); + // Found it, no need to continue + return Ok(()); + } + } + } + } + let params = &format!("[\"{}\", null, null]", excess)[..]; - let resp = call("get_kernel", params, "1", "foreign").await?; + resp = call("get_kernel", params, "1", "foreign").await?; if resp["result"]["Ok"].is_null() == false { kernel.height = resp["result"]["Ok"]["height"].to_string(); diff --git a/templates/kernel.html.tera b/templates/kernel.html.tera index 94b9250..c86b200 100644 --- a/templates/kernel.html.tera +++ b/templates/kernel.html.tera @@ -6,12 +6,18 @@
-
KERNEL
+
+
KERNEL
+ {% if kernel.status == "Unconfirmed" %} + UNCONFIRMED + {% endif %} +

Excess 
{{ kernel.excess }}
+ {% if kernel.status != "Unconfirmed" %}
Block Height 
@@ -21,6 +27,7 @@
+ {% endif %}
Type 
@@ -36,15 +43,16 @@
-
- -
-
-
RAW DATA
-
-
{{ kernel.raw_data }}
+ {% if kernel.status != "Unconfirmed" %} +
+
+
+
RAW DATA
+
+
{{ kernel.raw_data }}
+
-
+ {% endif %}