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
use crate::{
api::{
generated::api::{
gear::{calls::SendReply, Event as GearEvent},
runtime_types::gear_core::ids::MessageId,
},
signer::Signer,
Api,
},
result::Result,
};
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
pub struct Reply {
reply_to_id: String,
#[structopt(default_value = "0x")]
payload: String,
#[structopt(default_value = "0")]
gas_limit: u64,
#[structopt(default_value = "0")]
value: u128,
}
impl Reply {
pub async fn exec(&self, signer: Signer) -> Result<()> {
let events = signer.events().await?;
let r = tokio::try_join!(
self.send_reply(&signer),
Api::wait_for(events, |event| {
matches!(event, GearEvent::MessagesDispatched { .. })
})
);
r?;
Ok(())
}
async fn send_reply(&self, signer: &Signer) -> Result<()> {
let mut reply_to_id = [0; 32];
reply_to_id
.copy_from_slice(hex::decode(self.reply_to_id.trim_start_matches("0x"))?.as_ref());
signer
.send_reply(SendReply {
reply_to_id: MessageId(reply_to_id),
payload: hex::decode(self.payload.trim_start_matches("0x"))?,
gas_limit: self.gas_limit,
value: self.value,
})
.await?;
Ok(())
}
}