Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream 0.17.1 #79

Merged
merged 40 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a45653e
Downstream 0.15.2
dbaranovstonfi Jun 10, 2024
67bd45a
Merge branch 'downstream-0.15.2' into 'main'
dbaranovstonfi Jun 10, 2024
90541b6
Downstream 0.15.3
dbaranovstonfi Jun 12, 2024
efbeab6
Merge branch 'downstream-0.15.3' into 'main'
dbaranovstonfi Jun 12, 2024
70223d3
Impl 114: store_uint, store_int + tests
Jun 6, 2024
12df404
Impl #144: fix cargo clippy
Jun 11, 2024
03e07b7
fix comments
Jun 13, 2024
3afebe6
Merge branch '144-fix-store-int-panic' into 'main'
Jun 13, 2024
fbd556e
NI: bump rust-build container
dbaranovstonfi Jun 26, 2024
33c58d0
Merge branch 'NI-bump-container' into 'main'
dbaranovstonfi Jun 26, 2024
d29d3fc
Impl #NI: add trace logs around TvmEmulatorUnsafe methods
Jun 19, 2024
0244ab0
Merge branch 'ni-trace-logs-for-tonlibjson-usage' into 'main'
dbaranovstonfi Jun 26, 2024
d707be7
Impl #142: Added timestamp limit to LatestContactTransactionCache
Jun 26, 2024
87c2715
Merge branch '142-add_timestamp_limit' into 'main'
dbaranovstonfi Jun 26, 2024
d43113f
Merge remote-tracking branch 'upstream/main'
dbaranov34 Jun 28, 2024
ca4ad69
NI: misc fixes after updating clippy to 1.79
dbaranovstonfi Jul 1, 2024
cce737f
Merge branch 'NI-clippy-updated' into 'main'
dbaranovstonfi Jul 1, 2024
6ed55d5
Impl #147: parsers and some refactoring of jettons
dbaranovstonfi Jul 2, 2024
0e11a56
Merge branch '147-jetton-transfer-parser' into 'main'
dbaranovstonfi Jul 2, 2024
4552309
Impl #149: exotic cells support
Jul 4, 2024
b910921
Merge branch '149-exotic-cells' into 'main'
Jul 4, 2024
19d6c8a
Resolve "Implement exotic cells support"
Jul 4, 2024
c4dae48
Merge branch '149-exotic-cells' into 'main'
Jul 4, 2024
40f29ba
Impl #156: Remove AsRef<ArcCell>
SlavikBaranov Jul 8, 2024
086d485
Merge branch '156-no-asref' into 'main'
Jul 8, 2024
7788f64
NI: Downstream 0.16
dbaranovstonfi Jul 11, 2024
e032a37
Merge branch 'downstream-0.16.0' into 'main'
dbaranovstonfi Jul 11, 2024
351769d
NI: fix transfer_notification parser/builder, added tests
SathemBite Jul 11, 2024
440e501
Merge branch 'ni-fix-transfer-notification' into 'main'
dbaranovstonfi Jul 11, 2024
f5345b6
NI: fix tests
SathemBite Jul 11, 2024
3d907b4
Merge branch 'ni-fix-tests' into 'main'
dbaranovstonfi Jul 11, 2024
170251f
NI: downstram v0.17.0
dbaranovstonfi Jul 12, 2024
cee724e
Merge branch 'downstream-0.17.0' into 'main'
dbaranovstonfi Jul 12, 2024
8379e3e
NI: CellBuilder and CellParser modifications torn out from 0.18.0-dev
dbaranovstonfi Aug 7, 2024
d37fca6
Merge branch 'NI-cherry-pick-either-and-maybe' into '0.17-extended-su…
dbaranovstonfi Aug 7, 2024
8770433
ignoring remaining refs
dbaranov34 Aug 7, 2024
9874fe3
bump version
dbaranov34 Aug 7, 2024
9e2ef7a
Merge remote-tracking branch 'upstream/main' into upstream-0.17.1
dbaranov34 Aug 7, 2024
d5312a6
fmt
dbaranov34 Aug 7, 2024
7ce0789
fixed merge conflicts
dbaranov34 Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tonlib"
version = "0.17.0"
version = "0.17.1"
edition = "2021"
description = "Rust SDK for The Open Network"
license = "MIT"
Expand Down
89 changes: 68 additions & 21 deletions src/cell.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
use std::hash::Hash;
use std::io::Cursor;
use std::ops::Deref;
use std::sync::Arc;
use std::{fmt, io};
Expand All @@ -10,11 +9,12 @@ pub use bag_of_cells::*;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use base64::Engine;
use bit_string::*;
use bitstream_io::{BigEndian, BitReader, BitWrite, BitWriter};
use bitstream_io::{BigEndian, BitWrite, BitWriter};
pub use builder::*;
pub use dict_loader::*;
pub use error::*;
use hmac::digest::Digest;
use lazy_static::lazy_static;
use num_bigint::BigUint;
use num_traits::{One, ToPrimitive};
pub use parser::*;
Expand All @@ -26,6 +26,7 @@ pub use util::*;

use crate::cell::cell_type::CellType;
use crate::cell::level_mask::LevelMask;
use crate::types::{TonHash, DEFAULT_CELL_HASH};

