-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
VN Fosly
authored and
VN Fosly
committed
Aug 16, 2023
1 parent
061b76f
commit af724f3
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod math; | ||
mod chain; | ||
|
||
use math::{sha256 as hash}; | ||
|
||
|