Remastered domain mining interface!
This commit is contained in:
@@ -45,6 +45,7 @@ const SQL_GET_LAST_FULL_BLOCK_FOR_KEY: &str = "SELECT * FROM blocks WHERE `trans
|
||||
const SQL_GET_PUBLIC_KEY_BY_ID: &str = "SELECT pub_key FROM transactions WHERE identity = ? ORDER BY id DESC LIMIT 1;";
|
||||
const SQL_GET_ID_BY_ID: &str = "SELECT identity FROM transactions WHERE identity = ? ORDER BY id DESC LIMIT 1;";
|
||||
const SQL_GET_TRANSACTION_BY_ID: &str = "SELECT * FROM transactions WHERE identity = ? ORDER BY id DESC LIMIT 1;";
|
||||
const SQL_GET_TRANSACTIONS_WITH_ZONE: &str = "SELECT data FROM transactions WHERE data LIKE '%difficulty%';";
|
||||
|
||||
pub struct Chain {
|
||||
origin: Bytes,
|
||||
@@ -271,6 +272,25 @@ impl Chain {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn get_zones(&self) -> Vec<ZoneData> {
|
||||
let mut result = Vec::new();
|
||||
match self.db.prepare(SQL_GET_TRANSACTIONS_WITH_ZONE) {
|
||||
Ok(mut statement) => {
|
||||
while statement.next().unwrap() == State::Row {
|
||||
let data = statement.read::<String>(0).unwrap();
|
||||
info!("Got zone data {}", &data);
|
||||
if let Ok(zone_data) = serde_json::from_str(&data) {
|
||||
result.push(zone_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Can't get zones from DB {}", e);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Checks if some zone exists in our blockchain
|
||||
pub fn is_zone_in_blockchain(&self, zone: &str) -> bool {
|
||||
if self.zones.borrow().contains(zone) {
|
||||
|
||||
@@ -6,6 +6,7 @@ use serde::ser::SerializeStruct;
|
||||
use crate::blockchain::hash_utils::*;
|
||||
use crate::bytes::Bytes;
|
||||
use crate::dns::protocol::DnsRecord;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
@@ -90,8 +91,14 @@ impl DomainData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ZoneData {
|
||||
pub name: String,
|
||||
pub difficulty: u32
|
||||
}
|
||||
|
||||
impl Display for ZoneData {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
f.write_str(&format!("{} ({})", self.name, self.difficulty))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user