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
//! Command `claim`
use crate::{
    api::{
        generated::api::{gear::calls::ClaimValue, runtime_types::gear_core::ids::MessageId},
        signer::Signer,
    },
    result::Result,
};
use structopt::StructOpt;

/// Claim value from mailbox.
#[derive(StructOpt, Debug)]
pub struct Claim {
    /// Claim value from.
    message_id: String,
}

impl Claim {
    pub async fn exec(&self, signer: Signer) -> Result<()> {
        let mut message_id = [0; 32];

        message_id.copy_from_slice(hex::decode(self.message_id.trim_start_matches("0x"))?.as_ref());
        signer
            .claim_value_from_mailbox(ClaimValue {
                message_id: MessageId(message_id),
            })
            .await?;

        Ok(())
    }
}