Skip to content
Snippets Groups Projects
Commit 39becabb authored by Éloïs's avatar Éloïs
Browse files

Merge branch...

Merge branch '68-add-crates-blockchain-conf-core-dal-message-module-network-tui-and-ws2p' into 'dev'

Resolve "Add crates blockchain, conf, core, dal, message, module, network, tui and ws2p"

Closes #68

See merge request !58
parents ddf76f37 d976f9bc
No related branches found
No related tags found
1 merge request!58Resolve "Add crates blockchain, conf, core, dal, message, module, network, tui and ws2p"
Showing
with 1936 additions and 40 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
extern crate serde;
extern crate serde_json;
use duniter_crypto::keys::{ed25519, PublicKey};
pub fn parse_exclusions(json_datas: &str) -> Option<Vec<ed25519::PublicKey>> {
let raw_exclusions: serde_json::Value = serde_json::from_str(json_datas).unwrap();
if raw_exclusions.is_array() {
Some(parse_exclusions_from_json_value(
raw_exclusions.as_array().unwrap(),
))
} else {
None
}
}
pub fn parse_exclusions_from_json_value(
array_exclusions: &[serde_json::Value],
) -> Vec<ed25519::PublicKey> {
let mut exclusions: Vec<ed25519::PublicKey> = Vec::new();
for exclusion in array_exclusions.iter() {
exclusions.push(PublicKey::from_base58(exclusion.as_str().unwrap()).unwrap());
}
exclusions
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
extern crate serde;
extern crate serde_json;
extern crate sqlite;
use super::super::DuniterDB;
use duniter_crypto::keys::ed25519;
use duniter_documents::blockchain::v10::documents::certification::CompactCertificationDocument;
use duniter_documents::Blockstamp;
pub fn write_certification(
cert: &CompactCertificationDocument,
db: &DuniterDB,
written_blockstamp: Blockstamp,
written_timestamp: u64,
) {
let mut cursor = db
.0
.prepare("SELECT median_time FROM blocks WHERE number=? AND fork=0 LIMIT 1;")
.expect("invalid write_certification sql request")
.cursor();
cursor
.bind(&[sqlite::Value::Integer(cert.block_number.0 as i64)])
.expect("convert blockstamp to timestamp failure at step 1 !");
let mut created_timestamp: i64 = 0;
if let Some(row) = cursor
.next()
.expect("convert blockstamp to timestamp failure at step 2 !")
{
created_timestamp = row[0]
.as_integer()
.expect("Fail to write cert, impossible to get created_timestamp !");
}
db.0
.execute(
format!("INSERT INTO certifications (pubkey_from, pubkey_to, created_on, signature, written_on, expires_on, chainable_on) VALUES ('{}', '{}', '{}', '{}', '{}', {}, {});",
cert.issuer, cert.target, cert.block_number.0, cert.signature,
written_blockstamp.to_string(),
created_timestamp+super::super::constants::G1_PARAMS.sig_validity,
written_timestamp+super::super::constants::G1_PARAMS.sig_period
))
.expect("Fail to execute INSERT certification !");
}
pub fn remove_certification(from: ed25519::PublicKey, to: ed25519::PublicKey, db: &DuniterDB) {
db.0
.execute(format!(
"DELETE FROM certifications WHERE pubkey_from={} AND pubkey_to={}",
from, to
))
.expect("Fail to execute DELETE certification !");
}
This diff is collapsed.
pub mod block;
pub mod certification;
pub mod identity;
pub mod requests;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment