-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.rs
More file actions
90 lines (80 loc) · 2.83 KB
/
bridge.rs
File metadata and controls
90 lines (80 loc) · 2.83 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Bridge API example demonstrating deposit and supported assets endpoints.
//!
//! Run with tracing enabled:
//! ```sh
//! RUST_LOG=info,hyper_util=off,hyper=off,reqwest=off,h2=off,rustls=off cargo run --example bridge --features bridge,tracing
//! ```
//!
//! Optionally log to a file:
//! ```sh
//! LOG_FILE=bridge.log RUST_LOG=info,hyper_util=off,hyper=off,reqwest=off,h2=off,rustls=off cargo run --example bridge --features bridge,tracing
//! ```
use std::fs::File;
use kuest_client_sdk::bridge::Client;
use kuest_client_sdk::bridge::types::{DepositRequest, StatusRequest};
use kuest_client_sdk::types::address;
use tracing::{debug, info};
use tracing_subscriber::EnvFilter;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::util::SubscriberInitExt as _;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
if let Ok(path) = std::env::var("LOG_FILE") {
let file = File::create(path)?;
tracing_subscriber::registry()
.with(EnvFilter::from_default_env())
.with(
tracing_subscriber::fmt::layer()
.with_writer(file)
.with_ansi(false),
)
.init();
} else {
tracing_subscriber::fmt::init();
}
let client = Client::default();
match client.supported_assets().await {
Ok(response) => {
info!(
endpoint = "supported_assets",
count = response.supported_assets.len()
);
for asset in &response.supported_assets {
info!(
endpoint = "supported_assets",
name = %asset.token.name,
symbol = %asset.token.symbol,
chain = %asset.chain_name,
chain_id = asset.chain_id,
min_usd = %asset.min_checkout_usd
);
}
}
Err(e) => debug!(endpoint = "supported_assets", error = %e),
}
let request = DepositRequest::builder()
.address(address!("56687bf447db6ffa42ffe2204a05edaa20f55839"))
.build();
match client.deposit(&request).await {
Ok(response) => {
info!(
endpoint = "deposit",
evm = %response.address.evm,
svm = %response.address.svm,
btc = %response.address.btc,
note = ?response.note
);
}
Err(e) => debug!(endpoint = "deposit", error = %e),
}
let status_request = StatusRequest::builder()
.address("bc1qs82vw5pczv9uj44n4npscldkdjgfjqu7x9mlna")
.build();
match client.status(&status_request).await {
Ok(response) => {
info!(endpoint = "status", count = response.transactions.len());
}
Err(e) => debug!(endpoint = "status", error = %e),
}
Ok(())
}