tonlib_core/wallet/versioned/
v1_v2.rs

1use crate::cell::{ArcCell, CellBuilder, CellParser, TonCellError};
2use crate::tlb_types::tlb::TLB;
3use crate::types::TonHash;
4use crate::wallet::versioned::utils::write_up_to_4_msgs;
5
6/// Is not covered by tests and it generally means unsupported
7/// WalletVersion::V1R1 | WalletVersion::V1R2 | WalletVersion::V1R3 | WalletVersion::V2R1 | WalletVersion::V2R2
8#[derive(Debug, PartialEq, Clone)]
9pub struct WalletDataV1V2 {
10    pub seqno: u32,
11    pub public_key: TonHash,
12}
13
14/// https://docs.ton.org/participate/wallets/contracts#wallet-v2
15#[derive(Debug, PartialEq, Clone)]
16pub struct WalletExtMsgBodyV2 {
17    pub msg_seqno: u32,
18    pub valid_until: u32,
19    pub msgs_modes: Vec<u8>,
20    pub msgs: Vec<ArcCell>,
21}
22
23impl WalletDataV1V2 {
24    pub fn new(public_key: TonHash) -> Self {
25        Self {
26            seqno: 0,
27            public_key,
28        }
29    }
30}
31
32impl TLB for WalletDataV1V2 {
33    fn read_definition(parser: &mut CellParser) -> Result<Self, TonCellError> {
34        Ok(Self {
35            seqno: parser.load_u32(32)?,
36            public_key: parser.load_tonhash()?,
37        })
38    }
39
40    fn write_definition(&self, dst: &mut CellBuilder) -> Result<(), TonCellError> {
41        dst.store_u32(32, self.seqno)?;
42        dst.store_tonhash(&self.public_key)?;
43        Ok(())
44    }
45}
46
47impl TLB for WalletExtMsgBodyV2 {
48    fn read_definition(parser: &mut CellParser) -> Result<Self, TonCellError> {
49        let _signature = parser.load_bytes(64)?;
50        let msg_seqno = parser.load_u32(32)?;
51        let valid_until = parser.load_u32(32)?;
52        let msgs_cnt = parser.cell.references().len();
53        let mut msgs_modes = Vec::with_capacity(msgs_cnt);
54        let mut msgs = Vec::with_capacity(msgs_cnt);
55        for _ in 0..msgs_cnt {
56            msgs_modes.push(parser.load_u8(8)?);
57            msgs.push(parser.next_reference()?);
58        }
59        Ok(Self {
60            msg_seqno,
61            valid_until,
62            msgs_modes,
63            msgs,
64        })
65    }
66
67    fn write_definition(&self, dst: &mut CellBuilder) -> Result<(), TonCellError> {
68        dst.store_u32(32, self.msg_seqno)?;
69        dst.store_u32(32, self.valid_until)?;
70        write_up_to_4_msgs(dst, &self.msgs, &self.msgs_modes)?;
71        Ok(())
72    }
73}