mod bag_of_cells;
mod bit_string;
Expand All @@ -41,14 +42,17 @@ mod slice;
mod state_init;
mod util;

const HASH_BYTES: usize = 32;
const DEPTH_BYTES: usize = 2;
const MAX_LEVEL: u8 = 3;

pub type CellHash = [u8; HASH_BYTES];
pub type ArcCell = Arc<Cell>;

pub type SnakeFormattedDict = HashMap<CellHash, Vec<u8>>;
pub type SnakeFormattedDict = HashMap<TonHash, Vec<u8>>;

lazy_static! {
pub static ref EMPTY_CELL: Cell = Cell::default();
pub static ref EMPTY_ARC_CELL: ArcCell = Arc::new(Cell::default());
}

#[derive(PartialEq, Eq, Clone, Hash)]
pub struct Cell {
Expand All @@ -57,7 +61,7 @@ pub struct Cell {
references: Vec<ArcCell>,
cell_type: CellType,
level_mask: LevelMask,
hashes: [CellHash; 4],
hashes: [TonHash; 4],
depths: [u16; 4],
}

Expand Down Expand Up @@ -93,15 +97,7 @@ impl Cell {
}

pub fn parser(&self) -> CellParser {
let bit_len = self.bit_len;
let cursor = Cursor::new(&self.data);
let bit_reader: BitReader<Cursor<&Vec<u8>>, BigEndian> =
BitReader::endian(cursor, BigEndian);

CellParser {
bit_len,
bit_reader,
}
CellParser::new(self.bit_len, &self.data, &self.references)
}

#[allow(clippy::let_and_return)]
Expand Down Expand Up @@ -155,11 +151,11 @@ impl Cell {
self.depths[level.min(3) as usize]
}

pub fn cell_hash(&self) -> CellHash {
pub fn cell_hash(&self) -> TonHash {
self.get_hash(MAX_LEVEL)
}

pub fn get_hash(&self, level: u8) -> CellHash {
pub fn get_hash(&self, level: u8) -> TonHash {
self.hashes[level.min(3) as usize]
}

Expand Down Expand Up @@ -340,6 +336,8 @@ impl Cell {
Arc::new(self)
}

/// It is recommended to use CellParser::next_reference() instead
#[deprecated]
pub fn expect_reference_count(&self, expected_refs: usize) -> Result<(), TonCellError> {
let ref_count = self.references.len();
if ref_count != expected_refs {
Expand All @@ -360,15 +358,22 @@ impl Debug for Cell {
CellType::PrunedBranch | CellType::MerkleProof => 'p',
CellType::MerkleUpdate => 'u',
};

// Our completion tag ONLY shows that the last byte is incomplete
// It does not correspond to real completion tag defined in
// p1.0.2 of https://docs.ton.org/tvm.pdf for details
// Null termination of bit-string defined in that document is omitted for clarity
let completion_tag = if self.bit_len % 8 != 0 { "_" } else { "" };
writeln!(
f,
"Cell {}{{ data: [{}], bit_len: {}, references: [\n",
"Cell {}{{ data: [{}{}]\n, bit_len: {}\n, references: [",
t,
self.data
.iter()
.map(|&byte| format!("{:02X}", byte))
.collect::<Vec<_>>()
.join(""),
completion_tag,
self.bit_len,
)?;

Expand All @@ -380,7 +385,35 @@ impl Debug for Cell {
)?;
}

write!(f, "] }}")
write!(
f,
"]\n cell_type: {:?}\n level_mask: {:?}\n hashes {:?}\n depths {:?}\n }}",
self.cell_type,
self.level_mask,
self.hashes
.iter()
.map(|h| h
.iter()
.map(|&byte| format!("{:02X}", byte))
.collect::<Vec<_>>()
.join(""))
.collect::<Vec<_>>(),
self.depths
)
}
}

impl Default for Cell {
fn default() -> Self {
Self {
data: Default::default(),
bit_len: Default::default(),
references: Default::default(),
cell_type: Default::default(),
level_mask: Default::default(),
hashes: [DEFAULT_CELL_HASH; 4],
depths: Default::default(),
}
}
}

Expand Down Expand Up @@ -426,7 +459,7 @@ fn calculate_hashes_and_depths(
bit_len: usize,
references: &[ArcCell],
level_mask: LevelMask,
) -> Result<([CellHash; 4], [u16; 4]), TonCellError> {
) -> Result<([TonHash; 4], [u16; 4]), TonCellError> {
let hash_count = if cell_type == CellType::PrunedBranch {
1
} else {
Expand All @@ -437,7 +470,7 @@ fn calculate_hashes_and_depths(
let hash_i_offset = total_hash_count - hash_count;

let mut depths: Vec<u16> = Vec::with_capacity(hash_count);
let mut hashes: Vec<CellHash> = Vec::with_capacity(hash_count);
let mut hashes: Vec<TonHash> = Vec::with_capacity(hash_count);

// Iterate through significant levels
for (hash_i, level_i) in (0..=level_mask.level())
Expand Down Expand Up @@ -569,3 +602,17 @@ fn write_ref_hashes(

Ok(())
}

#[cfg(test)]
mod test {
use super::Cell;

#[test]
fn default_cell() {
let result = Cell::default();

let expected = Cell::new(vec![], 0, vec![], false).unwrap();

assert_eq!(result, expected)
}
}
Loading
Loading