forked from iotaledger/iota.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_time.rs
39 lines (32 loc) · 1.11 KB
/
message_time.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
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example message_time --release
use iota_client::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();
let message_id = message.id().0;
println!("Message ID: {}", message_id);
let _ = iota.retry_until_included(&message_id, None, None).await.unwrap();
let metadata = iota.get_message().metadata(&message_id).await.unwrap();
match metadata.referenced_by_milestone_index {
Some(ms_index) => {
let ms = iota.get_milestone(ms_index).await.unwrap();
println!("Message got referenced by milestone {} at {}", ms_index, ms.timestamp);
}
_ => println!("Message is not referenced by a milestone"),
}
}