forked from iotaledger/iota.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.rs
41 lines (33 loc) · 1.02 KB
/
storage.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
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example storage --release
use iota_client::{
storage::{sqlite, StorageAdapter},
Client,
};
#[tokio::main]
async fn main() {
// Create a client instance
let iota = Client::builder()
.with_node("https://api.lb-0.testnet.chrysalis2.com") // Insert your node URL here
.unwrap()
.finish()
.await
.unwrap();
let message = iota
.message()
.with_index("Hello")
.with_data("Tangle".as_bytes().to_vec())
.finish()
.await
.unwrap();
println!("Message ID: {}", message.id().0);
let path = "./the-storage-path.db";
let mut storage_adapter = sqlite::SqliteStorageAdapter::new(path, "table_name").unwrap();
storage_adapter
.set("message_id", message.id().0.to_string())
.await
.unwrap();
let message_id = storage_adapter.get("message_id").await.unwrap();
println!("Message ID from storage: {:?}", message_id);
}