Skip to content

Commit

Permalink
#1 add blockchain (processing)
Browse files Browse the repository at this point in the history
  • Loading branch information
VN Fosly authored and VN Fosly committed Aug 16, 2023
1 parent 061b76f commit af724f3
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Empty file removed src/block.rs
Empty file.
73 changes: 73 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
mod block;

use rand::{distributions::Alphanumeric, Rng};
use crate::math::{sha256 as hash};
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
use block::{BlockData as Data};
use block::{ChainFLD as FLD};
use block::{providerData as Provider};

pub impl FLD {
fn new() -> Self {
Self {
blocks: vec![],
provider: Provider {
name: "Folody Crypto Wallet".to_owned(),
shortName: "FLCWL".to_owned(),
version: "V1.0.2RTM".to_owned(),
author: "Folody Crypto".to_owned(),
provider: "Discord".to_owned(),
}
}
}

fn hash2binary(hash: &[u8]) {

}

pub fn initialization(&mut self, fromAddr: String, toAddr: String) {
let mut block: [Any; 2] = [
hash(
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect()
)
];
let mut blockInside = HashMap::new();
let blockData = Data {
fromAddr: fromAddr,
toAddr: toAddr,
amount: 0.0,
transactionMsg: "".to_owned(),
createdAt: SystemTime::now(),
verifiedBy: [],
providerData: self.provider
};

blockInside.insert(block[0].to_string().to_owned(), hash(
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect()
));
blockInside.insert("blockData".to_owned(), blockData);
block[1] = blockData;
self.blocks.push(block);
}

pub fn isValid(&self, block: &[Any; 2], previous_block: &[Any; 2]) {

}
pub fn tryAdd (&mut self, block: [Any; 2]) {
let latest = self.blocks.last().expect("there is at least one block");
if self.isValid(&block, latest) {
self.blocks.push(block);
} else {
error!("could not add block");
}
}
}
23 changes: 23 additions & 0 deletions src/chain/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub struct ChainFLD {
pub blocks: Vec,
pub(crate) provider: providerData,
}

pub struct providerData {
pub name: String,
pub shortName: String,
pub version: String,
pub author: String,
pub provider: String,

}
pub struct BlockData {
pub fromAddr: String,
pub toAddr: String,
pub amount: f32,
pub transactionMsg: String,
pub createdAt: i64,
pub verifiedBy: Vec<String>,
pub providerData: providerData

}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod math;
mod chain;

use math::{sha256 as hash};

Expand Down

0 comments on commit af724f3

Please sign in to comment.