Skip to content

Commit ed63292

Browse files
authored
Merge pull request #30 from tonlabs/master-RC
Automatic update project. #none
2 parents d184970 + 5a6e703 commit ed63292

File tree

6 files changed

+77
-87
lines changed

6 files changed

+77
-87
lines changed

commit_hash.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8a4777b6bc1065019a9b5c52ac2a740a48fd926c
1+
44cb7e493735f425c1191e5df6239a4a6fd53d26

deps_map.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"ton-block":"447a265d0013336b3c506cad45558922aa67f9f6","ton-types":"164867fa842b1efd0eeb378e727a17677ae8a322"}
1+
{"ton-block":"20dd6ecb7dec5163d7316fdacd9bb2876008a8c7","ton-types":"164867fa842b1efd0eeb378e727a17677ae8a322"}

ton_api/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = [ 'Aaron Gallagher <[email protected]>', 'Connie Hilarides <[email protected]
33
description = 'Minimal wrappers for TON serialization using TL-schema'
44
edition = '2018'
55
name = 'ton_api'
6-
version = '0.2.116'
6+
version = '0.2.117'
77

88
[dependencies]
99
byteorder = '1.4'
@@ -15,7 +15,7 @@ ordered-float = '2.8'
1515
secstr = '0.4'
1616
serde = '1.0'
1717
serde_derive = '1.0'
18-
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block', tag = '1.7.35' }
18+
ton_block = { git = 'https://github.com/tonlabs/ton-labs-block', tag = '1.7.36' }
1919
ton_types = { git = 'https://github.com/tonlabs/ton-labs-types', tag = '1.10.12' }
2020

2121
[build-dependencies]

ton_api/src/lib.rs

+56-79
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@
1414
#![allow(clippy::unreadable_literal)]
1515
#![deny(private_in_public)]
1616

17-
use std::{fmt, io};
18-
use std::any::Any;
19-
use std::cmp::Ordering;
20-
use std::convert::TryInto;
21-
use std::fmt::{Display, Formatter};
22-
use std::hash::Hash;
23-
2417
use failure::Fail;
18+
use std::{any::Any, fmt, hash::Hash, io::{self, Read, Write}};
2519

26-
use ton_block::ShardIdent;
27-
pub use ton_types::Result;
20+
use ton_block::{BlockIdExt, ShardIdent};
21+
use ton_types::Result;
2822
use ton_types::UInt256;
2923

30-
use crate::ton::ton_node::blockidext::BlockIdExt;
31-
3224
macro_rules! _invalid_id {
3325
($id:ident) => {
3426
Err(crate::InvalidConstructor { expected: Self::possible_constructors(), received: $id }.into())
@@ -60,12 +52,12 @@ pub struct InvalidConstructor {
6052

6153
/// Struct for deserializing TL-scheme objects from any `io::Read`
6254
pub struct Deserializer<'r> {
63-
reader: &'r mut dyn io::Read,
55+
reader: &'r mut dyn Read,
6456
}
6557

6658
impl<'r> Deserializer<'r> {
6759
/// Create `Deserializer` with given `io::Read` trait object
68-
pub fn new(reader: &'r mut dyn io::Read) -> Self {
60+
pub fn new(reader: &'r mut dyn Read) -> Self {
6961
Deserializer { reader }
7062
}
7163

@@ -95,7 +87,7 @@ impl<'r> Deserializer<'r> {
9587
}
9688
}
9789

98-
impl<'r> io::Read for Deserializer<'r> {
90+
impl<'r> Read for Deserializer<'r> {
9991
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
10092
self.reader.read(buf)
10193
}
@@ -165,12 +157,12 @@ impl DynamicDeserializer {
165157

166158
/// Struct for serializing TL-scheme objects into any `io::Write`
167159
pub struct Serializer<'w> {
168-
writer: &'w mut dyn io::Write,
160+
writer: &'w mut dyn Write,
169161
}
170162

171163
impl<'w> Serializer<'w> {
172164
/// Create `Serializer` with given `io::Write` trait object
173-
pub fn new(writer: &'w mut dyn io::Write) -> Self {
165+
pub fn new(writer: &'w mut dyn Write) -> Self {
174166
Serializer { writer }
175167
}
176168

@@ -205,7 +197,7 @@ impl<'w> Serializer<'w> {
205197
}
206198
}
207199

208-
impl<'w> io::Write for Serializer<'w> {
200+
impl<'w> Write for Serializer<'w> {
209201
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
210202
self.writer.write(buf)
211203
}
@@ -266,85 +258,70 @@ pub trait Function: AnyBoxedSerialize {
266258
type Reply: BoxedDeserialize + AnyBoxedSerialize;
267259
}
268260

269-
impl PartialOrd for BlockIdExt {
270-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
271-
Some(self.cmp(other))
272-
}
273-
}
274-
275-
impl Ord for BlockIdExt {
276-
fn cmp(&self, other: &Self) -> Ordering {
277-
self.workchain.cmp(&other.workchain)
278-
.then(self.shard.cmp(&other.shard))
279-
.then(self.seqno.cmp(&other.seqno))
280-
.then(self.root_hash.cmp(&other.root_hash))
281-
.then(self.file_hash.cmp(&other.file_hash))
261+
impl BareDeserialize for BlockIdExt {
262+
fn deserialize_bare(de: &mut Deserializer) -> Result<Self> {
263+
let shard = ShardIdent::with_tagged_prefix(
264+
de.read_bare::<crate::ton::int>()?,
265+
de.read_bare::<crate::ton::long>()? as u64
266+
)?;
267+
let ret = Self::with_params(
268+
shard,
269+
de.read_bare::<crate::ton::int>()? as u32,
270+
de.read_bare::<UInt256>()?,
271+
de.read_bare::<UInt256>()?
272+
);
273+
Ok(ret)
282274
}
283275
}
284276

285-
impl Display for BlockIdExt {
286-
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
287-
write!(f, "({}:{:016x}, {}, rh {}, fh {})", self.workchain, self.shard, self.seqno, hex::encode(self.root_hash.0), hex::encode(self.file_hash.0))
277+
impl BareSerialize for BlockIdExt {
278+
fn constructor(&self) -> ConstructorNumber {
279+
crate::ton::ton_node::blockidext::TL_TAG
288280
}
289-
}
290-
291-
impl From<&ton_block::BlockIdExt> for BlockIdExt {
292-
fn from(block_id_ext: &ton_block::BlockIdExt) -> Self {
293-
Self {
294-
workchain: block_id_ext.shard().workchain_id(),
295-
shard: block_id_ext.shard().shard_prefix_with_tag() as i64,
296-
seqno: block_id_ext.seq_no() as i32,
297-
root_hash: block_id_ext.root_hash().into(),
298-
file_hash: block_id_ext.file_hash().into(),
299-
}
300-
}
301-
}
302-
303-
impl From<ton_block::BlockIdExt> for BlockIdExt {
304-
fn from(block_id_ext: ton_block::BlockIdExt) -> Self {
305-
Self::from(&block_id_ext)
281+
fn serialize_bare(&self, se: &mut Serializer) -> Result<()> {
282+
let shard = self.shard();
283+
se.write_bare::<crate::ton::int>(&shard.workchain_id())?;
284+
se.write_bare::<crate::ton::long>(&(shard.shard_prefix_with_tag() as i64))?;
285+
se.write_bare::<crate::ton::int>(&(self.seq_no() as i32))?;
286+
se.write_bare::<UInt256>(self.root_hash())?;
287+
se.write_bare::<UInt256>(self.file_hash())?;
288+
Ok(())
306289
}
307290
}
308291

309-
impl TryInto<ton_block::BlockIdExt> for &BlockIdExt {
310-
type Error = failure::Error;
311-
312-
fn try_into(self) -> Result<ton_block::BlockIdExt> {
313-
Ok(ton_block::BlockIdExt::with_params(
314-
ShardIdent::with_tagged_prefix(self.workchain, self.shard as u64)?,
315-
self.seqno as u32,
316-
self.root_hash.into(),
317-
self.file_hash.into(),
318-
))
292+
impl BoxedDeserialize for BlockIdExt {
293+
fn possible_constructors() -> Vec<crate::ConstructorNumber> {
294+
vec![crate::ton::ton_node::blockidext::TL_TAG]
319295
}
320-
}
321-
322-
impl Display for crate::ton::int256 {
323-
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
324-
write!(f, "{}", hex::encode(self.0))
296+
fn deserialize_boxed(id: ConstructorNumber, de: &mut Deserializer) -> Result<Self> {
297+
if id == crate::ton::ton_node::blockidext::TL_TAG {
298+
de.read_bare()
299+
} else {
300+
_invalid_id!(id)
301+
}
325302
}
326303
}
327304

328-
impl From<UInt256> for crate::ton::int256 {
329-
fn from(value: UInt256) -> Self {
330-
Self(value.into())
305+
impl BoxedSerialize for BlockIdExt {
306+
fn serialize_boxed(&self) -> (ConstructorNumber, &dyn BareSerialize) {
307+
(crate::ton::ton_node::blockidext::TL_TAG, self)
331308
}
332309
}
333310

334-
impl From<&UInt256> for crate::ton::int256 {
335-
fn from(value: &UInt256) -> Self {
336-
Self(value.clone().into())
311+
impl BareDeserialize for UInt256 {
312+
fn deserialize_bare(de: &mut Deserializer) -> Result<Self> {
313+
let mut data = [0u8; 32];
314+
de.read_exact(&mut data)?;
315+
Ok(Self::with_array(data))
337316
}
338317
}
339318

340-
impl Into<UInt256> for crate::ton::int256 {
341-
fn into(self) -> UInt256 {
342-
UInt256::from(self.0)
319+
impl BareSerialize for UInt256 {
320+
fn constructor(&self) -> ConstructorNumber {
321+
unreachable!()
343322
}
344-
}
345-
346-
impl Into<UInt256> for &crate::ton::int256 {
347-
fn into(self) -> UInt256 {
348-
UInt256::from(self.0)
323+
fn serialize_bare(&self, se: &mut Serializer) -> Result<()> {
324+
se.write_all(self.as_slice())?;
325+
Ok(())
349326
}
350327
}

ton_api/src/ton_prelude.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ impl From<Vec<u8>> for bytes {
104104
pub struct int128(pub [u8; 16]);
105105

106106
/// Represents 256-bit unsigned integer.
107-
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
108-
pub struct int256(pub [u8; 32]);
107+
//#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
108+
//pub struct int256(pub [u8; 32]);
109+
pub(crate) type int256 = ton_types::UInt256;
109110

110111
impl_byteslike!(@common bytes);
111112
impl_byteslike!(@arraylike int128);
112-
impl_byteslike!(@arraylike int256);
113+
//impl_byteslike!(@arraylike int256);
113114

114115
/// Represents base TL-object type.
115116
pub struct TLObject(Box<dyn AnyBoxedSerialize>);

ton_tl_codegen/src/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ impl Constructor<TypeIR, FieldIR> {
14221422
let derives = gen_derives(config, quote! { Debug, Default, Clone, PartialEq }, name.to_string());
14231423
let impl_generics = self.impl_generics();
14241424
let fields = self.fields_tokens(quote! {pub}, quote! {;});
1425-
1425+
14261426
quote! {
14271427
#[derive(#derives)]
14281428
#[doc = #doc]
@@ -1534,6 +1534,13 @@ impl Constructor<TypeIR, FieldIR> {
15341534
}
15351535

15361536
fn as_variant_type_struct(&self, config: &Option<Config>, matched: &str) -> Tokens {
1537+
if self.variant_name() == "BlockIdExt" {
1538+
let tl_id = self.tl_id().unwrap();
1539+
return quote! {
1540+
pub(crate) type BlockIdExt = ton_block::BlockIdExt;
1541+
pub(crate) const TL_TAG: crate::ConstructorNumber = #tl_id;
1542+
}
1543+
}
15371544
if self.fields.is_empty() {
15381545
quote!()
15391546
} else {
@@ -2065,6 +2072,11 @@ impl Constructors<TypeIR, FieldIR> {
20652072
}
20662073
let name = self.first_constructor().output.name();
20672074
let doc = self.as_enum_doc();
2075+
if name == "BlockIdExt" {
2076+
return quote! {
2077+
pub(crate) type BlockIdExt = ton_block::BlockIdExt;
2078+
}
2079+
}
20682080
let derives = gen_derives(config, quote! { Debug, Clone, PartialEq }, name.to_string());
20692081
let variants = self.0.iter()
20702082
.map(|cm| cm.0.as_variant());

0 commit comments

Comments
 (0)