2021-02-12 14:42:51 +03:00
|
|
|
use crate::dto::Certificate;
|
2021-08-26 17:27:05 +03:00
|
|
|
use crate::results::{AddRootResult, AllCertsResult, InsertResult, WeightResult, GetTrustMetadataResult};
|
|
|
|
use crate::service_impl::{add_root_impl, get_all_certs_impl, get_weight_impl, insert_cert_impl, insert_cert_impl_raw, get_trust_metadata_imp};
|
2021-08-01 16:31:13 +03:00
|
|
|
use marine_rs_sdk::{CallParameters, marine};
|
2021-02-12 14:34:23 +03:00
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-12 14:27:22 +03:00
|
|
|
/// add a certificate in string representation to trust graph if it is valid
|
2021-02-12 14:34:23 +03:00
|
|
|
/// see `trust_graph::Certificate` class for string encoding/decoding
|
2021-02-12 14:27:22 +03:00
|
|
|
// TODO change `current_time` to time service
|
2021-02-12 14:34:23 +03:00
|
|
|
fn insert_cert_raw(certificate: String, current_time: u64) -> InsertResult {
|
|
|
|
insert_cert_impl_raw(certificate, current_time).into()
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-12 14:34:23 +03:00
|
|
|
/// add a certificate in JSON representation to trust graph if it is valid
|
|
|
|
/// see `dto::Certificate` class for structure
|
|
|
|
fn insert_cert(certificate: Certificate, current_time: u64) -> InsertResult {
|
2021-02-12 14:27:22 +03:00
|
|
|
insert_cert_impl(certificate, current_time).into()
|
2021-01-27 12:57:19 +03:00
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-08-12 16:16:58 +03:00
|
|
|
fn get_weight(peer_id: String) -> WeightResult {
|
|
|
|
get_weight_impl(peer_id).into()
|
2021-02-10 15:23:51 +03:00
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-10 15:23:51 +03:00
|
|
|
fn get_all_certs(issued_for: String) -> AllCertsResult {
|
|
|
|
get_all_certs_impl(issued_for).into()
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-12 14:54:08 +03:00
|
|
|
/// could add only a host of a trust graph service
|
2021-08-12 16:16:58 +03:00
|
|
|
fn add_root(peer_id: String, weight: u32) -> AddRootResult {
|
2021-08-01 16:31:13 +03:00
|
|
|
let call_parameters: CallParameters = marine_rs_sdk::get_call_parameters();
|
2021-02-12 14:54:08 +03:00
|
|
|
let init_peer_id = call_parameters.init_peer_id.clone();
|
|
|
|
if call_parameters.host_id == init_peer_id {
|
2021-08-12 16:16:58 +03:00
|
|
|
add_root_impl(peer_id, weight).into()
|
2021-02-12 14:54:08 +03:00
|
|
|
} else {
|
|
|
|
return AddRootResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: true,
|
2021-02-12 14:54:38 +03:00
|
|
|
error: "Root could add only a host of trust graph service".to_string(),
|
2021-02-12 14:54:08 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 17:27:05 +03:00
|
|
|
|
|
|
|
#[marine]
|
|
|
|
fn get_trust_metadata(peer_id: String, expires_at: u64, issued_at: u64) -> GetTrustMetadataResult {
|
|
|
|
get_trust_metadata_imp(peer_id, expires_at, issued_at).into()
|
|
|
|
}
|
|
|
|
|
|
|
|
// #[marine]
|
|
|
|
// fn issue_trust(peer_id: String, expires_at: u64, issued_at: u64, signed_metadata: Vec<u8>, sig_type: String) -> IssueTrustResult {
|
|
|
|
// issue_trust_impl(peer_id, expires_at, issued_at, signed_metadata).into()
|
|
|
|
// }
|