safe_nd/messaging/cmd.rs
1// Copyright 2019 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under the MIT license <LICENSE-MIT
4// https://opensource.org/licenses/MIT> or the Modified BSD license <LICENSE-BSD
5// https://opensource.org/licenses/BSD-3-Clause>, at your option. This file may not be copied,
6// modified, or distributed except according to those terms. Please review the Licences for the
7// specific language governing permissions and limitations relating to use of the SAFE Network
8// Software.
9
10use super::{auth::AuthCmd, data::DataCmd, transfer::TransferCmd, AuthorisationKind};
11use crate::{DebitAgreementProof, XorName};
12use serde::{Deserialize, Serialize};
13
14/// TODO: docs
15#[allow(clippy::large_enum_variant)]
16#[derive(Hash, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
17pub enum Cmd {
18 ///
19 Auth(AuthCmd),
20 ///
21 Data {
22 ///
23 cmd: DataCmd,
24 ///
25 payment: DebitAgreementProof,
26 },
27 ///
28 Transfer(TransferCmd),
29}
30
31impl Cmd {
32 /// Returns the type of authorisation needed for the cuest.
33 pub fn authorisation_kind(&self) -> AuthorisationKind {
34 use Cmd::*;
35 match self {
36 Auth(c) => c.authorisation_kind(),
37 Data { cmd, .. } => cmd.authorisation_kind(),
38 Transfer(c) => c.authorisation_kind(),
39 }
40 }
41
42 /// Returns the address of the destination for `cuest`.
43 pub fn dst_address(&self) -> XorName {
44 use Cmd::*;
45 match self {
46 Auth(c) => c.dst_address(),
47 Data { cmd, .. } => cmd.dst_address(),
48 Transfer(c) => c.dst_address(),
49 }
50 }
51}