Skip to content

Commit

Permalink
Major GUI refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Mar 17, 2021
1 parent a4e9d92 commit 7e24383
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 207 deletions.
35 changes: 33 additions & 2 deletions src/blockchain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ use chrono::Utc;
use log::{debug, error, info, trace, warn};
use sqlite::{Connection, State, Statement};

use crate::{Block, Bytes, Keystore, Transaction};
use crate::{Block, Bytes, Keystore, Transaction, check_domain, get_domain_zone};
use crate::blockchain::constants::*;
use crate::blockchain::enums::BlockQuality;
use crate::blockchain::enums::{BlockQuality, MineResult};
use crate::blockchain::enums::BlockQuality::*;
use crate::blockchain::hash_utils::*;
use crate::settings::Settings;
use crate::keys::check_public_key_strength;
use std::cmp::{min, max};
use crate::blockchain::transaction::{ZoneData, DomainData};
use std::ops::Deref;
use crate::dns::protocol::DnsRecord;
use crate::blockchain::enums::MineResult::*;

const DB_NAME: &str = "blockchain.db";
const SQL_CREATE_TABLES: &str = "CREATE TABLE blocks (
Expand Down Expand Up @@ -297,6 +299,35 @@ impl Chain {
false
}

pub fn can_mine_domain(&self, domain: &str, records: &str, pub_key: &Bytes) -> MineResult {
let name = domain.to_lowercase();
if !check_domain(&name, true) {
return WrongName;
}
let zone = get_domain_zone(&name);
if !self.is_zone_in_blockchain(&zone) {
return WrongZone;
}
if let Some(transaction) = self.get_domain_transaction(&name) {
if transaction.pub_key.ne(pub_key) {
return NotOwned;
}
}
if serde_json::from_str::<Vec<DnsRecord>>(&records).is_err() {
return WrongData;
}
let identity_hash = hash_identity(&name, None);
if let Some(last) = self.get_last_full_block(Some(&pub_key)) {
let new_id = !self.is_id_in_blockchain(&identity_hash);
let time = last.timestamp + FULL_BLOCKS_INTERVAL - Utc::now().timestamp();
if new_id && time > 0 {
return Cooldown { time }
}
}

Fine
}

/// Gets full Transaction info for any domain. Used by DNS part.
pub fn get_domain_transaction(&self, domain: &str) -> Option<Transaction> {
if domain.is_empty() {
Expand Down
10 changes: 10 additions & 0 deletions src/blockchain/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ pub enum BlockQuality {
Bad,
Fork,
}

pub enum MineResult {
Fine,
WrongName,
WrongData,
WrongKey,
WrongZone,
NotOwned,
Cooldown { time: i64 }
}
Loading

0 comments on commit 7e24383

Please sign in to comment.