This commit is contained in:
DieMyst 2021-02-10 15:26:26 +03:00
parent 3a9530b92d
commit 5889ad77a3
4 changed files with 16 additions and 19 deletions

View File

@ -1,9 +1,9 @@
use fluence::WasmLoggerBuilder;
mod proxy_structs;
mod results;
mod service_api;
mod storage_impl;
mod results;
mod proxy_structs;
pub fn main() {
WasmLoggerBuilder::new()

View File

@ -1,5 +1,5 @@
use trust_graph::{Trust as TGTrust, Certificate as TGCertificate};
use fluence::fce;
use trust_graph::{Certificate as TGCertificate, Trust as TGTrust};
#[fce]
pub struct Certificate {
@ -7,12 +7,9 @@ pub struct Certificate {
}
impl From<TGCertificate> for Certificate {
fn from(t: TGCertificate) -> Self {
let chain: Vec<Trust> = t.chain.into_iter().map(|t| t.into()).collect();
return Certificate {
chain
}
return Certificate { chain };
}
}
@ -30,7 +27,6 @@ pub struct Trust {
}
impl From<TGTrust> for Trust {
fn from(t: TGTrust) -> Self {
let issued_for = bs58::encode(t.issued_for.to_bytes()).into_string();
let signature = bs58::encode(t.signature.to_bytes()).into_string();
@ -40,7 +36,7 @@ impl From<TGTrust> for Trust {
issued_for,
expires_at,
signature,
issued_at
}
issued_at,
};
}
}
}

View File

@ -1,5 +1,5 @@
use fluence::fce;
use crate::proxy_structs::Certificate;
use fluence::fce;
#[fce]
pub struct InsertResult {
@ -26,7 +26,7 @@ impl From<Result<(), String>> for InsertResult {
pub struct WeightResult {
pub ret_code: u32,
pub weight: Vec<u32>,
pub error: String
pub error: String,
}
impl From<Result<Option<u32>, String>> for WeightResult {
@ -50,7 +50,7 @@ impl From<Result<Option<u32>, String>> for WeightResult {
pub struct AllCertsResult {
pub ret_code: u32,
pub certificates: Vec<Certificate>,
pub error: String
pub error: String,
}
impl From<Result<Vec<Certificate>, String>> for AllCertsResult {
@ -68,4 +68,4 @@ impl From<Result<Vec<Certificate>, String>> for AllCertsResult {
},
}
}
}
}

View File

@ -1,3 +1,5 @@
use crate::proxy_structs::Certificate;
use crate::results::{AllCertsResult, InsertResult, WeightResult};
use crate::storage_impl::get_data;
use fluence::fce;
use fluence_identity::{KeyPair, PublicKey};
@ -5,9 +7,7 @@ use std::convert::{From, Into};
use std::fmt::Display;
use std::str::FromStr;
use std::time::Duration;
use trust_graph::{Certificate as TGCertificate};
use crate::proxy_structs::Certificate;
use crate::results::{WeightResult, InsertResult, AllCertsResult};
use trust_graph::Certificate as TGCertificate;
fn insert_cert_impl(certificate: String, duration: u64) -> Result<(), String> {
let duration = Duration::from_millis(duration);
@ -41,7 +41,8 @@ fn get_weight(public_key: String) -> WeightResult {
fn string_to_public_key(public_key: String) -> Result<PublicKey, String> {
let public_key = bs58::decode(public_key)
.into_vec().map_err(|e| format!("Couldn't decode public_key from base58: {}", e))?;
.into_vec()
.map_err(|e| format!("Couldn't decode public_key from base58: {}", e))?;
let public_key = PublicKey::from_bytes(&public_key)
.map_err(|e| format!("Couldn't decode public_key: {}", e))?;