Skip to content

Commit

Permalink
update fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SeHor05 committed Oct 31, 2024
1 parent 438f77c commit 536b491
Show file tree
Hide file tree
Showing 360 changed files with 4,271 additions and 6,028 deletions.
12 changes: 2 additions & 10 deletions api/derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,7 @@ pub(crate) fn doc_from(attrs: &[Attribute]) -> (Option<String>, Option<String>)
}
}
fn non_empty(s: String) -> Option<String> {
if s.is_empty() {
None
} else {
Some(s)
}
if s.is_empty() { None } else { Some(s) }
}
let (summary, description) = get_doc(summary, description);
(non_empty(summary), non_empty(description))
Expand Down Expand Up @@ -477,11 +473,7 @@ fn unqualified_type_name(qualified_name: String) -> String {
}

pub(crate) fn path_is(path: &Path, expected: &str) -> bool {
if let Some(ident) = path.get_ident() {
*ident == expected
} else {
false
}
if let Some(ident) = path.get_ident() { *ident == expected } else { false }
}

pub fn fields_from(fields: &Fields) -> Vec<api_info::Field> {
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use_try_shorthand = true
use_small_heuristics = "Max"


style_edition = "2021"
style_edition = "2024"
unstable_features = true

# better grepping
Expand Down
56 changes: 26 additions & 30 deletions tools/update_trusted_blocks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::env;
use std::sync::Arc;

use serde_json::json;
use tvm_client::net::query_collection;
use tvm_client::ClientContext;
use tvm_client::net::OrderBy;
use tvm_client::net::ParamsOfQueryCollection;
use tvm_client::net::SortDirection;
use tvm_client::proofs::proof_block_data;
use tvm_client::net::query_collection;
use tvm_client::proofs::ParamsOfProofBlockData;
use tvm_client::ClientContext;
use tvm_client::proofs::proof_block_data;
use tvm_types::Result;
use tvm_types::UInt256;

Expand Down Expand Up @@ -49,29 +49,26 @@ async fn query_network_keyblocks(
let mut last_gen_utime = 0;

loop {
let key_blocks = query_collection(
Arc::clone(&context),
ParamsOfQueryCollection {
collection: "blocks".to_string(),
result: "id seq_no gen_utime boc".to_string(),
filter: Some(json!({
"workchain_id": {
"eq": -1,
},
"key_block": {
"eq": true,
},
"seq_no": {
"gt": last_seq_no,
}
})),
order: Some(vec![OrderBy {
path: "seq_no".to_string(),
direction: SortDirection::ASC,
}]),
..Default::default()
},
)
let key_blocks = query_collection(Arc::clone(&context), ParamsOfQueryCollection {
collection: "blocks".to_string(),
result: "id seq_no gen_utime boc".to_string(),
filter: Some(json!({
"workchain_id": {
"eq": -1,
},
"key_block": {
"eq": true,
},
"seq_no": {
"gt": last_seq_no,
}
})),
order: Some(vec![OrderBy {
path: "seq_no".to_string(),
direction: SortDirection::ASC,
}]),
..Default::default()
})
.await?
.result;

Expand All @@ -84,10 +81,9 @@ async fn query_network_keyblocks(
let seq_no =
key_block["seq_no"].as_u64().expect("Field `seq_no` must be an integer") as u32;
print!("Proof for key_block #{}...", seq_no);
proof_block_data(
Arc::clone(&context),
ParamsOfProofBlockData { block: key_block.clone() },
)
proof_block_data(Arc::clone(&context), ParamsOfProofBlockData {
block: key_block.clone(),
})
.await?;
let root_hash = <UInt256 as std::str::FromStr>::from_str(
key_block["id"].as_str().expect("Field `id` must be a string"),
Expand Down
2 changes: 1 addition & 1 deletion tvm_abi/rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use_try_shorthand = true
use_small_heuristics = "Max"


style_edition = "2021"
style_edition = "2024"
unstable_features = true

# better grepping
Expand Down
10 changes: 5 additions & 5 deletions tvm_abi/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ use std::io;
use serde::de::Error as SerdeError;
use tvm_block::MsgAddressInt;
use tvm_block::Serializable;
use tvm_types::error;
use tvm_types::fail;
use tvm_types::BuilderData;
use tvm_types::ED25519_PUBLIC_KEY_LENGTH;
use tvm_types::ED25519_SIGNATURE_LENGTH;
use tvm_types::HashmapE;
use tvm_types::Result;
use tvm_types::SliceData;
use tvm_types::ED25519_PUBLIC_KEY_LENGTH;
use tvm_types::ED25519_SIGNATURE_LENGTH;
use tvm_types::error;
use tvm_types::fail;

use crate::TokenValue;
use crate::error::AbiError;
use crate::event::Event;
use crate::function::Function;
use crate::param::Param;
use crate::param::SerdeParam;
use crate::param_type::ParamType;
use crate::token::Token;
use crate::TokenValue;

pub const MIN_SUPPORTED_VERSION: AbiVersion = ABI_VERSION_1_0;
pub const MAX_SUPPORTED_VERSION: AbiVersion = ABI_VERSION_2_4;
Expand Down
6 changes: 3 additions & 3 deletions tvm_abi/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
use tvm_types::Result;
use tvm_types::SliceData;

use crate::contract::AbiVersion;
use crate::contract::SerdeEvent;
use crate::error::AbiError;
use crate::Function;
use crate::Param;
use crate::Token;
use crate::TokenValue;
use crate::contract::AbiVersion;
use crate::contract::SerdeEvent;
use crate::error::AbiError;

/// Contract event specification.
#[derive(Debug, Clone, PartialEq)]
Expand Down
39 changes: 18 additions & 21 deletions tvm_abi/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ use std::collections::HashMap;

use tvm_block::MsgAddressInt;
use tvm_block::Serializable;
use tvm_types::error;
use tvm_types::fail;
use tvm_types::sha256_digest;
use tvm_types::BuilderData;
use tvm_types::Cell;
use tvm_types::ED25519_SIGNATURE_LENGTH;
use tvm_types::Ed25519PrivateKey;
use tvm_types::IBitstring;
use tvm_types::MAX_DATA_BYTES;
use tvm_types::Result;
use tvm_types::SliceData;
use tvm_types::ED25519_SIGNATURE_LENGTH;
use tvm_types::MAX_DATA_BYTES;
use tvm_types::error;
use tvm_types::fail;
use tvm_types::sha256_digest;

use crate::contract::AbiVersion;
use crate::contract::SerdeFunction;
use crate::ParamType;
use crate::PublicKeyData;
use crate::SignatureData;
use crate::contract::ABI_VERSION_1_0;
use crate::contract::ABI_VERSION_2_3;
use crate::contract::AbiVersion;
use crate::contract::SerdeFunction;
use crate::error::AbiError;
use crate::param::Param;
use crate::token::Cursor;
use crate::token::SerializedValue;
use crate::token::Token;
use crate::token::TokenValue;
use crate::ParamType;
use crate::PublicKeyData;
use crate::SignatureData;

/// Contract function specification.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -411,18 +411,15 @@ impl Function {
remove_bits = 1;
}
}
cells.insert(
0,
SerializedValue {
data: sign_builder,
max_bits: if self.abi_version >= ABI_VERSION_2_3 {
TokenValue::max_bit_size(&ParamType::Address, &self.abi_version)
} else {
1 + ED25519_SIGNATURE_LENGTH * 8
},
max_refs: if remove_ref { 1 } else { 0 },
cells.insert(0, SerializedValue {
data: sign_builder,
max_bits: if self.abi_version >= ABI_VERSION_2_3 {
TokenValue::max_bit_size(&ParamType::Address, &self.abi_version)
} else {
1 + ED25519_SIGNATURE_LENGTH * 8
},
);
max_refs: if remove_ref { 1 } else { 0 },
});
}

// encoding itself
Expand Down
4 changes: 2 additions & 2 deletions tvm_abi/src/json_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use tvm_types::Ed25519PrivateKey;
use tvm_types::Result;
use tvm_types::SliceData;

use crate::PublicKeyData;
use crate::SignatureData;
use crate::contract::Contract;
use crate::error::AbiError;
use crate::token::Detokenizer;
use crate::token::TokenValue;
use crate::token::Tokenizer;
use crate::PublicKeyData;
use crate::SignatureData;

/// Encodes `parameters` for given `function` of contract described by `abi`
/// into `BuilderData` which can be used as message body for calling contract
Expand Down
6 changes: 3 additions & 3 deletions tvm_abi/src/param_type/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

use std::fmt;

use serde::de::Error as SerdeError;
use serde::de::Visitor;
use serde::Deserialize;
use serde::Deserializer;
use serde::de::Error as SerdeError;
use serde::de::Visitor;
use tvm_types::Result;
use tvm_types::error;
use tvm_types::fail;
use tvm_types::Result;

use crate::error::AbiError;
use crate::param_type::ParamType;
Expand Down
8 changes: 4 additions & 4 deletions tvm_abi/src/param_type/param_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

use std::fmt;

use tvm_types::error;
use tvm_types::Result;
use tvm_types::error;

use crate::contract::AbiVersion;
use crate::AbiError;
use crate::Param;
use crate::contract::ABI_VERSION_1_0;
use crate::contract::ABI_VERSION_2_0;
use crate::contract::ABI_VERSION_2_1;
use crate::contract::ABI_VERSION_2_4;
use crate::AbiError;
use crate::Param;
use crate::contract::AbiVersion;

/// Function and event param types.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
76 changes: 37 additions & 39 deletions tvm_abi/src/param_type/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ mod param_type_tests {
"bytes[][2]".to_owned()
);

let tuple_params = vec![
Param { name: "a".to_owned(), kind: ParamType::Uint(123) },
Param { name: "b".to_owned(), kind: ParamType::Int(8) },
];
let tuple_params =
vec![Param { name: "a".to_owned(), kind: ParamType::Uint(123) }, Param {
name: "b".to_owned(),
kind: ParamType::Int(8),
}];

let tuple_with_tuple = vec![
Param { name: "a".to_owned(), kind: ParamType::Tuple(tuple_params.clone()) },
Expand Down Expand Up @@ -92,40 +93,37 @@ mod deserialize_tests {
"address", "bytes", "fixedbytes32", "token", "time", "expire", "pubkey", "string",
"varuint16", "varint32", "optional(bytes)", "ref(bool)"]"#;
let deserialized: Vec<ParamType> = serde_json::from_str(s).unwrap();
assert_eq!(
deserialized,
vec![
ParamType::Uint(256),
ParamType::Int(64),
ParamType::Bool,
ParamType::Array(Box::new(ParamType::Bool)),
ParamType::FixedArray(Box::new(ParamType::Int(33)), 2),
ParamType::FixedArray(Box::new(ParamType::Array(Box::new(ParamType::Bool))), 2),
ParamType::Tuple(vec![]),
ParamType::Array(Box::new(ParamType::Tuple(vec![]))),
ParamType::FixedArray(Box::new(ParamType::Tuple(vec![])), 4),
ParamType::Cell,
ParamType::Map(Box::new(ParamType::Int(3)), Box::new(ParamType::Bool)),
ParamType::Map(
Box::new(ParamType::Uint(1023)),
Box::new(ParamType::FixedArray(
Box::new(ParamType::Array(Box::new(ParamType::Tuple(vec![])))),
5
))
),
ParamType::Address,
ParamType::Bytes,
ParamType::FixedBytes(32),
ParamType::Token,
ParamType::Time,
ParamType::Expire,
ParamType::PublicKey,
ParamType::String,
ParamType::VarUint(16),
ParamType::VarInt(32),
ParamType::Optional(Box::new(ParamType::Bytes)),
ParamType::Ref(Box::new(ParamType::Bool)),
]
);
assert_eq!(deserialized, vec![
ParamType::Uint(256),
ParamType::Int(64),
ParamType::Bool,
ParamType::Array(Box::new(ParamType::Bool)),
ParamType::FixedArray(Box::new(ParamType::Int(33)), 2),
ParamType::FixedArray(Box::new(ParamType::Array(Box::new(ParamType::Bool))), 2),
ParamType::Tuple(vec![]),
ParamType::Array(Box::new(ParamType::Tuple(vec![]))),
ParamType::FixedArray(Box::new(ParamType::Tuple(vec![])), 4),
ParamType::Cell,
ParamType::Map(Box::new(ParamType::Int(3)), Box::new(ParamType::Bool)),
ParamType::Map(
Box::new(ParamType::Uint(1023)),
Box::new(ParamType::FixedArray(
Box::new(ParamType::Array(Box::new(ParamType::Tuple(vec![])))),
5
))
),
ParamType::Address,
ParamType::Bytes,
ParamType::FixedBytes(32),
ParamType::Token,
ParamType::Time,
ParamType::Expire,
ParamType::PublicKey,
ParamType::String,
ParamType::VarUint(16),
ParamType::VarInt(32),
ParamType::Optional(Box::new(ParamType::Bytes)),
ParamType::Ref(Box::new(ParamType::Bool)),
]);
}
}
2 changes: 1 addition & 1 deletion tvm_abi/src/tests/test_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

use tvm_block::Deserializable;
use tvm_block::StateInit;
use tvm_types::read_single_root_boc;
use tvm_types::Result;
use tvm_types::SliceData;
use tvm_types::read_single_root_boc;

use crate::Contract;
use crate::PublicKeyData;
Expand Down
Loading

0 comments on commit 536b491

Please sign in to comment.