Added second keypair for encryption of domain names.
Changed keys file format to include second pair of keys, it will be in TOML now. Made many adjustments to block and transaction structures. Changed block serialization to binary format for hashing/mining. Removed old build dependencies.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use std::fmt;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::blockchain::hash_utils::*;
|
||||
use crate::bytes::Bytes;
|
||||
@@ -12,7 +11,7 @@ use crate::{CLASS_ORIGIN, CLASS_DOMAIN};
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
#[derive(Clone, Deserialize, PartialEq)]
|
||||
#[derive(Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Transaction {
|
||||
pub class: String,
|
||||
#[serde(default, skip_serializing_if = "Bytes::is_zero")]
|
||||
@@ -20,35 +19,27 @@ pub struct Transaction {
|
||||
#[serde(default, skip_serializing_if = "Bytes::is_zero")]
|
||||
pub confirmation: Bytes,
|
||||
#[serde(default, skip_serializing_if = "Bytes::is_zero")]
|
||||
pub owner: Bytes,
|
||||
pub signing: Bytes,
|
||||
#[serde(default, skip_serializing_if = "Bytes::is_zero")]
|
||||
pub encryption: Bytes,
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
impl Transaction {
|
||||
pub fn from_str(identity: String, method: String, data: String, miner: Bytes, owner: Bytes) -> Self {
|
||||
pub fn from_str(identity: String, method: String, data: String, signing: Bytes, encryption: Bytes) -> Self {
|
||||
let hash = hash_identity(&identity, None);
|
||||
let key = if owner.is_empty() {
|
||||
&miner
|
||||
} else {
|
||||
&owner
|
||||
};
|
||||
let confirmation = hash_identity(&identity, Some(key));
|
||||
// If the miner doesn't change owner, we don't include owner at all
|
||||
let owner = if owner.is_empty() || owner == miner {
|
||||
miner
|
||||
} else {
|
||||
owner
|
||||
};
|
||||
return Self::new(hash, confirmation, method, data, owner);
|
||||
let confirmation = hash_identity(&identity, Some(&signing));
|
||||
return Self::new(hash, confirmation, method, data, signing, encryption);
|
||||
}
|
||||
|
||||
pub fn new(identity: Bytes, confirmation: Bytes, method: String, data: String, owner: Bytes) -> Self {
|
||||
Transaction { identity, confirmation, class: method, data, owner }
|
||||
pub fn new(identity: Bytes, confirmation: Bytes, method: String, data: String, signing: Bytes, encryption: Bytes) -> Self {
|
||||
Transaction { identity, confirmation, class: method, data, signing, encryption }
|
||||
}
|
||||
|
||||
pub fn origin(hash: Bytes, owner: Bytes) -> Self {
|
||||
pub fn origin(hash: Bytes, signing: Bytes, encryption: Bytes) -> Self {
|
||||
let data = serde_json::to_string(&Origin { zones: hash }).unwrap();
|
||||
Transaction { identity: Bytes::default(), confirmation: Bytes::default(), class: String::from(CLASS_ORIGIN), data, owner }
|
||||
Transaction { identity: Bytes::default(), confirmation: Bytes::default(), class: String::from(CLASS_ORIGIN), data, signing, encryption }
|
||||
}
|
||||
|
||||
pub fn from_json(json: &str) -> Option<Self> {
|
||||
@@ -70,7 +61,7 @@ impl Transaction {
|
||||
|
||||
pub fn check_identity(&self, domain: &str) -> bool {
|
||||
let hash = hash_identity(&domain, None);
|
||||
let confirmation = hash_identity(&domain, Some(&self.owner));
|
||||
let confirmation = hash_identity(&domain, Some(&self.signing));
|
||||
self.identity.eq(&hash) && self.confirmation.eq(&confirmation)
|
||||
}
|
||||
|
||||
@@ -107,24 +98,13 @@ impl fmt::Debug for Transaction {
|
||||
.field("class", &self.class)
|
||||
.field("identity", &self.identity)
|
||||
.field("confirmation", &self.confirmation)
|
||||
.field("owner", &&self.owner)
|
||||
.field("signing", &&self.signing)
|
||||
.field("encryption", &&self.encryption)
|
||||
.field("data", &self.data)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Transaction {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where S: Serializer {
|
||||
let mut structure = serializer.serialize_struct("Transaction", 5).unwrap();
|
||||
structure.serialize_field("class", &self.class)?;
|
||||
structure.serialize_field("identity", &self.identity)?;
|
||||
structure.serialize_field("confirmation", &self.confirmation)?;
|
||||
structure.serialize_field("owner", &self.owner)?;
|
||||
structure.serialize_field("data", &self.data)?;
|
||||
structure.end()
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TransactionType {
|
||||
Unknown,
|
||||
Signing,
|
||||
@@ -134,7 +114,7 @@ pub enum TransactionType {
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct DomainData {
|
||||
pub domain: Bytes,
|
||||
pub encrypted: Bytes,
|
||||
pub zone: String,
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
pub info: String,
|
||||
@@ -145,8 +125,8 @@ pub struct DomainData {
|
||||
}
|
||||
|
||||
impl DomainData {
|
||||
pub fn new(domain: Bytes, zone: String, info: String, records: Vec<DnsRecord>, contacts: Vec<ContactsData>) -> Self {
|
||||
Self { domain, zone, info, records, contacts }
|
||||
pub fn new(encrypted: Bytes, zone: String, info: String, records: Vec<DnsRecord>, contacts: Vec<ContactsData>) -> Self {
|
||||
Self { encrypted, zone, info, records, contacts }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user