mirror of
https://github.com/fluencelabs/trust-graph
synced 2025-04-24 23:32:13 +00:00
add_root function
This commit is contained in:
parent
a9d1e72653
commit
3bcc928a72
@ -70,3 +70,24 @@ impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fce]
|
||||||
|
pub struct AddRootResult {
|
||||||
|
pub ret_code: u32,
|
||||||
|
pub error: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Result<(), ServiceError>> for AddRootResult {
|
||||||
|
fn from(result: Result<(), ServiceError>) -> Self {
|
||||||
|
match result {
|
||||||
|
Ok(()) => AddRootResult {
|
||||||
|
ret_code: 0,
|
||||||
|
error: "".to_string(),
|
||||||
|
},
|
||||||
|
Err(e) => AddRootResult {
|
||||||
|
ret_code: 1,
|
||||||
|
error: format!("{}", e),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::dto::Certificate;
|
use crate::dto::Certificate;
|
||||||
use crate::results::{AllCertsResult, InsertResult, WeightResult};
|
use crate::results::{AddRootResult, AllCertsResult, InsertResult, WeightResult};
|
||||||
use crate::service_impl::{
|
use crate::service_impl::{
|
||||||
get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw,
|
add_root_impl, get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw,
|
||||||
};
|
};
|
||||||
use fluence::fce;
|
use fluence::{fce, CallParameters};
|
||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
/// add a certificate in string representation to trust graph if it is valid
|
/// add a certificate in string representation to trust graph if it is valid
|
||||||
@ -30,6 +30,21 @@ fn get_all_certs(issued_for: String) -> AllCertsResult {
|
|||||||
get_all_certs_impl(issued_for).into()
|
get_all_certs_impl(issued_for).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fce]
|
||||||
|
/// could add only a host of a trust graph service
|
||||||
|
fn add_root(pk: String, weight: u32) -> AddRootResult {
|
||||||
|
let call_parameters: CallParameters = fluence::get_call_parameters();
|
||||||
|
let init_peer_id = call_parameters.init_peer_id.clone();
|
||||||
|
if call_parameters.host_id == init_peer_id {
|
||||||
|
add_root_impl(pk, weight).into()
|
||||||
|
} else {
|
||||||
|
return AddRootResult {
|
||||||
|
ret_code: 1,
|
||||||
|
error: "Root could add only a host of trust graph service",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO rewrite test after #[fce_test] will be implemented
|
// TODO rewrite test after #[fce_test] will be implemented
|
||||||
// #[fce]
|
// #[fce]
|
||||||
// fn test() -> String {
|
// fn test() -> String {
|
||||||
|
@ -6,7 +6,7 @@ use std::convert::{Into, TryInto};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use thiserror::Error as ThisError;
|
use thiserror::Error as ThisError;
|
||||||
use trust_graph::{CertificateError, TrustGraphError};
|
use trust_graph::{CertificateError, PublicKeyHashable, TrustGraphError};
|
||||||
|
|
||||||
#[derive(ThisError, Debug)]
|
#[derive(ThisError, Debug)]
|
||||||
pub enum ServiceError {
|
pub enum ServiceError {
|
||||||
@ -61,3 +61,10 @@ pub fn insert_cert_impl(certificate: Certificate, duration: u64) -> Result<(), S
|
|||||||
add_cert(certificate, duration)?;
|
add_cert(certificate, duration)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_root_impl(pk: String, weight: u32) -> Result<(), ServiceError> {
|
||||||
|
let mut tg = get_data().lock();
|
||||||
|
let pk = PublicKey::from_base58(&pk)?.into();
|
||||||
|
tg.add_root_weight(pk, weight)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user