-
Notifications
You must be signed in to change notification settings - Fork 11
/
service-api.rs
59 lines (47 loc) · 1.38 KB
/
service-api.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[allow(unused_imports)]
use tracing::{debug, error, info, instrument, span, trace, warn, Level};
use ate::prelude::*;
#[derive(Clone, Serialize, Deserialize)]
struct Ping {
msg: String,
}
#[derive(Serialize, Deserialize)]
struct Pong {
msg: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct PingError {}
#[derive(Default)]
struct PingPongTable {}
impl PingPongTable {
async fn process(self: Arc<Self>, ping: Ping) -> Result<Pong, PingError> {
Ok(Pong { msg: ping.msg })
}
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), AteError> {
ate::log_init(0, true);
info!("creating test chain");
// Create the chain with a public/private key to protect its integrity
let conf = ConfAte::default();
let builder = ChainBuilder::new(&conf).await.build();
let chain = builder.open(&ChainKey::from("cmd")).await?;
info!("start the service on the chain");
let session = AteSessionUser::new();
chain.add_service(
&session,
Arc::new(PingPongTable::default()),
PingPongTable::process,
);
info!("sending ping");
let pong: Result<Pong, PingError> = chain
.invoke(Ping {
msg: "hi".to_string(),
})
.await?;
let pong = pong.unwrap();
info!("received pong with msg [{}]", pong.msg);
Ok(())
}