mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
sh script, several deps about serialization
This commit is contained in:
parent
c9196bc11d
commit
29f15f2b4e
22
bin/Cargo.lock
generated
22
bin/Cargo.lock
generated
@ -66,6 +66,16 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@ -1293,6 +1303,16 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bencode"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "934d8bdbaa0126dafaea9a8833424a211d9661897717846c6bb782349ca1c30d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.5"
|
||||
@ -1524,6 +1544,7 @@ name = "trust-graph-wasm"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"boolinator",
|
||||
"bs58 0.3.1",
|
||||
"fce-sqlite-connector",
|
||||
@ -1533,6 +1554,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"rmp-serde",
|
||||
"serde_bencode",
|
||||
"serde_json",
|
||||
"trust-graph",
|
||||
]
|
||||
|
@ -23,3 +23,5 @@ fce-sqlite-connector = "0.1.3"
|
||||
serde_json = "1.0"
|
||||
bs58 = "0.3.1"
|
||||
rmp-serde = "0.15.0"
|
||||
bincode = "1.3.1"
|
||||
serde_bencode = "^0.2.3"
|
||||
|
5
bin/run-repl.sh
Executable file
5
bin/run-repl.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
fce build
|
||||
mv target/wasm32-wasi/debug/trust-graph.wasm artifacts/
|
||||
RUST_LOG="info" fce-repl Config.toml
|
@ -3,6 +3,36 @@ use fluence::fce;
|
||||
use fluence_identity::KeyPair;
|
||||
use std::time::Duration;
|
||||
use trust_graph::Certificate;
|
||||
use std::str::FromStr;
|
||||
|
||||
struct InsertResult {
|
||||
ret_code: u32,
|
||||
error: String,
|
||||
}
|
||||
|
||||
// TODO: some sort of auth?
|
||||
fn insert_cert(certificate: String, duration: u64) -> InsertResult {
|
||||
|
||||
let duration = Duration::from_millis(duration);
|
||||
let certificate = Certificate::from_str(&certificate).unwrap();
|
||||
|
||||
let mut tg = get_data().lock();
|
||||
tg.add(certificate, duration).unwrap();
|
||||
|
||||
return InsertResult {
|
||||
ret_code: 0,
|
||||
error: "".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[fce]
|
||||
fn looper() {
|
||||
let mut a = 0;
|
||||
while true {
|
||||
a = a + 1;
|
||||
log::info!("{}", a)
|
||||
}
|
||||
}
|
||||
|
||||
#[fce]
|
||||
fn test() -> String {
|
||||
|
@ -12,12 +12,13 @@ use fce_sqlite_connector::Value;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use trust_graph::{Auth, PublicKeyHashable, Revoke, Storage, TrustGraph, TrustNode, Weight};
|
||||
use std::ops::Deref;
|
||||
|
||||
static INSTANCE: OnceCell<Mutex<TrustGraph>> = OnceCell::new();
|
||||
|
||||
pub fn get_data() -> &'static Mutex<TrustGraph> {
|
||||
INSTANCE.get_or_init(|| {
|
||||
let db_path = "/tmp/users.sqlite";
|
||||
let db_path = "/tmp/users123123.sqlite";
|
||||
let connection = fce_sqlite_connector::open(db_path).unwrap();
|
||||
|
||||
let init_sql = "CREATE TABLE IF NOT EXISTS trustnodes(
|
||||
@ -59,11 +60,16 @@ impl Storage for SqliteStorage {
|
||||
|
||||
match cursor.next().unwrap() {
|
||||
Some(r) => {
|
||||
let tn_bin = r[0]
|
||||
log::info!("row: {:?}", r);
|
||||
let tn_bin: &[u8] = r[0]
|
||||
.as_binary()
|
||||
.expect("unexpected: 'trustnode' in a table should be as binary");
|
||||
|
||||
log::info!("binary: {:?}", tn_bin);
|
||||
|
||||
let trust_node: TrustNode = rmp_serde::from_read_ref(tn_bin)
|
||||
// let trust_node: TrustNode = bincode::deserialize(tn_bin)
|
||||
// let trust_node: TrustNode = serde_bencode::de::from_bytes(tn_bin)
|
||||
.expect("unexpected: 'trustnode' should be as correct binary");
|
||||
|
||||
log::info!("trustnode: {:?}", trust_node);
|
||||
@ -82,9 +88,11 @@ impl Storage for SqliteStorage {
|
||||
.unwrap()
|
||||
.cursor();
|
||||
|
||||
log::info!("insert trustnode: {:?}", node);
|
||||
|
||||
let tn_vec = rmp_serde::to_vec(&node).unwrap();
|
||||
// let tn_vec = bincode::serialize(&node).unwrap();
|
||||
let tn_vec = serde_bencode::to_bytes(&node).unwrap();
|
||||
|
||||
|
||||
|
||||
cursor
|
||||
.bind(&[Value::String(format!("{}", pk)), Value::Binary(tn_vec)])
|
||||
|
Loading…
Reference in New Issue
Block a user