tonlib_core/message/
common_msg_info.rs

1use num_bigint::BigUint;
2
3use super::ZERO_COINS;
4use crate::TonAddress;
5
6#[derive(Clone, Debug, PartialEq)]
7pub enum CommonMsgInfo {
8    InternalMessage(InternalMessage),
9    ExternalIncomingMessage(ExternalIncomingMessage),
10    ExternalOutgoingMessage(ExternalOutgoingMessage),
11}
12
13#[derive(Clone, Debug, PartialEq)]
14pub struct InternalMessage {
15    /// Hyper cube routing flag.
16    pub ihr_disabled: bool,
17    /// Message should be bounced if there are errors during processing.
18    /// If message's flat bounce = 1, it calls bounceable.
19    pub bounce: bool,
20    /// Flag that describes, that message itself is a result of bounce.
21    pub bounced: bool,
22    /// Address of smart contract sender of message.
23    pub src: TonAddress,
24    /// Address of smart contract destination of message.
25    pub dest: TonAddress,
26    /// Structure which describes currency information including total funds transferred in message.
27    pub value: BigUint,
28    /// Fees for hyper routing delivery
29    pub ihr_fee: BigUint,
30    /// Fees for forwarding messages assigned by validators
31    pub fwd_fee: BigUint,
32    /// Logic time of sending message assigned by validator. Using for ordering actions in smart contract.
33    pub created_lt: u64,
34    /// Unix time
35    pub created_at: u32,
36}
37
38#[derive(Clone, Debug, PartialEq)]
39pub struct ExternalIncomingMessage {
40    /// Address of a external sender of the message.
41    pub src: TonAddress,
42    /// Address of smart contract destination of message.
43    pub dest: TonAddress,
44    /// Fee for executing and delivering of message.
45    pub import_fee: BigUint,
46}
47
48#[derive(Clone, Debug, PartialEq)]
49pub struct ExternalOutgoingMessage {
50    /// Address of a external sender of the message.
51    pub src: TonAddress,
52    /// Address of smart contract destination of message.
53    pub dest: TonAddress,
54    /// Logic time of sending message assigned by validator. Using for ordering actions in smart contract.
55    pub created_lt: u64,
56    /// Unix time
57    pub created_at: u32,
58}
59
60impl CommonMsgInfo {
61    pub fn new_default_internal(dest: &TonAddress, value: &BigUint) -> Self {
62        CommonMsgInfo::InternalMessage(InternalMessage {
63            ihr_disabled: false,
64            bounce: true,
65            bounced: true,
66            src: TonAddress::NULL,
67            dest: dest.clone(),
68            value: value.clone(),
69            ihr_fee: ZERO_COINS.clone(),
70            fwd_fee: ZERO_COINS.clone(),
71            created_lt: 0,
72            created_at: 0,
73        })
74    }
75    pub fn src(&self) -> TonAddress {
76        match self {
77            CommonMsgInfo::InternalMessage(m) => m.src.clone(),
78            CommonMsgInfo::ExternalIncomingMessage(m) => m.src.clone(),
79            CommonMsgInfo::ExternalOutgoingMessage(m) => m.src.clone(),
80        }
81    }
82    pub fn dest(&self) -> TonAddress {
83        match self {
84            CommonMsgInfo::InternalMessage(m) => m.dest.clone(),
85            CommonMsgInfo::ExternalIncomingMessage(m) => m.dest.clone(),
86            CommonMsgInfo::ExternalOutgoingMessage(m) => m.dest.clone(),
87        }
88    }
89
90    // todo impl others and think about better api
91}