From 536b4913c858a2825b848c729707fee03fed94d8 Mon Sep 17 00:00:00 2001 From: sehor05 Date: Thu, 31 Oct 2024 15:53:51 +0300 Subject: [PATCH] update fmt --- api/derive/src/utils.rs | 12 +- rustfmt.toml | 2 +- tools/update_trusted_blocks/src/main.rs | 56 +- tvm_abi/rustfmt.toml | 2 +- tvm_abi/src/contract.rs | 10 +- tvm_abi/src/event.rs | 6 +- tvm_abi/src/function.rs | 39 +- tvm_abi/src/json_abi.rs | 4 +- tvm_abi/src/param_type/deserialize.rs | 6 +- tvm_abi/src/param_type/param_type.rs | 8 +- tvm_abi/src/param_type/tests.rs | 76 +- tvm_abi/src/tests/test_contract.rs | 2 +- tvm_abi/src/tests/test_param.rs | 106 ++- tvm_abi/src/tests/v1/full_stack_tests.rs | 10 +- tvm_abi/src/tests/v1/test_contract.rs | 188 ++--- tvm_abi/src/tests/v2/full_stack_tests.rs | 50 +- tvm_abi/src/tests/v2/test_contract.rs | 200 ++--- tvm_abi/src/token/deserialize.rs | 8 +- tvm_abi/src/token/detokenizer.rs | 6 +- tvm_abi/src/token/mod.rs | 4 +- tvm_abi/src/token/serialize.rs | 24 +- tvm_abi/src/token/test_encoding.rs | 275 +++--- tvm_abi/src/token/tests.rs | 174 ++-- tvm_abi/src/token/tokenizer.rs | 6 +- tvm_api/src/lib.rs | 8 +- tvm_api/src/ton/rpc/adnl.rs | 6 +- tvm_api/src/ton/rpc/catchain.rs | 24 +- tvm_api/src/ton/rpc/dht.rs | 36 +- tvm_api/src/ton/rpc/dns.rs | 6 +- tvm_api/src/ton/rpc/engine/validator.rs | 234 +----- tvm_api/src/ton/rpc/http.rs | 12 +- tvm_api/src/ton/rpc/lite_server.rs | 144 +--- tvm_api/src/ton/rpc/mbpp.rs | 6 +- tvm_api/src/ton/rpc/mod.rs | 222 +---- tvm_api/src/ton/rpc/msg.rs | 12 +- tvm_api/src/ton/rpc/options.rs | 12 +- tvm_api/src/ton/rpc/overlay.rs | 24 +- tvm_api/src/ton/rpc/pchan.rs | 24 +- tvm_api/src/ton/rpc/query.rs | 24 +- tvm_api/src/ton/rpc/raw.rs | 60 +- tvm_api/src/ton/rpc/smc.rs | 54 +- tvm_api/src/ton/rpc/tcp.rs | 6 +- tvm_api/src/ton/rpc/ton_node/mod.rs | 210 +---- tvm_api/src/ton/rpc/ton_node/slave.rs | 6 +- tvm_api/src/ton/rpc/validator_session.rs | 12 +- tvm_api/src/ton_prelude.rs | 8 +- tvm_assembler/rustfmt.toml | 2 +- tvm_assembler/src/bin/disasm.rs | 4 +- tvm_assembler/src/complex.rs | 12 +- tvm_assembler/src/convert.rs | 2 +- tvm_assembler/src/debug.rs | 4 +- tvm_assembler/src/disasm/codedict.rs | 2 +- tvm_assembler/src/disasm/loader.rs | 2 +- tvm_assembler/src/disasm/types.rs | 2 +- tvm_assembler/src/parse.rs | 6 +- tvm_assembler/src/simple.rs | 4 +- tvm_assembler/src/writer.rs | 2 +- tvm_block/rustfmt.toml | 2 +- tvm_block/src/accounts.rs | 16 +- tvm_block/src/bintree.rs | 14 +- tvm_block/src/blocks.rs | 14 +- tvm_block/src/config_params.rs | 22 +- tvm_block/src/envelope_message.rs | 8 +- tvm_block/src/hashmapaug.rs | 6 +- tvm_block/src/inbound_messages.rs | 10 +- tvm_block/src/lib.rs | 10 +- tvm_block/src/master.rs | 34 +- tvm_block/src/merkle_proof.rs | 12 +- tvm_block/src/merkle_update.rs | 6 +- tvm_block/src/messages.rs | 18 +- tvm_block/src/miscellaneous.rs | 4 +- tvm_block/src/out_actions.rs | 10 +- tvm_block/src/outbound_messages.rs | 18 +- tvm_block/src/shard.rs | 20 +- tvm_block/src/shard_accounts.rs | 12 +- tvm_block/src/signature.rs | 8 +- tvm_block/src/tests/test_accounts.rs | 2 +- tvm_block/src/tests/test_blocks.rs | 58 +- tvm_block/src/tests/test_config_params.rs | 24 +- tvm_block/src/tests/test_envelope_message.rs | 4 +- tvm_block/src/tests/test_hashmapaug.rs | 2 +- tvm_block/src/tests/test_in_msgs.rs | 4 +- tvm_block/src/tests/test_master.rs | 150 ++-- tvm_block/src/tests/test_merkle_proof.rs | 17 +- tvm_block/src/tests/test_merkle_update.rs | 10 +- tvm_block/src/tests/test_miscellaneous.rs | 2 +- tvm_block/src/tests/test_out_msgs.rs | 6 +- tvm_block/src/tests/test_shard.rs | 458 +++++----- tvm_block/src/tests/test_signature.rs | 4 +- tvm_block/src/tests/test_validators.rs | 4 +- tvm_block/src/transactions.rs | 18 +- tvm_block/src/types.rs | 24 +- tvm_block/src/validators.rs | 16 +- tvm_block_json/rustfmt.toml | 2 +- tvm_block_json/src/block_parser/accounts.rs | 8 +- tvm_block_json/src/block_parser/entry.rs | 2 +- tvm_block_json/src/block_parser/parser.rs | 10 +- .../src/block_parser/transactions.rs | 8 +- tvm_block_json/src/deserialize.rs | 28 +- tvm_block_json/src/serialize.rs | 98 +-- tvm_block_json/src/tests/test_deserialize.rs | 2 +- tvm_block_json/src/tests/test_parser.rs | 4 +- tvm_block_json/src/tests/test_reducers.rs | 49 +- tvm_block_json/src/tests/test_serialize.rs | 23 +- tvm_cli/rustfmt.toml | 2 +- tvm_cli/src/account.rs | 59 +- tvm_cli/src/call.rs | 46 +- tvm_cli/src/config.rs | 2 +- tvm_cli/src/crypto.rs | 87 +- tvm_cli/src/debot/callbacks.rs | 4 +- tvm_cli/src/debot/interfaces/address_input.rs | 2 +- tvm_cli/src/debot/interfaces/amount_input.rs | 2 +- tvm_cli/src/debot/interfaces/confirm_input.rs | 2 +- tvm_cli/src/debot/interfaces/dinterface.rs | 4 +- tvm_cli/src/debot/interfaces/echo.rs | 2 +- .../debot/interfaces/encryption_box_input.rs | 2 +- .../src/debot/interfaces/input_interface.rs | 4 +- tvm_cli/src/debot/interfaces/menu.rs | 4 +- tvm_cli/src/debot/interfaces/number_input.rs | 2 +- .../src/debot/interfaces/signing_box_input.rs | 4 +- tvm_cli/src/debot/interfaces/stdout.rs | 2 +- tvm_cli/src/debot/interfaces/terminal.rs | 4 +- tvm_cli/src/debot/interfaces/userinfo.rs | 2 +- tvm_cli/src/debot/term_browser.rs | 60 +- tvm_cli/src/debot/term_encryption_box.rs | 13 +- tvm_cli/src/debot/term_signing_box.rs | 13 +- tvm_cli/src/debug.rs | 80 +- tvm_cli/src/decode.rs | 25 +- tvm_cli/src/deploy.rs | 6 +- tvm_cli/src/depool.rs | 125 ++- tvm_cli/src/genaddr.rs | 15 +- tvm_cli/src/getconfig.rs | 20 +- tvm_cli/src/helpers.rs | 96 +-- tvm_cli/src/main.rs | 25 +- tvm_cli/src/message.rs | 4 +- tvm_cli/src/multisig.rs | 35 +- tvm_cli/src/replay.rs | 105 +-- tvm_cli/src/run.rs | 46 +- tvm_cli/src/test.rs | 12 +- tvm_cli/src/voting.rs | 2 +- tvm_cli/tests/browser.rs | 4 +- tvm_cli/tests/json_output_test.rs | 6 +- tvm_cli/tests/test_cli.rs | 12 +- tvm_client/build.rs | 19 +- tvm_client/src/abi/decode_boc.rs | 2 +- tvm_client/src/abi/decode_data.rs | 2 +- tvm_client/src/abi/decode_message.rs | 4 +- tvm_client/src/abi/encode_account.rs | 2 +- tvm_client/src/abi/encode_boc.rs | 6 +- tvm_client/src/abi/encode_message.rs | 10 +- tvm_client/src/abi/init_data.rs | 4 +- tvm_client/src/abi/internal.rs | 2 +- tvm_client/src/abi/mod.rs | 32 +- tvm_client/src/abi/signing.rs | 2 +- tvm_client/src/abi/tests.rs | 467 +++++------ tvm_client/src/abi/types.rs | 2 +- tvm_client/src/boc/cache.rs | 21 +- tvm_client/src/boc/encode.rs | 6 +- .../src/boc/encode_external_in_message.rs | 2 +- tvm_client/src/boc/internal.rs | 4 +- tvm_client/src/boc/mod.rs | 40 +- tvm_client/src/boc/parse.rs | 2 +- tvm_client/src/boc/state_init.rs | 2 +- tvm_client/src/boc/tests.rs | 147 ++-- tvm_client/src/boc/tvc.rs | 2 +- tvm_client/src/client/client.rs | 18 +- tvm_client/src/client/client_env_tests.rs | 2 +- tvm_client/src/client/network_mock.rs | 2 +- tvm_client/src/client/std_client_env.rs | 8 +- tvm_client/src/client/tests.rs | 4 +- tvm_client/src/client/wasm_client_env.rs | 4 +- .../src/crypto/boxes/crypto_box/encryption.rs | 2 +- tvm_client/src/crypto/boxes/crypto_box/mod.rs | 42 +- .../src/crypto/boxes/encryption_box/aes.rs | 6 +- .../crypto/boxes/encryption_box/chacha20.rs | 10 +- .../crypto/boxes/encryption_box/nacl_box.rs | 46 +- .../boxes/encryption_box/nacl_secret_box.rs | 32 +- tvm_client/src/crypto/encryption.rs | 6 +- tvm_client/src/crypto/errors.rs | 2 +- tvm_client/src/crypto/hdkey.rs | 6 +- tvm_client/src/crypto/keys.rs | 2 +- tvm_client/src/crypto/math.rs | 6 +- tvm_client/src/crypto/mnemonic.rs | 2 +- tvm_client/src/crypto/mod.rs | 114 +-- tvm_client/src/crypto/nacl.rs | 4 +- tvm_client/src/crypto/tests.rs | 780 +++++++----------- tvm_client/src/debot/action.rs | 2 +- tvm_client/src/debot/base64_interface.rs | 4 +- tvm_client/src/debot/browser.rs | 2 +- tvm_client/src/debot/calltype.rs | 61 +- tvm_client/src/debot/context.rs | 2 +- tvm_client/src/debot/dengine.rs | 112 ++- tvm_client/src/debot/dinterface.rs | 6 +- tvm_client/src/debot/hex_interface.rs | 4 +- tvm_client/src/debot/info.rs | 6 +- tvm_client/src/debot/json_interface.rs | 4 +- tvm_client/src/debot/json_lib_utils.rs | 4 +- tvm_client/src/debot/mod.rs | 2 +- tvm_client/src/debot/msg_interface.rs | 34 +- tvm_client/src/debot/network_interface.rs | 6 +- tvm_client/src/debot/query_interface.rs | 41 +- tvm_client/src/debot/routines.rs | 64 +- tvm_client/src/debot/run_output.rs | 4 +- tvm_client/src/debot/sdk_interface.rs | 209 +++-- tvm_client/src/debot/tests.rs | 291 +++---- tvm_client/src/debot/tests_interfaces.rs | 4 +- tvm_client/src/encoding.rs | 6 +- tvm_client/src/error.rs | 6 +- tvm_client/src/json_interface/crypto.rs | 8 +- tvm_client/src/json_interface/handlers.rs | 2 +- tvm_client/src/json_interface/interop.rs | 6 +- tvm_client/src/json_interface/net.rs | 2 +- tvm_client/src/json_interface/registrar.rs | 2 +- tvm_client/src/json_interface/request.rs | 4 +- tvm_client/src/json_interface/runtime.rs | 4 +- tvm_client/src/json_interface/utils.rs | 2 +- tvm_client/src/net/endpoint.rs | 10 +- tvm_client/src/net/errors.rs | 2 +- tvm_client/src/net/iterators/block.rs | 23 +- .../net/iterators/block_iterator/branch.rs | 4 +- .../net/iterators/block_iterator/filter.rs | 2 +- .../src/net/iterators/block_iterator/mod.rs | 35 +- .../src/net/iterators/block_iterator/state.rs | 2 +- tvm_client/src/net/iterators/mod.rs | 17 +- tvm_client/src/net/iterators/tests.rs | 19 +- .../net/iterators/transaction_iterator/mod.rs | 27 +- tvm_client/src/net/mod.rs | 44 +- tvm_client/src/net/network.rs | 6 +- tvm_client/src/net/queries.rs | 2 +- tvm_client/src/net/server_link.rs | 14 +- tvm_client/src/net/tests.rs | 356 ++++---- tvm_client/src/net/transaction_tree.rs | 13 +- tvm_client/src/net/tvm_gql.rs | 4 +- tvm_client/src/net/websocket_link.rs | 10 +- tvm_client/src/processing/blocks_walking.rs | 4 +- tvm_client/src/processing/errors.rs | 2 +- tvm_client/src/processing/fetching.rs | 52 +- tvm_client/src/processing/internal.rs | 15 +- tvm_client/src/processing/message_monitor.rs | 2 +- .../message_monitor_sdk_services.rs | 8 +- tvm_client/src/processing/mod.rs | 20 +- tvm_client/src/processing/parsing.rs | 13 +- tvm_client/src/processing/process_message.rs | 6 +- tvm_client/src/processing/send_message.rs | 4 +- tvm_client/src/processing/tests.rs | 25 +- .../src/processing/wait_for_transaction.rs | 6 +- tvm_client/src/proofs/engine.rs | 237 +++--- tvm_client/src/proofs/mod.rs | 2 +- tvm_client/src/proofs/tests/mod.rs | 196 ++--- tvm_client/src/proofs/validators.rs | 2 +- tvm_client/src/tests/common.rs | 17 +- tvm_client/src/tests/mod.rs | 81 +- tvm_client/src/tvm/call_tvm.rs | 6 +- tvm_client/src/tvm/errors.rs | 6 +- tvm_client/src/tvm/mod.rs | 8 +- tvm_client/src/tvm/run_get.rs | 2 +- tvm_client/src/tvm/run_message.rs | 15 +- tvm_client/src/tvm/stack.rs | 2 +- tvm_client/src/tvm/tests.rs | 488 +++++------ tvm_client/src/utils/conversion.rs | 4 +- tvm_client/src/utils/mod.rs | 6 +- tvm_client/src/utils/tests.rs | 40 +- .../src/message_monitor/message.rs | 2 +- .../src/message_monitor/monitor.rs | 4 +- .../src/message_monitor/monitor_queues.rs | 10 +- .../src/message_monitor/queue.rs | 8 +- .../src/sdk_services/mock_sdk_services.rs | 6 +- tvm_client_processing/src/tests.rs | 35 +- tvm_common/rustfmt.toml | 2 +- tvm_debugger/src/decode.rs | 6 +- tvm_debugger/src/execute.rs | 12 +- tvm_debugger/src/message.rs | 6 +- tvm_debugger/src/result.rs | 2 +- tvm_executor/rustfmt.toml | 2 +- tvm_executor/src/blockchain_config.rs | 12 +- tvm_executor/src/ordinary_transaction.rs | 14 +- tvm_executor/src/tick_tock_transaction.rs | 12 +- tvm_executor/src/transaction_executor.rs | 61 +- tvm_executor/src/vmsetup.rs | 4 +- tvm_sdk/src/block.rs | 4 +- tvm_sdk/src/contract.rs | 10 +- tvm_sdk/src/json_helper.rs | 2 +- tvm_sdk/src/lib.rs | 2 +- tvm_sdk/src/message.rs | 2 +- tvm_sdk/src/transaction.rs | 6 +- tvm_sdk/src/types.rs | 2 +- tvm_struct/rustfmt.toml | 2 +- tvm_tests/src/test_framework.rs | 6 +- tvm_tests/src/test_zk.rs | 67 +- tvm_tl_codegen/src/lib.rs | 28 +- tvm_types/benches/benchmarks.rs | 8 +- tvm_types/rustfmt.toml | 2 +- tvm_types/src/bls.rs | 2 +- tvm_types/src/boc.rs | 32 +- tvm_types/src/cell/builder.rs | 6 +- tvm_types/src/cell/builder_operations.rs | 10 +- tvm_types/src/cell/mod.rs | 28 +- tvm_types/src/crypto.rs | 6 +- tvm_types/src/dictionary/mod.rs | 36 +- tvm_types/src/dictionary/pfxhashmap.rs | 8 +- tvm_types/src/wrappers.rs | 12 +- tvm_vm/benches/benchmarks.rs | 8 +- tvm_vm/rustfmt.toml | 2 +- tvm_vm/src/error.rs | 4 +- tvm_vm/src/executor/accounts.rs | 8 +- tvm_vm/src/executor/blockchain.rs | 18 +- tvm_vm/src/executor/config.rs | 4 +- tvm_vm/src/executor/continuation.rs | 14 +- tvm_vm/src/executor/crypto.rs | 8 +- tvm_vm/src/executor/currency.rs | 8 +- tvm_vm/src/executor/deserialization.rs | 10 +- tvm_vm/src/executor/dictionary.rs | 14 +- tvm_vm/src/executor/diff.rs | 14 +- tvm_vm/src/executor/dump.rs | 2 +- tvm_vm/src/executor/engine/core.rs | 8 +- tvm_vm/src/executor/engine/data.rs | 4 +- tvm_vm/src/executor/engine/handlers.rs | 4 +- tvm_vm/src/executor/engine/storage.rs | 10 +- tvm_vm/src/executor/exceptions.rs | 28 +- tvm_vm/src/executor/gas/gas_state.rs | 14 +- tvm_vm/src/executor/gas/mod.rs | 8 +- tvm_vm/src/executor/globals.rs | 4 +- tvm_vm/src/executor/math.rs | 18 +- tvm_vm/src/executor/null.rs | 6 +- tvm_vm/src/executor/rand.rs | 8 +- tvm_vm/src/executor/serialization.rs | 12 +- tvm_vm/src/executor/slice_comparison.rs | 10 +- tvm_vm/src/executor/stack.rs | 6 +- tvm_vm/src/executor/token.rs | 10 +- tvm_vm/src/executor/tuple.rs | 8 +- tvm_vm/src/executor/types.rs | 10 +- tvm_vm/src/executor/zk.rs | 16 +- tvm_vm/src/executor/zk_stuff/bn254/api.rs | 2 +- .../zk_stuff/bn254/poseidon/constants.rs | 18 +- .../executor/zk_stuff/bn254/poseidon/mod.rs | 4 +- .../src/executor/zk_stuff/bn254/verifier.rs | 2 +- tvm_vm/src/executor/zk_stuff/curve_utils.rs | 6 +- tvm_vm/src/executor/zk_stuff/zk_login.rs | 4 +- tvm_vm/src/smart_contract_info.rs | 4 +- tvm_vm/src/stack/continuation.rs | 6 +- tvm_vm/src/stack/integer/behavior.rs | 12 +- tvm_vm/src/stack/integer/bitlogics.rs | 2 +- tvm_vm/src/stack/integer/conversion.rs | 6 +- tvm_vm/src/stack/integer/math.rs | 6 +- tvm_vm/src/stack/integer/mod.rs | 2 +- .../src/stack/integer/serialization/common.rs | 6 +- .../serialization/signed_big_endian.rs | 6 +- .../serialization/signed_little_endian.rs | 8 +- .../tests/test_integer_encoding.rs | 6 +- .../serialization/tests/test_ser_deser.rs | 4 +- .../serialization/unsigned_big_endian.rs | 8 +- .../serialization/unsigned_little_endian.rs | 6 +- .../src/stack/integer/tests/test_integer.rs | 8 +- tvm_vm/src/stack/mod.rs | 18 +- tvm_vm/src/stack/savelist.rs | 8 +- tvm_vm/src/tests/test_dump.rs | 8 +- tvm_vm/src/tests/test_executor.rs | 6 +- tvm_vm/src/tests/test_microfunctions.rs | 6 +- tvm_vm/src/types.rs | 16 +- tvm_vm/src/utils.rs | 6 +- 360 files changed, 4271 insertions(+), 6028 deletions(-) diff --git a/api/derive/src/utils.rs b/api/derive/src/utils.rs index 203a1a951..34c3204e0 100644 --- a/api/derive/src/utils.rs +++ b/api/derive/src/utils.rs @@ -374,11 +374,7 @@ pub(crate) fn doc_from(attrs: &[Attribute]) -> (Option, Option) } } fn non_empty(s: String) -> Option { - 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)) @@ -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 { diff --git a/rustfmt.toml b/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tools/update_trusted_blocks/src/main.rs b/tools/update_trusted_blocks/src/main.rs index 3d5f31e97..61fd8d4d9 100644 --- a/tools/update_trusted_blocks/src/main.rs +++ b/tools/update_trusted_blocks/src/main.rs @@ -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; @@ -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; @@ -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 = ::from_str( key_block["id"].as_str().expect("Field `id` must be a string"), diff --git a/tvm_abi/rustfmt.toml b/tvm_abi/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_abi/rustfmt.toml +++ b/tvm_abi/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_abi/src/contract.rs b/tvm_abi/src/contract.rs index 92f353e12..49e6eecee 100644 --- a/tvm_abi/src/contract.rs +++ b/tvm_abi/src/contract.rs @@ -17,15 +17,16 @@ 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; @@ -33,7 +34,6 @@ 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; diff --git a/tvm_abi/src/event.rs b/tvm_abi/src/event.rs index 07870beb9..ea142bae0 100644 --- a/tvm_abi/src/event.rs +++ b/tvm_abi/src/event.rs @@ -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)] diff --git a/tvm_abi/src/function.rs b/tvm_abi/src/function.rs index b7b1d6986..92629e8f8 100644 --- a/tvm_abi/src/function.rs +++ b/tvm_abi/src/function.rs @@ -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)] @@ -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 diff --git a/tvm_abi/src/json_abi.rs b/tvm_abi/src/json_abi.rs index 3f9ec3f60..297bfca08 100644 --- a/tvm_abi/src/json_abi.rs +++ b/tvm_abi/src/json_abi.rs @@ -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 diff --git a/tvm_abi/src/param_type/deserialize.rs b/tvm_abi/src/param_type/deserialize.rs index 667593934..43b0e1b23 100644 --- a/tvm_abi/src/param_type/deserialize.rs +++ b/tvm_abi/src/param_type/deserialize.rs @@ -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; diff --git a/tvm_abi/src/param_type/param_type.rs b/tvm_abi/src/param_type/param_type.rs index 3bd9470a0..9e7987c7d 100644 --- a/tvm_abi/src/param_type/param_type.rs +++ b/tvm_abi/src/param_type/param_type.rs @@ -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)] diff --git a/tvm_abi/src/param_type/tests.rs b/tvm_abi/src/param_type/tests.rs index 570c4b8bf..59922b185 100644 --- a/tvm_abi/src/param_type/tests.rs +++ b/tvm_abi/src/param_type/tests.rs @@ -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()) }, @@ -92,40 +93,37 @@ mod deserialize_tests { "address", "bytes", "fixedbytes32", "token", "time", "expire", "pubkey", "string", "varuint16", "varint32", "optional(bytes)", "ref(bool)"]"#; let deserialized: Vec = 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)), + ]); } } diff --git a/tvm_abi/src/tests/test_contract.rs b/tvm_abi/src/tests/test_contract.rs index 5068aa5ef..97efcdf92 100644 --- a/tvm_abi/src/tests/test_contract.rs +++ b/tvm_abi/src/tests/test_contract.rs @@ -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; diff --git a/tvm_abi/src/tests/test_param.rs b/tvm_abi/src/tests/test_param.rs index 787fe2987..1ed94f298 100644 --- a/tvm_abi/src/tests/test_param.rs +++ b/tvm_abi/src/tests/test_param.rs @@ -12,8 +12,6 @@ use tvm_types::BuilderData; use tvm_types::IBitstring; -use crate::contract::ABI_VERSION_2_0; -use crate::token::Detokenizer; use crate::Function; use crate::Int; use crate::Param; @@ -21,6 +19,8 @@ use crate::ParamType; use crate::Token; use crate::TokenValue; use crate::Uint; +use crate::contract::ABI_VERSION_2_0; +use crate::token::Detokenizer; #[test] fn int_json_representation() { @@ -124,16 +124,13 @@ fn test_tuple_param_deserialization() { let deserialized: Param = serde_json::from_str(s).unwrap(); - assert_eq!( - deserialized, - Param { - name: "a".to_owned(), - kind: ParamType::Tuple(vec![ - Param { name: "a".to_owned(), kind: ParamType::Int(8) }, - Param { name: "b".to_owned(), kind: ParamType::Int(8) }, - ]), - } - ); + assert_eq!(deserialized, Param { + name: "a".to_owned(), + kind: ParamType::Tuple(vec![ + Param { name: "a".to_owned(), kind: ParamType::Int(8) }, + Param { name: "b".to_owned(), kind: ParamType::Int(8) }, + ]), + }); } #[test] @@ -165,25 +162,22 @@ fn test_tuples_array_deserialization() { let deserialized: Param = serde_json::from_str(s).unwrap(); - assert_eq!( - deserialized, - Param { - name: "a".to_owned(), - kind: ParamType::Array(Box::new(ParamType::Tuple(vec![ - Param { name: "a".to_owned(), kind: ParamType::Bool }, - Param { - name: "b".to_owned(), - kind: ParamType::FixedArray( - Box::new(ParamType::Tuple(vec![ - Param { name: "a".to_owned(), kind: ParamType::Uint(8) }, - Param { name: "b".to_owned(), kind: ParamType::Int(15) }, - ])), - 5 - ) - }, - ]))), - } - ); + assert_eq!(deserialized, Param { + name: "a".to_owned(), + kind: ParamType::Array(Box::new(ParamType::Tuple(vec![ + Param { name: "a".to_owned(), kind: ParamType::Bool }, + Param { + name: "b".to_owned(), + kind: ParamType::FixedArray( + Box::new(ParamType::Tuple(vec![ + Param { name: "a".to_owned(), kind: ParamType::Uint(8) }, + Param { name: "b".to_owned(), kind: ParamType::Int(15) }, + ])), + 5 + ) + }, + ]))), + }); } #[test] @@ -205,25 +199,22 @@ fn test_tuples_array_map_map() { let deserialized: Param = serde_json::from_str(s).unwrap(); - assert_eq!( - deserialized, - Param { - name: "d".to_owned(), - kind: ParamType::Map( + assert_eq!(deserialized, Param { + name: "d".to_owned(), + kind: ParamType::Map( + Box::new(ParamType::Uint(32)), + Box::new(ParamType::Map( Box::new(ParamType::Uint(32)), - Box::new(ParamType::Map( - Box::new(ParamType::Uint(32)), - Box::new(ParamType::FixedArray( - Box::new(ParamType::Array(Box::new(ParamType::Tuple(vec![ - Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, - Param { name: "b".to_owned(), kind: ParamType::Uint(256) }, - ])))), - 5 - )), - )) - ), - } - ); + Box::new(ParamType::FixedArray( + Box::new(ParamType::Array(Box::new(ParamType::Tuple(vec![ + Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, + Param { name: "b".to_owned(), kind: ParamType::Uint(256) }, + ])))), + 5 + )), + )) + ), + }); } #[test] @@ -254,14 +245,11 @@ fn test_optional_tuple_param_deserialization() { let deserialized: Param = serde_json::from_str(s).unwrap(); - assert_eq!( - deserialized, - Param { - name: "a".to_owned(), - kind: ParamType::Optional(Box::new(ParamType::Tuple(vec![ - Param { name: "a".to_owned(), kind: ParamType::Int(8) }, - Param { name: "b".to_owned(), kind: ParamType::Int(8) }, - ]))), - } - ); + assert_eq!(deserialized, Param { + name: "a".to_owned(), + kind: ParamType::Optional(Box::new(ParamType::Tuple(vec![ + Param { name: "a".to_owned(), kind: ParamType::Int(8) }, + Param { name: "b".to_owned(), kind: ParamType::Int(8) }, + ]))), + }); } diff --git a/tvm_abi/src/tests/v1/full_stack_tests.rs b/tvm_abi/src/tests/v1/full_stack_tests.rs index 9568fb978..96fa319b0 100644 --- a/tvm_abi/src/tests/v1/full_stack_tests.rs +++ b/tvm_abi/src/tests/v1/full_stack_tests.rs @@ -10,9 +10,9 @@ // limitations under the License. use tvm_block::Serializable; +use tvm_types::Ed25519PublicKey; use tvm_types::dictionary::HashmapE; use tvm_types::ed25519_generate_private_key; -use tvm_types::Ed25519PublicKey; use crate::json_abi::*; @@ -216,9 +216,11 @@ fn test_signed_call() { let hash = test_tree.into_cell().repr_hash(); assert_eq!(hash.clone().into_vec(), test_hash); - assert!(Ed25519PublicKey::from_bytes(&key.verifying_key()) - .unwrap() - .verify(hash.as_slice(), &sign.try_into().unwrap())); + assert!( + Ed25519PublicKey::from_bytes(&key.verifying_key()) + .unwrap() + .verify(hash.as_slice(), &sign.try_into().unwrap()) + ); let expected_response = r#"{"value0":"0"}"#; diff --git a/tvm_abi/src/tests/v1/test_contract.rs b/tvm_abi/src/tests/v1/test_contract.rs index 188bbfd16..ced5fa12b 100644 --- a/tvm_abi/src/tests/v1/test_contract.rs +++ b/tvm_abi/src/tests/v1/test_contract.rs @@ -74,118 +74,96 @@ fn test_abi_parse() { let mut functions = HashMap::new(); let header = vec![Param { name: "time".into(), kind: ParamType::Time }]; - functions.insert( - "input_and_output".to_owned(), - Function { - abi_version: 1.into(), - name: "input_and_output".to_owned(), - header: header.clone(), - inputs: vec![ - Param { name: "a".to_owned(), kind: ParamType::Uint(64) }, - Param { - name: "b".to_owned(), - kind: ParamType::Array(Box::new(ParamType::Uint(8))), - }, - Param { name: "c".to_owned(), kind: ParamType::Bytes }, - ], - outputs: vec![ - Param { name: "a".to_owned(), kind: ParamType::Int(16) }, - Param { name: "b".to_owned(), kind: ParamType::Uint(8) }, - ], - input_id: Function::calc_function_id( - "input_and_output(time,uint64,uint8[],bytes)(int16,uint8)v1", - ) & 0x7FFFFFFF, - output_id: Function::calc_function_id( - "input_and_output(time,uint64,uint8[],bytes)(int16,uint8)v1", - ) | 0x80000000, - }, - ); - - functions.insert( - "no_output".to_owned(), - Function { - abi_version: 1.into(), - name: "no_output".to_owned(), - header: header.clone(), - inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(15) }], - outputs: vec![], - input_id: Function::calc_function_id("no_output(time,uint15)()v1") & 0x7FFFFFFF, - output_id: Function::calc_function_id("no_output(time,uint15)()v1") | 0x80000000, - }, - ); - - functions.insert( - "no_input".to_owned(), - Function { - abi_version: 1.into(), - name: "no_input".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(8) }], - input_id: Function::calc_function_id("no_input(time)(uint8)v1") & 0x7FFFFFFF, - output_id: Function::calc_function_id("no_input(time)(uint8)v1") | 0x80000000, - }, - ); - - functions.insert( - "constructor".to_owned(), - Function { - abi_version: 1.into(), - name: "constructor".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![], - input_id: Function::calc_function_id("constructor(time)()v1") & 0x7FFFFFFF, - output_id: Function::calc_function_id("constructor(time)()v1") | 0x80000000, - }, - ); - - functions.insert( - "has_id".to_owned(), - Function { - abi_version: 1.into(), - name: "has_id".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![], - input_id: 0x01234567, - output_id: 0x01234567, - }, - ); + functions.insert("input_and_output".to_owned(), Function { + abi_version: 1.into(), + name: "input_and_output".to_owned(), + header: header.clone(), + inputs: vec![ + Param { name: "a".to_owned(), kind: ParamType::Uint(64) }, + Param { name: "b".to_owned(), kind: ParamType::Array(Box::new(ParamType::Uint(8))) }, + Param { name: "c".to_owned(), kind: ParamType::Bytes }, + ], + outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Int(16) }, Param { + name: "b".to_owned(), + kind: ParamType::Uint(8), + }], + input_id: Function::calc_function_id( + "input_and_output(time,uint64,uint8[],bytes)(int16,uint8)v1", + ) & 0x7FFFFFFF, + output_id: Function::calc_function_id( + "input_and_output(time,uint64,uint8[],bytes)(int16,uint8)v1", + ) | 0x80000000, + }); + + functions.insert("no_output".to_owned(), Function { + abi_version: 1.into(), + name: "no_output".to_owned(), + header: header.clone(), + inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(15) }], + outputs: vec![], + input_id: Function::calc_function_id("no_output(time,uint15)()v1") & 0x7FFFFFFF, + output_id: Function::calc_function_id("no_output(time,uint15)()v1") | 0x80000000, + }); + + functions.insert("no_input".to_owned(), Function { + abi_version: 1.into(), + name: "no_input".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(8) }], + input_id: Function::calc_function_id("no_input(time)(uint8)v1") & 0x7FFFFFFF, + output_id: Function::calc_function_id("no_input(time)(uint8)v1") | 0x80000000, + }); + + functions.insert("constructor".to_owned(), Function { + abi_version: 1.into(), + name: "constructor".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![], + input_id: Function::calc_function_id("constructor(time)()v1") & 0x7FFFFFFF, + output_id: Function::calc_function_id("constructor(time)()v1") | 0x80000000, + }); + + functions.insert("has_id".to_owned(), Function { + abi_version: 1.into(), + name: "has_id".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![], + input_id: 0x01234567, + output_id: 0x01234567, + }); let mut events = HashMap::new(); - events.insert( - "input".to_owned(), - Event { - abi_version: 1.into(), - name: "input".to_owned(), - inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(64) }], - id: Function::calc_function_id("input(uint64)v1") & 0x7FFFFFFF, - }, - ); - - events.insert( - "no_input".to_owned(), - Event { - abi_version: 1.into(), - name: "no_input".to_owned(), - inputs: vec![], - id: Function::calc_function_id("no_input()v1") & 0x7FFFFFFF, - }, - ); + events.insert("input".to_owned(), Event { + abi_version: 1.into(), + name: "input".to_owned(), + inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(64) }], + id: Function::calc_function_id("input(uint64)v1") & 0x7FFFFFFF, + }); + + events.insert("no_input".to_owned(), Event { + abi_version: 1.into(), + name: "no_input".to_owned(), + inputs: vec![], + id: Function::calc_function_id("no_input()v1") & 0x7FFFFFFF, + }); - events.insert( - "has_id".to_owned(), - Event { abi_version: 1.into(), name: "has_id".to_owned(), inputs: vec![], id: 0x89abcdef }, - ); + events.insert("has_id".to_owned(), Event { + abi_version: 1.into(), + name: "has_id".to_owned(), + inputs: vec![], + id: 0x89abcdef, + }); let mut data = HashMap::new(); - data.insert( - "a".to_owned(), - DataItem { value: Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, key: 100 }, - ); + data.insert("a".to_owned(), DataItem { + value: Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, + key: 100, + }); let expected_contract = Contract { abi_version: 1.into(), diff --git a/tvm_abi/src/tests/v2/full_stack_tests.rs b/tvm_abi/src/tests/v2/full_stack_tests.rs index 63300616d..1cbe786bb 100644 --- a/tvm_abi/src/tests/v2/full_stack_tests.rs +++ b/tvm_abi/src/tests/v2/full_stack_tests.rs @@ -12,11 +12,11 @@ use serde_json::json; use tvm_block::Deserializable; use tvm_block::Serializable; +use tvm_types::ED25519_SIGNATURE_LENGTH; +use tvm_types::IBitstring; use tvm_types::dictionary::HashmapE; use tvm_types::ed25519_generate_private_key; use tvm_types::ed25519_verify; -use tvm_types::IBitstring; -use tvm_types::ED25519_SIGNATURE_LENGTH; use crate::json_abi::*; @@ -703,27 +703,31 @@ fn test_encode_storage_fields() { assert_eq!(test_tree, expected_tree); - assert!(dbg!(encode_storage_fields( - ABI_WITH_FIELDS_V24, - Some( - r#"{ + assert!( + dbg!(encode_storage_fields( + ABI_WITH_FIELDS_V24, + Some( + r#"{ "ok": true }"# - ), - )) - .is_err()); + ), + )) + .is_err() + ); - assert!(dbg!(encode_storage_fields( - ABI_WITH_FIELDS_V24, - Some( - r#"{ + assert!( + dbg!(encode_storage_fields( + ABI_WITH_FIELDS_V24, + Some( + r#"{ "__pubkey": "0x11c0a428b6768562df09db05326595337dbb5f8dde0e128224d4df48df760f17", "__timestamp": 123, "ok": true }"# - ), - )) - .is_err()); + ), + )) + .is_err() + ); } const ABI_WRONG_STORAGE_LAYOUT: &str = r#"{ @@ -754,10 +758,12 @@ fn test_wrong_storage_layout() { let image = include_bytes!("FairNFTCollection.tvc"); let image = tvm_block::StateInit::construct_from_bytes(image).unwrap(); - assert!(decode_storage_fields( - ABI_WRONG_STORAGE_LAYOUT, - SliceData::load_cell(image.data.unwrap()).unwrap(), - false - ) - .is_ok()); + assert!( + decode_storage_fields( + ABI_WRONG_STORAGE_LAYOUT, + SliceData::load_cell(image.data.unwrap()).unwrap(), + false + ) + .is_ok() + ); } diff --git a/tvm_abi/src/tests/v2/test_contract.rs b/tvm_abi/src/tests/v2/test_contract.rs index d5099c072..e4a0d5990 100644 --- a/tvm_abi/src/tests/v2/test_contract.rs +++ b/tvm_abi/src/tests/v2/test_contract.rs @@ -11,13 +11,13 @@ use std::collections::HashMap; -use crate::contract::ABI_VERSION_2_4; use crate::Contract; use crate::DataItem; use crate::Event; use crate::Function; use crate::Param; use crate::ParamType; +use crate::contract::ABI_VERSION_2_4; const TEST_ABI: &str = r#" { @@ -91,123 +91,101 @@ fn test_abi_parse() { ]; let abi_version = ABI_VERSION_2_4; - functions.insert( - "input_and_output".to_owned(), - Function { - abi_version, - name: "input_and_output".to_owned(), - header: header.clone(), - inputs: vec![ - Param { name: "a".to_owned(), kind: ParamType::Uint(64) }, - Param { - name: "b".to_owned(), - kind: ParamType::Array(Box::new(ParamType::Uint(8))), - }, - Param { name: "c".to_owned(), kind: ParamType::Bytes }, - ], - outputs: vec![ - Param { name: "a".to_owned(), kind: ParamType::Int(16) }, - Param { name: "b".to_owned(), kind: ParamType::Uint(8) }, - ], - input_id: Function::calc_function_id( - "input_and_output(uint64,uint8[],bytes)(int16,uint8)v2", - ) & 0x7FFFFFFF, - output_id: Function::calc_function_id( - "input_and_output(uint64,uint8[],bytes)(int16,uint8)v2", - ) | 0x80000000, - }, - ); - - functions.insert( - "no_output".to_owned(), - Function { - abi_version, - name: "no_output".to_owned(), - header: header.clone(), - inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(15) }], - outputs: vec![], - input_id: Function::calc_function_id("no_output(uint15)()v2") & 0x7FFFFFFF, - output_id: Function::calc_function_id("no_output(uint15)()v2") | 0x80000000, - }, - ); - - functions.insert( - "no_input".to_owned(), - Function { - abi_version, - name: "no_input".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(8) }], - input_id: Function::calc_function_id("no_input()(uint8)v2") & 0x7FFFFFFF, - output_id: Function::calc_function_id("no_input()(uint8)v2") | 0x80000000, - }, - ); - - functions.insert( - "constructor".to_owned(), - Function { - abi_version, - name: "constructor".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![], - input_id: Function::calc_function_id("constructor()()v2") & 0x7FFFFFFF, - output_id: Function::calc_function_id("constructor()()v2") | 0x80000000, - }, - ); - - functions.insert( - "has_id".to_owned(), - Function { - abi_version, - name: "has_id".to_owned(), - header: header.clone(), - inputs: vec![], - outputs: vec![], - input_id: 0x01234567, - output_id: 0x01234567, - }, - ); + functions.insert("input_and_output".to_owned(), Function { + abi_version, + name: "input_and_output".to_owned(), + header: header.clone(), + inputs: vec![ + Param { name: "a".to_owned(), kind: ParamType::Uint(64) }, + Param { name: "b".to_owned(), kind: ParamType::Array(Box::new(ParamType::Uint(8))) }, + Param { name: "c".to_owned(), kind: ParamType::Bytes }, + ], + outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Int(16) }, Param { + name: "b".to_owned(), + kind: ParamType::Uint(8), + }], + input_id: Function::calc_function_id( + "input_and_output(uint64,uint8[],bytes)(int16,uint8)v2", + ) & 0x7FFFFFFF, + output_id: Function::calc_function_id( + "input_and_output(uint64,uint8[],bytes)(int16,uint8)v2", + ) | 0x80000000, + }); + + functions.insert("no_output".to_owned(), Function { + abi_version, + name: "no_output".to_owned(), + header: header.clone(), + inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(15) }], + outputs: vec![], + input_id: Function::calc_function_id("no_output(uint15)()v2") & 0x7FFFFFFF, + output_id: Function::calc_function_id("no_output(uint15)()v2") | 0x80000000, + }); + + functions.insert("no_input".to_owned(), Function { + abi_version, + name: "no_input".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(8) }], + input_id: Function::calc_function_id("no_input()(uint8)v2") & 0x7FFFFFFF, + output_id: Function::calc_function_id("no_input()(uint8)v2") | 0x80000000, + }); + + functions.insert("constructor".to_owned(), Function { + abi_version, + name: "constructor".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![], + input_id: Function::calc_function_id("constructor()()v2") & 0x7FFFFFFF, + output_id: Function::calc_function_id("constructor()()v2") | 0x80000000, + }); + + functions.insert("has_id".to_owned(), Function { + abi_version, + name: "has_id".to_owned(), + header: header.clone(), + inputs: vec![], + outputs: vec![], + input_id: 0x01234567, + output_id: 0x01234567, + }); let mut events = HashMap::new(); - events.insert( - "input".to_owned(), - Event { - abi_version, - name: "input".to_owned(), - inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(64) }], - id: Function::calc_function_id("input(uint64)v2") & 0x7FFFFFFF, - }, - ); - - events.insert( - "no_input".to_owned(), - Event { - abi_version, - name: "no_input".to_owned(), - inputs: vec![], - id: Function::calc_function_id("no_input()v2") & 0x7FFFFFFF, - }, - ); - - events.insert( - "has_id".to_owned(), - Event { abi_version, name: "has_id".to_owned(), inputs: vec![], id: 0x89abcdef }, - ); + events.insert("input".to_owned(), Event { + abi_version, + name: "input".to_owned(), + inputs: vec![Param { name: "a".to_owned(), kind: ParamType::Uint(64) }], + id: Function::calc_function_id("input(uint64)v2") & 0x7FFFFFFF, + }); + + events.insert("no_input".to_owned(), Event { + abi_version, + name: "no_input".to_owned(), + inputs: vec![], + id: Function::calc_function_id("no_input()v2") & 0x7FFFFFFF, + }); + + events.insert("has_id".to_owned(), Event { + abi_version, + name: "has_id".to_owned(), + inputs: vec![], + id: 0x89abcdef, + }); let mut data = HashMap::new(); - data.insert( - "a".to_owned(), - DataItem { value: Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, key: 100 }, - ); + data.insert("a".to_owned(), DataItem { + value: Param { name: "a".to_owned(), kind: ParamType::Uint(256) }, + key: 100, + }); - let fields = vec![ - Param { name: "a".into(), kind: ParamType::Uint(32) }, - Param { name: "b".into(), kind: ParamType::Int(128) }, - ]; + let fields = vec![Param { name: "a".into(), kind: ParamType::Uint(32) }, Param { + name: "b".into(), + kind: ParamType::Int(128), + }]; let init_fields = vec!["b".to_owned()].into_iter().collect(); diff --git a/tvm_abi/src/token/deserialize.rs b/tvm_abi/src/token/deserialize.rs index 9209a8547..82ce32d0f 100644 --- a/tvm_abi/src/token/deserialize.rs +++ b/tvm_abi/src/token/deserialize.rs @@ -14,10 +14,8 @@ use std::collections::BTreeMap; use num_bigint::BigInt; use num_bigint::BigUint; use num_traits::ToPrimitive; -use tvm_block::types::Grams; use tvm_block::MsgAddress; -use tvm_types::error; -use tvm_types::fail; +use tvm_block::types::Grams; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; @@ -25,12 +23,14 @@ use tvm_types::HashmapType; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; -use crate::contract::AbiVersion; use crate::contract::ABI_VERSION_1_0; use crate::contract::ABI_VERSION_2_0; use crate::contract::ABI_VERSION_2_2; use crate::contract::ABI_VERSION_2_4; +use crate::contract::AbiVersion; use crate::error::AbiError; use crate::int::Int; use crate::int::Uint; diff --git a/tvm_abi/src/token/detokenizer.rs b/tvm_abi/src/token/detokenizer.rs index bd12889b3..9ce4067c7 100644 --- a/tvm_abi/src/token/detokenizer.rs +++ b/tvm_abi/src/token/detokenizer.rs @@ -17,15 +17,15 @@ use num_bigint::BigUint; use serde::ser::Serialize; use serde::ser::SerializeMap; use serde::ser::Serializer; -use tvm_types::base64_encode; -use tvm_types::write_boc; use tvm_types::Cell; use tvm_types::Result; +use tvm_types::base64_encode; +use tvm_types::write_boc; +use crate::PublicKeyData; use crate::param_type::ParamType; use crate::token::Token; use crate::token::TokenValue; -use crate::PublicKeyData; pub struct Detokenizer; diff --git a/tvm_abi/src/token/mod.rs b/tvm_abi/src/token/mod.rs index 995ba9ff4..b0ea30411 100644 --- a/tvm_abi/src/token/mod.rs +++ b/tvm_abi/src/token/mod.rs @@ -22,14 +22,14 @@ use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::Result; -use crate::contract::AbiVersion; +use crate::PublicKeyData; use crate::contract::ABI_VERSION_2_4; +use crate::contract::AbiVersion; use crate::error::AbiError; use crate::int::Int; use crate::int::Uint; use crate::param::Param; use crate::param_type::ParamType; -use crate::PublicKeyData; mod deserialize; mod detokenizer; diff --git a/tvm_abi/src/token/serialize.rs b/tvm_abi/src/token/serialize.rs index d4ec05288..77eaf4b3f 100644 --- a/tvm_abi/src/token/serialize.rs +++ b/tvm_abi/src/token/serialize.rs @@ -15,19 +15,20 @@ use num_bigint::BigInt; use num_bigint::BigUint; use num_bigint::Sign; use tvm_block::Serializable; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; -use crate::contract::AbiVersion; +use crate::PublicKeyData; use crate::contract::ABI_VERSION_1_0; use crate::contract::ABI_VERSION_2_2; use crate::contract::ABI_VERSION_2_4; +use crate::contract::AbiVersion; use crate::error::AbiError; use crate::int::Int; use crate::int::Uint; @@ -35,7 +36,6 @@ use crate::param_type::ParamType; use crate::token::Token; use crate::token::TokenValue; use crate::token::Tokenizer; -use crate::PublicKeyData; pub struct SerializedValue { pub data: BuilderData, @@ -468,17 +468,13 @@ fn test_pack_cells() { ]; let builder = BuilderData::with_raw(vec![0x55; 127], 127 * 8).unwrap(); - let builder = BuilderData::with_raw_and_refs( - vec![0x55; 127], - 127 * 8, - vec![builder.into_cell().unwrap()], - ) + let builder = BuilderData::with_raw_and_refs(vec![0x55; 127], 127 * 8, vec![ + builder.into_cell().unwrap(), + ]) .unwrap(); - let builder = BuilderData::with_raw_and_refs( - vec![0x55; 100], - 100 * 8, - vec![builder.into_cell().unwrap()], - ) + let builder = BuilderData::with_raw_and_refs(vec![0x55; 100], 100 * 8, vec![ + builder.into_cell().unwrap(), + ]) .unwrap(); let tree = TokenValue::pack_cells_into_chain(cells, &ABI_VERSION_1_0).unwrap(); assert_eq!(tree, builder); diff --git a/tvm_abi/src/token/test_encoding.rs b/tvm_abi/src/token/test_encoding.rs index ee25429a7..f27f1299a 100644 --- a/tvm_abi/src/token/test_encoding.rs +++ b/tvm_abi/src/token/test_encoding.rs @@ -18,32 +18,32 @@ use tvm_block::AnycastInfo; use tvm_block::Grams; use tvm_block::MsgAddress; use tvm_block::Serializable; -use tvm_types::dictionary::HashmapE; -use tvm_types::dictionary::HashmapType; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; +use tvm_types::ED25519_PUBLIC_KEY_LENGTH; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; -use tvm_types::ED25519_PUBLIC_KEY_LENGTH; +use tvm_types::dictionary::HashmapE; +use tvm_types::dictionary::HashmapType; -use crate::contract::AbiVersion; +use crate::AbiError; +use crate::Int; +use crate::Param; +use crate::ParamType; +use crate::Token; +use crate::TokenValue; +use crate::Uint; 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_2; use crate::contract::ABI_VERSION_2_3; use crate::contract::ABI_VERSION_2_4; +use crate::contract::AbiVersion; use crate::contract::MAX_SUPPORTED_VERSION; use crate::token::Cursor; -use crate::AbiError; -use crate::Int; -use crate::Param; -use crate::ParamType; -use crate::Token; -use crate::TokenValue; -use crate::Uint; fn put_array_into_map(array: &[T]) -> HashmapE { let mut map = HashmapE::with_bit_len(32); @@ -142,12 +142,11 @@ fn test_one_input_and_output() { let values = vec![TokenValue::Uint(Uint { number: BigUint::from(1123u128), size: 128 })]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -162,12 +161,11 @@ fn test_with_grams() { let values = vec![TokenValue::Token(grams)]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -222,12 +220,10 @@ fn test_with_address() { values.push(TokenValue::Address(address.clone())); }); - test_parameters_set( - &tokens_from_values(values.clone()), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0], - ); + test_parameters_set(&tokens_from_values(values.clone()), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ]); test_parameters_set(&tokens_from_values(values), None, builder_v2_2, &[ABI_VERSION_2_2]); } @@ -243,12 +239,11 @@ fn test_one_input_and_output_by_data() { let values = vec![TokenValue::Int(Int { number: BigInt::from(-596784153684i64), size: 64 })]; - test_parameters_set( - &tokens_from_values(values), - None, - expected_tree, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, expected_tree, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -276,12 +271,11 @@ fn test_two_params() { TokenValue::Int(Int { number: BigInt::from(9434567), size: 32 }), ]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -359,12 +353,10 @@ fn test_five_refs_v2() { TokenValue::Int(Int::new(9434567, 32)), ]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -408,12 +400,11 @@ fn test_nested_tuples_with_all_simples() { ])), ]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -432,12 +423,11 @@ fn test_static_array_of_ints() { input_array.iter().map(|i| TokenValue::Uint(Uint::new(i.to_owned() as u128, 32))).collect(), )]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -454,12 +444,11 @@ fn test_empty_dynamic_array() { let params = vec![Param { name: "a".to_owned(), kind: ParamType::Array(Box::new(ParamType::Uint(16))) }]; - test_parameters_set( - &tokens_from_values(values), - Some(¶ms), - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), Some(¶ms), builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -478,12 +467,11 @@ fn test_dynamic_array_of_ints() { input_array.iter().map(|i| TokenValue::Uint(Uint::new(i.to_owned() as u128, 16))).collect(), )]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } struct TupleDwordBool(u32, bool); @@ -535,12 +523,11 @@ fn test_dynamic_array_of_tuples() { .collect(), )]; - test_parameters_set( - &tokens_from_values(values), - None, - expected_tree, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, expected_tree, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -613,16 +600,14 @@ fn test_tuples_with_combined_types() { input_array2.iter().map(|i| TokenValue::Int(Int::new(*i as i128, 64))).collect(), ); - let array3_token_value = TokenValue::FixedArray( - ParamType::Array(Box::new(ParamType::Int(64))), - vec![ + let array3_token_value = + TokenValue::FixedArray(ParamType::Array(Box::new(ParamType::Int(64))), vec![ array2_token_value.clone(), array2_token_value.clone(), array2_token_value.clone(), array2_token_value.clone(), array2_token_value.clone(), - ], - ); + ]); let values = vec![ TokenValue::Uint(Uint::new(18, 8)), @@ -633,19 +618,14 @@ fn test_tuples_with_combined_types() { TokenValue::Tuple(tokens_from_values(vec![array2_token_value, array3_token_value])), ]; - test_parameters_set( - &tokens_from_values(values.clone()), - None, - chain_builder, - &[ABI_VERSION_1_0], - ); + test_parameters_set(&tokens_from_values(values.clone()), None, chain_builder, &[ + ABI_VERSION_1_0, + ]); - test_parameters_set( - &tokens_from_values(values), - None, - chain_builder_v2, - &[ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, chain_builder_v2, &[ + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -683,12 +663,11 @@ fn test_four_refs_and_four_int256() { TokenValue::Uint(Uint { number: BigUint::from_bytes_be(&bytes), size: 256 }), ]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -723,12 +702,10 @@ fn test_four_refs_and_one_int256() { test_parameters_set(&tokens_from_values(values.clone()), None, builder, &[ABI_VERSION_1_0]); - test_parameters_set( - &tokens_from_values(values), - None, - builder_v2, - &[ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder_v2, &[ + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -753,12 +730,11 @@ fn test_header_params() { TokenValue::Expire(67890), ]; - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } fn vec_to_map(vec: &[(K, BuilderData)], size: usize) -> HashmapE { @@ -862,12 +838,10 @@ fn test_map() { TokenValue::Map(ParamType::Int(256), ParamType::Bool, BTreeMap::new()), ]; - test_parameters_set( - &tokens_from_values(values.clone()), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values.clone()), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_2, + ]); test_parameters_set(&tokens_from_values(values.clone()), None, builder_v2, &[ABI_VERSION_2_0]); } @@ -904,12 +878,11 @@ fn test_address_map_key() { builder.append_builder(&map.write_to_new_cell().unwrap()).unwrap(); - test_parameters_set( - &tokens_from_values(vec![value]), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(vec![value]), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -972,12 +945,10 @@ fn test_big_map_value() { builder.append_u32(1).unwrap(); builder.append_builder(&array.write_to_new_cell().unwrap()).unwrap(); - test_parameters_set( - &tokens_from_values(vec![value_map, value_array]), - None, - builder, - &[ABI_VERSION_2_0, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(vec![value_map, value_array]), None, builder, &[ + ABI_VERSION_2_0, + ABI_VERSION_2_2, + ]); } #[test] @@ -1037,16 +1008,12 @@ fn test_abi_2_1_types() { BuilderData::with_raw_and_refs(vec![0x80], 1, vec![varuint_builder.into_cell().unwrap()]) .unwrap(); - let tuple_builder = BuilderData::with_raw_and_refs( - vec![], - 0, - vec![ - string_builder.clone().into_cell().unwrap(), - string_builder.clone().into_cell().unwrap(), - string_builder.clone().into_cell().unwrap(), - string_builder.clone().into_cell().unwrap(), - ], - ) + let tuple_builder = BuilderData::with_raw_and_refs(vec![], 0, vec![ + string_builder.clone().into_cell().unwrap(), + string_builder.clone().into_cell().unwrap(), + string_builder.clone().into_cell().unwrap(), + string_builder.clone().into_cell().unwrap(), + ]) .unwrap(); let tuple_builder = BuilderData::with_raw_and_refs(vec![0x80], 1, vec![tuple_builder.into_cell().unwrap()]) @@ -1056,12 +1023,10 @@ fn test_abi_2_1_types() { uint_builder.checked_append_reference(varuint_builder.into_cell().unwrap()).unwrap(); builder.checked_append_reference(uint_builder.into_cell().unwrap()).unwrap(); - test_parameters_set( - &tokens_from_values(values), - None, - builder, - &[ABI_VERSION_2_1, ABI_VERSION_2_2], - ); + test_parameters_set(&tokens_from_values(values), None, builder, &[ + ABI_VERSION_2_1, + ABI_VERSION_2_2, + ]); } #[test] @@ -1149,11 +1114,9 @@ fn test_four_optional_strings() { builder.append_bits(1, 2).unwrap(); builder.checked_append_reference(string_builder.clone().into_cell().unwrap()).unwrap(); - let second_builder = BuilderData::with_raw_and_refs( - vec![0x40], - 2, - vec![string_builder.clone().into_cell().unwrap()], - ) + let second_builder = BuilderData::with_raw_and_refs(vec![0x40], 2, vec![ + string_builder.clone().into_cell().unwrap(), + ]) .unwrap(); builder.checked_append_reference(second_builder.into_cell().unwrap()).unwrap(); @@ -1352,11 +1315,9 @@ fn test_fixed_bytes() { let values = vec![TokenValue::FixedBytes(bytes)]; - test_parameters_set( - &tokens_from_values(values.clone()), - None, - builder, - &[ABI_VERSION_1_0, ABI_VERSION_2_3], - ); + test_parameters_set(&tokens_from_values(values.clone()), None, builder, &[ + ABI_VERSION_1_0, + ABI_VERSION_2_3, + ]); test_parameters_set(&tokens_from_values(values), None, builder_v24, &[ABI_VERSION_2_4]); } diff --git a/tvm_abi/src/token/tests.rs b/tvm_abi/src/token/tests.rs index 75135a1c8..0ea527021 100644 --- a/tvm_abi/src/token/tests.rs +++ b/tvm_abi/src/token/tests.rs @@ -17,17 +17,17 @@ mod tokenize_tests { use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; - use tvm_types::SliceData; use tvm_types::ED25519_PUBLIC_KEY_LENGTH; + use tvm_types::SliceData; - use crate::token::Detokenizer; - use crate::token::Tokenizer; use crate::Int; use crate::Param; use crate::ParamType; use crate::Token; use crate::TokenValue; use crate::Uint; + use crate::token::Detokenizer; + use crate::token::Tokenizer; #[test] fn test_tokenize_ints() { @@ -107,23 +107,28 @@ mod tokenize_tests { let input_not_fit = r#"{ "a" : -129 }"#; let params = vec![Param { name: "a".to_owned(), kind: ParamType::Int(8) }]; - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_fit).unwrap()) - .is_ok()); - assert!(Tokenizer::tokenize_all_params( - ¶ms, - &serde_json::from_str(input_not_fit).unwrap() - ) - .is_err()); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_fit).unwrap()) + .is_ok() + ); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_not_fit).unwrap()) + .is_err() + ); // negative values for uint let input_num = r#"{ "a" : -1 }"#; let input_str = r#"{ "a" : "-5" }"#; let params = vec![Param { name: "a".to_owned(), kind: ParamType::Uint(8) }]; - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) - .is_err()); - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) - .is_err()); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) + .is_err() + ); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) + .is_err() + ); // varint max check let input = r#"{ "a" : "0xffffffffffffffffffffffffffffffff" }"#; @@ -138,10 +143,14 @@ mod tokenize_tests { let input_str = r#"{ "a" : "-5" }"#; let params = vec![Param { name: "a".to_owned(), kind: ParamType::VarUint(8) }]; - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) - .is_err()); - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) - .is_err()); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) + .is_err() + ); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) + .is_err() + ); } #[test] @@ -151,15 +160,16 @@ mod tokenize_tests { "b" : "false" }"#; - let params = vec![ - Param { name: "a".to_owned(), kind: ParamType::Bool }, - Param { name: "b".to_owned(), kind: ParamType::Bool }, - ]; + let params = vec![Param { name: "a".to_owned(), kind: ParamType::Bool }, Param { + name: "b".to_owned(), + kind: ParamType::Bool, + }]; - let expected_tokens = vec![ - Token { name: "a".to_owned(), value: TokenValue::Bool(true) }, - Token { name: "b".to_owned(), value: TokenValue::Bool(false) }, - ]; + let expected_tokens = + vec![Token { name: "a".to_owned(), value: TokenValue::Bool(true) }, Token { + name: "b".to_owned(), + value: TokenValue::Bool(false), + }]; assert_eq!( Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input).unwrap()).unwrap(), @@ -239,13 +249,10 @@ mod tokenize_tests { }, Token { name: "b".to_owned(), - value: TokenValue::FixedArray( - ParamType::Array(Box::new(ParamType::Bool)), - vec![ - TokenValue::Array(ParamType::Bool, bool_array1), - TokenValue::Array(ParamType::Bool, bool_array2), - ], - ), + value: TokenValue::FixedArray(ParamType::Array(Box::new(ParamType::Bool)), vec![ + TokenValue::Array(ParamType::Bool, bool_array1), + TokenValue::Array(ParamType::Bool, bool_array2), + ]), }, ]; @@ -294,18 +301,16 @@ mod tokenize_tests { Param { name: "c".to_owned(), kind: ParamType::Int(16) }, ]; - let tuple_params2 = vec![ - Param { name: "a".to_owned(), kind: ParamType::Bool }, - Param { name: "b".to_owned(), kind: ParamType::Int(8) }, - ]; + let tuple_params2 = vec![Param { name: "a".to_owned(), kind: ParamType::Bool }, Param { + name: "b".to_owned(), + kind: ParamType::Int(8), + }]; - let params = vec![ - Param { name: "t1".to_owned(), kind: ParamType::Tuple(tuple_params1) }, - Param { + let params = + vec![Param { name: "t1".to_owned(), kind: ParamType::Tuple(tuple_params1) }, Param { name: "t2".to_owned(), kind: ParamType::Array(Box::new(ParamType::Tuple(tuple_params2))), - }, - ]; + }]; let expected_tokens = vec![ Token { @@ -313,14 +318,11 @@ mod tokenize_tests { value: TokenValue::Tuple(vec![ Token { name: "a".to_owned(), - value: TokenValue::Array( - ParamType::Int(16), - vec![ - TokenValue::Int(Int::new(-123, 16)), - TokenValue::Int(Int::new(456, 16)), - TokenValue::Int(Int::new(0x789, 16)), - ], - ), + value: TokenValue::Array(ParamType::Int(16), vec![ + TokenValue::Int(Int::new(-123, 16)), + TokenValue::Int(Int::new(456, 16)), + TokenValue::Int(Int::new(0x789, 16)), + ]), }, Token { name: "b".to_owned(), value: TokenValue::Bool(false) }, Token { name: "c".to_owned(), value: TokenValue::Int(Int::new(0x1234, 16)) }, @@ -664,10 +666,14 @@ mod tokenize_tests { let input_str = r#"{ "a" : "-5" }"#; let params = vec![Param { name: "a".to_owned(), kind: ParamType::Time }]; - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) - .is_err()); - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) - .is_err()); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) + .is_err() + ); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) + .is_err() + ); } #[test] @@ -723,10 +729,14 @@ mod tokenize_tests { let input_str = r#"{ "a" : "-5" }"#; let params = vec![Param { name: "a".to_owned(), kind: ParamType::Expire }]; - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) - .is_err()); - assert!(Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) - .is_err()); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_num).unwrap()) + .is_err() + ); + assert!( + Tokenizer::tokenize_all_params(¶ms, &serde_json::from_str(input_str).unwrap()) + .is_err() + ); } #[test] @@ -849,11 +859,10 @@ mod tokenize_tests { let params = vec![Param::new("a", ParamType::Time)]; - assert!(Tokenizer::tokenize_optional_params( - ¶ms, - &serde_json::from_str(input).unwrap(), - ) - .is_err(),); + assert!( + Tokenizer::tokenize_optional_params(¶ms, &serde_json::from_str(input).unwrap(),) + .is_err(), + ); } } @@ -893,17 +902,17 @@ mod types_check_tests { Token { name: "e".to_owned(), value: TokenValue::Bool(false) }, Token { name: "f".to_owned(), - value: TokenValue::Array( - ParamType::Bool, - vec![TokenValue::Bool(false), TokenValue::Bool(true)], - ), + value: TokenValue::Array(ParamType::Bool, vec![ + TokenValue::Bool(false), + TokenValue::Bool(true), + ]), }, Token { name: "g".to_owned(), - value: TokenValue::FixedArray( - ParamType::Int(64), - vec![TokenValue::Int(big_int.clone()), TokenValue::Int(big_int.clone())], - ), + value: TokenValue::FixedArray(ParamType::Int(64), vec![ + TokenValue::Int(big_int.clone()), + TokenValue::Int(big_int.clone()), + ]), }, Token { name: "j".to_owned(), @@ -947,10 +956,10 @@ mod types_check_tests { }, ]; - let tuple_params = vec![ - Param { name: "a".to_owned(), kind: ParamType::Bool }, - Param { name: "b".to_owned(), kind: ParamType::Uint(32) }, - ]; + let tuple_params = vec![Param { name: "a".to_owned(), kind: ParamType::Bool }, Param { + name: "b".to_owned(), + kind: ParamType::Uint(32), + }]; let params = vec![ Param { name: "a".to_owned(), kind: ParamType::Uint(32) }, @@ -1007,20 +1016,19 @@ mod types_check_tests { let mut tokens_wrong_fixed_array_size = tokens.clone(); tokens_wrong_fixed_array_size[6] = Token { name: "g".to_owned(), - value: TokenValue::FixedArray( - ParamType::Int(64), - vec![TokenValue::Int(big_int.clone())], - ), + value: TokenValue::FixedArray(ParamType::Int(64), vec![TokenValue::Int( + big_int.clone(), + )]), }; assert_not_type_check(&tokens_wrong_fixed_array_size, ¶ms); let mut tokens_wrong_array_type = tokens.clone(); tokens_wrong_array_type[5] = Token { name: "f".to_owned(), - value: TokenValue::Array( - ParamType::Bool, - vec![TokenValue::Bool(false), TokenValue::Int(big_int.clone())], - ), + value: TokenValue::Array(ParamType::Bool, vec![ + TokenValue::Bool(false), + TokenValue::Int(big_int.clone()), + ]), }; assert_not_type_check(&tokens_wrong_array_type, ¶ms); diff --git a/tvm_abi/src/token/tokenizer.rs b/tvm_abi/src/token/tokenizer.rs index 6a292db9c..93ff36cc6 100644 --- a/tvm_abi/src/token/tokenizer.rs +++ b/tvm_abi/src/token/tokenizer.rs @@ -21,13 +21,13 @@ use num_traits::cast::ToPrimitive; use serde_json::Value; use tvm_block::Grams; use tvm_block::MsgAddress; +use tvm_types::Cell; +use tvm_types::ED25519_PUBLIC_KEY_LENGTH; +use tvm_types::Result; use tvm_types::base64_decode; use tvm_types::error; use tvm_types::fail; use tvm_types::read_single_root_boc; -use tvm_types::Cell; -use tvm_types::Result; -use tvm_types::ED25519_PUBLIC_KEY_LENGTH; use crate::error::AbiError; use crate::int::Int; diff --git a/tvm_api/src/lib.rs b/tvm_api/src/lib.rs index 784747c95..2fb556756 100644 --- a/tvm_api/src/lib.rs +++ b/tvm_api/src/lib.rs @@ -24,11 +24,11 @@ use std::sync::Arc; use thiserror::Error; use tvm_block::BlockIdExt; use tvm_block::ShardIdent; -use tvm_types::fail; use tvm_types::Ed25519KeyOption; use tvm_types::KeyOption; use tvm_types::Result; use tvm_types::UInt256; +use tvm_types::fail; use crate::ton::ton_node::RempMessageLevel; use crate::ton::ton_node::RempMessageStatus; @@ -570,11 +570,7 @@ pub fn tag_from_boxed_type() -> u32 { /// Get TL tag from data bytes pub fn tag_from_data(data: &[u8]) -> u32 { - if data.len() < 4 { - 0 - } else { - u32::from_le_bytes([data[0], data[1], data[2], data[3]]) - } + if data.len() < 4 { 0 } else { u32::from_le_bytes([data[0], data[1], data[2], data[3]]) } } impl TryFrom<&Arc> for ton::PublicKey { diff --git a/tvm_api/src/ton/rpc/adnl.rs b/tvm_api/src/ton/rpc/adnl.rs index 450417981..90659b2dc 100644 --- a/tvm_api/src/ton/rpc/adnl.rs +++ b/tvm_api/src/ton/rpc/adnl.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for Ping { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1faaa1bf) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1faaa1bf) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Ping { diff --git a/tvm_api/src/ton/rpc/catchain.rs b/tvm_api/src/ton/rpc/catchain.rs index a0c012171..84a874d65 100644 --- a/tvm_api/src/ton/rpc/catchain.rs +++ b/tvm_api/src/ton/rpc/catchain.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for GetBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x093ddd78) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x093ddd78) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlock { @@ -90,11 +86,7 @@ impl crate::BoxedDeserialize for GetBlockHistory { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa8566df6) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa8566df6) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlockHistory { @@ -140,11 +132,7 @@ impl crate::BoxedDeserialize for GetBlocks { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0329abc2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0329abc2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlocks { @@ -189,11 +177,7 @@ impl crate::BoxedDeserialize for GetDifference { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd06cced8) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd06cced8) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetDifference { diff --git a/tvm_api/src/ton/rpc/dht.rs b/tvm_api/src/ton/rpc/dht.rs index bc6d3b116..21da419e5 100644 --- a/tvm_api/src/ton/rpc/dht.rs +++ b/tvm_api/src/ton/rpc/dht.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for FindNode { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6ce2ce6b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6ce2ce6b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for FindNode { @@ -89,11 +85,7 @@ impl crate::BoxedDeserialize for FindValue { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xae4b6011) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xae4b6011) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for FindValue { @@ -131,11 +123,7 @@ impl crate::BoxedDeserialize for GetSignedAddressList { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa97948ed) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa97948ed) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetSignedAddressList { @@ -180,11 +168,7 @@ impl crate::BoxedDeserialize for Ping { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xcbeb3f18) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xcbeb3f18) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Ping { @@ -229,11 +213,7 @@ impl crate::BoxedDeserialize for Query { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7d530769) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7d530769) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Query { @@ -278,11 +258,7 @@ impl crate::BoxedDeserialize for Store { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x34934212) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x34934212) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Store { diff --git a/tvm_api/src/ton/rpc/dns.rs b/tvm_api/src/ton/rpc/dns.rs index f1a3ad54a..a0b3ee07e 100644 --- a/tvm_api/src/ton/rpc/dns.rs +++ b/tvm_api/src/ton/rpc/dns.rs @@ -43,11 +43,7 @@ impl crate::BoxedDeserialize for Resolve { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf71acecf) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf71acecf) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Resolve { diff --git a/tvm_api/src/ton/rpc/engine/validator.rs b/tvm_api/src/ton/rpc/engine/validator.rs index 521751265..44902a348 100644 --- a/tvm_api/src/ton/rpc/engine/validator.rs +++ b/tvm_api/src/ton/rpc/engine/validator.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for AddAdnlId { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xed8554ab) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xed8554ab) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddAdnlId { @@ -89,11 +85,7 @@ impl crate::BoxedDeserialize for AddControlInterface { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x348bf3fc) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x348bf3fc) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddControlInterface { @@ -147,11 +139,7 @@ impl crate::BoxedDeserialize for AddControlProcess { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5ae0f750) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5ae0f750) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddControlProcess { @@ -196,11 +184,7 @@ impl crate::BoxedDeserialize for AddDhtId { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf50c1e8c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf50c1e8c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddDhtId { @@ -258,11 +242,7 @@ impl crate::BoxedDeserialize for AddListeningPort { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xea6b89b5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xea6b89b5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddListeningPort { @@ -310,11 +290,7 @@ impl crate::BoxedDeserialize for AddLiteserver { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf08a0f47) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf08a0f47) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddLiteserver { @@ -382,11 +358,7 @@ impl crate::BoxedDeserialize for AddProxy { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf6fd33f5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf6fd33f5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddProxy { @@ -437,11 +409,7 @@ impl crate::BoxedDeserialize for AddValidatorAdnlAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xdacba682) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xdacba682) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddValidatorAdnlAddress { @@ -492,11 +460,7 @@ impl crate::BoxedDeserialize for AddValidatorBlsKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x4a8aa32c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x4a8aa32c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddValidatorBlsKey { @@ -547,11 +511,7 @@ impl crate::BoxedDeserialize for AddValidatorPermanentKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x92150578) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x92150578) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddValidatorPermanentKey { @@ -602,11 +562,7 @@ impl crate::BoxedDeserialize for AddValidatorTempKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8d336f32) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8d336f32) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddValidatorTempKey { @@ -651,11 +607,7 @@ impl crate::BoxedDeserialize for ChangeFullNodeAdnlAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xbec6c985) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xbec6c985) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ChangeFullNodeAdnlAddress { @@ -700,11 +652,7 @@ impl crate::BoxedDeserialize for CheckDhtServers { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd1e420ca) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd1e420ca) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CheckDhtServers { @@ -749,11 +697,7 @@ impl crate::BoxedDeserialize for ControlQuery { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa476bdc0) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa476bdc0) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ControlQuery { @@ -801,11 +745,7 @@ impl crate::BoxedDeserialize for CreateComplaintVote { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb083ff2a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb083ff2a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateComplaintVote { @@ -856,11 +796,7 @@ impl crate::BoxedDeserialize for CreateElectionBid { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe51db145) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe51db145) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateElectionBid { @@ -905,11 +841,7 @@ impl crate::BoxedDeserialize for CreateProposalVote { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1db3216d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1db3216d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateProposalVote { @@ -954,11 +886,7 @@ impl crate::BoxedDeserialize for DelAdnlId { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x293a74f2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x293a74f2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelAdnlId { @@ -1003,11 +931,7 @@ impl crate::BoxedDeserialize for DelDhtId { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x84fd5b3e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x84fd5b3e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelDhtId { @@ -1065,11 +989,7 @@ impl crate::BoxedDeserialize for DelListeningPort { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x315bb84f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x315bb84f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelListeningPort { @@ -1127,11 +1047,7 @@ impl crate::BoxedDeserialize for DelProxy { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7578cc7d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7578cc7d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelProxy { @@ -1179,11 +1095,7 @@ impl crate::BoxedDeserialize for DelValidatorAdnlAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf708435a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf708435a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelValidatorAdnlAddress { @@ -1228,11 +1140,7 @@ impl crate::BoxedDeserialize for DelValidatorPermanentKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x174ac8fa) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x174ac8fa) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelValidatorPermanentKey { @@ -1280,11 +1188,7 @@ impl crate::BoxedDeserialize for DelValidatorTempKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa0e6e0d1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa0e6e0d1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DelValidatorTempKey { @@ -1329,11 +1233,7 @@ impl crate::BoxedDeserialize for ExportPrivateKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xcc728048) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xcc728048) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportPrivateKey { @@ -1378,11 +1278,7 @@ impl crate::BoxedDeserialize for ExportPublicKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6234a8b9) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6234a8b9) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportPublicKey { @@ -1420,11 +1316,7 @@ impl crate::BoxedDeserialize for GenerateBlsKeyPair { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5ba28a06) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5ba28a06) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GenerateBlsKeyPair { @@ -1462,11 +1354,7 @@ impl crate::BoxedDeserialize for GenerateKeyPair { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xeb25607b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xeb25607b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GenerateKeyPair { @@ -1511,11 +1399,7 @@ impl crate::BoxedDeserialize for GetBundle { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x93343076) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x93343076) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBundle { @@ -1553,11 +1437,7 @@ impl crate::BoxedDeserialize for GetConfig { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x59ad2225) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x59ad2225) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetConfig { @@ -1606,11 +1486,7 @@ impl crate::BoxedDeserialize for GetFutureBundle { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x2834ba00) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x2834ba00) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetFutureBundle { @@ -1655,11 +1531,7 @@ impl crate::BoxedDeserialize for GetSelectedStats { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xbbda1565) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xbbda1565) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetSelectedStats { @@ -1697,11 +1569,7 @@ impl crate::BoxedDeserialize for GetSessionStats { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xcf28e512) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xcf28e512) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetSessionStats { @@ -1739,11 +1607,7 @@ impl crate::BoxedDeserialize for GetStats { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x52d5c311) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x52d5c311) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetStats { @@ -1781,11 +1645,7 @@ impl crate::BoxedDeserialize for GetTime { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe140bed1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe140bed1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetTime { @@ -1830,11 +1690,7 @@ impl crate::BoxedDeserialize for ImportPrivateKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x15807ac7) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x15807ac7) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ImportPrivateKey { @@ -1879,11 +1735,7 @@ impl crate::BoxedDeserialize for SetStatesGcInterval { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe7cef50b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe7cef50b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetStatesGcInterval { @@ -1928,11 +1780,7 @@ impl crate::BoxedDeserialize for SetVerbosity { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb1825e82) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb1825e82) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetVerbosity { @@ -1980,11 +1828,7 @@ impl crate::BoxedDeserialize for Sign { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1aea1a28) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1aea1a28) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Sign { diff --git a/tvm_api/src/ton/rpc/http.rs b/tvm_api/src/ton/rpc/http.rs index ab9964e33..33058be5c 100644 --- a/tvm_api/src/ton/rpc/http.rs +++ b/tvm_api/src/ton/rpc/http.rs @@ -40,11 +40,7 @@ impl crate::BoxedDeserialize for GetNextPayloadPart { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x90745d0c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x90745d0c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetNextPayloadPart { @@ -103,11 +99,7 @@ impl crate::BoxedDeserialize for Request { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x61b191e1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x61b191e1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Request { diff --git a/tvm_api/src/ton/rpc/lite_server.rs b/tvm_api/src/ton/rpc/lite_server.rs index 30f222e9e..f2d559105 100644 --- a/tvm_api/src/ton/rpc/lite_server.rs +++ b/tvm_api/src/ton/rpc/lite_server.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for GetAccountState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6b890e25) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6b890e25) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccountState { @@ -86,11 +82,7 @@ impl crate::BoxedDeserialize for GetAllShardsInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x74d3fd6b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x74d3fd6b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAllShardsInfo { @@ -135,11 +127,7 @@ impl crate::BoxedDeserialize for GetBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6377cf0d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6377cf0d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlock { @@ -187,11 +175,7 @@ impl crate::BoxedDeserialize for GetBlockHeader { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x21ec069e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x21ec069e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlockHeader { @@ -248,11 +232,7 @@ impl crate::BoxedDeserialize for GetBlockProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8aea9c44) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8aea9c44) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBlockProof { @@ -300,11 +280,7 @@ impl crate::BoxedDeserialize for GetConfigAll { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x911b26b7) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x911b26b7) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetConfigAll { @@ -356,11 +332,7 @@ impl crate::BoxedDeserialize for GetConfigParams { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x2a111c19) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x2a111c19) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetConfigParams { @@ -398,11 +370,7 @@ impl crate::BoxedDeserialize for GetInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x558d5bee) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x558d5bee) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetInfo { @@ -440,11 +408,7 @@ impl crate::BoxedDeserialize for GetMasterchainInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x89b5e62e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x89b5e62e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetMasterchainInfo { @@ -489,11 +453,7 @@ impl crate::BoxedDeserialize for GetMasterchainInfoExt { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x70a671df) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x70a671df) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetMasterchainInfoExt { @@ -544,11 +504,7 @@ impl crate::BoxedDeserialize for GetOneTransaction { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd40f24ea) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd40f24ea) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetOneTransaction { @@ -602,11 +558,7 @@ impl crate::BoxedDeserialize for GetShardInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x46a2f425) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x46a2f425) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetShardInfo { @@ -651,11 +603,7 @@ impl crate::BoxedDeserialize for GetState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xba6e2eb6) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xba6e2eb6) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetState { @@ -693,11 +641,7 @@ impl crate::BoxedDeserialize for GetTime { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x16ad5a34) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x16ad5a34) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetTime { @@ -751,11 +695,7 @@ impl crate::BoxedDeserialize for GetTransactions { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1c40e7a1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1c40e7a1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetTransactions { @@ -824,11 +764,7 @@ impl crate::BoxedDeserialize for GetValidatorStats { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x091a58bc) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x091a58bc) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetValidatorStats { @@ -866,11 +802,7 @@ impl crate::BoxedDeserialize for GetVersion { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x232b940b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x232b940b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetVersion { @@ -934,11 +866,7 @@ impl crate::BoxedDeserialize for ListBlockTransactions { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xadfcc7da) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xadfcc7da) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ListBlockTransactions { @@ -1004,11 +932,7 @@ impl crate::BoxedDeserialize for LookupBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xfac8f71e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xfac8f71e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for LookupBlock { @@ -1053,11 +977,7 @@ impl crate::BoxedDeserialize for Query { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x798c06df) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x798c06df) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Query { @@ -1095,11 +1015,7 @@ impl crate::BoxedDeserialize for QueryPrefix { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x72d3e686) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x72d3e686) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for QueryPrefix { @@ -1156,11 +1072,7 @@ impl crate::BoxedDeserialize for RunSmcMethod { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5cc65dd2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5cc65dd2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunSmcMethod { @@ -1205,11 +1117,7 @@ impl crate::BoxedDeserialize for SendMessage { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x690ad482) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x690ad482) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SendMessage { @@ -1257,11 +1165,7 @@ impl crate::BoxedDeserialize for WaitMasterchainSeqno { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xbaeab892) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xbaeab892) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for WaitMasterchainSeqno { diff --git a/tvm_api/src/ton/rpc/mbpp.rs b/tvm_api/src/ton/rpc/mbpp.rs index 49f6ef557..dd2366b36 100644 --- a/tvm_api/src/ton/rpc/mbpp.rs +++ b/tvm_api/src/ton/rpc/mbpp.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for SubmitNewShardBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0e70042c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0e70042c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SubmitNewShardBlock { diff --git a/tvm_api/src/ton/rpc/mod.rs b/tvm_api/src/ton/rpc/mod.rs index 06cdcdeaa..016eb4ddb 100644 --- a/tvm_api/src/ton/rpc/mod.rs +++ b/tvm_api/src/ton/rpc/mod.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for AddLogMessage { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5f36cfec) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5f36cfec) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for AddLogMessage { @@ -89,11 +85,7 @@ impl crate::BoxedDeserialize for ChangeLocalPassword { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe81037bf) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe81037bf) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ChangeLocalPassword { @@ -131,11 +123,7 @@ impl crate::BoxedDeserialize for Close { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb933e17f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb933e17f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Close { @@ -186,11 +174,7 @@ impl crate::BoxedDeserialize for CreateNewKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x910d8210) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x910d8210) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateNewKey { @@ -247,11 +231,7 @@ impl crate::BoxedDeserialize for CreateQuery { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf18b20c5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf18b20c5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateQuery { @@ -299,11 +279,7 @@ impl crate::BoxedDeserialize for Decrypt { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x155685ae) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x155685ae) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Decrypt { @@ -341,11 +317,7 @@ impl crate::BoxedDeserialize for DeleteAllKeys { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5fe3fb23) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5fe3fb23) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DeleteAllKeys { @@ -390,11 +362,7 @@ impl crate::BoxedDeserialize for DeleteKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa1d948cd) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa1d948cd) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DeleteKey { @@ -442,11 +410,7 @@ impl crate::BoxedDeserialize for Encrypt { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x936f4b1c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x936f4b1c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Encrypt { @@ -494,11 +458,7 @@ impl crate::BoxedDeserialize for ExportEncryptedKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0d02097f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0d02097f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportEncryptedKey { @@ -543,11 +503,7 @@ impl crate::BoxedDeserialize for ExportKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x9f4cd973) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x9f4cd973) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportKey { @@ -595,11 +551,7 @@ impl crate::BoxedDeserialize for ExportPemKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd9a8a3ba) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd9a8a3ba) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportPemKey { @@ -644,11 +596,7 @@ impl crate::BoxedDeserialize for ExportUnencryptedKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xda2bc740) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xda2bc740) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ExportUnencryptedKey { @@ -699,11 +647,7 @@ impl crate::BoxedDeserialize for GetAccountAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1e8ba5c8) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1e8ba5c8) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccountAddress { @@ -748,11 +692,7 @@ impl crate::BoxedDeserialize for GetAccountState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x81daf446) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x81daf446) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccountState { @@ -797,11 +737,7 @@ impl crate::BoxedDeserialize for GetBip39Hints { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8f5e5dea) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8f5e5dea) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBip39Hints { @@ -839,11 +775,7 @@ impl crate::BoxedDeserialize for GetLogStream { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x45984b5b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x45984b5b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetLogStream { @@ -888,11 +820,7 @@ impl crate::BoxedDeserialize for GetLogTagVerbosityLevel { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x38af2d83) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x38af2d83) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetLogTagVerbosityLevel { @@ -930,11 +858,7 @@ impl crate::BoxedDeserialize for GetLogTags { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf0d569da) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf0d569da) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetLogTags { @@ -972,11 +896,7 @@ impl crate::BoxedDeserialize for GetLogVerbosityLevel { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x23689ae4) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x23689ae4) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetLogVerbosityLevel { @@ -1024,11 +944,7 @@ impl crate::BoxedDeserialize for GuessAccount { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x986d6c60) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x986d6c60) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GuessAccount { @@ -1076,11 +992,7 @@ impl crate::BoxedDeserialize for GuessAccountRevision { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6eb892a2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6eb892a2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GuessAccountRevision { @@ -1134,11 +1046,7 @@ impl crate::BoxedDeserialize for ImportEncryptedKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x2724d3de) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x2724d3de) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ImportEncryptedKey { @@ -1189,11 +1097,7 @@ impl crate::BoxedDeserialize for ImportKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa0296119) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa0296119) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ImportKey { @@ -1244,11 +1148,7 @@ impl crate::BoxedDeserialize for ImportPemKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x048d8d51) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x048d8d51) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ImportPemKey { @@ -1299,11 +1199,7 @@ impl crate::BoxedDeserialize for ImportUnencryptedKey { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb9635915) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb9635915) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ImportUnencryptedKey { @@ -1348,11 +1244,7 @@ impl crate::BoxedDeserialize for Init { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xc45c22b6) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xc45c22b6) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Init { @@ -1403,11 +1295,7 @@ impl crate::BoxedDeserialize for Kdf { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x9c96737d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x9c96737d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Kdf { @@ -1455,11 +1343,7 @@ impl crate::BoxedDeserialize for OnLiteServerQueryError { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd79f46b3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd79f46b3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for OnLiteServerQueryError { @@ -1507,11 +1391,7 @@ impl crate::BoxedDeserialize for OnLiteServerQueryResult { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7a92da5e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7a92da5e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for OnLiteServerQueryResult { @@ -1559,11 +1439,7 @@ impl crate::BoxedDeserialize for PackAccountAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xad3c39ec) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xad3c39ec) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PackAccountAddress { @@ -1608,11 +1484,7 @@ impl crate::BoxedDeserialize for RunTests { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8669354d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8669354d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunTests { @@ -1657,11 +1529,7 @@ impl crate::BoxedDeserialize for SetLogStream { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xaeaff791) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xaeaff791) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetLogStream { @@ -1709,11 +1577,7 @@ impl crate::BoxedDeserialize for SetLogTagVerbosityLevel { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8317d696) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8317d696) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetLogTagVerbosityLevel { @@ -1758,11 +1622,7 @@ impl crate::BoxedDeserialize for SetLogVerbosityLevel { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xedea07d2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xedea07d2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetLogVerbosityLevel { @@ -1800,11 +1660,7 @@ impl crate::BoxedDeserialize for Sync { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf89f182b) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf89f182b) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Sync { @@ -1849,11 +1705,7 @@ impl crate::BoxedDeserialize for UnpackAccountAddress { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd7528049) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd7528049) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for UnpackAccountAddress { diff --git a/tvm_api/src/ton/rpc/msg.rs b/tvm_api/src/ton/rpc/msg.rs index 1230bca07..721d9dc54 100644 --- a/tvm_api/src/ton/rpc/msg.rs +++ b/tvm_api/src/ton/rpc/msg.rs @@ -38,11 +38,7 @@ impl crate::BoxedDeserialize for Decrypt { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0d53cf09) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0d53cf09) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Decrypt { @@ -90,11 +86,7 @@ impl crate::BoxedDeserialize for DecryptWithProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8222c881) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8222c881) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DecryptWithProof { diff --git a/tvm_api/src/ton/rpc/options.rs b/tvm_api/src/ton/rpc/options.rs index bbb70399e..40a82bb75 100644 --- a/tvm_api/src/ton/rpc/options.rs +++ b/tvm_api/src/ton/rpc/options.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for SetConfig { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6f76ebc3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6f76ebc3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SetConfig { @@ -83,11 +79,7 @@ impl crate::BoxedDeserialize for ValidateConfig { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xeb51ba39) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xeb51ba39) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ValidateConfig { diff --git a/tvm_api/src/ton/rpc/overlay.rs b/tvm_api/src/ton/rpc/overlay.rs index 5f7b44626..a0d698870 100644 --- a/tvm_api/src/ton/rpc/overlay.rs +++ b/tvm_api/src/ton/rpc/overlay.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for GetBroadcast { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x2d35f2a0) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x2d35f2a0) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBroadcast { @@ -83,11 +79,7 @@ impl crate::BoxedDeserialize for GetBroadcastList { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x421c283a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x421c283a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetBroadcastList { @@ -132,11 +124,7 @@ impl crate::BoxedDeserialize for GetRandomPeers { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x48ee64ab) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x48ee64ab) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetRandomPeers { @@ -181,11 +169,7 @@ impl crate::BoxedDeserialize for Query { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xccfd8443) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xccfd8443) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Query { diff --git a/tvm_api/src/ton/rpc/pchan.rs b/tvm_api/src/ton/rpc/pchan.rs index 67a0e432c..da3c27569 100644 --- a/tvm_api/src/ton/rpc/pchan.rs +++ b/tvm_api/src/ton/rpc/pchan.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for PackPromise { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xcd3c0ac1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xcd3c0ac1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PackPromise { @@ -86,11 +82,7 @@ impl crate::BoxedDeserialize for SignPromise { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6c245f1e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6c245f1e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SignPromise { @@ -135,11 +127,7 @@ impl crate::BoxedDeserialize for UnpackPromise { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb57ce4d3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb57ce4d3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for UnpackPromise { @@ -187,11 +175,7 @@ impl crate::BoxedDeserialize for ValidatePromise { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0f64c4e2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0f64c4e2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for ValidatePromise { diff --git a/tvm_api/src/ton/rpc/query.rs b/tvm_api/src/ton/rpc/query.rs index 22a68ff41..34bd6ccc3 100644 --- a/tvm_api/src/ton/rpc/query.rs +++ b/tvm_api/src/ton/rpc/query.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for EstimateFees { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xc6f54e41) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xc6f54e41) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for EstimateFees { @@ -86,11 +82,7 @@ impl crate::BoxedDeserialize for Forget { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb7c2925f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb7c2925f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Forget { @@ -135,11 +127,7 @@ impl crate::BoxedDeserialize for GetInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd05b22db) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd05b22db) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetInfo { @@ -184,11 +172,7 @@ impl crate::BoxedDeserialize for Send { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x37261573) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x37261573) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Send { diff --git a/tvm_api/src/ton/rpc/raw.rs b/tvm_api/src/ton/rpc/raw.rs index 9323ed5f9..9ee9bacff 100644 --- a/tvm_api/src/ton/rpc/raw.rs +++ b/tvm_api/src/ton/rpc/raw.rs @@ -40,11 +40,7 @@ impl crate::BoxedDeserialize for CreateAndSendMessage { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xd1f8c9a5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xd1f8c9a5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateAndSendMessage { @@ -98,11 +94,7 @@ impl crate::BoxedDeserialize for CreateQuery { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8d0c8aab) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8d0c8aab) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for CreateQuery { @@ -150,11 +142,7 @@ impl crate::BoxedDeserialize for GetAccount { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x165742b9) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x165742b9) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccount { @@ -202,11 +190,7 @@ impl crate::BoxedDeserialize for GetAccountByBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x290e6f24) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x290e6f24) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccountByBlock { @@ -254,11 +238,7 @@ impl crate::BoxedDeserialize for GetAccountMetaByBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xfe31dae0) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xfe31dae0) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAccountMetaByBlock { @@ -296,11 +276,7 @@ impl crate::BoxedDeserialize for GetAppliedShardsInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xfc01cdbb) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xfc01cdbb) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetAppliedShardsInfo { @@ -345,11 +321,7 @@ impl crate::BoxedDeserialize for GetShardAccountMeta { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5ae44062) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5ae44062) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetShardAccountMeta { @@ -394,11 +366,7 @@ impl crate::BoxedDeserialize for GetShardAccountState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x34adc00a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x34adc00a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetShardAccountState { @@ -450,11 +418,7 @@ impl crate::BoxedDeserialize for GetTransactions { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x3d5ea31d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x3d5ea31d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetTransactions { @@ -499,11 +463,7 @@ impl crate::BoxedDeserialize for SendMessage { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x955780e0) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x955780e0) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SendMessage { diff --git a/tvm_api/src/ton/rpc/smc.rs b/tvm_api/src/ton/rpc/smc.rs index 1a69cad68..fb4d9efdb 100644 --- a/tvm_api/src/ton/rpc/smc.rs +++ b/tvm_api/src/ton/rpc/smc.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for GetCode { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x81e61b98) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x81e61b98) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetCode { @@ -83,11 +79,7 @@ impl crate::BoxedDeserialize for GetData { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe6835349) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe6835349) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetData { @@ -132,11 +124,7 @@ impl crate::BoxedDeserialize for GetState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf338a9eb) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf338a9eb) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetState { @@ -181,11 +169,7 @@ impl crate::BoxedDeserialize for Load { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xca25d03f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xca25d03f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Load { @@ -240,11 +224,7 @@ impl crate::BoxedDeserialize for RunGetMethod { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf0c905aa) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf0c905aa) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunGetMethod { @@ -299,11 +279,7 @@ impl crate::BoxedDeserialize for RunTvm { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa83be941) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa83be941) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunTvm { @@ -361,11 +337,7 @@ impl crate::BoxedDeserialize for RunTvmByBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x607c4db1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x607c4db1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunTvmByBlock { @@ -413,11 +385,7 @@ impl crate::BoxedDeserialize for RunTvmMsg { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xef831db1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xef831db1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunTvmMsg { @@ -468,11 +436,7 @@ impl crate::BoxedDeserialize for RunTvmMsgByBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x03758f4e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x03758f4e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for RunTvmMsgByBlock { diff --git a/tvm_api/src/ton/rpc/tcp.rs b/tvm_api/src/ton/rpc/tcp.rs index 18b421316..1d04775fd 100644 --- a/tvm_api/src/ton/rpc/tcp.rs +++ b/tvm_api/src/ton/rpc/tcp.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for Ping { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x4d082b9a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x4d082b9a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Ping { diff --git a/tvm_api/src/ton/rpc/ton_node/mod.rs b/tvm_api/src/ton/rpc/ton_node/mod.rs index 6f8bbc000..8e3019916 100644 --- a/tvm_api/src/ton/rpc/ton_node/mod.rs +++ b/tvm_api/src/ton/rpc/ton_node/mod.rs @@ -34,11 +34,7 @@ impl crate::BoxedDeserialize for DownloadBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe27279c3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe27279c3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlock { @@ -83,11 +79,7 @@ impl crate::BoxedDeserialize for DownloadBlockFull { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6a27c49d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6a27c49d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlockFull { @@ -132,11 +124,7 @@ impl crate::BoxedDeserialize for DownloadBlockProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x4bd6478a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x4bd6478a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlockProof { @@ -181,11 +169,7 @@ impl crate::BoxedDeserialize for DownloadBlockProofLink { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x25b300c6) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x25b300c6) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlockProofLink { @@ -233,11 +217,7 @@ impl crate::BoxedDeserialize for DownloadBlockProofLinks { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x28d12b63) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x28d12b63) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlockProofLinks { @@ -285,11 +265,7 @@ impl crate::BoxedDeserialize for DownloadBlockProofs { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xa5b053f5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xa5b053f5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlockProofs { @@ -337,11 +313,7 @@ impl crate::BoxedDeserialize for DownloadBlocks { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7659c57d) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7659c57d) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadBlocks { @@ -386,11 +358,7 @@ impl crate::BoxedDeserialize for DownloadKeyBlockProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xec23483a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xec23483a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadKeyBlockProof { @@ -435,11 +403,7 @@ impl crate::BoxedDeserialize for DownloadKeyBlockProofLink { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x12e42ad2) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x12e42ad2) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadKeyBlockProofLink { @@ -487,11 +451,7 @@ impl crate::BoxedDeserialize for DownloadKeyBlockProofLinks { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x75c38550) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x75c38550) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadKeyBlockProofLinks { @@ -539,11 +499,7 @@ impl crate::BoxedDeserialize for DownloadKeyBlockProofs { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xc327de3a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xc327de3a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadKeyBlockProofs { @@ -588,11 +544,7 @@ impl crate::BoxedDeserialize for DownloadNextBlockFull { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6ea0374a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6ea0374a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadNextBlockFull { @@ -656,11 +608,7 @@ impl crate::BoxedDeserialize for DownloadPersistentMsgQueueSlice { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x32fb50b1) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x32fb50b1) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadPersistentMsgQueueSlice { @@ -709,11 +657,7 @@ impl crate::BoxedDeserialize for DownloadPersistentState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7f99e3b8) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7f99e3b8) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadPersistentState { @@ -768,11 +712,7 @@ impl crate::BoxedDeserialize for DownloadPersistentStateSlice { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf5e9e6e3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf5e9e6e3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadPersistentStateSlice { @@ -820,11 +760,7 @@ impl crate::BoxedDeserialize for DownloadQueueUpdate { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xb67c0e6c) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xb67c0e6c) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadQueueUpdate { @@ -869,11 +805,7 @@ impl crate::BoxedDeserialize for DownloadZeroState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xadcc1e5a) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xadcc1e5a) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadZeroState { @@ -918,11 +850,7 @@ impl crate::BoxedDeserialize for GetArchiveInfo { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x7b2dd941) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x7b2dd941) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetArchiveInfo { @@ -973,11 +901,7 @@ impl crate::BoxedDeserialize for GetArchiveSlice { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x203b5168) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x203b5168) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetArchiveSlice { @@ -1015,11 +939,7 @@ impl crate::BoxedDeserialize for GetCapabilities { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xdee618f8) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xdee618f8) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetCapabilities { @@ -1064,11 +984,7 @@ impl crate::BoxedDeserialize for GetNextBlockDescription { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x1455b0f3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x1455b0f3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetNextBlockDescription { @@ -1116,11 +1032,7 @@ impl crate::BoxedDeserialize for GetNextBlocksDescription { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x3f2812c4) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x3f2812c4) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetNextBlocksDescription { @@ -1168,11 +1080,7 @@ impl crate::BoxedDeserialize for GetNextKeyBlockIds { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf2e7cfbb) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf2e7cfbb) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetNextKeyBlockIds { @@ -1223,11 +1131,7 @@ impl crate::BoxedDeserialize for GetPrevBlocksDescription { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x5c6d6cc9) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x5c6d6cc9) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for GetPrevBlocksDescription { @@ -1272,11 +1176,7 @@ impl crate::BoxedDeserialize for PrepareBlock { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x75a37f4e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x75a37f4e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareBlock { @@ -1324,11 +1224,7 @@ impl crate::BoxedDeserialize for PrepareBlockProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x875c3308) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x875c3308) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareBlockProof { @@ -1379,11 +1275,7 @@ impl crate::BoxedDeserialize for PrepareBlockProofs { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xed79b2b8) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xed79b2b8) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareBlockProofs { @@ -1431,11 +1323,7 @@ impl crate::BoxedDeserialize for PrepareBlocks { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x6affabfc) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x6affabfc) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareBlocks { @@ -1483,11 +1371,7 @@ impl crate::BoxedDeserialize for PrepareKeyBlockProof { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x77364c38) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x77364c38) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareKeyBlockProof { @@ -1538,11 +1422,7 @@ impl crate::BoxedDeserialize for PrepareKeyBlockProofs { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x8c6cfbe4) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x8c6cfbe4) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareKeyBlockProofs { @@ -1594,11 +1474,7 @@ impl crate::BoxedDeserialize for PreparePersistentMsgQueue { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xf4ea081f) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xf4ea081f) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PreparePersistentMsgQueue { @@ -1647,11 +1523,7 @@ impl crate::BoxedDeserialize for PreparePersistentState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xfeea269e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xfeea269e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PreparePersistentState { @@ -1699,11 +1571,7 @@ impl crate::BoxedDeserialize for PrepareQueueUpdate { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x2032ce4e) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x2032ce4e) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareQueueUpdate { @@ -1748,11 +1616,7 @@ impl crate::BoxedDeserialize for PrepareZeroState { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x41ce0825) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x41ce0825) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for PrepareZeroState { @@ -1790,11 +1654,7 @@ impl crate::BoxedDeserialize for Query { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x69f324d3) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x69f324d3) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Query { diff --git a/tvm_api/src/ton/rpc/ton_node/slave.rs b/tvm_api/src/ton/rpc/ton_node/slave.rs index 2c58b535b..91cd20a40 100644 --- a/tvm_api/src/ton/rpc/ton_node/slave.rs +++ b/tvm_api/src/ton/rpc/ton_node/slave.rs @@ -35,11 +35,7 @@ impl crate::BoxedDeserialize for SendExtMessage { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x0376f2a9) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x0376f2a9) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for SendExtMessage { diff --git a/tvm_api/src/ton/rpc/validator_session.rs b/tvm_api/src/ton/rpc/validator_session.rs index 0e0a0165e..1de6646d2 100644 --- a/tvm_api/src/ton/rpc/validator_session.rs +++ b/tvm_api/src/ton/rpc/validator_session.rs @@ -37,11 +37,7 @@ impl crate::BoxedDeserialize for DownloadCandidate { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0xe0fd3df5) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0xe0fd3df5) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for DownloadCandidate { @@ -86,11 +82,7 @@ impl crate::BoxedDeserialize for Ping { id: crate::ConstructorNumber, de: &mut crate::Deserializer, ) -> crate::Result { - if id == crate::ConstructorNumber(0x680449ad) { - de.read_bare() - } else { - _invalid_id!(id) - } + if id == crate::ConstructorNumber(0x680449ad) { de.read_bare() } else { _invalid_id!(id) } } } impl crate::BoxedSerialize for Ping { diff --git a/tvm_api/src/ton_prelude.rs b/tvm_api/src/ton_prelude.rs index f2160c8a8..6e3fbe17e 100644 --- a/tvm_api/src/ton_prelude.rs +++ b/tvm_api/src/ton_prelude.rs @@ -28,7 +28,6 @@ use serde_derive::Deserialize; use serde_derive::Serialize; use tvm_types::error; -use crate::ton::Bool; use crate::AnyBoxedSerialize; use crate::BareDeserialize; use crate::BareSerialize; @@ -38,6 +37,7 @@ use crate::ConstructorNumber; use crate::Deserializer; use crate::Result; use crate::Serializer; +use crate::ton::Bool; const MAX_BYTES_DEBUG_LEN: usize = 4; @@ -296,11 +296,7 @@ impl BareSerialize for () { impl From for &'static Bool { fn from(b: bool) -> Self { - if b { - &Bool::BoolTrue - } else { - &Bool::BoolFalse - } + if b { &Bool::BoolTrue } else { &Bool::BoolFalse } } } diff --git a/tvm_assembler/rustfmt.toml b/tvm_assembler/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_assembler/rustfmt.toml +++ b/tvm_assembler/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_assembler/src/bin/disasm.rs b/tvm_assembler/src/bin/disasm.rs index 71e41800b..763503d56 100644 --- a/tvm_assembler/src/bin/disasm.rs +++ b/tvm_assembler/src/bin/disasm.rs @@ -18,11 +18,11 @@ use clap::Subcommand; use tvm_assembler::disasm::disasm_ex; use tvm_assembler::disasm::fmt::print_tree_of_cells; use tvm_assembler::disasm::loader::Loader; -use tvm_types::read_boc; -use tvm_types::write_boc; use tvm_types::Cell; use tvm_types::SliceData; use tvm_types::Status; +use tvm_types::read_boc; +use tvm_types::write_boc; #[derive(Parser)] #[command(author, version, about, long_about = None)] diff --git a/tvm_assembler/src/complex.rs b/tvm_assembler/src/complex.rs index f4bbbe390..5ec4e643e 100644 --- a/tvm_assembler/src/complex.rs +++ b/tvm_assembler/src/complex.rs @@ -24,19 +24,19 @@ use tvm_types::HashmapType; use tvm_types::SliceData; use tvm_types::Status; -use super::convert::to_big_endian_octet_string; -use super::errors::OperationError; -use super::errors::ParameterError; -use super::errors::ToOperationParameterError; -use super::parse::*; use super::CompileResult; use super::Engine; use super::EnsureParametersCountInRange; use super::Unit; use super::Units; +use super::convert::to_big_endian_octet_string; +use super::errors::OperationError; +use super::errors::ParameterError; +use super::errors::ToOperationParameterError; +use super::parse::*; +use crate::DbgInfo; use crate::debug::DbgNode; use crate::debug::DbgPos; -use crate::DbgInfo; trait CommandBehaviourModifier { fn modify(code: Vec) -> Vec; diff --git a/tvm_assembler/src/convert.rs b/tvm_assembler/src/convert.rs index bd23f928f..da3f1e217 100644 --- a/tvm_assembler/src/convert.rs +++ b/tvm_assembler/src/convert.rs @@ -9,8 +9,8 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use num::bigint::Sign; use num::BigInt; +use num::bigint::Sign; #[inline] fn bits_to_bytes(length_in_bits: usize) -> usize { diff --git a/tvm_assembler/src/debug.rs b/tvm_assembler/src/debug.rs index 2b588bb1d..07b04febe 100644 --- a/tvm_assembler/src/debug.rs +++ b/tvm_assembler/src/debug.rs @@ -11,12 +11,12 @@ use std::collections::BTreeMap; +use serde::Deserialize; +use serde::Serialize; use serde::de::Error; use serde::de::MapAccess; use serde::de::Visitor; use serde::ser::SerializeMap; -use serde::Deserialize; -use serde::Serialize; use tvm_types::Cell; use tvm_types::UInt256; diff --git a/tvm_assembler/src/disasm/codedict.rs b/tvm_assembler/src/disasm/codedict.rs index 9878250ac..e2e9dbd07 100644 --- a/tvm_assembler/src/disasm/codedict.rs +++ b/tvm_assembler/src/disasm/codedict.rs @@ -11,12 +11,12 @@ use std::collections::HashMap; -use tvm_types::fail; use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::fail; use super::loader::Loader; use super::types::Code; diff --git a/tvm_assembler/src/disasm/loader.rs b/tvm_assembler/src/disasm/loader.rs index 68625a94d..aae04599c 100644 --- a/tvm_assembler/src/disasm/loader.rs +++ b/tvm_assembler/src/disasm/loader.rs @@ -3,11 +3,11 @@ use std::collections::HashMap; use std::ops::Not; use num_traits::Zero; -use tvm_types::fail; use tvm_types::Cell; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::fail; use super::handlers::Handlers; use super::types::Code; diff --git a/tvm_assembler/src/disasm/types.rs b/tvm_assembler/src/disasm/types.rs index 9c8d730d4..f5e224216 100644 --- a/tvm_assembler/src/disasm/types.rs +++ b/tvm_assembler/src/disasm/types.rs @@ -12,7 +12,7 @@ use std::collections::HashMap; use std::slice::ChunksMut; -use tvm_types::{fail, Cell, Result, /* Bitmask, */ SliceData}; +use tvm_types::{Cell, Result, /* Bitmask, */ SliceData, fail}; #[derive(Debug, Default, Clone)] pub struct Code { diff --git a/tvm_assembler/src/parse.rs b/tvm_assembler/src/parse.rs index acd663267..3a80c03ec 100644 --- a/tvm_assembler/src/parse.rs +++ b/tvm_assembler/src/parse.rs @@ -221,11 +221,7 @@ pub(super) fn parse_stack_register_u4_minus_two(par: &str) -> Result Result { (parse_range(32u16..=256))(par).and_then(|c| { - if c % 32 == 0 { - Ok(((c / 32) - 1) as u8) - } else { - Err(ParameterError::OutOfRange) - } + if c % 32 == 0 { Ok(((c / 32) - 1) as u8) } else { Err(ParameterError::OutOfRange) } }) } diff --git a/tvm_assembler/src/simple.rs b/tvm_assembler/src/simple.rs index 2aae0a29b..f9ce18079 100644 --- a/tvm_assembler/src/simple.rs +++ b/tvm_assembler/src/simple.rs @@ -9,13 +9,13 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use super::errors::ToOperationParameterError; -use super::parse::*; use super::CompileHandler; use super::CompileResult; use super::Engine; use super::EnsureParametersCountInRange; use super::Units; +use super::errors::ToOperationParameterError; +use super::parse::*; use crate::debug::DbgNode; use crate::debug::DbgPos; use crate::simple_commands; diff --git a/tvm_assembler/src/writer.rs b/tvm_assembler/src/writer.rs index 901501c37..4cb1f313c 100644 --- a/tvm_assembler/src/writer.rs +++ b/tvm_assembler/src/writer.rs @@ -12,10 +12,10 @@ use tvm_types::BuilderData; use tvm_types::SliceData; -use crate::debug::DbgNode; use crate::CompileResult; use crate::DbgInfo; use crate::OperationError; +use crate::debug::DbgNode; #[derive(Clone, Default)] pub struct Unit { diff --git a/tvm_block/rustfmt.toml b/tvm_block/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_block/rustfmt.toml +++ b/tvm_block/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_block/src/accounts.rs b/tvm_block/src/accounts.rs index 2fe5c3359..acda3a94c 100644 --- a/tvm_block/src/accounts.rs +++ b/tvm_block/src/accounts.rs @@ -12,8 +12,6 @@ use std::collections::HashSet; use std::fmt; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -23,7 +21,15 @@ use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; use tvm_types::UsageTree; +use tvm_types::error; +use tvm_types::fail; +use crate::ConfigParams; +use crate::Deserializable; +use crate::GetRepresentationHash; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::Serializable; use crate::error::BlockError; use crate::hashmapaug::Augmentation; use crate::hashmapaug::HashmapAugType; @@ -44,12 +50,6 @@ use crate::types::CurrencyCollection; use crate::types::Grams; use crate::types::Number5; use crate::types::VarUInteger7; -use crate::ConfigParams; -use crate::Deserializable; -use crate::GetRepresentationHash; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_accounts.rs"] diff --git a/tvm_block/src/bintree.rs b/tvm_block/src/bintree.rs index 6308be52c..a7c69e931 100644 --- a/tvm_block/src/bintree.rs +++ b/tvm_block/src/bintree.rs @@ -10,18 +10,18 @@ use std::marker::PhantomData; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; -use crate::error::BlockError; -use crate::hashmapaug::Augmentable; use crate::Deserializable; use crate::Serializable; +use crate::error::BlockError; +use crate::hashmapaug::Augmentable; #[cfg(test)] #[path = "tests/test_bintree.rs"] @@ -42,11 +42,7 @@ pub trait BinTreeType { _ => return Ok(None), } } - if key.is_empty() { - Ok(Some(X::construct_from(&mut cursor)?)) - } else { - Ok(None) - } + if key.is_empty() { Ok(Some(X::construct_from(&mut cursor)?)) } else { Ok(None) } } fn find(&self, mut key: SliceData) -> Result> { diff --git a/tvm_block/src/blocks.rs b/tvm_block/src/blocks.rs index ed8dcf5b2..6721db1fe 100644 --- a/tvm_block/src/blocks.rs +++ b/tvm_block/src/blocks.rs @@ -18,8 +18,6 @@ use std::io::Cursor; use std::io::Write; use std::str::FromStr; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -30,7 +28,14 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::RefShardBlocks; +use crate::Serializable; use crate::config_params::CatchainConfig; use crate::config_params::GlobalVersion; use crate::define_HashmapE; @@ -50,11 +55,6 @@ use crate::types::Grams; use crate::types::InRefValue; use crate::types::UnixTime32; use crate::validators::ValidatorSet; -use crate::Deserializable; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::RefShardBlocks; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_blocks.rs"] diff --git a/tvm_block/src/config_params.rs b/tvm_block/src/config_params.rs index 6f9c2d1db..2392e6cb1 100644 --- a/tvm_block/src/config_params.rs +++ b/tvm_block/src/config_params.rs @@ -9,8 +9,6 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; @@ -20,7 +18,11 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::Serializable; use crate::define_HashmapE; use crate::error::BlockError; use crate::hashmapaug::HashmapAugType; @@ -31,15 +33,13 @@ use crate::signature::SigPubKey; use crate::types::ChildCell; use crate::types::ExtraCurrencyCollection; use crate::types::Grams; +use crate::types::Number8; use crate::types::Number12; use crate::types::Number13; use crate::types::Number16; use crate::types::Number32; -use crate::types::Number8; use crate::validators::ValidatorDescr; use crate::validators::ValidatorSet; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_config_params.rs"] @@ -3112,17 +3112,9 @@ impl ParamLimits { pub fn classify(&self, value: u32) -> ParamLimitIndex { if value >= self.medium() { - if value >= self.hard_limit() { - ParamLimitIndex::Hard - } else { - ParamLimitIndex::Medium - } + if value >= self.hard_limit() { ParamLimitIndex::Hard } else { ParamLimitIndex::Medium } } else if value >= self.underload() { - if value >= self.soft_limit() { - ParamLimitIndex::Soft - } else { - ParamLimitIndex::Normal - } + if value >= self.soft_limit() { ParamLimitIndex::Soft } else { ParamLimitIndex::Normal } } else { ParamLimitIndex::Underload } diff --git a/tvm_block/src/envelope_message.rs b/tvm_block/src/envelope_message.rs index d4b72e017..aa15b7f80 100644 --- a/tvm_block/src/envelope_message.rs +++ b/tvm_block/src/envelope_message.rs @@ -11,15 +11,17 @@ use std::cmp::Ordering; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::Serializable; use crate::error::BlockError; use crate::messages::Message; use crate::shard::AccountIdPrefixFull; @@ -27,8 +29,6 @@ use crate::shard::ShardIdent; use crate::types::AddSub; use crate::types::ChildCell; use crate::types::Grams; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_envelope_message.rs"] diff --git a/tvm_block/src/hashmapaug.rs b/tvm_block/src/hashmapaug.rs index a1cbf5a13..6f0f13ae6 100644 --- a/tvm_block/src/hashmapaug.rs +++ b/tvm_block/src/hashmapaug.rs @@ -11,8 +11,6 @@ use std::cmp::Ordering; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::ExceptionCode; @@ -23,10 +21,12 @@ use tvm_types::IBitstring; use tvm_types::Leaf; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; -use crate::error::BlockError; use crate::Deserializable; use crate::Serializable; +use crate::error::BlockError; /// trait for types used as Augment to calc aug on forks pub trait Augmentable: Clone + Default + Serializable + Deserializable { diff --git a/tvm_block/src/inbound_messages.rs b/tvm_block/src/inbound_messages.rs index bac50b6ca..88e2422eb 100644 --- a/tvm_block/src/inbound_messages.rs +++ b/tvm_block/src/inbound_messages.rs @@ -16,9 +16,6 @@ use std::fmt; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::hm_label; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapType; @@ -26,7 +23,12 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::hm_label; +use crate::Deserializable; +use crate::Serializable; use crate::define_HashmapAugE; use crate::envelope_message::MsgEnvelope; use crate::error::BlockError; @@ -39,8 +41,6 @@ use crate::types::AddSub; use crate::types::ChildCell; use crate::types::CurrencyCollection; use crate::types::Grams; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_in_msgs.rs"] diff --git a/tvm_block/src/lib.rs b/tvm_block/src/lib.rs index 4ecc95d7e..327ec22c2 100644 --- a/tvm_block/src/lib.rs +++ b/tvm_block/src/lib.rs @@ -76,11 +76,6 @@ use std::collections::HashMap; use std::hash::Hash; use base64::Engine; -use tvm_types::base64_decode; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::read_single_root_boc; -use tvm_types::write_boc; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -90,6 +85,11 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::base64_decode; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::read_single_root_boc; +use tvm_types::write_boc; pub use self::config_params::*; diff --git a/tvm_block/src/master.rs b/tvm_block/src/master.rs index eb9440783..e87ef88d5 100644 --- a/tvm_block/src/master.rs +++ b/tvm_block/src/master.rs @@ -12,9 +12,6 @@ use std::collections::HashMap; use std::fmt; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::hm_label; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -24,7 +21,17 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::hm_label; +use crate::Augmentation; +use crate::CopyleftRewards; +use crate::Deserializable; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::Serializable; +use crate::U15; use crate::bintree::BinTree; use crate::bintree::BinTreeType; use crate::blocks::Block; @@ -40,20 +47,13 @@ use crate::hashmapaug::HashmapAugType; use crate::hashmapaug::TraverseNextStep; use crate::inbound_messages::InMsg; use crate::shard::AccountIdPrefixFull; -use crate::shard::ShardIdent; use crate::shard::SHARD_FULL; +use crate::shard::ShardIdent; use crate::signature::CryptoSignaturePair; use crate::types::ChildCell; use crate::types::CurrencyCollection; use crate::types::InRefValue; use crate::validators::ValidatorInfo; -use crate::Augmentation; -use crate::CopyleftRewards; -use crate::Deserializable; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::Serializable; -use crate::U15; #[cfg(test)] #[path = "tests/test_master.rs"] @@ -787,15 +787,15 @@ impl OldMcBlocksInfo { std::cmp::Ordering::Less => { // (x << d) > req_seqno <=> x > (req_seqno >> d) = (y >> 1) <=> 2 * x > y Ok(TraverseNextStep::Stop) // all nodes in subtree have - // block.seqno > req_seqno => - // skip + // block.seqno > req_seqno => + // skip } std::cmp::Ordering::Equal => { Ok(TraverseNextStep::VisitZero) // visit only left ("0") } _ => { Ok(TraverseNextStep::VisitOneZero) // visit right, then left - // ("1" then "0") + // ("1" then "0") } } })?; @@ -838,15 +838,15 @@ impl OldMcBlocksInfo { // ((x + 1) << d) <= req_seqno <=> (x+1) <= (req_seqno >> d) = (y >> 1) <=> // 2*x+2 <= y <=> y > 2*x+1 Ok(TraverseNextStep::Stop) // all nodes in subtree have - // block.seqno < req_seqno => - // skip + // block.seqno < req_seqno => + // skip } std::cmp::Ordering::Equal => { Ok(TraverseNextStep::VisitOne) // visit only right ("1") } _ => { Ok(TraverseNextStep::VisitZeroOne) // visit left, then right - // ("0" then "1") + // ("0" then "1") } } })?; diff --git a/tvm_block/src/merkle_proof.rs b/tvm_block/src/merkle_proof.rs index 74518210f..6adce348f 100644 --- a/tvm_block/src/merkle_proof.rs +++ b/tvm_block/src/merkle_proof.rs @@ -13,9 +13,6 @@ use std::cmp::max; use std::collections::HashMap; use std::collections::HashSet; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::types::UInt256; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::CellType; @@ -23,7 +20,13 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UsageTree; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::types::UInt256; +use crate::Deserializable; +use crate::GetRepresentationHash; +use crate::Serializable; use crate::accounts::Account; use crate::blocks::Block; use crate::blocks::BlockInfo; @@ -34,9 +37,6 @@ use crate::merkle_update::MerkleUpdate; use crate::messages::Message; use crate::shard::ShardStateUnsplit; use crate::transactions::Transaction; -use crate::Deserializable; -use crate::GetRepresentationHash; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_merkle_proof.rs"] diff --git a/tvm_block/src/merkle_update.rs b/tvm_block/src/merkle_update.rs index 471605f1b..a1cb7dee6 100644 --- a/tvm_block/src/merkle_update.rs +++ b/tvm_block/src/merkle_update.rs @@ -13,8 +13,6 @@ use std::collections::HashMap; use std::collections::HashSet; use std::time::Duration; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::CellType; @@ -23,11 +21,13 @@ use tvm_types::LevelMask; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; -use crate::error::BlockError; use crate::Deserializable; use crate::MerkleProof; use crate::Serializable; +use crate::error::BlockError; #[cfg(test)] #[path = "tests/test_merkle_update.rs"] diff --git a/tvm_block/src/messages.rs b/tvm_block/src/messages.rs index aea61094b..5238f7739 100644 --- a/tvm_block/src/messages.rs +++ b/tvm_block/src/messages.rs @@ -12,21 +12,26 @@ use std::fmt; use std::str::FromStr; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::HashmapType; use tvm_types::IBitstring; +use tvm_types::MAX_DATA_BITS; +use tvm_types::MAX_REFERENCES_COUNT; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; use tvm_types::UsageTree; -use tvm_types::MAX_DATA_BITS; -use tvm_types::MAX_REFERENCES_COUNT; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::GetRepresentationHash; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::Serializable; use crate::blocks::Block; use crate::define_HashmapE; use crate::error::BlockError; @@ -39,11 +44,6 @@ use crate::types::Grams; use crate::types::Number5; use crate::types::Number9; use crate::types::UnixTime32; -use crate::Deserializable; -use crate::GetRepresentationHash; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_messages.rs"] diff --git a/tvm_block/src/miscellaneous.rs b/tvm_block/src/miscellaneous.rs index dd76e2662..1bb0f8f80 100644 --- a/tvm_block/src/miscellaneous.rs +++ b/tvm_block/src/miscellaneous.rs @@ -9,7 +9,6 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; @@ -18,10 +17,11 @@ use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::fail; -use crate::define_HashmapE; use crate::Deserializable; use crate::Serializable; +use crate::define_HashmapE; #[cfg(test)] #[path = "tests/test_miscellaneous.rs"] diff --git a/tvm_block/src/out_actions.rs b/tvm_block/src/out_actions.rs index aee84c005..c6c0a57c2 100644 --- a/tvm_block/src/out_actions.rs +++ b/tvm_block/src/out_actions.rs @@ -11,8 +11,6 @@ use std::collections::LinkedList; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -20,13 +18,15 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; -use crate::error::BlockError; -use crate::messages::Message; -use crate::types::CurrencyCollection; use crate::Deserializable; use crate::ExtraCurrencyCollection; use crate::Serializable; +use crate::error::BlockError; +use crate::messages::Message; +use crate::types::CurrencyCollection; pub const ACTION_SEND_MSG: u32 = 0x0ec3c86d; pub const ACTION_SET_CODE: u32 = 0xad4de08e; diff --git a/tvm_block/src/outbound_messages.rs b/tvm_block/src/outbound_messages.rs index 4f9354069..ba06c08f9 100644 --- a/tvm_block/src/outbound_messages.rs +++ b/tvm_block/src/outbound_messages.rs @@ -12,9 +12,6 @@ use std::collections::HashSet; use std::fmt; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::hm_label; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -25,7 +22,16 @@ use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; use tvm_types::UsageTree; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::hm_label; +use crate::Deserializable; +use crate::MerkleProof; +use crate::MerkleUpdate; +use crate::OutQueueUpdate; +use crate::Serializable; +use crate::ShardStateUnsplit; use crate::define_HashmapAugE; use crate::envelope_message::MsgEnvelope; use crate::error::BlockError; @@ -43,12 +49,6 @@ use crate::transactions::Transaction; use crate::types::AddSub; use crate::types::ChildCell; use crate::types::CurrencyCollection; -use crate::Deserializable; -use crate::MerkleProof; -use crate::MerkleUpdate; -use crate::OutQueueUpdate; -use crate::Serializable; -use crate::ShardStateUnsplit; #[cfg(test)] #[path = "tests/test_out_msgs.rs"] diff --git a/tvm_block/src/shard.rs b/tvm_block/src/shard.rs index e349a9a29..6e37002cc 100644 --- a/tvm_block/src/shard.rs +++ b/tvm_block/src/shard.rs @@ -13,8 +13,6 @@ use std::fmt::Display; use std::fmt::Formatter; use std::fmt::{self}; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -24,7 +22,17 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Account; +use crate::CopyleftRewards; +use crate::Deserializable; +use crate::IntermediateAddress; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::RefShardBlocks; +use crate::Serializable; use crate::accounts::ShardAccount; use crate::config_params::CatchainConfig; use crate::define_HashmapE; @@ -41,14 +49,6 @@ use crate::shard_accounts::ShardAccounts; use crate::types::ChildCell; use crate::types::CurrencyCollection; use crate::validators::ValidatorSet; -use crate::Account; -use crate::CopyleftRewards; -use crate::Deserializable; -use crate::IntermediateAddress; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::RefShardBlocks; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_shard.rs"] diff --git a/tvm_block/src/shard_accounts.rs b/tvm_block/src/shard_accounts.rs index 9f0d796c5..b8e89d413 100644 --- a/tvm_block/src/shard_accounts.rs +++ b/tvm_block/src/shard_accounts.rs @@ -11,9 +11,6 @@ use std::fmt; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::hm_label; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -23,7 +20,13 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::hm_label; +use crate::Augmentation; +use crate::Deserializable; +use crate::Serializable; use crate::accounts::Account; use crate::accounts::ShardAccount; use crate::define_HashmapAugE; @@ -31,9 +34,6 @@ use crate::hashmapaug::Augmentable; use crate::hashmapaug::HashmapAugType; use crate::types::CurrencyCollection; use crate::types::Number5; -use crate::Augmentation; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_shard_accounts.rs"] diff --git a/tvm_block/src/signature.rs b/tvm_block/src/signature.rs index b49625159..acf3dd6d0 100644 --- a/tvm_block/src/signature.rs +++ b/tvm_block/src/signature.rs @@ -15,8 +15,6 @@ use std::io::Write; use std::str::FromStr; use ed25519::signature::Verifier; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; @@ -25,14 +23,16 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::Serializable; use crate::blocks::BlockIdExt; use crate::define_HashmapE; use crate::error::BlockError; use crate::validators::ValidatorBaseInfo; use crate::validators::ValidatorDescr; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_signature.rs"] diff --git a/tvm_block/src/tests/test_accounts.rs b/tvm_block/src/tests/test_accounts.rs index 92b9d329f..7613de99c 100644 --- a/tvm_block/src/tests/test_accounts.rs +++ b/tvm_block/src/tests/test_accounts.rs @@ -14,8 +14,8 @@ use std::fs::File; use tvm_types::BocReader; use super::*; -use crate::write_read_and_assert; use crate::MsgAddressExt; +use crate::write_read_and_assert; #[test] fn test_serialize_storage_used() { diff --git a/tvm_block/src/tests/test_blocks.rs b/tvm_block/src/tests/test_blocks.rs index e1ab08317..0f3a8d743 100644 --- a/tvm_block/src/tests/test_blocks.rs +++ b/tvm_block/src/tests/test_blocks.rs @@ -17,13 +17,13 @@ use tvm_types::read_boc; use tvm_types::read_single_root_boc; use super::*; +use crate::AccountBlock; +use crate::Message; +use crate::TickTock; use crate::bintree::BinTreeType; use crate::hashmapaug::HashmapAugType; use crate::transactions::tests::generate_test_shard_account_block; use crate::write_read_and_assert; -use crate::AccountBlock; -use crate::Message; -use crate::TickTock; #[test] fn test_serialize_tick_tock() { @@ -109,25 +109,22 @@ fn test_block_info_with_invalid_vertical_stuff_2() { fn test_block_info_with_seq_no() { let mut info = BlockInfo::new(); info.set_seq_no(1).unwrap(); - info.set_prev_stuff( - true, - &BlkPrevInfo::Blocks { - prev1: ChildCell::with_struct(&ExtBlkRef { - end_lt: 1, - seq_no: 1000, - root_hash: UInt256::from([10; 32]), - file_hash: UInt256::from([10; 32]), - }) - .unwrap(), - prev2: ChildCell::with_struct(&ExtBlkRef { - end_lt: 1, - seq_no: 999, - root_hash: UInt256::from([10; 32]), - file_hash: UInt256::from([10; 32]), - }) - .unwrap(), - }, - ) + info.set_prev_stuff(true, &BlkPrevInfo::Blocks { + prev1: ChildCell::with_struct(&ExtBlkRef { + end_lt: 1, + seq_no: 1000, + root_hash: UInt256::from([10; 32]), + file_hash: UInt256::from([10; 32]), + }) + .unwrap(), + prev2: ChildCell::with_struct(&ExtBlkRef { + end_lt: 1, + seq_no: 999, + root_hash: UInt256::from([10; 32]), + file_hash: UInt256::from([10; 32]), + }) + .unwrap(), + }) .unwrap(); write_read_and_assert(info.clone()); @@ -152,17 +149,14 @@ fn test_blockinfo_some_some_none() { let mut info = BlockInfo::new(); info.set_shard(ShardIdent::with_workchain_id(0x22222222).unwrap()); info.set_seq_no(u32::MAX - 22).unwrap(); - info.set_prev_stuff( - false, - &BlkPrevInfo::Block { - prev: ExtBlkRef { - end_lt: 1, - seq_no: 1000, - root_hash: UInt256::from([10; 32]), - file_hash: UInt256::from([10; 32]), - }, + info.set_prev_stuff(false, &BlkPrevInfo::Block { + prev: ExtBlkRef { + end_lt: 1, + seq_no: 1000, + root_hash: UInt256::from([10; 32]), + file_hash: UInt256::from([10; 32]), }, - ) + }) .unwrap(); test_blockinfo(info); } diff --git a/tvm_block/src/tests/test_config_params.rs b/tvm_block/src/tests/test_config_params.rs index 43a402e29..b7bfe1fb5 100644 --- a/tvm_block/src/tests/test_config_params.rs +++ b/tvm_block/src/tests/test_config_params.rs @@ -16,8 +16,8 @@ use rand::Rng; use tvm_types::read_single_root_boc; use super::*; -use crate::write_read_and_assert; use crate::VarUInteger32; +use crate::write_read_and_assert; fn get_config_param0() -> ConfigParam0 { let mut c = ConfigParam0::default(); @@ -487,11 +487,12 @@ fn test_config_params() { write_read_and_assert(cp.clone()); - assert!(cp - .prev_validator_set() - .expect("it should not fail, but gives empty list") - .list() - .is_empty()); + assert!( + cp.prev_validator_set() + .expect("it should not fail, but gives empty list") + .list() + .is_empty() + ); assert!(!cp.prev_validator_set_present().unwrap()); let mut cp32 = ConfigParam32::default(); @@ -513,11 +514,12 @@ fn test_config_params() { write_read_and_assert(cp.clone()); - assert!(cp - .next_validator_set() - .expect("it should not fail, but gives empty list") - .list() - .is_empty()); + assert!( + cp.next_validator_set() + .expect("it should not fail, but gives empty list") + .list() + .is_empty() + ); assert!(!cp.next_validator_set_present().unwrap()); let mut cp36 = ConfigParam36::default(); diff --git a/tvm_block/src/tests/test_envelope_message.rs b/tvm_block/src/tests/test_envelope_message.rs index 1f68274a5..66a73f96d 100644 --- a/tvm_block/src/tests/test_envelope_message.rs +++ b/tvm_block/src/tests/test_envelope_message.rs @@ -10,13 +10,13 @@ // limitations under the License. use super::*; -use crate::types::Number5; -use crate::write_read_and_assert; use crate::CurrencyCollection; use crate::InternalMessageHeader; use crate::MsgAddressInt; use crate::StateInit; use crate::TickTock; +use crate::types::Number5; +use crate::write_read_and_assert; fn check_serialization_intermediate_addr_regular(addr_orig: IntermediateAddressRegular) { let mut b = BuilderData::new(); diff --git a/tvm_block/src/tests/test_hashmapaug.rs b/tvm_block/src/tests/test_hashmapaug.rs index 9424f3437..5699cbbc7 100644 --- a/tvm_block/src/tests/test_hashmapaug.rs +++ b/tvm_block/src/tests/test_hashmapaug.rs @@ -14,8 +14,8 @@ #![allow(clippy::vec_init_then_push)] use std::fmt; -use tvm_types::hm_label; use tvm_types::HashmapSubtree; +use tvm_types::hm_label; use super::*; use crate::AddSub; diff --git a/tvm_block/src/tests/test_in_msgs.rs b/tvm_block/src/tests/test_in_msgs.rs index c2a554b71..9f8df7935 100644 --- a/tvm_block/src/tests/test_in_msgs.rs +++ b/tvm_block/src/tests/test_in_msgs.rs @@ -12,8 +12,6 @@ use std::sync::Arc; use super::*; -use crate::types::Number5; -use crate::write_read_and_assert; use crate::AccountId; use crate::AccountStatus; use crate::ExternalInboundMessageHeader; @@ -24,6 +22,8 @@ use crate::MsgAddressInt; use crate::StateInit; use crate::TickTock; use crate::TransactionDescr; +use crate::types::Number5; +use crate::write_read_and_assert; fn create_external_message() -> Arc { let src = diff --git a/tvm_block/src/tests/test_master.rs b/tvm_block/src/tests/test_master.rs index 036db6c68..27fc71ad1 100644 --- a/tvm_block/src/tests/test_master.rs +++ b/tvm_block/src/tests/test_master.rs @@ -15,12 +15,12 @@ use rand::Rng; use tvm_types::read_single_root_boc; use super::*; -use crate::transactions::tests::generate_test_shard_account_block; -use crate::write_read_and_assert; +use crate::BASE_WORKCHAIN_ID; use crate::BlockExtra; use crate::MsgAddressInt; use crate::ShardStateUnsplit; -use crate::BASE_WORKCHAIN_ID; +use crate::transactions::tests::generate_test_shard_account_block; +use crate::write_read_and_assert; #[test] fn test_libraries() { @@ -59,20 +59,16 @@ fn test_libraries() { fn test_shard_descr() { let descr_none = ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::None); - let descr_split = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); - let descr_merge = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Merge { merge_utime: 0x12345678, interval: 0x87654321 }, - ); + let descr_split = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); + let descr_merge = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Merge { + merge_utime: 0x12345678, + interval: 0x87654321, + }); write_read_and_assert(descr_none); write_read_and_assert(descr_split); @@ -90,21 +86,17 @@ fn test_shard_descr_with_copyleft() { let mut descr_none = ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::None); descr_none.copyleft_rewards = copyleft_rewards.clone(); - let mut descr_split = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); + let mut descr_split = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); descr_split.copyleft_rewards = copyleft_rewards.clone(); - let mut descr_merge = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Merge { merge_utime: 0x12345678, interval: 0x87654321 }, - ); + let mut descr_merge = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Merge { + merge_utime: 0x12345678, + interval: 0x87654321, + }); descr_merge.copyleft_rewards = copyleft_rewards.clone(); write_read_and_assert(descr_none); @@ -127,13 +119,11 @@ fn test_shard_descr_fast_finality() { updated_at: 0x12345678, }); - let mut descr_split = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); + let mut descr_split = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); descr_split.collators = Some(ShardCollators { prev: gen_collator(), prev2: None, @@ -143,13 +133,11 @@ fn test_shard_descr_fast_finality() { updated_at: 0x12345678, }); - let mut descr_merge = ShardDescr::with_params( - 42, - 17, - 25, - UInt256::from([70; 32]), - FutureSplitMerge::Merge { merge_utime: 0x12345678, interval: 0x87654321 }, - ); + let mut descr_merge = + ShardDescr::with_params(42, 17, 25, UInt256::from([70; 32]), FutureSplitMerge::Merge { + merge_utime: 0x12345678, + interval: 0x87654321, + }); descr_merge.collators = Some(ShardCollators { prev: gen_collator(), prev2: Some(gen_collator()), @@ -171,20 +159,16 @@ fn test_mc_state_extra() { ShardDescr::with_params(23, 77, 234, UInt256::from([131; 32]), FutureSplitMerge::None); let shard1_1 = ShardDescr::with_params(25, 177, 230, UInt256::from([131; 32]), FutureSplitMerge::None); - let shard2 = ShardDescr::with_params( - 15, - 78, - 235, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); - let shard2_2 = ShardDescr::with_params( - 115, - 8, - 35, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); + let shard2 = + ShardDescr::with_params(15, 78, 235, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); + let shard2_2 = + ShardDescr::with_params(115, 8, 35, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); let ident = extra.add_workchain(11, &shard1).unwrap(); extra.shards.split_shard(&ident, |_| Ok((shard1, shard1_1))).unwrap(); let ident = extra.add_workchain(22, &shard2).unwrap(); @@ -239,20 +223,16 @@ fn test_mc_block_extra() { ShardDescr::with_params(23, 77, 234, UInt256::from([131; 32]), FutureSplitMerge::None); let shard1_1 = ShardDescr::with_params(25, 177, 230, UInt256::from([131; 32]), FutureSplitMerge::None); - let shard2 = ShardDescr::with_params( - 15, - 78, - 235, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); - let shard2_2 = ShardDescr::with_params( - 115, - 8, - 35, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); + let shard2 = + ShardDescr::with_params(15, 78, 235, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); + let shard2_2 = + ShardDescr::with_params(115, 8, 35, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); let ident = ShardIdent::with_workchain_id(11).unwrap(); extra.shards.add_workchain(11, 134, UInt256::default(), UInt256::default(), None).unwrap(); extra @@ -302,20 +282,16 @@ fn test_mc_block_extra_2() { ShardDescr::with_params(23, 77, 234, UInt256::from([131; 32]), FutureSplitMerge::None); let shard1_1 = ShardDescr::with_params(25, 177, 230, UInt256::from([131; 32]), FutureSplitMerge::None); - let shard2 = ShardDescr::with_params( - 15, - 78, - 235, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); - let shard2_2 = ShardDescr::with_params( - 115, - 8, - 35, - UInt256::from([77; 32]), - FutureSplitMerge::Split { split_utime: 0x12345678, interval: 0x87654321 }, - ); + let shard2 = + ShardDescr::with_params(15, 78, 235, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); + let shard2_2 = + ShardDescr::with_params(115, 8, 35, UInt256::from([77; 32]), FutureSplitMerge::Split { + split_utime: 0x12345678, + interval: 0x87654321, + }); let ident = ShardIdent::with_workchain_id(11).unwrap(); extra.shards.add_workchain(11, 134, UInt256::default(), UInt256::default(), None).unwrap(); extra diff --git a/tvm_block/src/tests/test_merkle_proof.rs b/tvm_block/src/tests/test_merkle_proof.rs index 997ec744b..fd976882f 100644 --- a/tvm_block/src/tests/test_merkle_proof.rs +++ b/tvm_block/src/tests/test_merkle_proof.rs @@ -201,17 +201,14 @@ fn test_merkle_proof_hi_hashes() { block_info.set_shard(ShardIdent::with_workchain_id(0x22222222).unwrap()); block_info.set_seq_no(u32::MAX - 22).unwrap(); block_info - .set_prev_stuff( - false, - &BlkPrevInfo::Block { - prev: ExtBlkRef { - end_lt: 1, - seq_no: 1000, - root_hash: UInt256::from([10; 32]), - file_hash: UInt256::from([10; 32]), - }, + .set_prev_stuff(false, &BlkPrevInfo::Block { + prev: ExtBlkRef { + end_lt: 1, + seq_no: 1000, + root_hash: UInt256::from([10; 32]), + file_hash: UInt256::from([10; 32]), }, - ) + }) .unwrap(); let block = diff --git a/tvm_block/src/tests/test_merkle_update.rs b/tvm_block/src/tests/test_merkle_update.rs index b1be0a9a5..708fbdf42 100644 --- a/tvm_block/src/tests/test_merkle_update.rs +++ b/tvm_block/src/tests/test_merkle_update.rs @@ -13,17 +13,14 @@ use std::fs::read; use std::path::Path; use std::time::Instant; -use tvm_types::read_single_root_boc; -use tvm_types::write_boc; use tvm_types::AccountId; use tvm_types::BocWriter; use tvm_types::ExceptionCode; use tvm_types::UsageTree; +use tvm_types::read_single_root_boc; +use tvm_types::write_boc; use super::*; -use crate::define_HashmapE; -use crate::generate_test_account_by_init_code_hash; -use crate::hashmapaug::HashmapAugType; use crate::Block; use crate::CurrencyCollection; use crate::Grams; @@ -46,6 +43,9 @@ use crate::ShardStateSplit; use crate::ShardStateUnsplit; use crate::StateInit; use crate::TickTock; +use crate::define_HashmapE; +use crate::generate_test_account_by_init_code_hash; +use crate::hashmapaug::HashmapAugType; #[test] fn test_merkle_update() { diff --git a/tvm_block/src/tests/test_miscellaneous.rs b/tvm_block/src/tests/test_miscellaneous.rs index 2f0aa76a2..efdf3a99f 100644 --- a/tvm_block/src/tests/test_miscellaneous.rs +++ b/tvm_block/src/tests/test_miscellaneous.rs @@ -14,7 +14,6 @@ use std::str::FromStr; use tvm_types::AccountId; use super::*; -use crate::write_read_and_assert; use crate::Block; use crate::CurrencyCollection; use crate::IntermediateAddress; @@ -23,6 +22,7 @@ use crate::Message; use crate::MsgAddressInt; use crate::MsgEnvelope; use crate::ShardIdent; +use crate::write_read_and_assert; #[test] fn test_process_info_key() { diff --git a/tvm_block/src/tests/test_out_msgs.rs b/tvm_block/src/tests/test_out_msgs.rs index 196773cdc..0066380c7 100644 --- a/tvm_block/src/tests/test_out_msgs.rs +++ b/tvm_block/src/tests/test_out_msgs.rs @@ -13,9 +13,6 @@ use std::str::FromStr; use super::*; -use crate::types::Grams; -use crate::types::Number5; -use crate::write_read_and_assert; use crate::AccountStatus; use crate::HashUpdate; use crate::InMsgExternal; @@ -24,6 +21,9 @@ use crate::MsgAddressInt; use crate::StateInit; use crate::TickTock; use crate::TransactionDescr; +use crate::types::Grams; +use crate::types::Number5; +use crate::write_read_and_assert; fn get_message_with_addrs(src: AccountId, dst: AccountId) -> Message { let mut msg = Message::with_int_header(InternalMessageHeader::with_addresses( diff --git a/tvm_block/src/tests/test_shard.rs b/tvm_block/src/tests/test_shard.rs index c7bfdd973..31416b215 100644 --- a/tvm_block/src/tests/test_shard.rs +++ b/tvm_block/src/tests/test_shard.rs @@ -302,13 +302,15 @@ fn test_shard_ident_with_prefix_slice() { #[test] fn test_shard_ident_merge() { - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .merge() - .is_err()); + assert!( + ShardIdent::with_tagged_prefix( + 0, + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .merge() + .is_err() + ); assert_eq!( ShardIdent::with_tagged_prefix( 0, @@ -369,153 +371,177 @@ fn test_shard_ident_merge() { #[test] fn test_shard_ident_is_ancestor_for() { - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_ancestor_for( - &ShardIdent::with_tagged_prefix( + assert!( + ShardIdent::with_tagged_prefix( 0, - 0b0101_1010_00000000_00000000_00000000_01000000_00000000_01100000_10000000 + 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - -1, - 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_ancestor_for( - &ShardIdent::with_tagged_prefix( - 0, - 0b0101_1010_00000000_00000000_00000000_01000000_00000000_01100000_10000000 + .is_ancestor_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0101_1010_00000000_00000000_00000000_01000000_00000000_01100000_10000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( + -1, + 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_ancestor_for( - &ShardIdent::with_tagged_prefix( + .is_ancestor_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0101_1010_00000000_00000000_00000000_01000000_00000000_01100000_10000000 + ) + .unwrap() + ) + ); + assert!( + ShardIdent::with_tagged_prefix( 0, - 0b0101_1001_00000000_00010000_00000000_00000000_00000000_00000000_00000000 + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_ancestor_for( - &ShardIdent::with_tagged_prefix( + .is_ancestor_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0101_1001_00000000_00010000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + ShardIdent::with_tagged_prefix( 0, 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b1001_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_ancestor_for( - &ShardIdent::with_tagged_prefix( + .is_ancestor_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( 0, - 0b1000_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + 0b1001_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); + .is_ancestor_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b1000_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); } #[test] fn test_shard_ident_is_parent_for() { - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( + assert!( + ShardIdent::with_tagged_prefix( 0, - 0b0101_1100_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - -1, - 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( - 0, - 0b0101_1100_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0101_1100_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( + -1, + 0b0101_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0101_1100_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + ShardIdent::with_tagged_prefix( 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( 0, 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b1001_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( 0, 0b1001_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b1100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .is_parent_for( - &ShardIdent::with_tagged_prefix( + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b1001_1000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + 0b1100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 ) .unwrap() - )); + .is_parent_for( + &ShardIdent::with_tagged_prefix( + 0, + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + ) + ); } #[test] fn test_shard_ident_split() { - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0000_0000_00000000_00000000_00000000_00000000_00000000_00000000_0000_1000 - ) - .unwrap() - .split() - .is_err(),); + assert!( + ShardIdent::with_tagged_prefix( + 0, + 0b0000_0000_00000000_00000000_00000000_00000000_00000000_00000000_0000_1000 + ) + .unwrap() + .split() + .is_err(), + ); assert_eq!( ShardIdent::with_tagged_prefix( 0, @@ -604,34 +630,50 @@ fn test_shard_ident_split() { #[test] fn test_shard_ident_contains_account() { - assert!(ShardIdent::with_prefix_slice(0, SliceData::from_string("7ff95eed4bc8_").unwrap()) - .unwrap() - .contains_account( - AccountId::from_str("7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be") + assert!( + ShardIdent::with_prefix_slice(0, SliceData::from_string("7ff95eed4bc8_").unwrap()) + .unwrap() + .contains_account( + AccountId::from_str( + "7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be" + ) .unwrap() - ) - .unwrap()); - assert!(ShardIdent::with_tagged_prefix(0, 0x6000_0000_0000_0000) - .unwrap() - .contains_account( - AccountId::from_str("79b1756926764d88d0b9bc8f42806939f293fb7733fba0959bb024234447c900") + ) + .unwrap() + ); + assert!( + ShardIdent::with_tagged_prefix(0, 0x6000_0000_0000_0000) + .unwrap() + .contains_account( + AccountId::from_str( + "79b1756926764d88d0b9bc8f42806939f293fb7733fba0959bb024234447c900" + ) .unwrap() - ) - .unwrap()); - assert!(ShardIdent::with_prefix_slice(0, SliceData::from_string("_").unwrap()) - .unwrap() - .contains_account( - AccountId::from_str("7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be") + ) + .unwrap() + ); + assert!( + ShardIdent::with_prefix_slice(0, SliceData::from_string("_").unwrap()) + .unwrap() + .contains_account( + AccountId::from_str( + "7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be" + ) .unwrap() - ) - .unwrap()); - assert!(!ShardIdent::with_prefix_slice(0, SliceData::from_string("7ff950ed4bc8_").unwrap()) - .unwrap() - .contains_account( - AccountId::from_str("7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be") + ) + .unwrap() + ); + assert!( + !ShardIdent::with_prefix_slice(0, SliceData::from_string("7ff950ed4bc8_").unwrap()) + .unwrap() + .contains_account( + AccountId::from_str( + "7ff95eed4bc3a5fe1e590d8111f471281d100d2eadc737fd3ee8b209c21a21be" + ) .unwrap() - ) - .unwrap()); + ) + .unwrap() + ); } #[test] @@ -662,60 +704,72 @@ fn test_shard_prefix_without_tag() { #[test] fn test_shard_ident_contains_prefix() { - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b0110_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); - assert!(ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b0000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b1100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); - assert!(!ShardIdent::with_tagged_prefix( - 0, - 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - ) - .unwrap() - .contains_prefix( - 0, - 0b1010_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 - )); + assert!( + ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b0110_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); + assert!( + ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); + assert!( + ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b0000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b1000_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b1100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); + assert!( + !ShardIdent::with_tagged_prefix( + 0, + 0b0100_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + .unwrap() + .contains_prefix( + 0, + 0b1010_0000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 + ) + ); } #[test] @@ -862,20 +916,20 @@ mod account_id_prefix_full { assert_eq!(prefix1.interpolate_addr(&prefix2, 0), prefix1); - assert_eq!( - prefix1.interpolate_addr(&prefix2, 1), - AccountIdPrefixFull { workchain_id: 0x8000_0001u64 as i32, prefix: prefix1.prefix } - ); + assert_eq!(prefix1.interpolate_addr(&prefix2, 1), AccountIdPrefixFull { + workchain_id: 0x8000_0001u64 as i32, + prefix: prefix1.prefix + }); - assert_eq!( - prefix1.interpolate_addr(&prefix2, 20), - AccountIdPrefixFull { workchain_id: 0xFFFF_F001u64 as i32, prefix: prefix1.prefix } - ); + assert_eq!(prefix1.interpolate_addr(&prefix2, 20), AccountIdPrefixFull { + workchain_id: 0xFFFF_F001u64 as i32, + prefix: prefix1.prefix + }); - assert_eq!( - prefix1.interpolate_addr(&prefix2, 32 + 20), - AccountIdPrefixFull { workchain_id: prefix2.workchain_id, prefix: 0x0FEDC6789ABCDEF0 } - ); + assert_eq!(prefix1.interpolate_addr(&prefix2, 32 + 20), AccountIdPrefixFull { + workchain_id: prefix2.workchain_id, + prefix: 0x0FEDC6789ABCDEF0 + }); assert_eq!(prefix1.interpolate_addr(&prefix2, 32 + 64), prefix2); } diff --git a/tvm_block/src/tests/test_signature.rs b/tvm_block/src/tests/test_signature.rs index 1e4beab60..0cba1ee08 100644 --- a/tvm_block/src/tests/test_signature.rs +++ b/tvm_block/src/tests/test_signature.rs @@ -16,11 +16,11 @@ use ed25519_dalek::VerifyingKey; use tvm_types::read_boc; use super::*; -use crate::config_params::ConfigParamEnum; -use crate::write_read_and_assert; use crate::Block; use crate::ShardIdent; use crate::TopBlockDescr; +use crate::config_params::ConfigParamEnum; +use crate::write_read_and_assert; #[test] fn test_crypto_signature_new_default() { diff --git a/tvm_block/src/tests/test_validators.rs b/tvm_block/src/tests/test_validators.rs index e702ca72a..324a3783e 100644 --- a/tvm_block/src/tests/test_validators.rs +++ b/tvm_block/src/tests/test_validators.rs @@ -12,13 +12,13 @@ use ed25519_dalek::VerifyingKey; // See the License for the specific TON DEV software governing permissions and // limitations under the License. use super::*; +use crate::BASE_WORKCHAIN_ID; +use crate::ShardIdent; use crate::blocks::Block; use crate::config_params::ConfigParamEnum; use crate::merkle_proof::MerkleProof; use crate::signature::BlockProof; use crate::write_read_and_assert; -use crate::ShardIdent; -use crate::BASE_WORKCHAIN_ID; #[test] fn test_validator_info_new_default() { diff --git a/tvm_block/src/transactions.rs b/tvm_block/src/transactions.rs index bca1b7b4f..03b55b1d2 100644 --- a/tvm_block/src/transactions.rs +++ b/tvm_block/src/transactions.rs @@ -12,9 +12,6 @@ use std::fmt; use std::sync::Arc; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::hm_label; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -25,7 +22,14 @@ use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; use tvm_types::UsageTree; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::hm_label; +use crate::Deserializable; +use crate::MaybeDeserialize; +use crate::MaybeSerialize; +use crate::Serializable; use crate::accounts::Account; use crate::accounts::AccountStatus; use crate::accounts::StorageUsedShort; @@ -37,8 +41,8 @@ use crate::hashmapaug::Augmentable; use crate::hashmapaug::Augmentation; use crate::hashmapaug::HashmapAugType; use crate::merkle_proof::MerkleProof; -use crate::messages::generate_big_msg; use crate::messages::Message; +use crate::messages::generate_big_msg; use crate::shard::ShardStateUnsplit; use crate::types::ChildCell; use crate::types::CurrencyCollection; @@ -46,10 +50,6 @@ use crate::types::Grams; use crate::types::InRefValue; use crate::types::VarUInteger3; use crate::types::VarUInteger7; -use crate::Deserializable; -use crate::MaybeDeserialize; -use crate::MaybeSerialize; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_transactions.rs"] @@ -1600,7 +1600,7 @@ impl Serializable for Transaction { builder.append_bits(self.outmsg_cnt as usize, 15)?; // outmsg_cnt: u15 self.orig_status.write_to(builder)?; // orig_status: AccountStatus, self.end_status.write_to(builder)?; // end_status: AccountStatus - // self.in_msg.write_maybe_to(builder)?; + // self.in_msg.write_maybe_to(builder)?; let mut builder1 = BuilderData::new(); match &self.in_msg { Some(in_msg) => { diff --git a/tvm_block/src/types.rs b/tvm_block/src/types.rs index 3eaceacbf..887b1c505 100644 --- a/tvm_block/src/types.rs +++ b/tvm_block/src/types.rs @@ -19,12 +19,10 @@ use std::sync::Arc; use std::time::SystemTime; use std::time::UNIX_EPOCH; -use num::bigint::Sign; use num::BigInt; use num::One; use num::Zero; -use tvm_types::error; -use tvm_types::fail; +use num::bigint::Sign; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::CellType; @@ -34,12 +32,14 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; +use crate::Deserializable; +use crate::Serializable; use crate::define_HashmapE; use crate::error::BlockError; use crate::hashmapaug::Augmentable; -use crate::Deserializable; -use crate::Serializable; #[cfg(test)] #[path = "tests/test_types.rs"] @@ -589,19 +589,11 @@ impl Grams { } pub const fn as_u64(&self) -> Option { - if self.0 <= u64::MAX as u128 { - Some(self.0 as u64) - } else { - None - } + if self.0 <= u64::MAX as u128 { Some(self.0 as u64) } else { None } } pub const fn as_u64_quiet(&self) -> u64 { - if self.0 <= u64::MAX as u128 { - self.0 as u64 - } else { - u64::MAX - } + if self.0 <= u64::MAX as u128 { self.0 as u64 } else { u64::MAX } } } @@ -911,7 +903,7 @@ impl AddSub for CurrencyCollection { } } Ok(false) // coin not found in mine or amount is smaller - cannot - // subtract + // subtract }) } diff --git a/tvm_block/src/validators.rs b/tvm_block/src/validators.rs index b3a287d05..b32e79f1a 100644 --- a/tvm_block/src/validators.rs +++ b/tvm_block/src/validators.rs @@ -10,20 +10,16 @@ // limitations under the License. use std::borrow::Cow; -use std::cmp::min; use std::cmp::Ordering; +use std::cmp::min; use std::io::Cursor; use std::io::Write; -use crc::Crc; use crc::CRC_32_ISCSI; +use crc::Crc; use sha2::Digest; use sha2::Sha256; use sha2::Sha512; -use tvm_types::bls::BLS_PUBLIC_KEY_LEN; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::types::ByteOrderRead; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; @@ -32,7 +28,13 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::bls::BLS_PUBLIC_KEY_LEN; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::types::ByteOrderRead; +use crate::Deserializable; +use crate::Serializable; use crate::config_params::CatchainConfig; use crate::define_HashmapE; use crate::error::BlockError; @@ -42,8 +44,6 @@ use crate::signature::CryptoSignature; use crate::signature::SigPubKey; use crate::types::Number16; use crate::types::UnixTime32; -use crate::Deserializable; -use crate::Serializable; pub const CASTAGNOLI: Crc = Crc::::new(&CRC_32_ISCSI); diff --git a/tvm_block_json/rustfmt.toml b/tvm_block_json/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_block_json/rustfmt.toml +++ b/tvm_block_json/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_block_json/src/block_parser/accounts.rs b/tvm_block_json/src/block_parser/accounts.rs index b246caf3e..f2a81de45 100644 --- a/tvm_block_json/src/block_parser/accounts.rs +++ b/tvm_block_json/src/block_parser/accounts.rs @@ -6,8 +6,6 @@ use tvm_block::ChildCell; use tvm_block::Serializable; use tvm_block::ShardAccounts; use tvm_block::Transaction; -use tvm_types::fail; -use tvm_types::write_boc; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -15,9 +13,9 @@ use tvm_types::ExceptionCode; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::fail; +use tvm_types::write_boc; -use crate::block_parser::entry::get_sharding_depth; -use crate::block_parser::get_partition; use crate::BlockParserConfig; use crate::BlockParsingError; use crate::EntryConfig; @@ -25,6 +23,8 @@ use crate::JsonReducer; use crate::ParsedBlock; use crate::ParsedEntry; use crate::ParsingBlock; +use crate::block_parser::entry::get_sharding_depth; +use crate::block_parser::get_partition; pub(crate) enum AccountTransition { None, diff --git a/tvm_block_json/src/block_parser/entry.rs b/tvm_block_json/src/block_parser/entry.rs index 725ab94f6..9c71a40e0 100644 --- a/tvm_block_json/src/block_parser/entry.rs +++ b/tvm_block_json/src/block_parser/entry.rs @@ -2,9 +2,9 @@ use serde_json::Map; use serde_json::Value; use tvm_types::Result; +use crate::EntryConfig; use crate::block_parser::BlockParsingError; use crate::block_parser::JsonReducer; -use crate::EntryConfig; #[derive(Clone)] pub struct ParsedEntry { diff --git a/tvm_block_json/src/block_parser/parser.rs b/tvm_block_json/src/block_parser/parser.rs index cc97acfb0..a837d97e9 100644 --- a/tvm_block_json/src/block_parser/parser.rs +++ b/tvm_block_json/src/block_parser/parser.rs @@ -10,24 +10,24 @@ use tvm_block::BlockProof; use tvm_block::Deserializable; use tvm_block::HashmapAugType; use tvm_block::Transaction; -use tvm_types::fail; use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::fail; +use crate::JsonReducer; +use crate::block_parser::ParserTraceEvent; +use crate::block_parser::ParserTracer; use crate::block_parser::accounts::AccountTransition; use crate::block_parser::accounts::ParserAccounts; use crate::block_parser::block::ParsedBlock; use crate::block_parser::block::ParsingBlock; -use crate::block_parser::entry::get_sharding_depth; use crate::block_parser::entry::ParsedEntry; +use crate::block_parser::entry::get_sharding_depth; use crate::block_parser::is_account_none; use crate::block_parser::transactions::ParserTransactions; use crate::block_parser::unix_time_to_system_time; -use crate::block_parser::ParserTraceEvent; -use crate::block_parser::ParserTracer; -use crate::JsonReducer; pub struct EntryConfig { pub sharding_depth: Option, diff --git a/tvm_block_json/src/block_parser/transactions.rs b/tvm_block_json/src/block_parser/transactions.rs index da8cafd1c..7f3d52b10 100644 --- a/tvm_block_json/src/block_parser/transactions.rs +++ b/tvm_block_json/src/block_parser/transactions.rs @@ -10,15 +10,12 @@ use tvm_block::MessageProcessingStatus; use tvm_block::MsgAddressExt; use tvm_block::Transaction; use tvm_block::TransactionProcessingStatus; -use tvm_types::write_boc; use tvm_types::Cell; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::write_boc; -use crate::block_parser::entry::get_sharding_depth; -use crate::block_parser::get_partition; -use crate::block_parser::is_minter_address; use crate::BlockParserConfig; use crate::BlockParsingError; use crate::EntryConfig; @@ -27,6 +24,9 @@ use crate::ParsedEntry; use crate::ParserTraceEvent; use crate::ParserTracer; use crate::ParsingBlock; +use crate::block_parser::entry::get_sharding_depth; +use crate::block_parser::get_partition; +use crate::block_parser::is_minter_address; pub struct PreparedMessage { doc: Map, diff --git a/tvm_block_json/src/deserialize.rs b/tvm_block_json/src/deserialize.rs index 9b0610363..159a1b446 100644 --- a/tvm_block_json/src/deserialize.rs +++ b/tvm_block_json/src/deserialize.rs @@ -16,11 +16,11 @@ use std::str::FromStr; use serde_json::Map; use serde_json::Value; -use tvm_api::ton::ton_node::rempmessagestatus; +use tvm_api::IntoBoxed; use tvm_api::ton::ton_node::RempMessageLevel; use tvm_api::ton::ton_node::RempMessageStatus; use tvm_api::ton::ton_node::RempReceipt; -use tvm_api::IntoBoxed; +use tvm_api::ton::ton_node::rempmessagestatus; use tvm_block::Account; use tvm_block::Augmentation; use tvm_block::BlockCreateFees; @@ -29,6 +29,14 @@ use tvm_block::BlockLimits; use tvm_block::CatchainConfig; use tvm_block::ConfigParam0; use tvm_block::ConfigParam1; +use tvm_block::ConfigParam2; +use tvm_block::ConfigParam3; +use tvm_block::ConfigParam4; +use tvm_block::ConfigParam5; +use tvm_block::ConfigParam6; +use tvm_block::ConfigParam7; +use tvm_block::ConfigParam8; +use tvm_block::ConfigParam9; use tvm_block::ConfigParam10; use tvm_block::ConfigParam11; use tvm_block::ConfigParam12; @@ -39,9 +47,7 @@ use tvm_block::ConfigParam16; use tvm_block::ConfigParam17; use tvm_block::ConfigParam18; use tvm_block::ConfigParam18Map; -use tvm_block::ConfigParam2; use tvm_block::ConfigParam29; -use tvm_block::ConfigParam3; use tvm_block::ConfigParam31; use tvm_block::ConfigParam32; use tvm_block::ConfigParam33; @@ -50,13 +56,7 @@ use tvm_block::ConfigParam35; use tvm_block::ConfigParam36; use tvm_block::ConfigParam37; use tvm_block::ConfigParam39; -use tvm_block::ConfigParam4; use tvm_block::ConfigParam40; -use tvm_block::ConfigParam5; -use tvm_block::ConfigParam6; -use tvm_block::ConfigParam7; -use tvm_block::ConfigParam8; -use tvm_block::ConfigParam9; use tvm_block::ConfigParamEnum; use tvm_block::ConfigParams; use tvm_block::ConfigProposalSetup; @@ -72,11 +72,13 @@ use tvm_block::GlobalVersion; use tvm_block::Grams; use tvm_block::HashmapAugType; use tvm_block::LibDescr; +use tvm_block::MASTERCHAIN_ID; use tvm_block::MandatoryParams; use tvm_block::McStateExtra; use tvm_block::MsgAddressInt; use tvm_block::MsgForwardPrices; use tvm_block::ParamLimits; +use tvm_block::SHARD_FULL; use tvm_block::Serializable; use tvm_block::ShardAccount; use tvm_block::ShardIdent; @@ -95,14 +97,12 @@ use tvm_block::WorkchainFormat; use tvm_block::WorkchainFormat0; use tvm_block::WorkchainFormat1; use tvm_block::Workchains; -use tvm_block::MASTERCHAIN_ID; -use tvm_block::SHARD_FULL; +use tvm_types::Result; +use tvm_types::UInt256; use tvm_types::base64_decode; use tvm_types::error; use tvm_types::fail; use tvm_types::read_single_root_boc; -use tvm_types::Result; -use tvm_types::UInt256; pub trait ParseJson { fn as_uint256(&self) -> Result; diff --git a/tvm_block_json/src/serialize.rs b/tvm_block_json/src/serialize.rs index fac949dbd..c03d615f6 100644 --- a/tvm_block_json/src/serialize.rs +++ b/tvm_block_json/src/serialize.rs @@ -22,10 +22,6 @@ use tvm_api::ton::ton_node::RempMessageLevel; use tvm_api::ton::ton_node::RempMessageStatus; use tvm_api::ton::ton_node::RempReceipt; use tvm_block::*; -use tvm_types::base64_encode; -use tvm_types::fail; -use tvm_types::read_single_root_boc; -use tvm_types::write_boc; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::Cell; @@ -33,6 +29,10 @@ use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::base64_encode; +use tvm_types::fail; +use tvm_types::read_single_root_boc; +use tvm_types::write_boc; const VERSION: u32 = 8; // Version changes @@ -1604,16 +1604,12 @@ pub fn db_serialize_block_ex<'a>( serialize_file_hash(&mut map, set.file_hash, set.boc); serialize_field(&mut map, "status", set.status as u8); if mode.is_q_server() { - serialize_field( - &mut map, - "status_name", - match set.status { - BlockProcessingStatus::Unknown => "unknown", - BlockProcessingStatus::Proposed => "proposed", - BlockProcessingStatus::Finalized => "finalized", - BlockProcessingStatus::Refused => "refused", - }, - ); + serialize_field(&mut map, "status_name", match set.status { + BlockProcessingStatus::Unknown => "unknown", + BlockProcessingStatus::Proposed => "proposed", + BlockProcessingStatus::Finalized => "finalized", + BlockProcessingStatus::Refused => "refused", + }); } map.insert("boc".to_string(), base64_encode(set.boc).into()); map.insert("global_id".to_string(), set.block.global_id.into()); @@ -1851,17 +1847,13 @@ pub fn db_serialize_transaction_ex<'a>( serialize_field(&mut map, "boc", base64_encode(set.boc)); serialize_field(&mut map, "status", set.status as u8); if mode.is_q_server() { - serialize_field( - &mut map, - "status_name", - match set.status { - TransactionProcessingStatus::Unknown => "unknown", - TransactionProcessingStatus::Preliminary => "preliminary", - TransactionProcessingStatus::Proposed => "proposed", - TransactionProcessingStatus::Finalized => "finalized", - TransactionProcessingStatus::Refused => "refused", - }, - ); + serialize_field(&mut map, "status_name", match set.status { + TransactionProcessingStatus::Unknown => "unknown", + TransactionProcessingStatus::Preliminary => "preliminary", + TransactionProcessingStatus::Proposed => "proposed", + TransactionProcessingStatus::Finalized => "finalized", + TransactionProcessingStatus::Refused => "refused", + }); } let mut ext_in_msg_fee = None; let (tr_type, tr_type_name) = match &set.transaction.read_description()? { @@ -2014,29 +2006,21 @@ fn serialize_account_status( status: &AccountStatus, mode: SerializationMode, ) { - serialize_field( - map, - name, - match status { - AccountStatus::AccStateUninit => 0b00, - AccountStatus::AccStateFrozen => 0b10, - AccountStatus::AccStateActive => 0b01, - AccountStatus::AccStateNonexist => 0b11, - }, - ); + serialize_field(map, name, match status { + AccountStatus::AccStateUninit => 0b00, + AccountStatus::AccStateFrozen => 0b10, + AccountStatus::AccStateActive => 0b01, + AccountStatus::AccStateNonexist => 0b11, + }); if mode.is_q_server() { let name = format!("{}_name", name); - serialize_field( - map, - &name, - match status { - AccountStatus::AccStateUninit => "Uninit", - AccountStatus::AccStateFrozen => "Frozen", - AccountStatus::AccStateActive => "Active", - AccountStatus::AccStateNonexist => "NonExist", - }, - ); + serialize_field(map, &name, match status { + AccountStatus::AccStateUninit => "Uninit", + AccountStatus::AccStateFrozen => "Frozen", + AccountStatus::AccStateActive => "Active", + AccountStatus::AccStateNonexist => "NonExist", + }); } } @@ -2216,20 +2200,16 @@ pub fn db_serialize_message_ex( serialize_field(&mut map, "boc", base64_encode(&set.boc)); serialize_field(&mut map, "status", set.status as u8); if mode.is_q_server() { - serialize_field( - &mut map, - "status_name", - match set.status { - MessageProcessingStatus::Unknown => "unknown", - MessageProcessingStatus::Queued => "queued", - MessageProcessingStatus::Processing => "processing", - MessageProcessingStatus::Preliminary => "preliminary", - MessageProcessingStatus::Proposed => "proposed", - MessageProcessingStatus::Finalized => "finalized", - MessageProcessingStatus::Refused => "refused", - MessageProcessingStatus::Transiting => "transiting", - }, - ); + serialize_field(&mut map, "status_name", match set.status { + MessageProcessingStatus::Unknown => "unknown", + MessageProcessingStatus::Queued => "queued", + MessageProcessingStatus::Processing => "processing", + MessageProcessingStatus::Preliminary => "preliminary", + MessageProcessingStatus::Proposed => "proposed", + MessageProcessingStatus::Finalized => "finalized", + MessageProcessingStatus::Refused => "refused", + MessageProcessingStatus::Transiting => "transiting", + }); } if let Some(state) = &set.message.state_init() { if let Some(split_depth) = state.split_depth() { diff --git a/tvm_block_json/src/tests/test_deserialize.rs b/tvm_block_json/src/tests/test_deserialize.rs index e6b5ed536..9cc54aa15 100644 --- a/tvm_block_json/src/tests/test_deserialize.rs +++ b/tvm_block_json/src/tests/test_deserialize.rs @@ -20,9 +20,9 @@ use tvm_types::BuilderData; use tvm_types::IBitstring; use super::*; +use crate::SerializationMode; use crate::serialize_config; use crate::serialize_config_param; -use crate::SerializationMode; include!("./test_common.rs"); diff --git a/tvm_block_json/src/tests/test_parser.rs b/tvm_block_json/src/tests/test_parser.rs index cdfd47ee3..0a3b51d33 100644 --- a/tvm_block_json/src/tests/test_parser.rs +++ b/tvm_block_json/src/tests/test_parser.rs @@ -24,9 +24,9 @@ use tvm_block::OutMsg; use tvm_types::read_single_root_boc; use super::*; -use crate::block_parser::reducers::JsonFieldsReducer; -use crate::block_parser::MINTER_ADDRESS; use crate::NoTrace; +use crate::block_parser::MINTER_ADDRESS; +use crate::block_parser::reducers::JsonFieldsReducer; #[derive(Default)] pub struct ParseOptions { diff --git a/tvm_block_json/src/tests/test_reducers.rs b/tvm_block_json/src/tests/test_reducers.rs index b9860dc18..b10f9e0b6 100644 --- a/tvm_block_json/src/tests/test_reducers.rs +++ b/tvm_block_json/src/tests/test_reducers.rs @@ -33,15 +33,12 @@ fn test_config_parser() { assert_eq!(ReduceConfig::parse_str("a").unwrap(), minimal.clone()); - assert_eq!( - ReduceConfig::parse_str("{a b {c}}").unwrap(), - ReduceConfig { - fields: vec![ - Field::Scalar("a".to_owned()), - Field::Object("b".to_owned(), vec![Field::Scalar("c".to_owned())]) - ] - } - ); + assert_eq!(ReduceConfig::parse_str("{a b {c}}").unwrap(), ReduceConfig { + fields: vec![ + Field::Scalar("a".to_owned()), + Field::Object("b".to_owned(), vec![Field::Scalar("c".to_owned())]) + ] + }); assert_eq!( ReduceConfig::parse_str( @@ -61,26 +58,20 @@ fn test_config_parser() { fields: vec![ Field::Scalar("a".to_owned()), Field::Object("b".to_owned(), vec![Field::Scalar("c".to_owned())]), - Field::Object( - "d".to_owned(), - vec![ - Field::Object( - "e".to_owned(), - vec![Field::Scalar("f".to_owned()), Field::Scalar("g".to_owned()),] - ), - Field::Scalar("j".to_owned()), - Field::Scalar("k".to_owned()), - Field::Scalar("l".to_owned()), - Field::Object( - "m".to_owned(), - vec![ - Field::Scalar("o".to_owned()), - Field::Scalar("p".to_owned()), - Field::Scalar("q".to_owned()), - ] - ), - ] - ), + Field::Object("d".to_owned(), vec![ + Field::Object("e".to_owned(), vec![ + Field::Scalar("f".to_owned()), + Field::Scalar("g".to_owned()), + ]), + Field::Scalar("j".to_owned()), + Field::Scalar("k".to_owned()), + Field::Scalar("l".to_owned()), + Field::Object("m".to_owned(), vec![ + Field::Scalar("o".to_owned()), + Field::Scalar("p".to_owned()), + Field::Scalar("q".to_owned()), + ]), + ]), Field::Scalar("r".to_owned()), ] } diff --git a/tvm_block_json/src/tests/test_serialize.rs b/tvm_block_json/src/tests/test_serialize.rs index bd6f0faa0..6a3092135 100644 --- a/tvm_block_json/src/tests/test_serialize.rs +++ b/tvm_block_json/src/tests/test_serialize.rs @@ -16,10 +16,10 @@ use std::fs::read; use std::path::Path; use pretty_assertions::assert_eq; -use tvm_api::ton::ton_node::rempmessagestatus; use tvm_api::IntoBoxed; -use tvm_types::base64_decode; +use tvm_api::ton::ton_node::rempmessagestatus; use tvm_types::IBitstring; +use tvm_types::base64_decode; use super::*; @@ -1280,10 +1280,8 @@ fn test_crafted_key_block_into_json() { #[test] fn test_db_serialize_block_signatures() { - let doc = serde_json::to_string_pretty(&serde_json::json!(db_serialize_block_signatures( - "_id", - &UInt256::from([1; 32]), - &[ + let doc = serde_json::to_string_pretty(&serde_json::json!( + db_serialize_block_signatures("_id", &UInt256::from([1; 32]), &[ CryptoSignaturePair::with_params( UInt256::from([2; 32]), CryptoSignature::from_r_s(&[3; 32], &[4; 32]).unwrap() @@ -1292,9 +1290,9 @@ fn test_db_serialize_block_signatures() { UInt256::from([5; 32]), CryptoSignature::from_r_s(&[6; 32], &[7; 32]).unwrap() ) - ] - ) - .unwrap())) + ]) + .unwrap() + )) .unwrap(); println!("{}", doc); @@ -1367,10 +1365,9 @@ fn test_db_serialize_block_proof() { let proof = BlockProof::construct_from_cell(cell).unwrap(); - let json = serde_json::to_string_pretty(&serde_json::json!(db_serialize_block_proof( - "_id", &proof - ) - .unwrap())) + let json = serde_json::to_string_pretty(&serde_json::json!( + db_serialize_block_proof("_id", &proof).unwrap() + )) .unwrap(); assert_json_eq_file(&json, "proof"); diff --git a/tvm_cli/rustfmt.toml b/tvm_cli/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_cli/rustfmt.toml +++ b/tvm_cli/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_cli/src/account.rs b/tvm_cli/src/account.rs index 3db3e3215..e3ba46df0 100644 --- a/tvm_cli/src/account.rs +++ b/tvm_cli/src/account.rs @@ -11,18 +11,18 @@ use std::collections::BTreeMap; use std::sync::Arc; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_block::Account; use tvm_block::Deserializable; use tvm_block::Serializable; use tvm_client::error::ClientError; -use tvm_client::net::query_collection; use tvm_client::net::ParamsOfQueryCollection; use tvm_client::net::ParamsOfSubscribeCollection; use tvm_client::net::ResultOfSubscription; -use tvm_client::utils::calc_storage_fee; +use tvm_client::net::query_collection; use tvm_client::utils::ParamsOfCalcStorageFee; +use tvm_client::utils::calc_storage_fee; use tvm_types::base64_decode; use crate::config::Config; @@ -72,16 +72,13 @@ async fn query_accounts( }); } it += cnt; - let mut query_result = query_collection( - ton.clone(), - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(filter), - result: fields.to_string(), - limit: Some(cnt as u32), - ..Default::default() - }, - ) + let mut query_result = query_collection(ton.clone(), ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(filter), + result: fields.to_string(), + limit: Some(cnt as u32), + ..Default::default() + }) .await .map_err(|e| format!("failed to query account info: {}", e))?; res.append(query_result.result.as_mut()); @@ -311,10 +308,11 @@ pub async fn calc_storage(config: &Config, addr: &str, period: u32) -> Result<() let boc = query_account_field(ton.clone(), addr, "boc").await?; - let res = calc_storage_fee( - ton.clone(), - ParamsOfCalcStorageFee { account: boc, period, ..Default::default() }, - ) + let res = calc_storage_fee(ton.clone(), ParamsOfCalcStorageFee { + account: boc, + period, + ..Default::default() + }) .await .map_err(|e| format!("failed to calculate storage fee: {}", e))?; @@ -386,21 +384,18 @@ pub async fn wait_for_change( ) -> Result<(), String> { let context = create_client_verbose(config)?; - let query = tvm_client::net::query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(serde_json::json!({ - "id": { - "eq": account_address - } - })), - limit: None, - order: None, - result: "last_trans_lt".to_owned(), - ..Default::default() - }, - ) + let query = tvm_client::net::query_collection(context.clone(), ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(serde_json::json!({ + "id": { + "eq": account_address + } + })), + limit: None, + order: None, + result: "last_trans_lt".to_owned(), + ..Default::default() + }) .await .map_err(|e| format!("Failed to query the account: {}", e))?; diff --git a/tvm_cli/src/call.rs b/tvm_cli/src/call.rs index d75965450..d3cbad916 100644 --- a/tvm_cli/src/call.rs +++ b/tvm_cli/src/call.rs @@ -10,33 +10,34 @@ // limitations under the License. use std::str::FromStr; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_abi::ParamType; use tvm_block::Account; use tvm_block::Serializable; -use tvm_client::abi::decode_message; -use tvm_client::abi::encode_message; use tvm_client::abi::Abi; use tvm_client::abi::ParamsOfDecodeMessage; use tvm_client::abi::ParamsOfEncodeMessage; +use tvm_client::abi::decode_message; +use tvm_client::abi::encode_message; use tvm_client::error::ClientError; -use tvm_client::processing::send_message; -use tvm_client::processing::wait_for_transaction; use tvm_client::processing::ParamsOfProcessMessage; use tvm_client::processing::ParamsOfSendMessage; use tvm_client::processing::ParamsOfWaitForTransaction; use tvm_client::processing::ProcessingEvent; -use tvm_client::tvm::run_executor; +use tvm_client::processing::send_message; +use tvm_client::processing::wait_for_transaction; use tvm_client::tvm::AccountForExecutor; use tvm_client::tvm::ParamsOfRunExecutor; +use tvm_client::tvm::run_executor; use tvm_types::base64_encode; use crate::config::Config; use crate::convert; +use crate::debug::DebugParams; use crate::debug::debug_error; use crate::debug::init_debug_logger; -use crate::debug::DebugParams; +use crate::helpers::TonClient; use crate::helpers::create_client; use crate::helpers::create_client_verbose; use crate::helpers::get_blockchain_config; @@ -44,21 +45,21 @@ use crate::helpers::load_abi; use crate::helpers::load_ton_abi; use crate::helpers::now_ms; use crate::helpers::query_account_field; -use crate::helpers::TonClient; +use crate::message::EncodedMessage; use crate::message::prepare_message_params; use crate::message::print_encoded_message; use crate::message::unpack_message; -use crate::message::EncodedMessage; async fn decode_call_parameters( ton: TonClient, msg: &EncodedMessage, abi: Abi, ) -> Result<(String, String), String> { - let result = decode_message( - ton, - ParamsOfDecodeMessage { abi, message: msg.message.clone(), ..Default::default() }, - ) + let result = decode_message(ton, ParamsOfDecodeMessage { + abi, + message: msg.message.clone(), + ..Default::default() + }) .map_err(|e| format!("couldn't decode message: {}", e))?; Ok((result.name, format!("{:#}", result.value.unwrap_or(json!({}))))) @@ -145,17 +146,14 @@ pub async fn emulate_locally( } else { state = state_boc.unwrap(); } - let res = run_executor( - ton.clone(), - ParamsOfRunExecutor { - message: msg.clone(), - account: AccountForExecutor::Account { - boc: state, - unlimited_balance: if is_fee { Some(true) } else { None }, - }, - ..Default::default() + let res = run_executor(ton.clone(), ParamsOfRunExecutor { + message: msg.clone(), + account: AccountForExecutor::Account { + boc: state, + unlimited_balance: if is_fee { Some(true) } else { None }, }, - ) + ..Default::default() + }) .await; if res.is_err() { @@ -173,7 +171,7 @@ pub async fn emulate_locally( println!("}}"); } else { println!("Local run succeeded. Executing onchain."); // TODO: check - // is_json + // is_json } Ok(()) } diff --git a/tvm_cli/src/config.rs b/tvm_cli/src/config.rs index bafbe7f89..5b69e5bcc 100644 --- a/tvm_cli/src/config.rs +++ b/tvm_cli/src/config.rs @@ -586,9 +586,9 @@ pub fn set_config( #[cfg(test)] mod tests { - use super::resolve_net_name; use super::MAINNET; use super::TESTNET; + use super::resolve_net_name; #[test] fn test_endpoints_resolver() { diff --git a/tvm_cli/src/crypto.rs b/tvm_cli/src/crypto.rs index fb7212f42..1d69d303f 100644 --- a/tvm_cli/src/crypto.rs +++ b/tvm_cli/src/crypto.rs @@ -8,11 +8,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_client::crypto::hdkey_derive_from_xprv_path; -use tvm_client::crypto::hdkey_secret_from_xprv; -use tvm_client::crypto::hdkey_xprv_from_mnemonic; -use tvm_client::crypto::mnemonic_from_random; -use tvm_client::crypto::nacl_sign_keypair_from_secret_key; use tvm_client::crypto::KeyPair; use tvm_client::crypto::MnemonicDictionary; use tvm_client::crypto::ParamsOfHDKeyDeriveFromXPrvPath; @@ -20,13 +15,18 @@ use tvm_client::crypto::ParamsOfHDKeySecretFromXPrv; use tvm_client::crypto::ParamsOfHDKeyXPrvFromMnemonic; use tvm_client::crypto::ParamsOfMnemonicFromRandom; use tvm_client::crypto::ParamsOfNaclSignKeyPairFromSecret; +use tvm_client::crypto::hdkey_derive_from_xprv_path; +use tvm_client::crypto::hdkey_secret_from_xprv; +use tvm_client::crypto::hdkey_xprv_from_mnemonic; +use tvm_client::crypto::mnemonic_from_random; +use tvm_client::crypto::nacl_sign_keypair_from_secret_key; +use crate::Config; +use crate::helpers::HD_PATH; +use crate::helpers::WORD_COUNT; use crate::helpers::check_dir; use crate::helpers::create_client_local; use crate::helpers::read_keys; -use crate::helpers::HD_PATH; -use crate::helpers::WORD_COUNT; -use crate::Config; pub fn load_keypair(keys: &str) -> Result { if keys.find(' ').is_none() { @@ -39,52 +39,44 @@ pub fn load_keypair(keys: &str) -> Result { pub fn gen_seed_phrase() -> Result { let client = create_client_local()?; - mnemonic_from_random( - client, - ParamsOfMnemonicFromRandom { - dictionary: Some(MnemonicDictionary::English), - word_count: Some(WORD_COUNT), - ..Default::default() - }, - ) + mnemonic_from_random(client, ParamsOfMnemonicFromRandom { + dictionary: Some(MnemonicDictionary::English), + word_count: Some(WORD_COUNT), + ..Default::default() + }) .map_err(|e| format!("{}", e)) .map(|r| r.phrase) } pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result { let client = create_client_local()?; - let hdk_master = hdkey_xprv_from_mnemonic( - client.clone(), - ParamsOfHDKeyXPrvFromMnemonic { - dictionary: Some(MnemonicDictionary::English), - word_count: Some(WORD_COUNT), - phrase: mnemonic.to_string(), - ..Default::default() - }, - ) + let hdk_master = hdkey_xprv_from_mnemonic(client.clone(), ParamsOfHDKeyXPrvFromMnemonic { + dictionary: Some(MnemonicDictionary::English), + word_count: Some(WORD_COUNT), + phrase: mnemonic.to_string(), + ..Default::default() + }) .map_err(|e| format!("{}", e))?; - let hdk_root = hdkey_derive_from_xprv_path( - client.clone(), - ParamsOfHDKeyDeriveFromXPrvPath { - xprv: hdk_master.xprv.clone(), - path: HD_PATH.to_string(), - ..Default::default() - }, - ) + let hdk_root = hdkey_derive_from_xprv_path(client.clone(), ParamsOfHDKeyDeriveFromXPrvPath { + xprv: hdk_master.xprv.clone(), + path: HD_PATH.to_string(), + ..Default::default() + }) .map_err(|e| format!("{}", e))?; - let secret = hdkey_secret_from_xprv( - client.clone(), - ParamsOfHDKeySecretFromXPrv { xprv: hdk_root.xprv.clone(), ..Default::default() }, - ) + let secret = hdkey_secret_from_xprv(client.clone(), ParamsOfHDKeySecretFromXPrv { + xprv: hdk_root.xprv.clone(), + ..Default::default() + }) .map_err(|e| format!("{}", e))?; - let mut keypair: KeyPair = nacl_sign_keypair_from_secret_key( - client, - ParamsOfNaclSignKeyPairFromSecret { secret: secret.secret.clone(), ..Default::default() }, - ) - .map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; + let mut keypair: KeyPair = + nacl_sign_keypair_from_secret_key(client, ParamsOfNaclSignKeyPairFromSecret { + secret: secret.secret.clone(), + ..Default::default() + }) + .map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; // special case if secret contains public key too. let secret = @@ -97,11 +89,12 @@ pub fn generate_keypair_from_mnemonic(mnemonic: &str) -> Result pub fn generate_keypair_from_secret(secret: String) -> Result { let client = create_client_local()?; - let mut keypair: KeyPair = nacl_sign_keypair_from_secret_key( - client, - ParamsOfNaclSignKeyPairFromSecret { secret, ..Default::default() }, - ) - .map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; + let mut keypair: KeyPair = + nacl_sign_keypair_from_secret_key(client, ParamsOfNaclSignKeyPairFromSecret { + secret, + ..Default::default() + }) + .map_err(|e| format!("failed to get KeyPair from secret key: {}", e))?; // special case if secret contains public key too. let secret = hex::decode(&keypair.secret).map_err(|e| format!("failed to decode the keypair: {}", e))?; diff --git a/tvm_cli/src/debot/callbacks.rs b/tvm_cli/src/debot/callbacks.rs index 63dc675a3..f7bb83b86 100644 --- a/tvm_cli/src/debot/callbacks.rs +++ b/tvm_cli/src/debot/callbacks.rs @@ -20,12 +20,12 @@ use tvm_client::debot::DebotActivity; use tvm_client::debot::STATE_EXIT; use tvm_client::error::ClientResult; +use super::ChainProcessor; +use super::ProcessorError; use super::action_input; use super::input; use super::term_signing_box::TerminalSigningBox; use super::terminal_input; -use super::ChainProcessor; -use super::ProcessorError; use crate::config::Config; use crate::convert::convert_u64_to_tokens; use crate::helpers::TonClient; diff --git a/tvm_cli/src/debot/interfaces/address_input.rs b/tvm_cli/src/debot/interfaces/address_input.rs index af35f0052..03883293f 100644 --- a/tvm_cli/src/debot/interfaces/address_input.rs +++ b/tvm_cli/src/debot/interfaces/address_input.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/amount_input.rs b/tvm_cli/src/debot/interfaces/amount_input.rs index 4fa923d21..0ff70d3c4 100644 --- a/tvm_cli/src/debot/interfaces/amount_input.rs +++ b/tvm_cli/src/debot/interfaces/amount_input.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/confirm_input.rs b/tvm_cli/src/debot/interfaces/confirm_input.rs index 967bc0ada..f2d275329 100644 --- a/tvm_cli/src/debot/interfaces/confirm_input.rs +++ b/tvm_cli/src/debot/interfaces/confirm_input.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/dinterface.rs b/tvm_cli/src/debot/interfaces/dinterface.rs index 72ab04a46..c503a7252 100644 --- a/tvm_cli/src/debot/interfaces/dinterface.rs +++ b/tvm_cli/src/debot/interfaces/dinterface.rs @@ -10,8 +10,6 @@ use tvm_client::debot::DebotInterfaceExecutor; use tvm_client::encoding::decode_abi_bigint; use tvm_client::encoding::decode_abi_number; -use super::echo::Echo; -use super::stdout::Stdout; use super::AddressInput; use super::AmountInput; use super::ConfirmInput; @@ -22,6 +20,8 @@ use super::NumberInput; use super::SigningBoxInput; use super::Terminal; use super::UserInfo; +use super::echo::Echo; +use super::stdout::Stdout; use crate::config::Config; use crate::debot::ChainProcessor; use crate::helpers::TonClient; diff --git a/tvm_cli/src/debot/interfaces/echo.rs b/tvm_cli/src/debot/interfaces/echo.rs index 0f038501c..596682bbd 100644 --- a/tvm_cli/src/debot/interfaces/echo.rs +++ b/tvm_cli/src/debot/interfaces/echo.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/encryption_box_input.rs b/tvm_cli/src/debot/interfaces/encryption_box_input.rs index 5b26d4ab8..aa88496ac 100644 --- a/tvm_cli/src/debot/interfaces/encryption_box_input.rs +++ b/tvm_cli/src/debot/interfaces/encryption_box_input.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tokio::sync::RwLock; use tvm_client::abi::Abi; use tvm_client::crypto::EncryptionBoxHandle; diff --git a/tvm_cli/src/debot/interfaces/input_interface.rs b/tvm_cli/src/debot/interfaces/input_interface.rs index 1a5a0d483..9f81712d2 100644 --- a/tvm_cli/src/debot/interfaces/input_interface.rs +++ b/tvm_cli/src/debot/interfaces/input_interface.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tokio::sync::RwLock; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; @@ -10,8 +10,8 @@ use tvm_client::debot::InterfaceResult; use super::dinterface::decode_answer_id; use super::dinterface::decode_prompt; use super::dinterface::decode_string_arg; -use super::menu::MenuItem; use super::menu::ID as MENU_ID; +use super::menu::MenuItem; use super::terminal::ID as TERMINAL_ID; use crate::debot::ChainProcessor; use crate::debot::ProcessorError; diff --git a/tvm_cli/src/debot/interfaces/menu.rs b/tvm_cli/src/debot/interfaces/menu.rs index b4b0dd5fe..8046dbd89 100644 --- a/tvm_cli/src/debot/interfaces/menu.rs +++ b/tvm_cli/src/debot/interfaces/menu.rs @@ -1,8 +1,8 @@ -use serde::de; use serde::Deserialize; use serde::Deserializer; -use serde_json::json; +use serde::de; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/number_input.rs b/tvm_cli/src/debot/interfaces/number_input.rs index f1f23260b..79768856d 100644 --- a/tvm_cli/src/debot/interfaces/number_input.rs +++ b/tvm_cli/src/debot/interfaces/number_input.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/signing_box_input.rs b/tvm_cli/src/debot/interfaces/signing_box_input.rs index 6f332dc23..c9339f7d2 100644 --- a/tvm_cli/src/debot/interfaces/signing_box_input.rs +++ b/tvm_cli/src/debot/interfaces/signing_box_input.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tokio::sync::RwLock; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; @@ -11,9 +11,9 @@ use tvm_client::encoding::decode_abi_bigint; use super::dinterface::decode_answer_id; use super::dinterface::decode_array; use super::dinterface::decode_prompt; -use crate::debot::term_signing_box::TerminalSigningBox; use crate::debot::ChainProcessor; use crate::debot::ProcessorError; +use crate::debot::term_signing_box::TerminalSigningBox; use crate::helpers::TonClient; pub const ID: &str = "c13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"; diff --git a/tvm_cli/src/debot/interfaces/stdout.rs b/tvm_cli/src/debot/interfaces/stdout.rs index 57a48863e..b34678457 100644 --- a/tvm_cli/src/debot/interfaces/stdout.rs +++ b/tvm_cli/src/debot/interfaces/stdout.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/interfaces/terminal.rs b/tvm_cli/src/debot/interfaces/terminal.rs index f4ac8e509..107739e2f 100644 --- a/tvm_cli/src/debot/interfaces/terminal.rs +++ b/tvm_cli/src/debot/interfaces/terminal.rs @@ -1,17 +1,17 @@ use std::io::Read; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; use tvm_client::encoding::decode_abi_bigint; +use super::dinterface::Printer; use super::dinterface::decode_answer_id; use super::dinterface::decode_bool_arg; use super::dinterface::decode_prompt; use super::dinterface::decode_string_arg; -use super::dinterface::Printer; use crate::convert::convert_token; use crate::debot::term_browser::terminal_input; diff --git a/tvm_cli/src/debot/interfaces/userinfo.rs b/tvm_cli/src/debot/interfaces/userinfo.rs index f94bb3a0d..6d845fa29 100644 --- a/tvm_cli/src/debot/interfaces/userinfo.rs +++ b/tvm_cli/src/debot/interfaces/userinfo.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_client::abi::Abi; use tvm_client::debot::DebotInterface; use tvm_client::debot::InterfaceResult; diff --git a/tvm_cli/src/debot/term_browser.rs b/tvm_cli/src/debot/term_browser.rs index 23bdcc331..98e330ff2 100644 --- a/tvm_cli/src/debot/term_browser.rs +++ b/tvm_cli/src/debot/term_browser.rs @@ -16,30 +16,30 @@ use std::io::{self}; use std::sync::Arc; use serde_json::json; -use tvm_client::abi::decode_message; -use tvm_client::abi::encode_internal_message; use tvm_client::abi::Abi; use tvm_client::abi::CallSet; use tvm_client::abi::ParamsOfDecodeMessage; use tvm_client::abi::ParamsOfEncodeInternalMessage; -use tvm_client::boc::parse_message; +use tvm_client::abi::decode_message; +use tvm_client::abi::encode_internal_message; use tvm_client::boc::ParamsOfParse; +use tvm_client::boc::parse_message; +use tvm_client::debot::DEBOT_WC; use tvm_client::debot::DEngine; use tvm_client::debot::DebotInfo; use tvm_client::debot::DebotInterfaceExecutor; -use tvm_client::debot::DEBOT_WC; -use super::term_signing_box::TerminalSigningBox; use super::Callbacks; use super::ChainLink; use super::ChainProcessor; use super::PipeChain; use super::SupportedInterfaces; +use super::term_signing_box::TerminalSigningBox; use crate::config::Config; +use crate::helpers::TonClient; use crate::helpers::create_client; use crate::helpers::load_abi; use crate::helpers::load_ton_address; -use crate::helpers::TonClient; const BROWSER_ID: &str = "0000000000000000000000000000000000000000000000000000000000000000"; /// Stores Debot info needed for DBrowser. @@ -100,17 +100,14 @@ impl TerminalBrowser { if !start && init_message.is_none() { init_message = Some( - encode_internal_message( - browser.client.clone(), - ParamsOfEncodeInternalMessage { - abi: Some(abi), - address: Some(addr.to_owned()), - src_address: Some(format!("{}:{}", DEBOT_WC, BROWSER_ID)), - call_set, - value: "1000000000000000".to_owned(), - ..Default::default() - }, - ) + encode_internal_message(browser.client.clone(), ParamsOfEncodeInternalMessage { + abi: Some(abi), + address: Some(addr.to_owned()), + src_address: Some(format!("{}:{}", DEBOT_WC, BROWSER_ID)), + call_set, + value: "1000000000000000".to_owned(), + ..Default::default() + }) .map_err(|e| format!("{}", e))? .message, ); @@ -191,18 +188,16 @@ impl TerminalBrowser { CallSet::some_with_function_and_input(&format!("0x{:x}", func_id), return_args) } }; - let response_msg = encode_internal_message( - self.client.clone(), - ParamsOfEncodeInternalMessage { + let response_msg = + encode_internal_message(self.client.clone(), ParamsOfEncodeInternalMessage { abi: Some(debot.abi.clone()), address: Some(debot_addr.to_owned()), call_set, value: "1000000000000000".to_owned(), ..Default::default() - }, - ) - .map_err(|e| format!("{}", e))? - .message; + }) + .map_err(|e| format!("{}", e))? + .message; let result = debot.dengine.send(response_msg).await; debot.callbacks.take_messages(&mut self.msg_queue); if let Err(e) = result { @@ -240,10 +235,11 @@ impl TerminalBrowser { async fn set_exit_arg(&mut self, message: String, _debot_addr: &str) -> Result<(), String> { let abi = self.processor.read().await.abi(); let arg = if let Some(abi) = abi { - let decoded = decode_message( - self.client.clone(), - ParamsOfDecodeMessage { abi, message, ..Default::default() }, - ) + let decoded = decode_message(self.client.clone(), ParamsOfDecodeMessage { + abi, + message, + ..Default::default() + }) .map_err(|e| format!("{}", e))?; decoded.value.unwrap_or(json!({})) } else { @@ -342,10 +338,10 @@ pub async fn run_debot_browser( loop { let mut next_msg = browser.msg_queue.pop_front(); while let Some(msg) = next_msg { - let parsed = parse_message( - ton.clone(), - ParamsOfParse { boc: msg.clone(), ..Default::default() }, - ) + let parsed = parse_message(ton.clone(), ParamsOfParse { + boc: msg.clone(), + ..Default::default() + }) .map_err(|e| format!("{}", e))? .parsed; diff --git a/tvm_cli/src/debot/term_encryption_box.rs b/tvm_cli/src/debot/term_encryption_box.rs index a747a4698..1e7ee8d54 100644 --- a/tvm_cli/src/debot/term_encryption_box.rs +++ b/tvm_cli/src/debot/term_encryption_box.rs @@ -1,7 +1,5 @@ use std::io::{self}; -use tvm_client::crypto::register_encryption_box; -use tvm_client::crypto::remove_encryption_box; use tvm_client::crypto::ChaCha20EncryptionBox; use tvm_client::crypto::ChaCha20ParamsEB; use tvm_client::crypto::EncryptionBoxHandle; @@ -10,11 +8,13 @@ use tvm_client::crypto::NaclEncryptionBox; use tvm_client::crypto::NaclSecretBoxParamsEB; use tvm_client::crypto::NaclSecretEncryptionBox; use tvm_client::crypto::RegisteredEncryptionBox; +use tvm_client::crypto::register_encryption_box; +use tvm_client::crypto::remove_encryption_box; use super::term_browser::input; use crate::crypto::load_keypair; -use crate::helpers::TonClient; use crate::helpers::HD_PATH; +use crate::helpers::TonClient; #[derive(Clone, Copy)] pub(crate) enum EncryptionBoxType { @@ -38,10 +38,9 @@ pub(super) struct TerminalEncryptionBox { impl Drop for TerminalEncryptionBox { fn drop(&mut self) { if self.handle.0 != 0 { - let _ = remove_encryption_box( - self.client.clone(), - RegisteredEncryptionBox { handle: self.handle() }, - ); + let _ = remove_encryption_box(self.client.clone(), RegisteredEncryptionBox { + handle: self.handle(), + }); } } } diff --git a/tvm_cli/src/debot/term_signing_box.rs b/tvm_cli/src/debot/term_signing_box.rs index 9a6fbe4e1..9282671fb 100644 --- a/tvm_cli/src/debot/term_signing_box.rs +++ b/tvm_cli/src/debot/term_signing_box.rs @@ -4,16 +4,16 @@ use std::io::Read; use std::io::Write; use std::io::{self}; -use tvm_client::crypto::get_signing_box; -use tvm_client::crypto::remove_signing_box; use tvm_client::crypto::KeyPair; use tvm_client::crypto::RegisteredSigningBox; use tvm_client::crypto::SigningBoxHandle; +use tvm_client::crypto::get_signing_box; +use tvm_client::crypto::remove_signing_box; use super::term_browser::input; use crate::crypto::load_keypair; -use crate::helpers::read_keys; use crate::helpers::TonClient; +use crate::helpers::read_keys; pub(super) struct TerminalSigningBox { handle: SigningBoxHandle, @@ -69,10 +69,9 @@ impl TerminalSigningBox { impl Drop for TerminalSigningBox { fn drop(&mut self) { if self.handle.0 != 0 { - let _ = remove_signing_box( - self.client.clone(), - RegisteredSigningBox { handle: self.handle.clone() }, - ); + let _ = remove_signing_box(self.client.clone(), RegisteredSigningBox { + handle: self.handle.clone(), + }); } } } diff --git a/tvm_cli/src/debug.rs b/tvm_cli/src/debug.rs index fcca4602b..cf78ab80a 100644 --- a/tvm_cli/src/debug.rs +++ b/tvm_cli/src/debug.rs @@ -14,15 +14,15 @@ use std::fmt; use std::fs::File; use std::io::BufRead; use std::io::Write; -use std::sync::atomic::AtomicU64; use std::sync::Arc; +use std::sync::atomic::AtomicU64; use clap::App; use clap::Arg; use clap::ArgMatches; use clap::SubCommand; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_assembler::DbgInfo; use tvm_block::Account; use tvm_block::ConfigParamEnum; @@ -36,30 +36,31 @@ use tvm_block::Serializable; use tvm_block::TrComputePhase; use tvm_block::Transaction; use tvm_block::TransactionTickTock; -use tvm_client::abi::encode_message; use tvm_client::abi::CallSet; use tvm_client::abi::FunctionHeader; use tvm_client::abi::ParamsOfEncodeMessage; use tvm_client::abi::Signer; +use tvm_client::abi::encode_message; use tvm_client::boc::internal::deserialize_cell_from_base64; use tvm_client::error::ClientError; -use tvm_client::net::query_collection; use tvm_client::net::OrderBy; use tvm_client::net::ParamsOfQueryCollection; use tvm_client::net::SortDirection; +use tvm_client::net::query_collection; use tvm_executor::BlockchainConfig; use tvm_executor::ExecuteParams; use tvm_executor::OrdinaryTransactionExecutor; use tvm_executor::TickTockTransactionExecutor; use tvm_executor::TransactionExecutor; -use tvm_types::base64_encode; use tvm_types::AccountId; use tvm_types::Cell; use tvm_types::UInt256; +use tvm_types::base64_encode; use tvm_vm::executor::Engine; use tvm_vm::executor::EngineTraceInfo; use tvm_vm::executor::EngineTraceInfoType; +use crate::FullConfig; use crate::config::Config; use crate::contract_data_from_matches_or_config_alias; use crate::crypto::load_keypair; @@ -81,14 +82,13 @@ use crate::helpers::query_with_limit; use crate::helpers::wc_from_matches_or_config; use crate::message::prepare_message; use crate::print_args; -use crate::replay::fetch; -use crate::replay::replay; use crate::replay::CONFIG_ADDR; use crate::replay::DUMP_ACCOUNT; use crate::replay::DUMP_CONFIG; use crate::replay::DUMP_NONE; +use crate::replay::fetch; +use crate::replay::replay; use crate::unpack_alternative_params; -use crate::FullConfig; const SDK_EXECUTION_ERROR_CODE: u32 = 414; pub const DEFAULT_TRACE_PATH: &str = "./trace.log"; @@ -565,21 +565,18 @@ async fn replay_transaction_command( } let ton_client = create_client(config)?; - let trans = query_collection( - ton_client.clone(), - ParamsOfQueryCollection { - collection: "transactions".to_owned(), - filter: Some(json!({ - "id": { - "eq": tx_id.unwrap() - }, - })), - result: "lt block { start_lt } boc".to_string(), - limit: Some(1), - order: None, - ..Default::default() - }, - ) + let trans = query_collection(ton_client.clone(), ParamsOfQueryCollection { + collection: "transactions".to_owned(), + filter: Some(json!({ + "id": { + "eq": tx_id.unwrap() + }, + })), + result: "lt block { start_lt } boc".to_string(), + limit: Some(1), + order: None, + ..Default::default() + }) .await .map_err(|e| format!("Failed to query transaction: {}", e))?; @@ -1438,26 +1435,23 @@ async fn fetch_transactions( let mut lt = String::from("0x0"); loop { let action = || async { - query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "transactions".to_owned(), - filter: Some(json!({ - "account_addr": { - "eq": address.clone() - }, - "lt": { - "gt": lt - } - })), - result: "lt boc id workchain_id".to_owned(), - order: Some(vec![OrderBy { - path: "lt".to_owned(), - direction: SortDirection::ASC, - }]), - limit: None, - }, - ) + query_collection(context.clone(), ParamsOfQueryCollection { + collection: "transactions".to_owned(), + filter: Some(json!({ + "account_addr": { + "eq": address.clone() + }, + "lt": { + "gt": lt + } + })), + result: "lt boc id workchain_id".to_owned(), + order: Some(vec![OrderBy { + path: "lt".to_owned(), + direction: SortDirection::ASC, + }]), + limit: None, + }) .await }; diff --git a/tvm_cli/src/decode.rs b/tvm_cli/src/decode.rs index e71394e1c..e5ce6b2e3 100644 --- a/tvm_cli/src/decode.rs +++ b/tvm_cli/src/decode.rs @@ -20,13 +20,13 @@ use tvm_block::AccountStatus; use tvm_block::Deserializable; use tvm_block::Serializable; use tvm_block::StateInit; -use tvm_client::abi::decode_account_data; use tvm_client::abi::ParamsOfDecodeAccountData; +use tvm_client::abi::decode_account_data; +use tvm_types::Cell; +use tvm_types::SliceData; use tvm_types::base64_decode; use tvm_types::read_single_root_boc; use tvm_types::write_boc; -use tvm_types::Cell; -use tvm_types::SliceData; use crate::config::Config; use crate::decode::msg_printer::tree_of_cells_into_base64; @@ -316,10 +316,11 @@ async fn decode_tvc_fields(m: &ArgMatches<'_>, config: &Config) -> Result<(), St .map_err(|e| format!("failed to load StateInit from the tvc file: {}", e))?; let b64 = tree_of_cells_into_base64(state.data.as_ref())?; let ton = create_client_local()?; - let res = decode_account_data( - ton, - ParamsOfDecodeAccountData { abi, data: b64, ..Default::default() }, - ) + let res = decode_account_data(ton, ParamsOfDecodeAccountData { + abi, + data: b64, + ..Default::default() + }) .map_err(|e| format!("failed to decode data: {}", e))?; if !config.is_json { println!("TVC fields:"); @@ -484,23 +485,23 @@ async fn decode_tvc_command(m: &ArgMatches<'_>, config: &Config) -> Result<(), S } pub mod msg_printer { - use serde_json::json; use serde_json::Value; + use serde_json::json; use tvm_block::CommonMsgInfo; use tvm_block::CurrencyCollection; use tvm_block::Grams; use tvm_block::Message; use tvm_block::StateInit; - use tvm_client::boc::get_compiler_version; use tvm_client::boc::ParamsOfGetCompilerVersion; + use tvm_client::boc::get_compiler_version; + use tvm_types::Cell; use tvm_types::base64_encode; use tvm_types::write_boc; - use tvm_types::Cell; + use crate::Config; + use crate::helpers::TonClient; use crate::helpers::create_client_local; use crate::helpers::decode_msg_body; - use crate::helpers::TonClient; - use crate::Config; pub fn tree_of_cells_into_base64(root_cell: Option<&Cell>) -> Result { match root_cell { diff --git a/tvm_cli/src/deploy.rs b/tvm_cli/src/deploy.rs index 41433cd53..53f5aa3ee 100644 --- a/tvm_cli/src/deploy.rs +++ b/tvm_cli/src/deploy.rs @@ -8,16 +8,17 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_client::abi::encode_message; use tvm_client::abi::Abi; use tvm_client::abi::CallSet; use tvm_client::abi::DeploySet; use tvm_client::abi::FunctionHeader; use tvm_client::abi::ParamsOfEncodeMessage; use tvm_client::abi::Signer; +use tvm_client::abi::encode_message; use tvm_client::crypto::KeyPair; use tvm_types::base64_encode; +use crate::Config; use crate::call::emulate_locally; use crate::call::process_message; use crate::call::send_message_and_wait; @@ -27,9 +28,8 @@ use crate::helpers::create_client_local; use crate::helpers::create_client_verbose; use crate::helpers::load_abi; use crate::helpers::now_ms; -use crate::message::display_generated_message; use crate::message::EncodedMessage; -use crate::Config; +use crate::message::display_generated_message; pub async fn deploy_contract( full_config: &mut FullConfig, diff --git a/tvm_cli/src/depool.rs b/tvm_cli/src/depool.rs index 335e22ff1..0f7d50ab7 100644 --- a/tvm_cli/src/depool.rs +++ b/tvm_cli/src/depool.rs @@ -29,6 +29,7 @@ use crate::config::Config; use crate::convert; use crate::depool_abi::DEPOOL_ABI; use crate::depool_abi::PARTICIPANT_ABI; +use crate::helpers::TonClient; use crate::helpers::answer_filter; use crate::helpers::create_client; use crate::helpers::create_client_local; @@ -38,7 +39,6 @@ use crate::helpers::load_abi; use crate::helpers::load_ton_address; use crate::helpers::now; use crate::helpers::print_message; -use crate::helpers::TonClient; use crate::multisig::CallArgs; use crate::multisig::MultisigArgs; use crate::print_args; @@ -398,18 +398,16 @@ impl<'a> DepoolCmd<'a> { ); let client = create_client(self.config)?; - let message = tvm_client::net::wait_for_collection( - client.clone(), - ParamsOfWaitForCollection { + let message = + tvm_client::net::wait_for_collection(client.clone(), ParamsOfWaitForCollection { collection: "messages".to_owned(), filter: Some(answer_filter(&wallet, &depool, since)), result: "id body created_at created_at_string".to_owned(), timeout: Some(self.config.timeout), ..Default::default() - }, - ) - .await - .map_err(|e| println!("failed to query message: {}", e)); + }) + .await + .map_err(|e| println!("failed to query message: {}", e)); if message.is_err() { println!( @@ -444,18 +442,16 @@ impl<'a> DepoolCmd<'a> { statuses.insert(26, "TRANSFER_WHILE_COMPLETING_STEP"); statuses.insert(27, "NO_POOLING_STAKE"); - let message = tvm_client::net::wait_for_collection( - client.clone(), - ParamsOfWaitForCollection { + let message = + tvm_client::net::wait_for_collection(client.clone(), ParamsOfWaitForCollection { collection: "messages".to_owned(), filter: Some(answer_filter(&depool, &wallet, since)), result: "id body created_at created_at_string value".to_owned(), timeout: Some(self.config.timeout), ..Default::default() - }, - ) - .await - .map_err(|e| println!("failed to query answer: {}", e)); + }) + .await + .map_err(|e| println!("failed to query answer: {}", e)); if message.is_ok() { let message = message.unwrap().result; println!("\nAnswer: "); @@ -590,19 +586,16 @@ async fn answer_command(m: &ArgMatches<'_>, config: &Config, depool: &str) -> Re let wallet = load_ton_address(&wallet, config).map_err(|e| format!("invalid depool address: {}", e))?; - let messages = tvm_client::net::query_collection( - ton.clone(), - ParamsOfQueryCollection { - collection: "messages".to_owned(), - filter: Some(answer_filter(depool, &wallet, since)), - result: "id value body created_at created_at_string".to_owned(), - order: Some(vec![OrderBy { - path: "created_at".to_owned(), - direction: SortDirection::DESC, - }]), - ..Default::default() - }, - ) + let messages = tvm_client::net::query_collection(ton.clone(), ParamsOfQueryCollection { + collection: "messages".to_owned(), + filter: Some(answer_filter(depool, &wallet, since)), + result: "id value body created_at created_at_string".to_owned(), + order: Some(vec![OrderBy { + path: "created_at".to_owned(), + direction: SortDirection::DESC, + }]), + ..Default::default() + }) .await .map_err(|e| format!("failed to query depool messages: {}", e))?; println!("{} answers found", messages.result.len()); @@ -645,17 +638,14 @@ async fn print_event(ton: TonClient, event: &serde_json::Value) -> Result<(), St let body = event["body"].as_str().ok_or("failed to serialize event body")?; let def_config = Config::default(); - let result = tvm_client::abi::decode_message_body( - ton.clone(), - ParamsOfDecodeMessageBody { - abi: load_abi(DEPOOL_ABI, &def_config) - .await - .map_err(|e| format!("failed to load depool abi: {}", e))?, - body: body.to_owned(), - is_internal: false, - ..Default::default() - }, - ); + let result = tvm_client::abi::decode_message_body(ton.clone(), ParamsOfDecodeMessageBody { + abi: load_abi(DEPOOL_ABI, &def_config) + .await + .map_err(|e| format!("failed to load depool abi: {}", e))?, + body: body.to_owned(), + is_internal: false, + ..Default::default() + }); let (name, args) = if result.is_err() { ("unknown".to_owned(), "{}".to_owned()) } else { @@ -681,19 +671,16 @@ async fn get_events(config: &Config, depool: &str, since: u32) -> Result<(), Str let ton = create_client_verbose(config)?; let _addr = load_ton_address(depool, config)?; - let events = tvm_client::net::query_collection( - ton.clone(), - ParamsOfQueryCollection { - collection: "messages".to_owned(), - filter: Some(events_filter(depool, since)), - result: "id body created_at created_at_string".to_owned(), - order: Some(vec![OrderBy { - path: "created_at".to_owned(), - direction: SortDirection::DESC, - }]), - ..Default::default() - }, - ) + let events = tvm_client::net::query_collection(ton.clone(), ParamsOfQueryCollection { + collection: "messages".to_owned(), + filter: Some(events_filter(depool, since)), + result: "id body created_at created_at_string".to_owned(), + order: Some(vec![OrderBy { + path: "created_at".to_owned(), + direction: SortDirection::DESC, + }]), + ..Default::default() + }) .await .map_err(|e| format!("failed to query depool events: {}", e))?; println!("{} events found", events.result.len()); @@ -708,16 +695,13 @@ async fn wait_for_event(config: &Config, depool: &str) -> Result<(), String> { let ton = create_client_verbose(config)?; let _addr = load_ton_address(depool, config)?; println!("Waiting for a new event..."); - let event = tvm_client::net::wait_for_collection( - ton.clone(), - ParamsOfWaitForCollection { - collection: "messages".to_owned(), - filter: Some(events_filter(depool, now())), - result: "id body created_at created_at_string".to_owned(), - timeout: Some(config.timeout), - ..Default::default() - }, - ) + let event = tvm_client::net::wait_for_collection(ton.clone(), ParamsOfWaitForCollection { + collection: "messages".to_owned(), + filter: Some(events_filter(depool, now())), + result: "id body created_at created_at_string".to_owned(), + timeout: Some(config.timeout), + ..Default::default() + }) .await .map_err(|e| println!("failed to query event: {}", e)); if event.is_ok() { @@ -729,16 +713,13 @@ async fn wait_for_event(config: &Config, depool: &str) -> Result<(), String> { async fn encode_body(func: &str, params: serde_json::Value) -> Result { let client = create_client_local()?; let def_config = Config::default(); - tvm_client::abi::encode_message_body( - client.clone(), - ParamsOfEncodeMessageBody { - abi: load_abi(DEPOOL_ABI, &def_config).await?, - call_set: CallSet::some_with_function_and_input(func, params) - .ok_or("failed to create CallSet with specified parameters.")?, - is_internal: true, - ..Default::default() - }, - ) + tvm_client::abi::encode_message_body(client.clone(), ParamsOfEncodeMessageBody { + abi: load_abi(DEPOOL_ABI, &def_config).await?, + call_set: CallSet::some_with_function_and_input(func, params) + .ok_or("failed to create CallSet with specified parameters.")?, + is_internal: true, + ..Default::default() + }) .await .map_err(|e| format!("failed to encode body: {}", e)) .map(|r| r.body) diff --git a/tvm_cli/src/genaddr.rs b/tvm_cli/src/genaddr.rs index 0c12b4868..ff5fa9679 100644 --- a/tvm_cli/src/genaddr.rs +++ b/tvm_cli/src/genaddr.rs @@ -11,9 +11,9 @@ use std::fs::OpenOptions; use serde_json::json; -use tvm_client::utils::convert_address; use tvm_client::utils::AddressStringFormat; use tvm_client::utils::ParamsOfConvertAddress; +use tvm_client::utils::convert_address; use crate::config::Config; use crate::crypto::gen_seed_phrase; @@ -139,14 +139,11 @@ pub async fn generate_address( } fn calc_userfriendly_address(address: &str, bounce: bool, test: bool) -> Result { - convert_address( - create_client_local()?, - ParamsOfConvertAddress { - address: address.to_owned(), - output_format: AddressStringFormat::Base64 { url: true, bounce, test }, - ..Default::default() - }, - ) + convert_address(create_client_local()?, ParamsOfConvertAddress { + address: address.to_owned(), + output_format: AddressStringFormat::Base64 { url: true, bounce, test }, + ..Default::default() + }) .map(|r| r.address) .map_err(|e| format!("failed to convert address to base64 form: {}", e)) } diff --git a/tvm_cli/src/getconfig.rs b/tvm_cli/src/getconfig.rs index 5a1d094f5..45b59ff29 100644 --- a/tvm_cli/src/getconfig.rs +++ b/tvm_cli/src/getconfig.rs @@ -10,8 +10,8 @@ // limitations under the License. use num_bigint::BigUint; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_abi::Contract; use tvm_abi::Token; use tvm_abi::TokenValue; @@ -22,24 +22,24 @@ use tvm_block::Message; use tvm_block::MsgAddressExt; use tvm_block::MsgAddressInt; use tvm_block::Serializable; -use tvm_client::boc::get_blockchain_config; use tvm_client::boc::ParamsOfGetBlockchainConfig; +use tvm_client::boc::get_blockchain_config; use tvm_client::net::OrderBy; use tvm_client::net::SortDirection; -use tvm_types::base64_decode; -use tvm_types::ed25519_create_private_key; -use tvm_types::ed25519_sign_with_secret; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::IBitstring; use tvm_types::SliceData; +use tvm_types::base64_decode; +use tvm_types::ed25519_create_private_key; +use tvm_types::ed25519_sign_with_secret; use crate::config::Config; +use crate::helpers::TonClient; use crate::helpers::create_client_verbose; use crate::helpers::now; use crate::helpers::now_ms; use crate::helpers::query_with_limit; -use crate::helpers::TonClient; const PREFIX_UPDATE_CONFIG_MESSAGE_DATA: &str = "43665021"; @@ -547,10 +547,10 @@ pub async fn dump_blockchain_config(config: &Config, path: &str) -> Result<(), S .ok_or("Failed to query last block BOC.")? .to_owned(); - let bc_config = get_blockchain_config( - ton.clone(), - ParamsOfGetBlockchainConfig { block_boc: block, ..Default::default() }, - ) + let bc_config = get_blockchain_config(ton.clone(), ParamsOfGetBlockchainConfig { + block_boc: block, + ..Default::default() + }) .map_err(|e| format!("Failed to get blockchain config: {}", e))?; let bc_config = diff --git a/tvm_cli/src/helpers.rs b/tvm_cli/src/helpers.rs index 438134cc3..c3893090b 100644 --- a/tvm_cli/src/helpers.rs +++ b/tvm_cli/src/helpers.rs @@ -16,14 +16,16 @@ use std::time::Duration; use std::time::SystemTime; use clap::ArgMatches; -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_block::Account; use tvm_block::CurrencyCollection; use tvm_block::Deserializable; use tvm_block::MsgAddressInt; use tvm_block::Serializable; use tvm_block::StateInit; +use tvm_client::ClientConfig; +use tvm_client::ClientContext; use tvm_client::abi::Abi; use tvm_client::abi::AbiConfig; use tvm_client::abi::AbiContract; @@ -36,25 +38,23 @@ use tvm_client::crypto::CryptoConfig; use tvm_client::crypto::KeyPair; use tvm_client::crypto::MnemonicDictionary; use tvm_client::error::ClientError; -use tvm_client::net::query_collection; use tvm_client::net::NetworkConfig; use tvm_client::net::OrderBy; use tvm_client::net::ParamsOfQueryCollection; -use tvm_client::ClientConfig; -use tvm_client::ClientContext; +use tvm_client::net::query_collection; use tvm_executor::BlockchainConfig; use tvm_types::base64_decode; use tvm_types::base64_encode; use url::Url; +use crate::FullConfig; use crate::call::parse_params; use crate::config::Config; use crate::config::LOCALNET; use crate::debug::debug_level_from_env; -use crate::replay::construct_blockchain_config; use crate::replay::CONFIG_ADDR; +use crate::replay::construct_blockchain_config; use crate::resolve_net_name; -use crate::FullConfig; pub const HD_PATH: &str = "m/44'/396'/0'/0/0"; pub const WORD_COUNT: u8 = 12; @@ -224,17 +224,14 @@ pub async fn query_raw( .transpose() .map_err(|e| format!("Failed to parse order field: {}", e))?; - let query = tvm_client::net::query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: collection.to_owned(), - filter, - limit, - order, - result: result.to_owned(), - ..Default::default() - }, - ) + let query = tvm_client::net::query_collection(context.clone(), ParamsOfQueryCollection { + collection: collection.to_owned(), + filter, + limit, + order, + result: result.to_owned(), + ..Default::default() + }) .await .map_err(|e| format!("Failed to execute query: {}", e))?; @@ -250,17 +247,14 @@ pub async fn query_with_limit( order: Option>, limit: Option, ) -> Result, ClientError> { - query_collection( - ton, - ParamsOfQueryCollection { - collection: collection.to_owned(), - filter: Some(filter), - result: result.to_owned(), - order, - limit, - ..Default::default() - }, - ) + query_collection(ton, ParamsOfQueryCollection { + collection: collection.to_owned(), + filter: Some(filter), + result: result.to_owned(), + order, + limit, + ..Default::default() + }) .await .map(|r| r.result) } @@ -319,10 +313,12 @@ pub async fn decode_msg_body( config: &Config, ) -> Result { let abi = load_abi(abi_path, config).await?; - tvm_client::abi::decode_message_body( - ton, - ParamsOfDecodeMessageBody { abi, body: body.to_owned(), is_internal, ..Default::default() }, - ) + tvm_client::abi::decode_message_body(ton, ParamsOfDecodeMessageBody { + abi, + body: body.to_owned(), + is_internal, + ..Default::default() + }) .map_err(|e| format!("failed to decode body: {}", e)) } @@ -400,19 +396,16 @@ pub async fn calc_acc_address( ..Default::default() } }; - let result = tvm_client::abi::encode_message( - ton.clone(), - ParamsOfEncodeMessage { - abi, - deploy_set: Some(dset), - signer: if pubkey.is_some() { - Signer::External { public_key: pubkey.unwrap() } - } else { - Signer::None - }, - ..Default::default() + let result = tvm_client::abi::encode_message(ton.clone(), ParamsOfEncodeMessage { + abi, + deploy_set: Some(dset), + signer: if pubkey.is_some() { + Signer::External { public_key: pubkey.unwrap() } + } else { + Signer::None }, - ) + ..Default::default() + }) .await .map_err(|e| format!("cannot generate address: {}", e))?; Ok(result.address) @@ -456,15 +449,12 @@ pub async fn print_message( if body.is_some() { let body = body.unwrap(); let def_config = Config::default(); - let result = tvm_client::abi::decode_message_body( - ton.clone(), - ParamsOfDecodeMessageBody { - abi: load_abi(abi, &def_config).await?, - body: body.to_owned(), - is_internal, - ..Default::default() - }, - ); + let result = tvm_client::abi::decode_message_body(ton.clone(), ParamsOfDecodeMessageBody { + abi: load_abi(abi, &def_config).await?, + body: body.to_owned(), + is_internal, + ..Default::default() + }); let (name, args) = if result.is_err() { ("unknown".to_owned(), "{}".to_owned()) } else { diff --git a/tvm_cli/src/main.rs b/tvm_cli/src/main.rs index 0e1ba4653..82e50dc43 100644 --- a/tvm_cli/src/main.rs +++ b/tvm_cli/src/main.rs @@ -49,9 +49,9 @@ use clap::AppSettings; use clap::Arg; use clap::ArgMatches; use clap::SubCommand; +use config::Config; use config::clear_config; use config::set_config; -use config::Config; use crypto::extract_pubkey; use crypto::generate_keypair; use crypto::generate_mnemonic; @@ -78,8 +78,8 @@ use multisig::multisig_command; use replay::fetch_block_command; use replay::fetch_command; use replay::replay_command; -use serde_json::json; use serde_json::Value; +use serde_json::json; use test::create_test_command; use test::create_test_sign_command; use test::test_command; @@ -91,9 +91,10 @@ use voting::decode_proposal; use voting::vote; use crate::account::dump_accounts; -use crate::config::resolve_net_name; use crate::config::FullConfig; +use crate::config::resolve_net_name; use crate::getconfig::gen_update_config_message; +use crate::helpers::AccountSource; use crate::helpers::abi_from_matches_or_config; use crate::helpers::default_config_name; use crate::helpers::global_config_path; @@ -102,7 +103,6 @@ use crate::helpers::load_params; use crate::helpers::parse_lifetime; use crate::helpers::unpack_alternative_params; use crate::helpers::wc_from_matches_or_config; -use crate::helpers::AccountSource; use crate::message::generate_message; use crate::run::run_command; use crate::run::run_get_method; @@ -1234,16 +1234,13 @@ async fn body_command(matches: &ArgMatches<'_>, config: &Config) -> Result<(), S .map_err(|e| format!("arguments are not in json format: {}", e))?; let client = create_client_local()?; - let body = tvm_client::abi::encode_message_body( - client.clone(), - ParamsOfEncodeMessageBody { - abi: load_abi(abi.as_ref().unwrap(), config).await?, - call_set: CallSet::some_with_function_and_input(method.unwrap(), params) - .ok_or("failed to create CallSet with specified parameters.")?, - is_internal: true, - ..Default::default() - }, - ) + let body = tvm_client::abi::encode_message_body(client.clone(), ParamsOfEncodeMessageBody { + abi: load_abi(abi.as_ref().unwrap(), config).await?, + call_set: CallSet::some_with_function_and_input(method.unwrap(), params) + .ok_or("failed to create CallSet with specified parameters.")?, + is_internal: true, + ..Default::default() + }) .await .map_err(|e| format!("failed to encode body: {}", e)) .map(|r| r.body)?; diff --git a/tvm_cli/src/message.rs b/tvm_cli/src/message.rs index 39156705c..5faa94a23 100644 --- a/tvm_cli/src/message.rs +++ b/tvm_cli/src/message.rs @@ -12,21 +12,21 @@ use chrono::Local; use chrono::TimeZone; use serde_json::json; -use tvm_client::abi::encode_message; use tvm_client::abi::Abi; use tvm_client::abi::CallSet; use tvm_client::abi::FunctionHeader; use tvm_client::abi::ParamsOfEncodeMessage; use tvm_client::abi::Signer; +use tvm_client::abi::encode_message; use tvm_types::base64_decode; use crate::config::Config; use crate::crypto::load_keypair; +use crate::helpers::TonClient; use crate::helpers::create_client_local; use crate::helpers::load_abi; use crate::helpers::load_ton_address; use crate::helpers::now; -use crate::helpers::TonClient; pub struct EncodedMessage { pub message_id: String, diff --git a/tvm_cli/src/multisig.rs b/tvm_cli/src/multisig.rs index 1f8dc9b83..725864da6 100644 --- a/tvm_cli/src/multisig.rs +++ b/tvm_cli/src/multisig.rs @@ -15,12 +15,12 @@ use clap::Arg; use clap::ArgMatches; use clap::SubCommand; use serde_json::json; -use tvm_client::abi::encode_message_body; use tvm_client::abi::Abi; use tvm_client::abi::AbiContract; use tvm_client::abi::AbiParam; use tvm_client::abi::CallSet; use tvm_client::abi::ParamsOfEncodeMessageBody; +use tvm_client::abi::encode_message_body; use crate::call; use crate::config::Config; @@ -248,11 +248,7 @@ impl CallArgs { let v2 = matches.is_present("V2"); let target = if v2 { - if is_setcode { - SETCODEMULTISIG_V2_LINK - } else { - SAFEMULTISIG_V2_LINK - } + if is_setcode { SETCODEMULTISIG_V2_LINK } else { SAFEMULTISIG_V2_LINK } } else if is_setcode { SETCODEMULTISIG_LINK } else { @@ -471,21 +467,18 @@ async fn multisig_send_command(matches: &ArgMatches<'_>, config: &Config) -> Res } pub async fn encode_transfer_body(text: &str) -> Result { - encode_message_body( - create_client_local()?, - ParamsOfEncodeMessageBody { - abi: Abi::Json(TRANSFER_WITH_COMMENT.to_owned()), - call_set: CallSet::some_with_function_and_input( - "transfer", - json!({ - "comment": hex::encode(text.as_bytes()) - }), - ) - .ok_or("failed to create CallSet with specified parameters")?, - is_internal: true, - ..Default::default() - }, - ) + encode_message_body(create_client_local()?, ParamsOfEncodeMessageBody { + abi: Abi::Json(TRANSFER_WITH_COMMENT.to_owned()), + call_set: CallSet::some_with_function_and_input( + "transfer", + json!({ + "comment": hex::encode(text.as_bytes()) + }), + ) + .ok_or("failed to create CallSet with specified parameters")?, + is_internal: true, + ..Default::default() + }) .await .map_err(|e| format!("failed to encode transfer body: {}", e)) .map(|r| r.body) diff --git a/tvm_cli/src/replay.rs b/tvm_cli/src/replay.rs index a71537a74..d54139576 100644 --- a/tvm_cli/src/replay.rs +++ b/tvm_cli/src/replay.rs @@ -16,8 +16,8 @@ use std::io::Read; use std::io::Write; use std::io::{self}; use std::process::exit; -use std::sync::atomic::AtomicU64; use std::sync::Arc; +use std::sync::atomic::AtomicU64; use clap::ArgMatches; use serde::Deserialize; @@ -32,24 +32,24 @@ use tvm_block::Message; use tvm_block::Serializable; use tvm_block::Transaction; use tvm_block::TransactionDescr; -use tvm_client::net::aggregate_collection; -use tvm_client::net::query_collection; use tvm_client::net::AggregationFn; use tvm_client::net::FieldAggregation; use tvm_client::net::OrderBy; use tvm_client::net::ParamsOfAggregateCollection; use tvm_client::net::ParamsOfQueryCollection; use tvm_client::net::SortDirection; +use tvm_client::net::aggregate_collection; +use tvm_client::net::query_collection; use tvm_executor::BlockchainConfig; use tvm_executor::ExecuteParams; use tvm_executor::OrdinaryTransactionExecutor; use tvm_executor::TickTockTransactionExecutor; use tvm_executor::TransactionExecutor; -use tvm_types::base64_encode; -use tvm_types::write_boc; use tvm_types::BuilderData; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::base64_encode; +use tvm_types::write_boc; use tvm_vm::executor::Engine; use tvm_vm::executor::EngineTraceInfo; @@ -115,18 +115,15 @@ pub async fn fetch( }) }; - let tr_count = aggregate_collection( - context.clone(), - ParamsOfAggregateCollection { - collection: "transactions".to_owned(), - filter: Some(filter), - fields: Some(vec![FieldAggregation { - field: "fn".to_owned(), - aggregation_fn: AggregationFn::COUNT, - }]), - ..Default::default() - }, - ) + let tr_count = aggregate_collection(context.clone(), ParamsOfAggregateCollection { + collection: "transactions".to_owned(), + filter: Some(filter), + fields: Some(vec![FieldAggregation { + field: "fn".to_owned(), + aggregation_fn: AggregationFn::COUNT, + }]), + ..Default::default() + }) .await .map_err(|e| format!("Failed to fetch txns count: {}", e))?; let tr_count = u64::from_str_radix( @@ -145,17 +142,14 @@ pub async fn fetch( let file = File::create(filename).map_err(|e| format!("Failed to create file: {}", e))?; let mut writer = std::io::LineWriter::new(file); - let zerostates = query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "zerostates".to_owned(), - filter: None, - result: "accounts { id boc }".to_owned(), - limit: Some(1), - order: None, - ..Default::default() - }, - ) + let zerostates = query_collection(context.clone(), ParamsOfQueryCollection { + collection: "zerostates".to_owned(), + filter: None, + result: "accounts { id boc }".to_owned(), + limit: Some(1), + order: None, + ..Default::default() + }) .await; let mut zerostate_found = false; @@ -216,20 +210,14 @@ pub async fn fetch( "lt": { "gt": lt }, }) }; - let query = query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "transactions".to_owned(), - filter: Some(filter), - result: "id lt block { start_lt } boc".to_owned(), - limit: None, - order: Some(vec![OrderBy { - path: "lt".to_owned(), - direction: SortDirection::ASC, - }]), - ..Default::default() - }, - ); + let query = query_collection(context.clone(), ParamsOfQueryCollection { + collection: "transactions".to_owned(), + filter: Some(filter), + result: "id lt block { start_lt } boc".to_owned(), + limit: None, + order: Some(vec![OrderBy { path: "lt".to_owned(), direction: SortDirection::ASC }]), + ..Default::default() + }); query.await }; @@ -320,11 +308,7 @@ impl State { fn choose<'a>(st1: &'a mut State, st2: &'a mut State) -> &'a mut State { let lt1 = st1.tr.as_ref().map_or(u64::MAX, |tr| tr.tr.logical_time()); let lt2 = st2.tr.as_ref().map_or(u64::MAX, |tr| tr.tr.logical_time()); - if lt1 <= lt2 { - st1 - } else { - st2 - } + if lt1 <= lt2 { st1 } else { st2 } } pub async fn replay( @@ -547,21 +531,18 @@ pub async fn fetch_block(config: &Config, block_id: &str, filename: &str) -> tvm let context = create_client(config) .map_err(|e| failure::err_msg(format!("Failed to create ctx: {}", e)))?; - let block = query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "blocks".to_owned(), - filter: Some(serde_json::json!({ - "id": { - "eq": block_id - }, - })), - result: "workchain_id end_lt boc".to_owned(), - limit: None, - order: None, - ..Default::default() - }, - ) + let block = query_collection(context.clone(), ParamsOfQueryCollection { + collection: "blocks".to_owned(), + filter: Some(serde_json::json!({ + "id": { + "eq": block_id + }, + })), + result: "workchain_id end_lt boc".to_owned(), + limit: None, + order: None, + ..Default::default() + }) .await?; if block.result.len() != 1 { diff --git a/tvm_cli/src/run.rs b/tvm_cli/src/run.rs index 667f4e9d5..1b25f5c13 100644 --- a/tvm_cli/src/run.rs +++ b/tvm_cli/src/run.rs @@ -16,19 +16,21 @@ use tvm_block::Account; use tvm_block::Deserializable; use tvm_block::Serializable; use tvm_client::abi::FunctionHeader; -use tvm_client::tvm::run_get; -use tvm_client::tvm::run_tvm; use tvm_client::tvm::ExecutionOptions; use tvm_client::tvm::ParamsOfRunGet; use tvm_client::tvm::ParamsOfRunTvm; +use tvm_client::tvm::run_get; +use tvm_client::tvm::run_tvm; use tvm_types::base64_encode; use crate::call::print_json_result; use crate::config::Config; use crate::config::FullConfig; +use crate::debug::DebugParams; use crate::debug::debug_error; use crate::debug::init_debug_logger; -use crate::debug::DebugParams; +use crate::helpers::AccountSource; +use crate::helpers::TonClient; use crate::helpers::abi_from_matches_or_config; use crate::helpers::contract_data_from_matches_or_config_alias; use crate::helpers::create_client; @@ -41,8 +43,6 @@ use crate::helpers::load_params; use crate::helpers::now; use crate::helpers::now_ms; use crate::helpers::unpack_alternative_params; -use crate::helpers::AccountSource; -use crate::helpers::TonClient; use crate::message::prepare_message; use crate::replay::construct_blockchain_config; @@ -159,17 +159,14 @@ async fn run( .await?; let execution_options = prepare_execution_options(bc_config)?; - let result = run_tvm( - ton_client.clone(), - ParamsOfRunTvm { - message: msg.message.clone(), - account: account_boc.clone(), - abi: Some(abi.clone()), - return_updated_account: Some(true), - execution_options, - ..Default::default() - }, - ) + let result = run_tvm(ton_client.clone(), ParamsOfRunTvm { + message: msg.message.clone(), + account: account_boc.clone(), + abi: Some(abi.clone()), + return_updated_account: Some(true), + execution_options, + ..Default::default() + }) .await; let result = match result { @@ -254,16 +251,13 @@ pub async fn run_get_method( println!("Running get-method..."); } let execution_options = prepare_execution_options(bc_config)?; - let result = run_get( - ton, - ParamsOfRunGet { - account: acc_boc, - function_name: method.to_owned(), - input: params, - execution_options, - ..Default::default() - }, - ) + let result = run_get(ton, ParamsOfRunGet { + account: acc_boc, + function_name: method.to_owned(), + input: params, + execution_options, + ..Default::default() + }) .await .map_err(|e| format!("run failed: {}", e))? .output; diff --git a/tvm_cli/src/test.rs b/tvm_cli/src/test.rs index 60d9c6a44..44908546b 100644 --- a/tvm_cli/src/test.rs +++ b/tvm_cli/src/test.rs @@ -23,28 +23,29 @@ use tvm_block::Deserializable; use tvm_block::Message; use tvm_block::Serializable; use tvm_block::TickTock; -use tvm_client::abi::encode_internal_message; -use tvm_client::abi::encode_message; use tvm_client::abi::CallSet; use tvm_client::abi::DeploySet; use tvm_client::abi::FunctionHeader; use tvm_client::abi::ParamsOfEncodeInternalMessage; use tvm_client::abi::ParamsOfEncodeMessage; use tvm_client::abi::Signer as AbiSigner; +use tvm_client::abi::encode_internal_message; +use tvm_client::abi::encode_message; +use tvm_types::BuilderData; +use tvm_types::SliceData; use tvm_types::base64_encode; use tvm_types::ed25519_sign_with_secret; use tvm_types::read_single_root_boc; use tvm_types::write_boc; -use tvm_types::BuilderData; -use tvm_types::SliceData; +use crate::FullConfig; use crate::config::Config; use crate::crypto::load_keypair; use crate::crypto::{self}; +use crate::debug::DEFAULT_TRACE_PATH; use crate::debug::decode_messages; use crate::debug::execute_debug; use crate::debug::init_debug_logger; -use crate::debug::DEFAULT_TRACE_PATH; use crate::getconfig::serialize_config_param; use crate::helpers::create_client_local; use crate::helpers::decode_data; @@ -53,7 +54,6 @@ use crate::helpers::load_abi; use crate::helpers::load_params; use crate::helpers::now_ms; use crate::helpers::unpack_alternative_params; -use crate::FullConfig; pub fn create_test_sign_command<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("sign") diff --git a/tvm_cli/src/voting.rs b/tvm_cli/src/voting.rs index 1cd7be3c4..d424657b2 100644 --- a/tvm_cli/src/voting.rs +++ b/tvm_cli/src/voting.rs @@ -15,9 +15,9 @@ use crate::config::Config; use crate::helpers::create_client_local; use crate::helpers::decode_msg_body; use crate::message; -use crate::multisig::encode_transfer_body; use crate::multisig::MSIG_ABI; use crate::multisig::TRANSFER_WITH_COMMENT; +use crate::multisig::encode_transfer_body; pub async fn create_proposal( config: &Config, diff --git a/tvm_cli/tests/browser.rs b/tvm_cli/tests/browser.rs index f09686b9b..f9056c4dd 100644 --- a/tvm_cli/tests/browser.rs +++ b/tvm_cli/tests/browser.rs @@ -7,10 +7,10 @@ use predicates::prelude::*; // use std::io::Write; use serde_json::json; mod common; -use common::giver_v3; -use common::grep_address; use common::BIN_NAME; use common::NETWORK; +use common::giver_v3; +use common::grep_address; fn get_debot_paths(name: &str) -> (String, String, String) { ( diff --git a/tvm_cli/tests/json_output_test.rs b/tvm_cli/tests/json_output_test.rs index a40afd660..2f6993a84 100644 --- a/tvm_cli/tests/json_output_test.rs +++ b/tvm_cli/tests/json_output_test.rs @@ -4,15 +4,15 @@ use assert_cmd::Command; use serde_json::Value; mod common; -use common::generate_key_and_address; -use common::generate_phrase_and_key; -use common::giver_v3; use common::BIN_NAME; use common::GIVER_ABI; use common::GIVER_ADDR; use common::GIVER_V2_ADDR; use common::GIVER_V2_KEY; use common::NETWORK; +use common::generate_key_and_address; +use common::generate_phrase_and_key; +use common::giver_v3; const DEPOOL_ABI: &str = "tests/samples/fakeDepool.abi.json"; const DEPOOL_TVC: &str = "tests/samples/fakeDepool.tvc"; diff --git a/tvm_cli/tests/test_cli.rs b/tvm_cli/tests/test_cli.rs index 1c8106545..be7909dcb 100644 --- a/tvm_cli/tests/test_cli.rs +++ b/tvm_cli/tests/test_cli.rs @@ -7,21 +7,21 @@ use std::time::SystemTime; use assert_cmd::Command; use common::giver_v3; use predicates::prelude::*; -use serde_json::json; use serde_json::Value; +use serde_json::json; mod common; -use common::generate_key_and_address; -use common::generate_phrase_and_key; -use common::giver_v2; -use common::grep_address; -use common::set_config; use common::BIN_NAME; use common::GIVER_ABI; use common::GIVER_V2_ABI; use common::GIVER_V2_ADDR; use common::GIVER_V2_KEY; use common::NETWORK; +use common::generate_key_and_address; +use common::generate_phrase_and_key; +use common::giver_v2; +use common::grep_address; +use common::set_config; use crate::common::grep_message_id; diff --git a/tvm_client/build.rs b/tvm_client/build.rs index 6dd89c445..b3fc66107 100644 --- a/tvm_client/build.rs +++ b/tvm_client/build.rs @@ -48,17 +48,14 @@ fn root() -> PathBuf { impl BuildInfo { fn load() -> Result { let manifest_path = root().join("Cargo.toml"); - let meta_out = exec( - "cargo", - &[ - "metadata", - "--locked", - "--format-version", - "1", - "--manifest-path", - manifest_path.to_str().unwrap(), - ], - )?; + let meta_out = exec("cargo", &[ + "metadata", + "--locked", + "--format-version", + "1", + "--manifest-path", + manifest_path.to_str().unwrap(), + ])?; let meta = serde_json::from_str::(&meta_out).unwrap(); let git_commit = exec("git", &["rev-parse", "HEAD"])?.trim().to_string(); let mut build_number = std::env::var("tvm_BUILD_NUMBER").unwrap_or("".into()); diff --git a/tvm_client/src/abi/decode_boc.rs b/tvm_client/src/abi/decode_boc.rs index 95ee40c8a..d1b066a14 100644 --- a/tvm_client/src/abi/decode_boc.rs +++ b/tvm_client/src/abi/decode_boc.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use serde_json::Value; use tvm_abi::token::Detokenizer; -use crate::abi::types::AbiParam; use crate::abi::Error; +use crate::abi::types::AbiParam; use crate::boc::internal::deserialize_cell_from_boc; use crate::client::ClientContext; use crate::encoding::slice_from_cell; diff --git a/tvm_client/src/abi/decode_data.rs b/tvm_client/src/abi/decode_data.rs index d30c114fd..fb68095cb 100644 --- a/tvm_client/src/abi/decode_data.rs +++ b/tvm_client/src/abi/decode_data.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use serde_json::Value; use tvm_abi::token::Detokenizer; -use crate::abi::types::Abi; use crate::abi::Error; +use crate::abi::types::Abi; use crate::boc::internal::deserialize_cell_from_boc; use crate::client::ClientContext; use crate::encoding::slice_from_cell; diff --git a/tvm_client/src/abi/decode_message.rs b/tvm_client/src/abi/decode_message.rs index a3c60e09e..fe676923c 100644 --- a/tvm_client/src/abi/decode_message.rs +++ b/tvm_client/src/abi/decode_message.rs @@ -6,13 +6,13 @@ use tvm_abi::token::Detokenizer; use tvm_sdk::AbiContract; use tvm_sdk::AbiEvent; use tvm_sdk::AbiFunction; -use tvm_types::base64_encode; use tvm_types::SliceData; +use tvm_types::base64_encode; use super::types::extend_data_to_sign; -use crate::abi::types::Abi; use crate::abi::Error; use crate::abi::FunctionHeader; +use crate::abi::types::Abi; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::deserialize_object_from_boc; use crate::client::ClientContext; diff --git a/tvm_client/src/abi/encode_account.rs b/tvm_client/src/abi/encode_account.rs index 5a2c91078..0944cd0a0 100644 --- a/tvm_client/src/abi/encode_account.rs +++ b/tvm_client/src/abi/encode_account.rs @@ -5,8 +5,8 @@ use tvm_block::CurrencyCollection; use tvm_block::MsgAddressInt; use crate::abi::Error; -use crate::boc::internal::serialize_object_to_boc; use crate::boc::BocCacheType; +use crate::boc::internal::serialize_object_to_boc; use crate::client::ClientContext; use crate::error::ClientResult; diff --git a/tvm_client/src/abi/encode_boc.rs b/tvm_client/src/abi/encode_boc.rs index 66c2c0575..b58840e55 100644 --- a/tvm_client/src/abi/encode_boc.rs +++ b/tvm_client/src/abi/encode_boc.rs @@ -1,16 +1,16 @@ use std::sync::Arc; use serde_json::Value; +use tvm_abi::TokenValue; use tvm_abi::contract::MAX_SUPPORTED_VERSION; use tvm_abi::token::Tokenizer; -use tvm_abi::TokenValue; +use crate::ClientContext; use crate::abi::AbiParam; use crate::abi::Error; -use crate::boc::internal::serialize_cell_to_boc; use crate::boc::BocCacheType; +use crate::boc::internal::serialize_cell_to_boc; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Serialize, Deserialize, ApiType, Default)] pub struct ParamsOfAbiEncodeBoc { diff --git a/tvm_client/src/abi/encode_message.rs b/tvm_client/src/abi/encode_message.rs index 7e1aac2dd..8aeb34d25 100644 --- a/tvm_client/src/abi/encode_message.rs +++ b/tvm_client/src/abi/encode_message.rs @@ -7,19 +7,19 @@ use tvm_block::CurrencyCollection; use tvm_block::MsgAddressInt; use tvm_sdk::ContractImage; use tvm_sdk::FunctionCallSet; -use tvm_types::base64_encode; use tvm_types::Cell; +use tvm_types::base64_encode; use super::types::extend_data_to_sign; +use crate::abi::Abi; +use crate::abi::Error; +use crate::abi::FunctionHeader; +use crate::abi::Signer; use crate::abi::internal::add_sign_to_message; use crate::abi::internal::add_sign_to_message_body; use crate::abi::internal::create_tvc_image; use crate::abi::internal::try_to_sign_message; use crate::abi::internal::update_pubkey; -use crate::abi::Abi; -use crate::abi::Error; -use crate::abi::FunctionHeader; -use crate::abi::Signer; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::get_boc_hash; use crate::boc::tvc::resolve_state_init_cell; diff --git a/tvm_client/src/abi/init_data.rs b/tvm_client/src/abi/init_data.rs index 414415fe3..afa335b41 100644 --- a/tvm_client/src/abi/init_data.rs +++ b/tvm_client/src/abi/init_data.rs @@ -4,12 +4,12 @@ use serde_json::Value; use tvm_types::Cell; use tvm_types::SliceData; -use crate::abi::types::Abi; use crate::abi::Error; +use crate::abi::types::Abi; +use crate::boc::BocCacheType; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::serialize_cell_to_boc; use crate::boc::state_init::builder_to_cell; -use crate::boc::BocCacheType; use crate::client::ClientContext; use crate::encoding::hex_decode; use crate::encoding::slice_from_cell; diff --git a/tvm_client/src/abi/internal.rs b/tvm_client/src/abi/internal.rs index ba20a87ae..a77c5037b 100644 --- a/tvm_client/src/abi/internal.rs +++ b/tvm_client/src/abi/internal.rs @@ -5,13 +5,13 @@ use tvm_abi::PublicKeyData; use tvm_sdk::ContractImage; use tvm_types::Cell; +use crate::ClientContext; use crate::abi::DeploySet; use crate::abi::Error; use crate::abi::Signer; use crate::crypto::internal::decode_public_key; use crate::encoding::hex_decode; use crate::error::ClientResult; -use crate::ClientContext; /// Combines `hex` encoded `signature` with `base64` encoded `unsigned_message`. /// Returns signed message encoded with `base64`. diff --git a/tvm_client/src/abi/mod.rs b/tvm_client/src/abi/mod.rs index 8bfedc2bd..d6bf64d34 100644 --- a/tvm_client/src/abi/mod.rs +++ b/tvm_client/src/abi/mod.rs @@ -26,15 +26,12 @@ mod internal; mod signing; mod types; -pub use decode_boc::decode_boc; pub use decode_boc::ParamsOfDecodeBoc; pub use decode_boc::ResultOfDecodeBoc; -pub use decode_data::decode_account_data; +pub use decode_boc::decode_boc; pub use decode_data::ParamsOfDecodeAccountData; pub use decode_data::ResultOfDecodeAccountData; -pub use decode_message::decode_message; -pub use decode_message::decode_message_body; -pub use decode_message::get_signature_data; +pub use decode_data::decode_account_data; pub use decode_message::DataLayout; pub use decode_message::DecodedMessageBody; pub use decode_message::MessageBodyType; @@ -42,17 +39,15 @@ pub use decode_message::ParamsOfDecodeMessage; pub use decode_message::ParamsOfDecodeMessageBody; pub use decode_message::ParamsOfGetSignatureData; pub use decode_message::ResultOfGetSignatureData; -pub use encode_account::encode_account; +pub use decode_message::decode_message; +pub use decode_message::decode_message_body; +pub use decode_message::get_signature_data; pub use encode_account::ParamsOfEncodeAccount; pub use encode_account::ResultOfEncodeAccount; -pub use encode_boc::encode_boc; +pub use encode_account::encode_account; pub use encode_boc::ParamsOfAbiEncodeBoc; pub use encode_boc::ResultOfAbiEncodeBoc; -pub use encode_message::attach_signature; -pub use encode_message::attach_signature_to_message_body; -pub use encode_message::encode_internal_message; -pub use encode_message::encode_message; -pub use encode_message::encode_message_body; +pub use encode_boc::encode_boc; pub use encode_message::CallSet; pub use encode_message::DeploySet; pub use encode_message::ParamsOfAttachSignature; @@ -65,20 +60,25 @@ pub use encode_message::ResultOfAttachSignatureToMessageBody; pub use encode_message::ResultOfEncodeInternalMessage; pub use encode_message::ResultOfEncodeMessage; pub use encode_message::ResultOfEncodeMessageBody; +pub use encode_message::attach_signature; +pub use encode_message::attach_signature_to_message_body; +pub use encode_message::encode_internal_message; +pub use encode_message::encode_message; +pub use encode_message::encode_message_body; pub use errors::Error; pub use errors::ErrorCode; -pub use function_id::calc_function_id; pub use function_id::ParamsOfCalcFunctionId; pub use function_id::ResultOfCalcFunctionId; -pub use init_data::decode_initial_data; -pub use init_data::encode_initial_data; -pub use init_data::update_initial_data; +pub use function_id::calc_function_id; pub use init_data::ParamsOfDecodeInitialData; pub use init_data::ParamsOfEncodeInitialData; pub use init_data::ParamsOfUpdateInitialData; pub use init_data::ResultOfDecodeInitialData; pub use init_data::ResultOfEncodeInitialData; pub use init_data::ResultOfUpdateInitialData; +pub use init_data::decode_initial_data; +pub use init_data::encode_initial_data; +pub use init_data::update_initial_data; use serde::Deserialize; use serde::Deserializer; pub use signing::Signer; diff --git a/tvm_client/src/abi/signing.rs b/tvm_client/src/abi/signing.rs index 131e6d881..69e3e8c2e 100644 --- a/tvm_client/src/abi/signing.rs +++ b/tvm_client/src/abi/signing.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use tvm_types::base64_encode; +use crate::ClientContext; use crate::crypto::KeyPair; use crate::crypto::SigningBoxHandle; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Serialize, Deserialize, Clone, Debug, ApiType, PartialEq)] #[serde(tag = "type")] diff --git a/tvm_client/src/abi/tests.rs b/tvm_client/src/abi/tests.rs index f718f6736..0a48eae78 100644 --- a/tvm_client/src/abi/tests.rs +++ b/tvm_client/src/abi/tests.rs @@ -12,16 +12,23 @@ use tvm_block::Serializable; use tvm_block::StateInit; use tvm_sdk::ContractImage; use tvm_struct::scheme::TVC; -use tvm_types::base64_decode; -use tvm_types::base64_encode; use tvm_types::BuilderData; use tvm_types::IBitstring; use tvm_types::Result; +use tvm_types::base64_decode; +use tvm_types::base64_encode; use super::*; use crate::abi::internal::create_tvc_image; use crate::abi::internal::is_empty_pubkey; use crate::abi::internal::resolve_pubkey; +use crate::boc::ParamsOfDecodeStateInit; +use crate::boc::ParamsOfGetCodeFromTvc; +use crate::boc::ParamsOfParse; +use crate::boc::ResultOfDecodeStateInit; +use crate::boc::ResultOfEncodeBoc; +use crate::boc::ResultOfGetCodeFromTvc; +use crate::boc::ResultOfParse; use crate::boc::internal::deserialize_cell_from_base64; use crate::boc::internal::deserialize_object_from_base64; use crate::boc::internal::deserialize_object_from_cell; @@ -30,20 +37,13 @@ use crate::boc::internal::serialize_cell_to_base64; use crate::boc::internal::serialize_object_to_base64; use crate::boc::parse_message; use crate::boc::tvc::resolve_state_init_cell; -use crate::boc::ParamsOfDecodeStateInit; -use crate::boc::ParamsOfGetCodeFromTvc; -use crate::boc::ParamsOfParse; -use crate::boc::ResultOfDecodeStateInit; -use crate::boc::ResultOfEncodeBoc; -use crate::boc::ResultOfGetCodeFromTvc; -use crate::boc::ResultOfParse; use crate::crypto::KeyPair; use crate::encoding::account_decode; -use crate::tests::TestClient; use crate::tests::EVENTS; use crate::tests::EVENTS_OLD; use crate::tests::HELLO; use crate::tests::T24_INIT_DATA; +use crate::tests::TestClient; use crate::utils::conversion::abi_uint; struct EncodeCheckEthalons { @@ -160,15 +160,12 @@ fn test_encode_v2_params(ethalons: EncodeCheckEthalons, signature_id: Option, ) -> Result<()> { let result: ResultOfEncodeInternalMessage = client - .request_async( - "abi.encode_internal_message", - ParamsOfEncodeInternalMessage { - abi: abi.cloned(), - src_address: src.clone(), - address: dst.clone(), - deploy_set: None, - call_set, - value: "1000000000".to_string(), - bounce: Some(true), - enable_ihr: None, - }, - ) + .request_async("abi.encode_internal_message", ParamsOfEncodeInternalMessage { + abi: abi.cloned(), + src_address: src.clone(), + address: dst.clone(), + deploy_set: None, + call_set, + value: "1000000000".to_string(), + bounce: Some(true), + enable_ihr: None, + }) .await?; if dst.is_some() { @@ -769,19 +748,16 @@ async fn test_encode_internal_message_deploy( expected_boc: Option<&str>, ) -> Result<()> { let result: ResultOfEncodeInternalMessage = client - .request_async( - "abi.encode_internal_message", - ParamsOfEncodeInternalMessage { - abi: Some(abi.clone()), - src_address: None, - address: None, - deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), - call_set, - value: "1000000000".to_string(), - bounce: None, - enable_ihr: None, - }, - ) + .request_async("abi.encode_internal_message", ParamsOfEncodeInternalMessage { + abi: Some(abi.clone()), + src_address: None, + address: None, + deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), + call_set, + value: "1000000000".to_string(), + bounce: None, + enable_ihr: None, + }) .await?; assert_eq!(result.address, image.msg_address(0).to_string()); @@ -794,10 +770,9 @@ async fn test_encode_internal_message_deploy( client.request_async("boc.parse_message", ParamsOfParse { boc: result.message }).await?; let code_from_tvc: ResultOfGetCodeFromTvc = client - .request_async( - "boc.get_code_from_tvc", - ParamsOfGetCodeFromTvc { tvc: tvc.clone().unwrap_or_default() }, - ) + .request_async("boc.get_code_from_tvc", ParamsOfGetCodeFromTvc { + tvc: tvc.clone().unwrap_or_default(), + }) .await?; assert_eq!(parsed.parsed["code"], code_from_tvc.code); @@ -917,32 +892,29 @@ fn test_init_data() { let (abi, tvc) = TestClient::package("t24_initdata", Some(2)); let data = client - .request::<_, ResultOfDecodeStateInit>( - "boc.decode_state_init", - ParamsOfDecodeStateInit { state_init: tvc.unwrap(), boc_cache: None }, - ) + .request::<_, ResultOfDecodeStateInit>("boc.decode_state_init", ParamsOfDecodeStateInit { + state_init: tvc.unwrap(), + boc_cache: None, + }) .unwrap() .data .unwrap(); let result: ResultOfDecodeInitialData = client - .request( - "abi.decode_initial_data", - ParamsOfDecodeInitialData { - abi: abi.clone(), - data: data.clone(), - allow_partial: false, - }, - ) + .request("abi.decode_initial_data", ParamsOfDecodeInitialData { + abi: abi.clone(), + data: data.clone(), + allow_partial: false, + }) .unwrap(); assert_eq!(result.initial_data, json!({})); assert_eq!(result.initial_pubkey, hex::encode([0u8; 32])); let result: ResultOfEncodeInitialData = client - .request( - "abi.encode_initial_data", - ParamsOfEncodeInitialData { abi: abi.clone(), ..Default::default() }, - ) + .request("abi.encode_initial_data", ParamsOfEncodeInitialData { + abi: abi.clone(), + ..Default::default() + }) .unwrap(); assert_eq!(result.data, data); @@ -952,68 +924,56 @@ fn test_init_data() { "s": "some string", }); - const ENCODED_INITIAL_DATA: &str = - "te6ccgEBBwEARwABAcABAgPPoAQCAQFIAwAWc29tZSBzdHJpbmcCASAGBQA\ + const ENCODED_INITIAL_DATA: &str = "te6ccgEBBwEARwABAcABAgPPoAQCAQFIAwAWc29tZSBzdHJpbmcCASAGBQA\ DHuAAQQiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIoA=="; let result: ResultOfEncodeInitialData = client - .request( - "abi.encode_initial_data", - ParamsOfEncodeInitialData { - abi: abi.clone(), - initial_data: Some(initial_data.clone()), - initial_pubkey: Some(hex::encode([0x22u8; 32])), - boc_cache: None, - }, - ) + .request("abi.encode_initial_data", ParamsOfEncodeInitialData { + abi: abi.clone(), + initial_data: Some(initial_data.clone()), + initial_pubkey: Some(hex::encode([0x22u8; 32])), + boc_cache: None, + }) .unwrap(); assert_eq!(result.data, ENCODED_INITIAL_DATA); let result: ResultOfUpdateInitialData = client - .request( - "abi.update_initial_data", - ParamsOfUpdateInitialData { - abi: abi.clone(), - data: data.clone(), - initial_data: Some(initial_data.clone()), - initial_pubkey: Some(hex::encode([0x22u8; 32])), - boc_cache: None, - }, - ) + .request("abi.update_initial_data", ParamsOfUpdateInitialData { + abi: abi.clone(), + data: data.clone(), + initial_data: Some(initial_data.clone()), + initial_pubkey: Some(hex::encode([0x22u8; 32])), + boc_cache: None, + }) .unwrap(); assert_eq!(result.data, ENCODED_INITIAL_DATA); let result: ResultOfDecodeInitialData = client - .request( - "abi.decode_initial_data", - ParamsOfDecodeInitialData { abi: abi.clone(), data: result.data, allow_partial: false }, - ) + .request("abi.decode_initial_data", ParamsOfDecodeInitialData { + abi: abi.clone(), + data: result.data, + allow_partial: false, + }) .unwrap(); assert_eq!(result.initial_data, initial_data.clone()); assert_eq!(result.initial_pubkey, hex::encode([0x22u8; 32])); let encode_result: ResultOfEncodeInitialData = client - .request( - "abi.encode_initial_data", - ParamsOfEncodeInitialData { - abi: abi.clone(), - initial_data: Some(initial_data.clone()), - ..Default::default() - }, - ) + .request("abi.encode_initial_data", ParamsOfEncodeInitialData { + abi: abi.clone(), + initial_data: Some(initial_data.clone()), + ..Default::default() + }) .unwrap(); let update_result: ResultOfUpdateInitialData = client - .request( - "abi.update_initial_data", - ParamsOfUpdateInitialData { - abi: abi.clone(), - data, - initial_data: Some(initial_data.clone()), - ..Default::default() - }, - ) + .request("abi.update_initial_data", ParamsOfUpdateInitialData { + abi: abi.clone(), + data, + initial_data: Some(initial_data.clone()), + ..Default::default() + }) .unwrap(); assert_eq!(encode_result.data, update_result.data); } @@ -1041,10 +1001,11 @@ fn test_decode_boc() { let client = TestClient::new(); let decoded = client - .request::<_, ResultOfDecodeBoc>( - "abi.decode_boc", - ParamsOfDecodeBoc { boc: boc.clone(), params: params.clone(), allow_partial: false }, - ) + .request::<_, ResultOfDecodeBoc>("abi.decode_boc", ParamsOfDecodeBoc { + boc: boc.clone(), + params: params.clone(), + allow_partial: false, + }) .unwrap() .data; @@ -1060,10 +1021,11 @@ fn test_decode_boc() { params.pop(); let decoded = client - .request::<_, ResultOfDecodeBoc>( - "abi.decode_boc", - ParamsOfDecodeBoc { boc: boc.clone(), params: params.clone(), allow_partial: true }, - ) + .request::<_, ResultOfDecodeBoc>("abi.decode_boc", ParamsOfDecodeBoc { + boc: boc.clone(), + params: params.clone(), + allow_partial: true, + }) .unwrap() .data; @@ -1095,18 +1057,15 @@ fn test_encode_boc() { ]; let boc = client - .request::<_, ResultOfAbiEncodeBoc>( - "abi.encode_boc", - ParamsOfAbiEncodeBoc { - params, - data: json!({ - "dest": "-1:3333333333333333333333333333333333333333333333333333333333333333", - "value": 1234567, - "bounce": true, - }), - boc_cache: None, - }, - ) + .request::<_, ResultOfAbiEncodeBoc>("abi.encode_boc", ParamsOfAbiEncodeBoc { + params, + data: json!({ + "dest": "-1:3333333333333333333333333333333333333333333333333333333333333333", + "value": 1234567, + "bounce": true, + }), + boc_cache: None, + }) .unwrap() .boc; @@ -1122,27 +1081,21 @@ fn test_calc_function_id() { let abi = TestClient::abi("GiverV2", Some(2)); let result: ResultOfCalcFunctionId = client - .request( - "abi.calc_function_id", - ParamsOfCalcFunctionId { - abi: abi.clone(), - function_name: "getMessages".to_owned(), - ..Default::default() - }, - ) + .request("abi.calc_function_id", ParamsOfCalcFunctionId { + abi: abi.clone(), + function_name: "getMessages".to_owned(), + ..Default::default() + }) .unwrap(); assert_eq!(result.function_id, 0x7744C7E2); let result: ResultOfCalcFunctionId = client - .request( - "abi.calc_function_id", - ParamsOfCalcFunctionId { - abi: abi.clone(), - function_name: "getMessages".to_owned(), - output: Some(true), - }, - ) + .request("abi.calc_function_id", ParamsOfCalcFunctionId { + abi: abi.clone(), + function_name: "getMessages".to_owned(), + output: Some(true), + }) .unwrap(); assert_eq!(result.function_id, 0xF744C7E2); @@ -1176,17 +1129,14 @@ fn decode_responsible() { let body = "te6ccgEBAgEAsQAB0IAAAAAAAABnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABDnTBYAAAAAAAAAAAAAAAAAO5rKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQCHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAD9YhN79S7hQOnrVCizdlF32dvf9Wk8XgGP1lsYvH/14AYHg="; let result: DecodedMessageBody = client - .request( - "abi.decode_message_body", - ParamsOfDecodeMessageBody { - abi, - body: body.to_owned(), - function_name: Some("onTip3LendOwnership".to_owned()), - data_layout: Some(DataLayout::Output), - is_internal: true, - ..Default::default() - }, - ) + .request("abi.decode_message_body", ParamsOfDecodeMessageBody { + abi, + body: body.to_owned(), + function_name: Some("onTip3LendOwnership".to_owned()), + data_layout: Some(DataLayout::Output), + is_internal: true, + ..Default::default() + }) .unwrap(); assert_eq!(expected, result); @@ -1302,16 +1252,14 @@ async fn test_deploy_code_variants_with_fn< convert_parsed(&encoded_with_code, ignore_data) ); - let data = crate::abi::encode_initial_data( - client.context(), - crate::abi::ParamsOfEncodeInitialData { + let data = + crate::abi::encode_initial_data(client.context(), crate::abi::ParamsOfEncodeInitialData { abi: abi.clone(), initial_data: initial_data.clone(), initial_pubkey: pubkey.clone(), ..Default::default() - }, - ) - .unwrap(); + }) + .unwrap(); let data = deserialize_cell_from_base64(&data.data, "Encoded initial data").unwrap(); state_init.set_data(data.1); @@ -1360,22 +1308,19 @@ async fn encode_internal_deploy( ) -> Value { let client = TestClient::new(); let encoded: ResultOfEncodeInternalMessage = client - .request_async( - "abi.encode_internal_message", - ParamsOfEncodeInternalMessage { - abi: Some(abi), - deploy_set: Some(DeploySet { - tvc, - code, - state_init, - initial_pubkey, - initial_data, - ..Default::default() - }), - value: "1000000000".to_string(), + .request_async("abi.encode_internal_message", ParamsOfEncodeInternalMessage { + abi: Some(abi), + deploy_set: Some(DeploySet { + tvc, + code, + state_init, + initial_pubkey, + initial_data, ..Default::default() - }, - ) + }), + value: "1000000000".to_string(), + ..Default::default() + }) .await .unwrap(); parse_message(client.context().clone(), ParamsOfParse { boc: encoded.message }).unwrap().parsed @@ -1391,21 +1336,18 @@ async fn encode_deploy( ) -> Value { let client = TestClient::new(); let encoded: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi, - deploy_set: Some(DeploySet { - tvc, - code, - state_init, - initial_pubkey, - initial_data, - ..Default::default() - }), + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi, + deploy_set: Some(DeploySet { + tvc, + code, + state_init, + initial_pubkey, + initial_data, ..Default::default() - }, - ) + }), + ..Default::default() + }) .await .unwrap(); parse_message(client.context().clone(), ParamsOfParse { boc: encoded.message }).unwrap().parsed @@ -1474,49 +1416,40 @@ fn test_abi_v24_changes() { assert_eq!(error.code, ErrorCode::PubKeyNotSupported as u32); let result: ResultOfEncodeInitialData = client - .request( - "abi.encode_initial_data", - ParamsOfEncodeInitialData { - abi: abi.clone(), - initial_data: Some(json!({ - "_pubkey": format!("0x{}", pubkey), - "value": 123, - })), - ..Default::default() - }, - ) + .request("abi.encode_initial_data", ParamsOfEncodeInitialData { + abi: abi.clone(), + initial_data: Some(json!({ + "_pubkey": format!("0x{}", pubkey), + "value": 123, + })), + ..Default::default() + }) .unwrap(); let abi_contract: AbiContract = serde_json::from_str(TINY_ABI_V24).unwrap(); let encoded_data: ResultOfEncodeBoc = client - .request( - "abi.encode_boc", - ParamsOfAbiEncodeBoc { - params: abi_contract.fields, - data: json!({ - "_pubkey": format!("0x{}", pubkey), - "value": 123, - "_constructorFlag": false, - "_timestamp": 0, - }), - ..Default::default() - }, - ) + .request("abi.encode_boc", ParamsOfAbiEncodeBoc { + params: abi_contract.fields, + data: json!({ + "_pubkey": format!("0x{}", pubkey), + "value": 123, + "_constructorFlag": false, + "_timestamp": 0, + }), + ..Default::default() + }) .unwrap(); assert_eq!(result.data, encoded_data.boc); let error = client - .request::<_, ResultOfEncodeMessage>( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - deploy_set: Some(DeploySet { - initial_pubkey: Some(pubkey.to_owned()), - tvc: Some(tvc.clone()), - ..Default::default() - }), + .request::<_, ResultOfEncodeMessage>("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + deploy_set: Some(DeploySet { + initial_pubkey: Some(pubkey.to_owned()), + tvc: Some(tvc.clone()), ..Default::default() - }, - ) + }), + ..Default::default() + }) .unwrap_err(); assert_eq!(error.code, ErrorCode::PubKeyNotSupported as u32); diff --git a/tvm_client/src/abi/types.rs b/tvm_client/src/abi/types.rs index 7c67415e6..0177dcae9 100644 --- a/tvm_client/src/abi/types.rs +++ b/tvm_client/src/abi/types.rs @@ -3,10 +3,10 @@ use std::sync::Arc; use tvm_abi::Token; use tvm_abi::TokenValue; +use crate::ClientContext; use crate::abi::Error; use crate::error::ClientError; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Serialize, Deserialize, Clone, Debug, ApiType, Default)] pub struct AbiHandle(u32); diff --git a/tvm_client/src/boc/cache.rs b/tvm_client/src/boc/cache.rs index d56c8a55e..707522a37 100644 --- a/tvm_client/src/boc/cache.rs +++ b/tvm_client/src/boc/cache.rs @@ -22,10 +22,10 @@ use tvm_types::Cell; use tvm_types::UInt256; use super::Error; +use crate::boc::internal::DeserializedBoc; use crate::boc::internal::deserialize_cell_from_base64; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::serialize_cell_to_base64; -use crate::boc::internal::DeserializedBoc; use crate::client::ClientContext; use crate::error::ClientResult; @@ -367,10 +367,10 @@ pub struct CachedBoc { impl CachedBoc { pub fn new(context: Arc, boc: String, pin: String) -> ClientResult { - let boc_ref = cache_set( - context.clone(), - ParamsOfBocCacheSet { boc, cache_type: BocCacheType::Pinned { pin: pin.clone() } }, - )? + let boc_ref = cache_set(context.clone(), ParamsOfBocCacheSet { + boc, + cache_type: BocCacheType::Pinned { pin: pin.clone() }, + })? .boc_ref; Ok(Self { context, boc_ref, pin }) @@ -387,12 +387,9 @@ impl CachedBoc { impl Drop for CachedBoc { fn drop(&mut self) { - let _ = cache_unpin( - self.context.clone(), - ParamsOfBocCacheUnpin { - pin: std::mem::take(&mut self.pin), - boc_ref: Some(std::mem::take(&mut self.boc_ref)), - }, - ); + let _ = cache_unpin(self.context.clone(), ParamsOfBocCacheUnpin { + pin: std::mem::take(&mut self.pin), + boc_ref: Some(std::mem::take(&mut self.boc_ref)), + }); } } diff --git a/tvm_client/src/boc/encode.rs b/tvm_client/src/boc/encode.rs index b3dfac450..8772b60b9 100644 --- a/tvm_client/src/boc/encode.rs +++ b/tvm_client/src/boc/encode.rs @@ -11,13 +11,13 @@ use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::IBitstring; -use super::internal::serialize_cell_to_boc; use super::Error; -use crate::boc::internal::deserialize_cell_from_boc; +use super::internal::serialize_cell_to_boc; +use crate::ClientContext; use crate::boc::BocCacheType; +use crate::boc::internal::deserialize_cell_from_boc; use crate::encoding::account_decode; use crate::error::ClientResult; -use crate::ClientContext; /// Cell builder operation. #[derive(Serialize, Deserialize, Clone, ApiType)] diff --git a/tvm_client/src/boc/encode_external_in_message.rs b/tvm_client/src/boc/encode_external_in_message.rs index 3f04cf3af..26e78577e 100644 --- a/tvm_client/src/boc/encode_external_in_message.rs +++ b/tvm_client/src/boc/encode_external_in_message.rs @@ -5,10 +5,10 @@ use tvm_block::GetRepresentationHash; use tvm_block::MsgAddressExt; use tvm_block::StateInit; +use crate::boc::BocCacheType; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::deserialize_object_from_boc; use crate::boc::internal::serialize_object_to_boc; -use crate::boc::BocCacheType; use crate::client::ClientContext; use crate::encoding::account_decode; use crate::encoding::slice_from_cell; diff --git a/tvm_client/src/boc/internal.rs b/tvm_client/src/boc/internal.rs index 98cb21537..ea5eb51a1 100644 --- a/tvm_client/src/boc/internal.rs +++ b/tvm_client/src/boc/internal.rs @@ -14,14 +14,14 @@ use std::str::FromStr; use tvm_block::Deserializable; use tvm_block::Serializable; +use tvm_types::UInt256; use tvm_types::base64_decode; use tvm_types::base64_encode; -use tvm_types::UInt256; +use crate::ClientContext; use crate::boc::BocCacheType; use crate::boc::Error; use crate::error::ClientResult; -use crate::ClientContext; pub(crate) fn get_boc_hash(boc: &[u8]) -> ClientResult { let cells = tvm_types::boc::read_single_root_boc(boc).map_err(Error::invalid_boc)?; diff --git a/tvm_client/src/boc/mod.rs b/tvm_client/src/boc/mod.rs index 7ca371046..bdd323254 100644 --- a/tvm_client/src/boc/mod.rs +++ b/tvm_client/src/boc/mod.rs @@ -26,12 +26,9 @@ pub(crate) mod encode_external_in_message; pub(crate) mod tests; pub(crate) mod tvc; -pub use blockchain_config::get_blockchain_config; pub use blockchain_config::ParamsOfGetBlockchainConfig; pub use blockchain_config::ResultOfGetBlockchainConfig; -pub use cache::cache_get; -pub use cache::cache_set; -pub use cache::cache_unpin; +pub use blockchain_config::get_blockchain_config; pub use cache::BocCacheType; pub use cache::CachedBoc; pub use cache::ParamsOfBocCacheGet; @@ -39,21 +36,27 @@ pub use cache::ParamsOfBocCacheSet; pub use cache::ParamsOfBocCacheUnpin; pub use cache::ResultOfBocCacheGet; pub use cache::ResultOfBocCacheSet; -pub use common::get_boc_depth; -pub use common::get_boc_hash; +pub use cache::cache_get; +pub use cache::cache_set; +pub use cache::cache_unpin; pub use common::ParamsOfGetBocDepth; pub use common::ParamsOfGetBocHash; pub use common::ResultOfGetBocDepth; pub use common::ResultOfGetBocHash; -pub use encode::encode_boc; +pub use common::get_boc_depth; +pub use common::get_boc_hash; pub use encode::BuilderOp; pub use encode::ParamsOfEncodeBoc; pub use encode::ResultOfEncodeBoc; -pub use encode_external_in_message::encode_external_in_message; +pub use encode::encode_boc; pub use encode_external_in_message::ParamsOfEncodeExternalInMessage; pub use encode_external_in_message::ResultOfEncodeExternalInMessage; +pub use encode_external_in_message::encode_external_in_message; pub use errors::Error; pub use errors::ErrorCode; +pub use parse::ParamsOfParse; +pub use parse::ParamsOfParseShardstate; +pub use parse::ResultOfParse; pub use parse::parse_account; pub use parse::parse_block; pub use parse::parse_message; @@ -61,17 +64,6 @@ pub use parse::parse_shardstate; pub use parse::parse_transaction; pub use parse::required_boc; pub use parse::source_boc; -pub use parse::ParamsOfParse; -pub use parse::ParamsOfParseShardstate; -pub use parse::ResultOfParse; -pub use state_init::decode_state_init; -pub use state_init::encode_state_init; -pub use state_init::get_code_from_tvc; -pub use state_init::get_code_salt; -pub use state_init::get_compiler_version; -pub use state_init::get_compiler_version_from_cell; -pub use state_init::set_code_salt; -pub use state_init::set_code_salt_cell; pub use state_init::ParamsOfDecodeStateInit; pub use state_init::ParamsOfEncodeStateInit; pub use state_init::ParamsOfGetCodeFromTvc; @@ -84,9 +76,17 @@ pub use state_init::ResultOfGetCodeFromTvc; pub use state_init::ResultOfGetCodeSalt; pub use state_init::ResultOfGetCompilerVersion; pub use state_init::ResultOfSetCodeSalt; -pub use tvc::decode_tvc; +pub use state_init::decode_state_init; +pub use state_init::encode_state_init; +pub use state_init::get_code_from_tvc; +pub use state_init::get_code_salt; +pub use state_init::get_compiler_version; +pub use state_init::get_compiler_version_from_cell; +pub use state_init::set_code_salt; +pub use state_init::set_code_salt_cell; pub use tvc::Tvc; pub use tvc::TvcV1; +pub use tvc::decode_tvc; pub fn default_cache_max_size() -> u32 { 10 * 1024 // * 1024 = 10 MB diff --git a/tvm_client/src/boc/parse.rs b/tvm_client/src/boc/parse.rs index d3289eab6..36b2dd022 100644 --- a/tvm_client/src/boc/parse.rs +++ b/tvm_client/src/boc/parse.rs @@ -14,8 +14,8 @@ use tvm_block::Deserializable; use super::internal::deserialize_cell_from_boc; use super::internal::deserialize_object_from_cell; -use crate::boc::internal::deserialize_object_from_boc; use crate::boc::Error; +use crate::boc::internal::deserialize_object_from_boc; use crate::client::ClientContext; use crate::error::ClientResult; diff --git a/tvm_client/src/boc/state_init.rs b/tvm_client/src/boc/state_init.rs index 2ea8b69db..14fe23235 100644 --- a/tvm_client/src/boc/state_init.rs +++ b/tvm_client/src/boc/state_init.rs @@ -17,13 +17,13 @@ use tvm_types::BuilderData; use tvm_types::Cell; use super::BocCacheType; +use crate::boc::Error; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::deserialize_object_from_boc; use crate::boc::internal::deserialize_object_from_cell; use crate::boc::internal::serialize_cell_to_boc; use crate::boc::internal::serialize_object_to_boc; use crate::boc::tvc::resolve_state_init_cell; -use crate::boc::Error; use crate::client::ClientContext; use crate::encoding::slice_from_cell; use crate::error::ClientResult; diff --git a/tvm_client/src/boc/tests.rs b/tvm_client/src/boc/tests.rs index 516bddf65..0d484e586 100644 --- a/tvm_client/src/boc/tests.rs +++ b/tvm_client/src/boc/tests.rs @@ -17,11 +17,11 @@ use serde_json::Value; use tvm_block::MsgAddrStd; use tvm_block::MsgAddressInt; use tvm_block::Serializable; -use tvm_types::base64_decode; -use tvm_types::base64_encode; use tvm_types::AccountId; use tvm_types::BuilderData; use tvm_types::IBitstring; +use tvm_types::base64_decode; +use tvm_types::base64_encode; use super::*; use crate::abi::CallSet; @@ -36,8 +36,8 @@ use crate::boc::tvc::ParamsOfDecodeTvc; use crate::boc::tvc::ResultOfDecodeTvc; use crate::crypto::KeyPair; use crate::json_interface::modules::BocModule; -use crate::tests::TestClient; use crate::tests::EVENTS_OLD; +use crate::tests::TestClient; #[test] fn test_encode_boc() { @@ -320,10 +320,9 @@ fn get_boc_depth() { let client = TestClient::new(); let result: ResultOfGetBocDepth = client - .request( - "boc.get_boc_depth", - ParamsOfGetBocDepth { boc: base64_encode(include_bytes!("test_data/account.boc")) }, - ) + .request("boc.get_boc_depth", ParamsOfGetBocDepth { + boc: base64_encode(include_bytes!("test_data/account.boc")), + }) .unwrap(); assert_eq!(result.depth, 24); @@ -385,10 +384,9 @@ fn parse_account() { let client = TestClient::new(); let result: ResultOfParse = client - .request( - "boc.parse_account", - ParamsOfParse { boc: base64_encode(include_bytes!("test_data/account.boc")) }, - ) + .request("boc.parse_account", ParamsOfParse { + boc: base64_encode(include_bytes!("test_data/account.boc")), + }) .unwrap(); assert_eq!( @@ -483,14 +481,11 @@ fn parse_shardstate() { let client = TestClient::new(); let result: ResultOfParse = client - .request( - "boc.parse_shardstate", - ParamsOfParseShardstate { - id: String::from("zerostate:-1"), - workchain_id: -1, - boc: base64_encode(include_bytes!("test_data/zerostate.boc")), - }, - ) + .request("boc.parse_shardstate", ParamsOfParseShardstate { + id: String::from("zerostate:-1"), + workchain_id: -1, + boc: base64_encode(include_bytes!("test_data/zerostate.boc")), + }) .unwrap(); assert_eq!(result.parsed["id"], "zerostate:-1"); @@ -504,23 +499,17 @@ fn get_blockchain_config() { let client = TestClient::new(); let result: ResultOfGetBlockchainConfig = client - .request( - "boc.get_blockchain_config", - ParamsOfGetBlockchainConfig { - block_boc: base64_encode(include_bytes!("test_data/block.boc")), - }, - ) + .request("boc.get_blockchain_config", ParamsOfGetBlockchainConfig { + block_boc: base64_encode(include_bytes!("test_data/block.boc")), + }) .unwrap(); assert_eq!(result.config_boc, base64_encode(include_bytes!("test_data/block_config.boc"))); let result: ResultOfGetBlockchainConfig = client - .request( - "boc.get_blockchain_config", - ParamsOfGetBlockchainConfig { - block_boc: base64_encode(include_bytes!("test_data/zerostate.boc")), - }, - ) + .request("boc.get_blockchain_config", ParamsOfGetBlockchainConfig { + block_boc: base64_encode(include_bytes!("test_data/zerostate.boc")), + }) .unwrap(); assert_eq!(result.config_boc, base64_encode(include_bytes!("test_data/zerostate_config.boc"))); @@ -539,22 +528,19 @@ fn check_salt( ) { let code = read_salted_boc(name); let result: ResultOfGetCodeSalt = client - .request( - "boc.get_code_salt", - ParamsOfGetCodeSalt { code: code.clone(), ..Default::default() }, - ) + .request("boc.get_code_salt", ParamsOfGetCodeSalt { + code: code.clone(), + ..Default::default() + }) .unwrap(); assert_eq!(result.salt.as_ref().map(AsRef::as_ref), read_salt); let result: ResultOfSetCodeSalt = client - .request( - "boc.set_code_salt", - ParamsOfSetCodeSalt { - code, - salt: set_salt.to_owned(), - boc_cache: Some(BocCacheType::Unpinned), - }, - ) + .request("boc.set_code_salt", ParamsOfSetCodeSalt { + code, + salt: set_salt.to_owned(), + boc_cache: Some(BocCacheType::Unpinned), + }) .unwrap(); if let Some(name_with_salt) = name_with_salt { @@ -565,10 +551,10 @@ fn check_salt( } let result: ResultOfGetCodeSalt = client - .request( - "boc.get_code_salt", - ParamsOfGetCodeSalt { code: result.code, ..Default::default() }, - ) + .request("boc.get_code_salt", ParamsOfGetCodeSalt { + code: result.code, + ..Default::default() + }) .unwrap(); assert_eq!(result.salt.unwrap(), set_salt); } @@ -650,36 +636,33 @@ fn test_code_salt() { let code = read_salted_boc("old_sol_sel.boc"); let result: ResultOfGetCodeSalt = client - .request( - "boc.get_code_salt", - ParamsOfGetCodeSalt { code: code.clone(), ..Default::default() }, - ) + .request("boc.get_code_salt", ParamsOfGetCodeSalt { + code: code.clone(), + ..Default::default() + }) .unwrap(); assert_eq!(result.salt, None); } fn check_encode_state_init(client: &TestClient, tvc: String, decoded: ResultOfDecodeStateInit) { let result: ResultOfDecodeStateInit = client - .request( - "boc.decode_state_init", - ParamsOfDecodeStateInit { state_init: tvc.clone(), boc_cache: None }, - ) + .request("boc.decode_state_init", ParamsOfDecodeStateInit { + state_init: tvc.clone(), + boc_cache: None, + }) .unwrap(); assert_eq!(result, decoded); let result: ResultOfEncodeStateInit = client - .request( - "boc.encode_state_init", - ParamsOfEncodeStateInit { - code: result.code, - data: result.data, - library: result.library, - split_depth: result.split_depth, - tick: result.tick, - tock: result.tock, - boc_cache: None, - }, - ) + .request("boc.encode_state_init", ParamsOfEncodeStateInit { + code: result.code, + data: result.data, + library: result.library, + split_depth: result.split_depth, + tick: result.tick, + tock: result.tock, + boc_cache: None, + }) .unwrap(); assert_eq!(result.state_init, tvc); } @@ -748,10 +731,10 @@ fn test_get_compiler_version() { let state_init = TestClient::tvc("t24_initdata", Some(2)).unwrap(); let code = client - .request::<_, ResultOfDecodeStateInit>( - "boc.decode_state_init", - ParamsOfDecodeStateInit { state_init, boc_cache: None }, - ) + .request::<_, ResultOfDecodeStateInit>("boc.decode_state_init", ParamsOfDecodeStateInit { + state_init, + boc_cache: None, + }) .unwrap() .code .unwrap(); @@ -800,10 +783,9 @@ fn encode_external_in_message() { ); let abi_parsed = client - .request::( - "boc.parse_message", - ParamsOfParse { boc: abi_encoded.message.clone() }, - ) + .request::("boc.parse_message", ParamsOfParse { + boc: abi_encoded.message.clone(), + }) .unwrap() .parsed; let init = client @@ -819,15 +801,12 @@ fn encode_external_in_message() { .unwrap() .state_init; let boc_encoded: ResultOfEncodeExternalInMessage = client - .request( - "boc.encode_external_in_message", - ParamsOfEncodeExternalInMessage { - dst: abi_encoded.address.clone(), - body: abi_parsed["body"].as_str().map(|x| x.to_string()), - init: Some(init), - ..Default::default() - }, - ) + .request("boc.encode_external_in_message", ParamsOfEncodeExternalInMessage { + dst: abi_encoded.address.clone(), + body: abi_parsed["body"].as_str().map(|x| x.to_string()), + init: Some(init), + ..Default::default() + }) .unwrap(); assert_eq!(boc_encoded.message, abi_encoded.message); diff --git a/tvm_client/src/boc/tvc.rs b/tvm_client/src/boc/tvc.rs index 5f7df9a7c..dfdfbe721 100644 --- a/tvm_client/src/boc/tvc.rs +++ b/tvm_client/src/boc/tvc.rs @@ -17,12 +17,12 @@ use tvm_block::StateInit; use tvm_struct::scheme::TVC; use tvm_types::Cell; +use crate::ClientContext; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::deserialize_object_from_boc; use crate::boc::internal::serialize_cell_to_base64; use crate::boc::internal::serialize_object_to_cell; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Serialize, Deserialize, ApiType, Default)] pub struct ParamsOfDecodeTvc { diff --git a/tvm_client/src/client/client.rs b/tvm_client/src/client/client.rs index ab7e59e79..78773e91d 100644 --- a/tvm_client/src/client/client.rs +++ b/tvm_client/src/client/client.rs @@ -10,38 +10,38 @@ // limitations under the License. use std::collections::HashMap; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; use lockfree::map::Map as LockfreeMap; -use serde::de::DeserializeOwned; use serde::Deserialize; use serde::Deserializer; use serde::Serialize; -use tokio::sync::oneshot; +use serde::de::DeserializeOwned; use tokio::sync::Mutex; use tokio::sync::RwLock; +use tokio::sync::oneshot; use tvm_client_processing::MessageMonitor; +use super::AppRequestResult; +use super::Error; +use super::ParamsOfAppRequest; #[cfg(not(feature = "wasm-base"))] use super::std_client_env::ClientEnv; #[cfg(feature = "wasm-base")] use super::wasm_client_env::ClientEnv; -use super::AppRequestResult; -use super::Error; -use super::ParamsOfAppRequest; use crate::abi::AbiConfig; -use crate::boc::cache::Bocs; use crate::boc::BocConfig; +use crate::boc::cache::Bocs; +use crate::client::BindingConfig; use crate::client::storage::KeyValueStorage; use crate::client::update_binding_config; -use crate::client::BindingConfig; +use crate::crypto::CryptoConfig; use crate::crypto::boxes::crypto_box::CryptoBox; use crate::crypto::boxes::crypto_box::DerivedKeys; use crate::crypto::boxes::encryption_box::EncryptionBox; use crate::crypto::boxes::signing_box::SigningBox; -use crate::crypto::CryptoConfig; use crate::debot::DEngine; use crate::error::ClientResult; use crate::json_interface::interop::ResponseType; diff --git a/tvm_client/src/client/client_env_tests.rs b/tvm_client/src/client/client_env_tests.rs index f75018a11..7cdc2fe20 100644 --- a/tvm_client/src/client/client_env_tests.rs +++ b/tvm_client/src/client/client_env_tests.rs @@ -1,7 +1,7 @@ use tvm_types::Result; -use crate::client::storage::KeyValueStorage; use crate::client::LocalStorage; +use crate::client::storage::KeyValueStorage; #[cfg(not(feature = "wasm-base"))] mod env { diff --git a/tvm_client/src/client/network_mock.rs b/tvm_client/src/client/network_mock.rs index b2148d7ac..926afbfe7 100644 --- a/tvm_client/src/client/network_mock.rs +++ b/tvm_client/src/client/network_mock.rs @@ -15,10 +15,10 @@ use std::collections::HashMap; use futures::SinkExt; use serde_json::Value; +use crate::ClientContext; use crate::client::FetchResult; use crate::client::WebSocket; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Debug, Clone)] pub(crate) struct FetchMock { diff --git a/tvm_client/src/client/std_client_env.rs b/tvm_client/src/client/std_client_env.rs index c48992754..16f3cf31a 100644 --- a/tvm_client/src/client/std_client_env.rs +++ b/tvm_client/src/client/std_client_env.rs @@ -18,12 +18,12 @@ use futures::Future; use futures::SinkExt; use futures::StreamExt; use lazy_static::lazy_static; -use reqwest::header::HeaderMap; -use reqwest::header::HeaderName; -use reqwest::header::HeaderValue; use reqwest::Client as HttpClient; use reqwest::ClientBuilder; use reqwest::Method; +use reqwest::header::HeaderMap; +use reqwest::header::HeaderName; +use reqwest::header::HeaderValue; use tokio::runtime::Runtime; #[cfg(test)] use tokio::sync::RwLock; @@ -33,10 +33,10 @@ use super::Error; use super::FetchMethod; use super::FetchResult; use super::WebSocket; +use crate::client::LOCAL_STORAGE_DEFAULT_DIR_NAME; #[cfg(test)] use crate::client::network_mock::NetworkMock; use crate::client::storage::KeyValueStorage; -use crate::client::LOCAL_STORAGE_DEFAULT_DIR_NAME; use crate::error::ClientResult; #[cfg(test)] diff --git a/tvm_client/src/client/tests.rs b/tvm_client/src/client/tests.rs index 1fa1e8ba4..ed5e40d79 100644 --- a/tvm_client/src/client/tests.rs +++ b/tvm_client/src/client/tests.rs @@ -3,17 +3,17 @@ use std::time::Duration; use api_info::ApiModule; use serde_json::Value; +use crate::ClientConfig; use crate::client::ResultOfGetApiReference; use crate::create_context; use crate::crypto::default_mnemonic_word_count; use crate::destroy_context; use crate::json_interface::modules::ClientModule; use crate::json_interface::runtime::Runtime; +use crate::net::ParamsOfSubscribeCollection; use crate::net::subscribe_collection; use crate::net::unsubscribe; -use crate::net::ParamsOfSubscribeCollection; use crate::tests::TestClient; -use crate::ClientConfig; #[test] fn test_config_fields() { diff --git a/tvm_client/src/client/wasm_client_env.rs b/tvm_client/src/client/wasm_client_env.rs index 0f06fc3ed..9ed448acd 100644 --- a/tvm_client/src/client/wasm_client_env.rs +++ b/tvm_client/src/client/wasm_client_env.rs @@ -16,10 +16,10 @@ use futures::Future; use futures::FutureExt; use futures::SinkExt; use futures::StreamExt; -use indexed_db_futures::request::IdbOpenDbRequestLike; use indexed_db_futures::IdbDatabase; use indexed_db_futures::IdbQuerySource; use indexed_db_futures::IdbVersionChangeEvent; +use indexed_db_futures::request::IdbOpenDbRequestLike; use js_sys::JSON; use tvm_types::base64_decode; use tvm_types::base64_encode; @@ -37,8 +37,8 @@ use super::Error; use super::FetchMethod; use super::FetchResult; use super::WebSocket; -use crate::client::storage::KeyValueStorage; use crate::client::LOCAL_STORAGE_DEFAULT_DIR_NAME; +use crate::client::storage::KeyValueStorage; use crate::error::ClientResult; #[cfg(test)] diff --git a/tvm_client/src/crypto/boxes/crypto_box/encryption.rs b/tvm_client/src/crypto/boxes/crypto_box/encryption.rs index f671e5aab..583decef9 100644 --- a/tvm_client/src/crypto/boxes/crypto_box/encryption.rs +++ b/tvm_client/src/crypto/boxes/crypto_box/encryption.rs @@ -10,11 +10,11 @@ use zeroize::Zeroize; use super::Error; use super::PasswordProvider; +use crate::ClientContext; use crate::crypto::boxes::crypto_box::SecretInternal; use crate::crypto::internal::SecretBuf; use crate::crypto::nacl::nacl_box_open_internal; use crate::error::ClientResult; -use crate::ClientContext; const NONCE_LEN: usize = 12; diff --git a/tvm_client/src/crypto/boxes/crypto_box/mod.rs b/tvm_client/src/crypto/boxes/crypto_box/mod.rs index a03072b3e..7af6b834e 100644 --- a/tvm_client/src/crypto/boxes/crypto_box/mod.rs +++ b/tvm_client/src/crypto/boxes/crypto_box/mod.rs @@ -7,6 +7,15 @@ use tokio::sync::RwLock; use tvm_types::base64_encode; use zeroize::Zeroize; +use crate::ClientContext; +use crate::crypto::CryptoConfig; +use crate::crypto::EncryptionBox; +use crate::crypto::EncryptionBoxInfo; +use crate::crypto::Error; +use crate::crypto::MnemonicDictionary; +use crate::crypto::RegisteredEncryptionBox; +use crate::crypto::RegisteredSigningBox; +use crate::crypto::SigningBox; use crate::crypto::boxes::crypto_box::encryption::decrypt_secret; use crate::crypto::boxes::crypto_box::encryption::encrypt_secret; use crate::crypto::boxes::encryption_box::chacha20::ChaCha20EncryptionBox; @@ -19,17 +28,8 @@ use crate::crypto::internal::SecretString; use crate::crypto::mnemonic::mnemonics; use crate::crypto::register_encryption_box; use crate::crypto::register_signing_box; -use crate::crypto::CryptoConfig; -use crate::crypto::EncryptionBox; -use crate::crypto::EncryptionBoxInfo; -use crate::crypto::Error; -use crate::crypto::MnemonicDictionary; -use crate::crypto::RegisteredEncryptionBox; -use crate::crypto::RegisteredSigningBox; -use crate::crypto::SigningBox; use crate::encoding::base64_decode; use crate::error::ClientResult; -use crate::ClientContext; mod derived_keys; mod encryption; @@ -325,17 +325,14 @@ pub async fn get_signing_box_from_crypto_box( context: Arc, params: ParamsOfGetSigningBoxFromCryptoBox, ) -> ClientResult { - register_signing_box( - context, - BoxFromCryptoBoxLifeCycleManager:: { - params: InternalBoxParams { - handle: params.handle, - hdpath: params.hdpath, - secret_lifetime: params.secret_lifetime, - }, - internal_box: Default::default(), + register_signing_box(context, BoxFromCryptoBoxLifeCycleManager:: { + params: InternalBoxParams { + handle: params.handle, + hdpath: params.hdpath, + secret_lifetime: params.secret_lifetime, }, - ) + internal_box: Default::default(), + }) .await } @@ -363,10 +360,9 @@ impl BoxFromCryptoBoxLifeCycleManager { return callback(Arc::clone(internal_box)).await; } - let seed_phrase = get_crypto_box_seed_phrase( - Arc::clone(&context), - RegisteredCryptoBox { handle: CryptoBoxHandle(self.params.handle) }, - ) + let seed_phrase = get_crypto_box_seed_phrase(Arc::clone(&context), RegisteredCryptoBox { + handle: CryptoBoxHandle(self.params.handle), + }) .await?; let hdpath = diff --git a/tvm_client/src/crypto/boxes/encryption_box/aes.rs b/tvm_client/src/crypto/boxes/encryption_box/aes.rs index a07eb8823..cc34a945f 100644 --- a/tvm_client/src/crypto/boxes/encryption_box/aes.rs +++ b/tvm_client/src/crypto/boxes/encryption_box/aes.rs @@ -27,13 +27,13 @@ use zeroize::ZeroizeOnDrop; use super::CipherMode; use super::EncryptionBox; use super::EncryptionBoxInfo; -use crate::crypto::internal::hex_decode_secret; -use crate::crypto::internal::SecretBuf; +use crate::ClientContext; use crate::crypto::Error; +use crate::crypto::internal::SecretBuf; +use crate::crypto::internal::hex_decode_secret; use crate::encoding::base64_decode; use crate::encoding::hex_decode; use crate::error::ClientResult; -use crate::ClientContext; #[derive(Serialize, Deserialize, Clone, Debug, ApiType, Default, PartialEq, ZeroizeOnDrop)] pub struct AesParamsEB { diff --git a/tvm_client/src/crypto/boxes/encryption_box/chacha20.rs b/tvm_client/src/crypto/boxes/encryption_box/chacha20.rs index b6e1ef03d..e5c4c9cc4 100644 --- a/tvm_client/src/crypto/boxes/encryption_box/chacha20.rs +++ b/tvm_client/src/crypto/boxes/encryption_box/chacha20.rs @@ -1,21 +1,21 @@ use std::sync::Arc; -use chacha20::cipher::NewStreamCipher; -use chacha20::cipher::SyncStreamCipher; use chacha20::Key; use chacha20::Nonce; +use chacha20::cipher::NewStreamCipher; +use chacha20::cipher::SyncStreamCipher; use tvm_types::base64_encode; use zeroize::Zeroize; -use crate::crypto::internal::hex_decode_secret; -use crate::crypto::internal::SecretBuf; +use crate::ClientContext; use crate::crypto::EncryptionBox; use crate::crypto::EncryptionBoxInfo; use crate::crypto::Error; +use crate::crypto::internal::SecretBuf; +use crate::crypto::internal::hex_decode_secret; use crate::encoding::base64_decode; use crate::encoding::hex_decode; use crate::error::ClientResult; -use crate::ClientContext; #[derive( Serialize, Deserialize, Clone, Debug, ApiType, Default, PartialEq, Zeroize, ZeroizeOnDrop, diff --git a/tvm_client/src/crypto/boxes/encryption_box/nacl_box.rs b/tvm_client/src/crypto/boxes/encryption_box/nacl_box.rs index e607de9b7..5382c1a96 100644 --- a/tvm_client/src/crypto/boxes/encryption_box/nacl_box.rs +++ b/tvm_client/src/crypto/boxes/encryption_box/nacl_box.rs @@ -2,16 +2,16 @@ use std::sync::Arc; use zeroize::Zeroize; -use crate::crypto::nacl_box; -use crate::crypto::nacl_box_keypair_from_secret_key; -use crate::crypto::nacl_box_open; +use crate::ClientContext; use crate::crypto::EncryptionBox; use crate::crypto::EncryptionBoxInfo; use crate::crypto::ParamsOfNaclBox; use crate::crypto::ParamsOfNaclBoxKeyPairFromSecret; use crate::crypto::ParamsOfNaclBoxOpen; +use crate::crypto::nacl_box; +use crate::crypto::nacl_box_keypair_from_secret_key; +use crate::crypto::nacl_box_open; use crate::error::ClientResult; -use crate::ClientContext; #[derive( Serialize, Deserialize, Clone, Debug, ApiType, Default, PartialEq, Zeroize, ZeroizeOnDrop, @@ -40,10 +40,10 @@ impl NaclEncryptionBox { #[async_trait::async_trait] impl EncryptionBox for NaclEncryptionBox { async fn get_info(&self, context: Arc) -> ClientResult { - let mut keys = nacl_box_keypair_from_secret_key( - context, - ParamsOfNaclBoxKeyPairFromSecret { secret: self.params.secret.clone() }, - )?; + let mut keys = + nacl_box_keypair_from_secret_key(context, ParamsOfNaclBoxKeyPairFromSecret { + secret: self.params.secret.clone(), + })?; Ok(EncryptionBoxInfo { algorithm: Some("NaclBox".to_owned()), hdpath: self.hdpath.clone(), @@ -56,28 +56,22 @@ impl EncryptionBox for NaclEncryptionBox { } async fn encrypt(&self, context: Arc, data: &String) -> ClientResult { - nacl_box( - context, - ParamsOfNaclBox { - decrypted: data.clone(), - nonce: self.params.nonce.clone(), - their_public: self.params.their_public.clone(), - secret: self.params.secret.clone(), - }, - ) + nacl_box(context, ParamsOfNaclBox { + decrypted: data.clone(), + nonce: self.params.nonce.clone(), + their_public: self.params.their_public.clone(), + secret: self.params.secret.clone(), + }) .map(|result| result.encrypted) } async fn decrypt(&self, context: Arc, data: &String) -> ClientResult { - nacl_box_open( - context, - ParamsOfNaclBoxOpen { - encrypted: data.clone(), - nonce: self.params.nonce.clone(), - their_public: self.params.their_public.clone(), - secret: self.params.secret.clone(), - }, - ) + nacl_box_open(context, ParamsOfNaclBoxOpen { + encrypted: data.clone(), + nonce: self.params.nonce.clone(), + their_public: self.params.their_public.clone(), + secret: self.params.secret.clone(), + }) .map(|result| result.decrypted) } } diff --git a/tvm_client/src/crypto/boxes/encryption_box/nacl_secret_box.rs b/tvm_client/src/crypto/boxes/encryption_box/nacl_secret_box.rs index 9c126a0ad..765a9a47f 100644 --- a/tvm_client/src/crypto/boxes/encryption_box/nacl_secret_box.rs +++ b/tvm_client/src/crypto/boxes/encryption_box/nacl_secret_box.rs @@ -2,14 +2,14 @@ use std::sync::Arc; use zeroize::Zeroize; -use crate::crypto::nacl_secret_box; -use crate::crypto::nacl_secret_box_open; +use crate::ClientContext; use crate::crypto::EncryptionBox; use crate::crypto::EncryptionBoxInfo; use crate::crypto::ParamsOfNaclSecretBox; use crate::crypto::ParamsOfNaclSecretBoxOpen; +use crate::crypto::nacl_secret_box; +use crate::crypto::nacl_secret_box_open; use crate::error::ClientResult; -use crate::ClientContext; #[derive( Serialize, Deserialize, Clone, Debug, ApiType, Default, PartialEq, Zeroize, ZeroizeOnDrop, @@ -45,26 +45,20 @@ impl EncryptionBox for NaclSecretEncryptionBox { } async fn encrypt(&self, context: Arc, data: &String) -> ClientResult { - nacl_secret_box( - context, - ParamsOfNaclSecretBox { - decrypted: data.clone(), - nonce: self.params.nonce.clone(), - key: self.params.key.clone(), - }, - ) + nacl_secret_box(context, ParamsOfNaclSecretBox { + decrypted: data.clone(), + nonce: self.params.nonce.clone(), + key: self.params.key.clone(), + }) .map(|result| result.encrypted) } async fn decrypt(&self, context: Arc, data: &String) -> ClientResult { - nacl_secret_box_open( - context, - ParamsOfNaclSecretBoxOpen { - encrypted: data.clone(), - nonce: self.params.nonce.clone(), - key: self.params.key.to_string(), - }, - ) + nacl_secret_box_open(context, ParamsOfNaclSecretBoxOpen { + encrypted: data.clone(), + nonce: self.params.nonce.clone(), + key: self.params.key.to_string(), + }) .map(|result| result.decrypted) } } diff --git a/tvm_client/src/crypto/encryption.rs b/tvm_client/src/crypto/encryption.rs index 93a3aa5e7..a385a75fa 100644 --- a/tvm_client/src/crypto/encryption.rs +++ b/tvm_client/src/crypto/encryption.rs @@ -12,15 +12,15 @@ use std::sync::Arc; -use chacha20::cipher::NewStreamCipher; -use chacha20::cipher::SyncStreamCipher; use chacha20::Key; use chacha20::Nonce; +use chacha20::cipher::NewStreamCipher; +use chacha20::cipher::SyncStreamCipher; use tvm_types::base64_encode; use zeroize::ZeroizeOnDrop; -use super::internal::hex_decode_secret; use super::Error; +use super::internal::hex_decode_secret; use crate::client::ClientContext; use crate::encoding::base64_decode; use crate::encoding::hex_decode; diff --git a/tvm_client/src/crypto/errors.rs b/tvm_client/src/crypto/errors.rs index c4a98fe5c..153c9aaf3 100644 --- a/tvm_client/src/crypto/errors.rs +++ b/tvm_client/src/crypto/errors.rs @@ -1,7 +1,7 @@ use std::fmt::Display; -use super::keys::strip_secret; use super::CipherMode; +use super::keys::strip_secret; use crate::error::ClientError; #[derive(ApiType)] diff --git a/tvm_client/src/crypto/hdkey.rs b/tvm_client/src/crypto/hdkey.rs index 8a71c17ff..1c78587d1 100644 --- a/tvm_client/src/crypto/hdkey.rs +++ b/tvm_client/src/crypto/hdkey.rs @@ -23,15 +23,15 @@ use zeroize::ZeroizeOnDrop; use crate::client::ClientContext; use crate::crypto; +use crate::crypto::MnemonicDictionary; use crate::crypto::default_hdkey_compliant; +use crate::crypto::internal::Key256; +use crate::crypto::internal::Key264; use crate::crypto::internal::key256; use crate::crypto::internal::key512; use crate::crypto::internal::sha256; -use crate::crypto::internal::Key256; -use crate::crypto::internal::Key264; use crate::crypto::mnemonic::check_phrase; use crate::crypto::mnemonic::mnemonics; -use crate::crypto::MnemonicDictionary; use crate::error::ClientError; use crate::error::ClientResult; diff --git a/tvm_client/src/crypto/keys.rs b/tvm_client/src/crypto/keys.rs index ccc4e8b1f..e662466b6 100644 --- a/tvm_client/src/crypto/keys.rs +++ b/tvm_client/src/crypto/keys.rs @@ -16,8 +16,8 @@ use base64::Engine; use ed25519_dalek::SigningKey; use tvm_types::base64_encode; -use super::internal::hex_decode_secret_const; use super::internal::SecretBufConst; +use super::internal::hex_decode_secret_const; use crate::client::ClientContext; use crate::crypto; use crate::crypto::internal::decode_public_key; diff --git a/tvm_client/src/crypto/math.rs b/tvm_client/src/crypto/math.rs index decb5b505..4a58236c5 100644 --- a/tvm_client/src/crypto/math.rs +++ b/tvm_client/src/crypto/math.rs @@ -177,11 +177,7 @@ fn gcd(mut a: u64, mut b: u64) -> u64 { } } - if b == 0 { - a - } else { - b - } + if b == 0 { a } else { b } } //------------------------------------------------------------------- tvm_crc16 diff --git a/tvm_client/src/crypto/mnemonic.rs b/tvm_client/src/crypto/mnemonic.rs index ee3366056..04a1bf5c9 100644 --- a/tvm_client/src/crypto/mnemonic.rs +++ b/tvm_client/src/crypto/mnemonic.rs @@ -21,6 +21,7 @@ use zeroize::ZeroizeOnDrop; use crate::client::ClientContext; use crate::crypto; +use crate::crypto::CryptoConfig; use crate::crypto::default_hdkey_compliant; use crate::crypto::hdkey::HDPrivateKey; use crate::crypto::internal::hex_decode_secret; @@ -28,7 +29,6 @@ use crate::crypto::internal::hmac_sha512; use crate::crypto::internal::key256; use crate::crypto::internal::pbkdf2_hmac_sha512; use crate::crypto::keys::KeyPair; -use crate::crypto::CryptoConfig; use crate::error::ClientError; use crate::error::ClientResult; diff --git a/tvm_client/src/crypto/mod.rs b/tvm_client/src/crypto/mod.rs index d36cc1f95..4ec0e8b9f 100644 --- a/tvm_client/src/crypto/mod.rs +++ b/tvm_client/src/crypto/mod.rs @@ -26,19 +26,12 @@ pub(crate) mod encryption; #[cfg(test)] mod tests; -pub use encryption::chacha20; pub use encryption::ParamsOfChaCha20; pub use encryption::ResultOfChaCha20; +pub use encryption::chacha20; use serde::Deserialize; use serde::Deserializer; -pub use crate::crypto::boxes::crypto_box::clear_crypto_box_secret_cache; -pub use crate::crypto::boxes::crypto_box::create_crypto_box; -pub use crate::crypto::boxes::crypto_box::get_crypto_box_info; -pub use crate::crypto::boxes::crypto_box::get_crypto_box_seed_phrase; -pub use crate::crypto::boxes::crypto_box::get_encryption_box_from_crypto_box; -pub use crate::crypto::boxes::crypto_box::get_signing_box_from_crypto_box; -pub use crate::crypto::boxes::crypto_box::remove_crypto_box; pub use crate::crypto::boxes::crypto_box::AppPasswordProvider; pub use crate::crypto::boxes::crypto_box::BoxEncryptionAlgorithm; pub use crate::crypto::boxes::crypto_box::ChaCha20ParamsCB; @@ -52,6 +45,25 @@ pub use crate::crypto::boxes::crypto_box::RegisteredCryptoBox; pub use crate::crypto::boxes::crypto_box::ResultOfGetCryptoBoxInfo; pub use crate::crypto::boxes::crypto_box::ResultOfGetCryptoBoxSeedPhrase; pub use crate::crypto::boxes::crypto_box::ResultOfGetPassword; +pub use crate::crypto::boxes::crypto_box::clear_crypto_box_secret_cache; +pub use crate::crypto::boxes::crypto_box::create_crypto_box; +pub use crate::crypto::boxes::crypto_box::get_crypto_box_info; +pub use crate::crypto::boxes::crypto_box::get_crypto_box_seed_phrase; +pub use crate::crypto::boxes::crypto_box::get_encryption_box_from_crypto_box; +pub use crate::crypto::boxes::crypto_box::get_signing_box_from_crypto_box; +pub use crate::crypto::boxes::crypto_box::remove_crypto_box; +pub use crate::crypto::boxes::encryption_box::CipherMode; +pub use crate::crypto::boxes::encryption_box::EncryptionAlgorithm; +pub use crate::crypto::boxes::encryption_box::EncryptionBox; +pub use crate::crypto::boxes::encryption_box::EncryptionBoxHandle; +pub use crate::crypto::boxes::encryption_box::EncryptionBoxInfo; +pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxDecrypt; +pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxEncrypt; +pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxGetInfo; +pub use crate::crypto::boxes::encryption_box::RegisteredEncryptionBox; +pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxDecrypt; +pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxEncrypt; +pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxGetInfo; pub use crate::crypto::boxes::encryption_box::aes::AesEncryptionBox; pub use crate::crypto::boxes::encryption_box::aes::AesInfo; pub use crate::crypto::boxes::encryption_box::aes::AesParamsEB; @@ -67,41 +79,24 @@ pub use crate::crypto::boxes::encryption_box::nacl_secret_box::NaclSecretBoxPara pub use crate::crypto::boxes::encryption_box::nacl_secret_box::NaclSecretEncryptionBox; pub use crate::crypto::boxes::encryption_box::register_encryption_box; pub use crate::crypto::boxes::encryption_box::remove_encryption_box; -pub use crate::crypto::boxes::encryption_box::CipherMode; -pub use crate::crypto::boxes::encryption_box::EncryptionAlgorithm; -pub use crate::crypto::boxes::encryption_box::EncryptionBox; -pub use crate::crypto::boxes::encryption_box::EncryptionBoxHandle; -pub use crate::crypto::boxes::encryption_box::EncryptionBoxInfo; -pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxDecrypt; -pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxEncrypt; -pub use crate::crypto::boxes::encryption_box::ParamsOfEncryptionBoxGetInfo; -pub use crate::crypto::boxes::encryption_box::RegisteredEncryptionBox; -pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxDecrypt; -pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxEncrypt; -pub use crate::crypto::boxes::encryption_box::ResultOfEncryptionBoxGetInfo; -pub use crate::crypto::boxes::signing_box::get_signing_box; -pub use crate::crypto::boxes::signing_box::register_signing_box; -pub use crate::crypto::boxes::signing_box::remove_signing_box; -pub use crate::crypto::boxes::signing_box::signing_box_get_public_key; -pub use crate::crypto::boxes::signing_box::signing_box_sign; pub use crate::crypto::boxes::signing_box::ParamsOfSigningBoxSign; pub use crate::crypto::boxes::signing_box::RegisteredSigningBox; pub use crate::crypto::boxes::signing_box::ResultOfSigningBoxGetPublicKey; pub use crate::crypto::boxes::signing_box::ResultOfSigningBoxSign; pub use crate::crypto::boxes::signing_box::SigningBox; pub use crate::crypto::boxes::signing_box::SigningBoxHandle; -pub use crate::crypto::encscrypt::scrypt; +pub use crate::crypto::boxes::signing_box::get_signing_box; +pub use crate::crypto::boxes::signing_box::register_signing_box; +pub use crate::crypto::boxes::signing_box::remove_signing_box; +pub use crate::crypto::boxes::signing_box::signing_box_get_public_key; +pub use crate::crypto::boxes::signing_box::signing_box_sign; pub use crate::crypto::encscrypt::ParamsOfScrypt; pub use crate::crypto::encscrypt::ResultOfScrypt; -pub use crate::crypto::hash::sha256; -pub use crate::crypto::hash::sha512; +pub use crate::crypto::encscrypt::scrypt; pub use crate::crypto::hash::ParamsOfHash; pub use crate::crypto::hash::ResultOfHash; -pub use crate::crypto::hdkey::hdkey_derive_from_xprv; -pub use crate::crypto::hdkey::hdkey_derive_from_xprv_path; -pub use crate::crypto::hdkey::hdkey_public_from_xprv; -pub use crate::crypto::hdkey::hdkey_secret_from_xprv; -pub use crate::crypto::hdkey::hdkey_xprv_from_mnemonic; +pub use crate::crypto::hash::sha256; +pub use crate::crypto::hash::sha512; pub use crate::crypto::hdkey::ParamsOfHDKeyDeriveFromXPrv; pub use crate::crypto::hdkey::ParamsOfHDKeyDeriveFromXPrvPath; pub use crate::crypto::hdkey::ParamsOfHDKeyPublicFromXPrv; @@ -112,10 +107,11 @@ pub use crate::crypto::hdkey::ResultOfHDKeyDeriveFromXPrvPath; pub use crate::crypto::hdkey::ResultOfHDKeyPublicFromXPrv; pub use crate::crypto::hdkey::ResultOfHDKeySecretFromXPrv; pub use crate::crypto::hdkey::ResultOfHDKeyXPrvFromMnemonic; -pub use crate::crypto::keys::convert_public_key_to_tvm_safe_format; -pub use crate::crypto::keys::generate_random_sign_keys; -pub use crate::crypto::keys::sign; -pub use crate::crypto::keys::verify_signature; +pub use crate::crypto::hdkey::hdkey_derive_from_xprv; +pub use crate::crypto::hdkey::hdkey_derive_from_xprv_path; +pub use crate::crypto::hdkey::hdkey_public_from_xprv; +pub use crate::crypto::hdkey::hdkey_secret_from_xprv; +pub use crate::crypto::hdkey::hdkey_xprv_from_mnemonic; pub use crate::crypto::keys::KeyPair; pub use crate::crypto::keys::ParamsOfConvertPublicKeyToTonSafeFormat; pub use crate::crypto::keys::ParamsOfSign; @@ -123,10 +119,10 @@ pub use crate::crypto::keys::ParamsOfVerifySignature; pub use crate::crypto::keys::ResultOfConvertPublicKeyToTonSafeFormat; pub use crate::crypto::keys::ResultOfSign; pub use crate::crypto::keys::ResultOfVerifySignature; -pub use crate::crypto::math::factorize; -pub use crate::crypto::math::generate_random_bytes; -pub use crate::crypto::math::modular_power; -pub use crate::crypto::math::tvm_crc16; +pub use crate::crypto::keys::convert_public_key_to_tvm_safe_format; +pub use crate::crypto::keys::generate_random_sign_keys; +pub use crate::crypto::keys::sign; +pub use crate::crypto::keys::verify_signature; pub use crate::crypto::math::ParamsOfFactorize; pub use crate::crypto::math::ParamsOfGenerateRandomBytes; pub use crate::crypto::math::ParamsOfModularPower; @@ -135,11 +131,10 @@ pub use crate::crypto::math::ResultOfFactorize; pub use crate::crypto::math::ResultOfGenerateRandomBytes; pub use crate::crypto::math::ResultOfModularPower; pub use crate::crypto::math::ResultOfTonCrc16; -pub use crate::crypto::mnemonic::mnemonic_derive_sign_keys; -pub use crate::crypto::mnemonic::mnemonic_from_entropy; -pub use crate::crypto::mnemonic::mnemonic_from_random; -pub use crate::crypto::mnemonic::mnemonic_verify; -pub use crate::crypto::mnemonic::mnemonic_words; +pub use crate::crypto::math::factorize; +pub use crate::crypto::math::generate_random_bytes; +pub use crate::crypto::math::modular_power; +pub use crate::crypto::math::tvm_crc16; pub use crate::crypto::mnemonic::MnemonicDictionary; pub use crate::crypto::mnemonic::ParamsOfMnemonicDeriveSignKeys; pub use crate::crypto::mnemonic::ParamsOfMnemonicFromEntropy; @@ -150,17 +145,11 @@ pub use crate::crypto::mnemonic::ResultOfMnemonicFromEntropy; pub use crate::crypto::mnemonic::ResultOfMnemonicFromRandom; pub use crate::crypto::mnemonic::ResultOfMnemonicVerify; pub use crate::crypto::mnemonic::ResultOfMnemonicWords; -pub use crate::crypto::nacl::nacl_box; -pub use crate::crypto::nacl::nacl_box_keypair; -pub use crate::crypto::nacl::nacl_box_keypair_from_secret_key; -pub use crate::crypto::nacl::nacl_box_open; -pub use crate::crypto::nacl::nacl_secret_box; -pub use crate::crypto::nacl::nacl_secret_box_open; -pub use crate::crypto::nacl::nacl_sign; -pub use crate::crypto::nacl::nacl_sign_detached; -pub use crate::crypto::nacl::nacl_sign_detached_verify; -pub use crate::crypto::nacl::nacl_sign_keypair_from_secret_key; -pub use crate::crypto::nacl::nacl_sign_open; +pub use crate::crypto::mnemonic::mnemonic_derive_sign_keys; +pub use crate::crypto::mnemonic::mnemonic_from_entropy; +pub use crate::crypto::mnemonic::mnemonic_from_random; +pub use crate::crypto::mnemonic::mnemonic_verify; +pub use crate::crypto::mnemonic::mnemonic_words; pub use crate::crypto::nacl::ParamsOfNaclBox; pub use crate::crypto::nacl::ParamsOfNaclBoxKeyPairFromSecret; pub use crate::crypto::nacl::ParamsOfNaclBoxOpen; @@ -177,6 +166,17 @@ pub use crate::crypto::nacl::ResultOfNaclSign; pub use crate::crypto::nacl::ResultOfNaclSignDetached; pub use crate::crypto::nacl::ResultOfNaclSignDetachedVerify; pub use crate::crypto::nacl::ResultOfNaclSignOpen; +pub use crate::crypto::nacl::nacl_box; +pub use crate::crypto::nacl::nacl_box_keypair; +pub use crate::crypto::nacl::nacl_box_keypair_from_secret_key; +pub use crate::crypto::nacl::nacl_box_open; +pub use crate::crypto::nacl::nacl_secret_box; +pub use crate::crypto::nacl::nacl_secret_box_open; +pub use crate::crypto::nacl::nacl_sign; +pub use crate::crypto::nacl::nacl_sign_detached; +pub use crate::crypto::nacl::nacl_sign_detached_verify; +pub use crate::crypto::nacl::nacl_sign_keypair_from_secret_key; +pub use crate::crypto::nacl::nacl_sign_open; pub fn default_mnemonic_word_count() -> u8 { 12 diff --git a/tvm_client/src/crypto/nacl.rs b/tvm_client/src/crypto/nacl.rs index 87997a9b8..35b8cf4da 100644 --- a/tvm_client/src/crypto/nacl.rs +++ b/tvm_client/src/crypto/nacl.rs @@ -14,17 +14,17 @@ use tvm_types::base64_encode; use zeroize::Zeroize; use zeroize::ZeroizeOnDrop; +use super::internal::SecretBufConst; use super::internal::decode_public_key; use super::internal::hex_decode_secret; use super::internal::hex_decode_secret_const; -use super::internal::SecretBufConst; use crate::client::ClientContext; +use crate::crypto::Error; use crate::crypto::internal; use crate::crypto::internal::key192; use crate::crypto::internal::key256; use crate::crypto::internal::key512; use crate::crypto::keys::KeyPair; -use crate::crypto::Error; use crate::encoding::base64_decode; use crate::encoding::hex_decode; use crate::error::ClientResult; diff --git a/tvm_client/src/crypto/tests.rs b/tvm_client/src/crypto/tests.rs index bf73857d2..2975d3e36 100644 --- a/tvm_client/src/crypto/tests.rs +++ b/tvm_client/src/crypto/tests.rs @@ -1,6 +1,6 @@ +use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; use tvm_types::base64_decode; use tvm_types::base64_encode; @@ -31,25 +31,19 @@ fn encryption() { let key = "01".repeat(32); let nonce = "ff".repeat(12); let encrypted: ResultOfChaCha20 = client - .request( - "crypto.chacha20", - ParamsOfChaCha20 { - data: base64_encode("Message"), - key: key.clone(), - nonce: nonce.clone(), - }, - ) + .request("crypto.chacha20", ParamsOfChaCha20 { + data: base64_encode("Message"), + key: key.clone(), + nonce: nonce.clone(), + }) .unwrap(); assert_eq!(encrypted.data, "w5QOGsJodQ=="); let decrypted: ResultOfChaCha20 = client - .request( - "crypto.chacha20", - ParamsOfChaCha20 { - data: encrypted.data.clone(), - key: key.clone(), - nonce: nonce.clone(), - }, - ) + .request("crypto.chacha20", ParamsOfChaCha20 { + data: encrypted.data.clone(), + key: key.clone(), + nonce: nonce.clone(), + }) .unwrap(); assert_eq!(decrypted.data, "TWVzc2FnZQ=="); } @@ -66,14 +60,11 @@ fn math() { assert_eq!("53911073", result.factors[1]); let result: ResultOfModularPower = client - .request( - "crypto.modular_power", - ParamsOfModularPower { - base: "0123456789ABCDEF".into(), - exponent: "0123".into(), - modulus: "01234567".into(), - }, - ) + .request("crypto.modular_power", ParamsOfModularPower { + base: "0123456789ABCDEF".into(), + exponent: "0123".into(), + modulus: "01234567".into(), + }) .unwrap(); assert_eq!("63bfdf", result.modular_power); @@ -94,10 +85,9 @@ fn hash() { let client = TestClient::new(); let result: ResultOfHash = client - .request( - "crypto.sha512", - ParamsOfHash { data: base64_encode("Message to hash with sha 512") }, - ) + .request("crypto.sha512", ParamsOfHash { + data: base64_encode("Message to hash with sha 512"), + }) .unwrap(); assert_eq!( "2616a44e0da827f0244e93c2b0b914223737a6129bc938b8edf2780ac9482960baa9b7c7cdb11457c1cebd5ae77e295ed94577f32d4c963dc35482991442daa5", @@ -105,36 +95,30 @@ fn hash() { ); let result: ResultOfHash = client - .request( - "crypto.sha256", - ParamsOfHash { data: base64_encode("Message to hash with sha 256") }, - ) + .request("crypto.sha256", ParamsOfHash { + data: base64_encode("Message to hash with sha 256"), + }) .unwrap(); assert_eq!("16fd057308dd358d5a9b3ba2de766b2dfd5e308478fc1f7ba5988db2493852f5", result.hash); let result: ResultOfHash = client - .request( - "crypto.sha256", - ParamsOfHash { - data: base64_from_hex("4d65737361676520746f206861736820776974682073686120323536"), - }, - ) + .request("crypto.sha256", ParamsOfHash { + data: base64_from_hex("4d65737361676520746f206861736820776974682073686120323536"), + }) .unwrap(); assert_eq!("16fd057308dd358d5a9b3ba2de766b2dfd5e308478fc1f7ba5988db2493852f5", result.hash); let result: ResultOfHash = client - .request( - "crypto.sha256", - ParamsOfHash { data: "TWVzc2FnZSB0byBoYXNoIHdpdGggc2hhIDI1Ng==".into() }, - ) + .request("crypto.sha256", ParamsOfHash { + data: "TWVzc2FnZSB0byBoYXNoIHdpdGggc2hhIDI1Ng==".into(), + }) .unwrap(); assert_eq!("16fd057308dd358d5a9b3ba2de766b2dfd5e308478fc1f7ba5988db2493852f5", result.hash); let result: ResultOfHash = client - .request( - "crypto.sha256", - ParamsOfHash { data: base64_encode("Message to hash with sha 256") }, - ) + .request("crypto.sha256", ParamsOfHash { + data: base64_encode("Message to hash with sha 256"), + }) .unwrap(); assert_eq!("16fd057308dd358d5a9b3ba2de766b2dfd5e308478fc1f7ba5988db2493852f5", result.hash); } @@ -161,18 +145,13 @@ fn keys() { assert_ne!(result.secret, result.public); let result: ResultOfSign = client - .request( - "crypto.sign", - ParamsOfSign { - unsigned: base64_encode("Test Message"), - keys: KeyPair { - public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e" - .into(), - secret: "56b6a77093d6fdf14e593f36275d872d75de5b341942376b2a08759f3cbae78f" - .into(), - }, + .request("crypto.sign", ParamsOfSign { + unsigned: base64_encode("Test Message"), + keys: KeyPair { + public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e".into(), + secret: "56b6a77093d6fdf14e593f36275d872d75de5b341942376b2a08759f3cbae78f".into(), }, - ) + }) .unwrap(); assert_eq!( result.signed, @@ -196,17 +175,14 @@ fn scrypt() { let client = TestClient::new(); let result: ResultOfScrypt = client - .request( - "crypto.scrypt", - ParamsOfScrypt { - password: base64_encode("Test Password"), - salt: base64_encode("Test Salt"), - log_n: 10, - r: 8, - p: 16, - dk_len: 64, - }, - ) + .request("crypto.scrypt", ParamsOfScrypt { + password: base64_encode("Test Password"), + salt: base64_encode("Test Salt"), + log_n: 10, + r: 8, + p: 16, + dk_len: 64, + }) .unwrap(); assert_eq!( result.key, @@ -222,12 +198,9 @@ fn nacl() { // Sign let result: KeyPair = client - .request( - "crypto.nacl_sign_keypair_from_secret_key", - ParamsOfNaclSignKeyPairFromSecret { - secret: "8fb4f2d256e57138fb310b0a6dac5bbc4bee09eb4821223a720e5b8e1f3dd674".into(), - }, - ) + .request("crypto.nacl_sign_keypair_from_secret_key", ParamsOfNaclSignKeyPairFromSecret { + secret: "8fb4f2d256e57138fb310b0a6dac5bbc4bee09eb4821223a720e5b8e1f3dd674".into(), + }) .unwrap(); assert_eq!(result.public, "aa5533618573860a7e1bf19f34bd292871710ed5b2eafa0dcdbb33405f2231c6"); @@ -256,26 +229,20 @@ fn nacl() { ); let signature = result.signature; let result: ResultOfNaclSignDetachedVerify = client - .request( - "crypto.nacl_sign_detached_verify", - ParamsOfNaclSignDetachedVerify { - unsigned: base64_encode("Test Message"), - signature: signature.clone(), - public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e".into(), - }, - ) + .request("crypto.nacl_sign_detached_verify", ParamsOfNaclSignDetachedVerify { + unsigned: base64_encode("Test Message"), + signature: signature.clone(), + public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e".into(), + }) .unwrap(); assert!(result.succeeded); let result: ResultOfNaclSignDetachedVerify = client - .request( - "crypto.nacl_sign_detached_verify", - ParamsOfNaclSignDetachedVerify { - unsigned: base64_encode("Test Message 1"), - signature: signature.clone(), - public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e".into(), - }, - ) + .request("crypto.nacl_sign_detached_verify", ParamsOfNaclSignDetachedVerify { + unsigned: base64_encode("Test Message 1"), + signature: signature.clone(), + public: "1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e".into(), + }) .unwrap(); assert!(!result.succeeded); @@ -287,92 +254,65 @@ fn nacl() { assert_ne!(result.public, result.secret); let result: KeyPair = client - .request( - "crypto.nacl_box_keypair_from_secret_key", - ParamsOfNaclBoxKeyPairFromSecret { - secret: "e207b5966fb2c5be1b71ed94ea813202706ab84253bdf4dc55232f82a1caf0d4".into(), - }, - ) + .request("crypto.nacl_box_keypair_from_secret_key", ParamsOfNaclBoxKeyPairFromSecret { + secret: "e207b5966fb2c5be1b71ed94ea813202706ab84253bdf4dc55232f82a1caf0d4".into(), + }) .unwrap(); assert_eq!(result.public, "a53b003d3ffc1e159355cb37332d67fc235a7feb6381e36c803274074dc3933a"); let result: ResultOfNaclBox = client - .request( - "crypto.nacl_box", - ParamsOfNaclBox { - decrypted: base64_encode("Test Message"), - nonce: "cd7f99924bf422544046e83595dd5803f17536f5c9a11746".into(), - their_public: "c4e2d9fe6a6baf8d1812b799856ef2a306291be7a7024837ad33a8530db79c6b" - .into(), - secret: "d9b9dc5033fb416134e5d2107fdbacab5aadb297cb82dbdcd137d663bac59f7f".into(), - }, - ) + .request("crypto.nacl_box", ParamsOfNaclBox { + decrypted: base64_encode("Test Message"), + nonce: "cd7f99924bf422544046e83595dd5803f17536f5c9a11746".into(), + their_public: "c4e2d9fe6a6baf8d1812b799856ef2a306291be7a7024837ad33a8530db79c6b".into(), + secret: "d9b9dc5033fb416134e5d2107fdbacab5aadb297cb82dbdcd137d663bac59f7f".into(), + }) .unwrap(); assert_eq!(result.encrypted, "li4XED4kx/pjQ2qdP0eR2d/K30uN94voNADxwA=="); let result: ResultOfNaclBoxOpen = client - .request( - "crypto.nacl_box_open", - ParamsOfNaclBoxOpen { - encrypted: base64_from_hex( - "962e17103e24c7fa63436a9d3f4791d9dfcadf4b8df78be83400f1c0", - ), - nonce: "cd7f99924bf422544046e83595dd5803f17536f5c9a11746".into(), - their_public: "c4e2d9fe6a6baf8d1812b799856ef2a306291be7a7024837ad33a8530db79c6b" - .into(), - secret: "d9b9dc5033fb416134e5d2107fdbacab5aadb297cb82dbdcd137d663bac59f7f".into(), - }, - ) + .request("crypto.nacl_box_open", ParamsOfNaclBoxOpen { + encrypted: base64_from_hex("962e17103e24c7fa63436a9d3f4791d9dfcadf4b8df78be83400f1c0"), + nonce: "cd7f99924bf422544046e83595dd5803f17536f5c9a11746".into(), + their_public: "c4e2d9fe6a6baf8d1812b799856ef2a306291be7a7024837ad33a8530db79c6b".into(), + secret: "d9b9dc5033fb416134e5d2107fdbacab5aadb297cb82dbdcd137d663bac59f7f".into(), + }) .unwrap(); assert_eq!(text_from_base64(&result.decrypted), "Test Message"); // Secret box let result: ResultOfNaclBox = client - .request( - "crypto.nacl_secret_box", - ParamsOfNaclSecretBox { - decrypted: base64_encode("Test Message"), - nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), - key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), - }, - ) + .request("crypto.nacl_secret_box", ParamsOfNaclSecretBox { + decrypted: base64_encode("Test Message"), + nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), + key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), + }) .unwrap(); assert_eq!(result.encrypted, "JL7ejKWe2KXmrsns41yfXoQF0t/C1Q8RGyzQ2A=="); let result: ResultOfNaclBoxOpen = client - .request( - "crypto.nacl_secret_box_open", - ParamsOfNaclSecretBoxOpen { - encrypted: base64_from_hex( - "24bede8ca59ed8a5e6aec9ece35c9f5e8405d2dfc2d50f111b2cd0d8", - ), - nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), - key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), - }, - ) + .request("crypto.nacl_secret_box_open", ParamsOfNaclSecretBoxOpen { + encrypted: base64_from_hex("24bede8ca59ed8a5e6aec9ece35c9f5e8405d2dfc2d50f111b2cd0d8"), + nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), + key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), + }) .unwrap(); assert_eq!(text_from_base64(&result.decrypted), "Test Message"); let e: ResultOfNaclBox = client - .request( - "crypto.nacl_secret_box", - ParamsOfNaclSecretBox { - decrypted: base64_encode("Text with \' and \" and : {}"), - nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), - key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), - }, - ) + .request("crypto.nacl_secret_box", ParamsOfNaclSecretBox { + decrypted: base64_encode("Text with \' and \" and : {}"), + nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), + key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), + }) .unwrap(); let d: ResultOfNaclBoxOpen = client - .request( - "crypto.nacl_secret_box_open", - ParamsOfNaclSecretBoxOpen { - encrypted: e.encrypted, - nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), - key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), - }, - ) + .request("crypto.nacl_secret_box_open", ParamsOfNaclSecretBoxOpen { + encrypted: e.encrypted, + nonce: "2a33564717595ebe53d91a785b9e068aba625c8453a76e45".into(), + key: "8f68445b4e78c000fe4d6b7fc826879c1e63e3118379219a754ae66327764bd8".into(), + }) .unwrap(); assert_eq!(text_from_base64(&d.decrypted), "Text with \' and \" and : {}"); } @@ -396,27 +336,21 @@ fn mnemonic() { for dictionary in 1..9 { for word_count in &[12u8, 15, 18, 21, 24] { let result: ResultOfMnemonicFromRandom = client - .request( - "crypto.mnemonic_from_random", - ParamsOfMnemonicFromRandom { - dictionary: Some(dictionary.try_into().unwrap()), - word_count: Some(*word_count), - }, - ) + .request("crypto.mnemonic_from_random", ParamsOfMnemonicFromRandom { + dictionary: Some(dictionary.try_into().unwrap()), + word_count: Some(*word_count), + }) .unwrap(); assert_eq!(result.phrase.split(' ').count(), *word_count as usize); } } let result: ResultOfMnemonicFromEntropy = client - .request( - "crypto.mnemonic_from_entropy", - ParamsOfMnemonicFromEntropy { - entropy: "00112233445566778899AABBCCDDEEFF".into(), - dictionary: Some(MnemonicDictionary::English), - word_count: Some(12), - }, - ) + .request("crypto.mnemonic_from_entropy", ParamsOfMnemonicFromEntropy { + entropy: "00112233445566778899AABBCCDDEEFF".into(), + dictionary: Some(MnemonicDictionary::English), + word_count: Some(12), + }) .unwrap(); assert_eq!( result.phrase, @@ -426,33 +360,28 @@ fn mnemonic() { for dictionary in 1..9 { for word_count in &[12u8, 15, 18, 21, 24] { let result: ResultOfMnemonicFromRandom = client - .request( - "crypto.mnemonic_from_random", - ParamsOfMnemonicFromRandom { - dictionary: Some(dictionary.try_into().unwrap()), - word_count: Some(*word_count), - }, - ) + .request("crypto.mnemonic_from_random", ParamsOfMnemonicFromRandom { + dictionary: Some(dictionary.try_into().unwrap()), + word_count: Some(*word_count), + }) .unwrap(); let verify_result: ResultOfMnemonicVerify = client - .request( - "crypto.mnemonic_verify", - ParamsOfMnemonicVerify { - phrase: result.phrase, - dictionary: Some(dictionary.try_into().unwrap()), - word_count: Some(*word_count), - }, - ) + .request("crypto.mnemonic_verify", ParamsOfMnemonicVerify { + phrase: result.phrase, + dictionary: Some(dictionary.try_into().unwrap()), + word_count: Some(*word_count), + }) .unwrap(); assert!(verify_result.valid); } } let result: ResultOfMnemonicVerify = client - .request( - "crypto.mnemonic_verify", - ParamsOfMnemonicVerify { phrase: "one two".into(), dictionary: None, word_count: None }, - ) + .request("crypto.mnemonic_verify", ParamsOfMnemonicVerify { + phrase: "one two".into(), + dictionary: None, + word_count: None, + }) .unwrap(); assert!(!result.valid); @@ -503,56 +432,44 @@ fn mnemonic() { assert_eq!(result.tvm_public_key, "PuZhw8W5ejPJwKA68RL7sn4_RNmeH4BIU_mEK7em5d4_-cIx"); let result: ResultOfMnemonicFromRandom = client - .request( - "crypto.mnemonic_from_random", - ParamsOfMnemonicFromRandom { dictionary: None, word_count: None }, - ) + .request("crypto.mnemonic_from_random", ParamsOfMnemonicFromRandom { + dictionary: None, + word_count: None, + }) .unwrap(); assert_eq!(result.phrase.split(' ').count(), 12); let result: ResultOfMnemonicFromRandom = client - .request( - "crypto.mnemonic_from_random", - ParamsOfMnemonicFromRandom { - dictionary: Some(MnemonicDictionary::Ton), - word_count: Some(12), - }, - ) + .request("crypto.mnemonic_from_random", ParamsOfMnemonicFromRandom { + dictionary: Some(MnemonicDictionary::Ton), + word_count: Some(12), + }) .unwrap(); assert_eq!(result.phrase.split(' ').count(), 12); let result: ResultOfMnemonicFromRandom = client - .request( - "crypto.mnemonic_from_random", - ParamsOfMnemonicFromRandom { - dictionary: Some(MnemonicDictionary::English), - word_count: Some(12), - }, - ) + .request("crypto.mnemonic_from_random", ParamsOfMnemonicFromRandom { + dictionary: Some(MnemonicDictionary::English), + word_count: Some(12), + }) .unwrap(); assert_eq!(result.phrase.split(' ').count(), 12); let result: ResultOfMnemonicFromEntropy = client - .request( - "crypto.mnemonic_from_entropy", - ParamsOfMnemonicFromEntropy { - entropy: "2199ebe996f14d9e4e2595113ad1e627".into(), - dictionary: None, - word_count: None, - }, - ) + .request("crypto.mnemonic_from_entropy", ParamsOfMnemonicFromEntropy { + entropy: "2199ebe996f14d9e4e2595113ad1e627".into(), + dictionary: None, + word_count: None, + }) .unwrap(); let result: KeyPair = client - .request( - "crypto.mnemonic_derive_sign_keys", - ParamsOfMnemonicDeriveSignKeys { - phrase: result.phrase, - path: None, - dictionary: None, - word_count: None, - }, - ) + .request("crypto.mnemonic_derive_sign_keys", ParamsOfMnemonicDeriveSignKeys { + phrase: result.phrase, + path: None, + dictionary: None, + word_count: None, + }) .unwrap(); let result: ResultOfConvertPublicKeyToTonSafeFormat = client .request( @@ -569,16 +486,12 @@ fn hdkey() { let client = TestClient::new(); let master: ResultOfHDKeyXPrvFromMnemonic = client - .request( - "crypto.hdkey_xprv_from_mnemonic", - ParamsOfHDKeyXPrvFromMnemonic { - dictionary: None, - word_count: None, - phrase: - "abuse boss fly battle rubber wasp afraid hamster guide essence vibrant tattoo" - .into(), - }, - ) + .request("crypto.hdkey_xprv_from_mnemonic", ParamsOfHDKeyXPrvFromMnemonic { + dictionary: None, + word_count: None, + phrase: "abuse boss fly battle rubber wasp afraid hamster guide essence vibrant tattoo" + .into(), + }) .unwrap(); assert_eq!( master.xprv, @@ -586,30 +499,25 @@ fn hdkey() { ); let result: ResultOfHDKeySecretFromXPrv = client - .request( - "crypto.hdkey_secret_from_xprv", - ParamsOfHDKeySecretFromXPrv { xprv: master.xprv.clone() }, - ) + .request("crypto.hdkey_secret_from_xprv", ParamsOfHDKeySecretFromXPrv { + xprv: master.xprv.clone(), + }) .unwrap(); assert_eq!(result.secret, "0c91e53128fa4d67589d63a6c44049c1068ec28a63069a55ca3de30c57f8b365"); let result: ResultOfHDKeyPublicFromXPrv = client - .request( - "crypto.hdkey_public_from_xprv", - ParamsOfHDKeyPublicFromXPrv { xprv: master.xprv.clone() }, - ) + .request("crypto.hdkey_public_from_xprv", ParamsOfHDKeyPublicFromXPrv { + xprv: master.xprv.clone(), + }) .unwrap(); assert_eq!(result.public, "7b70008d0c40992283d488b1046739cf827afeabf647a5f07c4ad1e7e45a6f89"); let child: ResultOfHDKeyDeriveFromXPrv = client - .request( - "crypto.hdkey_derive_from_xprv", - ParamsOfHDKeyDeriveFromXPrv { - xprv: master.xprv.clone(), - child_index: 0, - hardened: false, - }, - ) + .request("crypto.hdkey_derive_from_xprv", ParamsOfHDKeyDeriveFromXPrv { + xprv: master.xprv.clone(), + child_index: 0, + hardened: false, + }) .unwrap(); assert_eq!( child.xprv, @@ -617,29 +525,24 @@ fn hdkey() { ); let result: ResultOfHDKeySecretFromXPrv = client - .request( - "crypto.hdkey_secret_from_xprv", - ParamsOfHDKeySecretFromXPrv { xprv: child.xprv.clone() }, - ) + .request("crypto.hdkey_secret_from_xprv", ParamsOfHDKeySecretFromXPrv { + xprv: child.xprv.clone(), + }) .unwrap(); assert_eq!(result.secret, "518afc6489b61d4b738ee9ad9092815fa014ffa6e9a280fa17f84d95f31adb91"); let result: ResultOfHDKeyPublicFromXPrv = client - .request( - "crypto.hdkey_public_from_xprv", - ParamsOfHDKeyPublicFromXPrv { xprv: child.xprv.clone() }, - ) + .request("crypto.hdkey_public_from_xprv", ParamsOfHDKeyPublicFromXPrv { + xprv: child.xprv.clone(), + }) .unwrap(); assert_eq!(result.public, "b45e1297a5e767341a6eaaac9e20f8ccd7556a0106298316f1272e461b6fbe98"); let second: ResultOfHDKeyDeriveFromXPrvPath = client - .request( - "crypto.hdkey_derive_from_xprv_path", - ParamsOfHDKeyDeriveFromXPrvPath { - xprv: master.xprv.clone(), - path: "m/44'/60'/0'/0'".into(), - }, - ) + .request("crypto.hdkey_derive_from_xprv_path", ParamsOfHDKeyDeriveFromXPrvPath { + xprv: master.xprv.clone(), + path: "m/44'/60'/0'/0'".into(), + }) .unwrap(); assert_eq!( second.xprv, @@ -647,18 +550,16 @@ fn hdkey() { ); let result: ResultOfHDKeySecretFromXPrv = client - .request( - "crypto.hdkey_secret_from_xprv", - ParamsOfHDKeySecretFromXPrv { xprv: second.xprv.clone() }, - ) + .request("crypto.hdkey_secret_from_xprv", ParamsOfHDKeySecretFromXPrv { + xprv: second.xprv.clone(), + }) .unwrap(); assert_eq!(result.secret, "1c566ade41169763b155761406d3cef08b29b31cf8014f51be08c0cb4e67c5e1"); let result: ResultOfHDKeyPublicFromXPrv = client - .request( - "crypto.hdkey_public_from_xprv", - ParamsOfHDKeyPublicFromXPrv { xprv: second.xprv.clone() }, - ) + .request("crypto.hdkey_public_from_xprv", ParamsOfHDKeyPublicFromXPrv { + xprv: second.xprv.clone(), + }) .unwrap(); assert_eq!(result.public, "302a832bad9e5c9906422a82c28b39ae465dcd60178480f7309e183ee34b5e83"); } @@ -684,10 +585,9 @@ async fn test_signing_box() { match serde_json::from_value(request.request_data).unwrap() { ParamsOfAppSigningBox::GetPublicKey => { let result: ResultOfSigningBoxGetPublicKey = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: keys_box_handle.into() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: keys_box_handle.into(), + }) .await .unwrap(); client @@ -699,20 +599,16 @@ async fn test_signing_box() { } ParamsOfAppSigningBox::Sign { unsigned } => { let result: ResultOfSigningBoxSign = client - .request_async( - "crypto.signing_box_sign", - ParamsOfSigningBoxSign { - signing_box: keys_box_handle.into(), - unsigned, - }, - ) + .request_async("crypto.signing_box_sign", ParamsOfSigningBoxSign { + signing_box: keys_box_handle.into(), + unsigned, + }) .await .unwrap(); client - .resolve_app_request( - request.app_request_id, - ResultOfAppSigningBox::Sign { signature: result.signature }, - ) + .resolve_app_request(request.app_request_id, ResultOfAppSigningBox::Sign { + signature: result.signature, + }) .await; } } @@ -724,10 +620,9 @@ async fn test_signing_box() { client.request_async_callback("crypto.register_signing_box", (), callback).await.unwrap(); let box_pubkey: ResultOfSigningBoxGetPublicKey = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: external_box.handle.clone() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: external_box.handle.clone(), + }) .await .unwrap(); @@ -735,13 +630,10 @@ async fn test_signing_box() { let unsigned = base64_encode("Test Message"); let box_sign: ResultOfSigningBoxSign = client - .request_async( - "crypto.signing_box_sign", - ParamsOfSigningBoxSign { - signing_box: external_box.handle.clone(), - unsigned: unsigned.clone(), - }, - ) + .request_async("crypto.signing_box_sign", ParamsOfSigningBoxSign { + signing_box: external_box.handle.clone(), + unsigned: unsigned.clone(), + }) .await .unwrap(); @@ -751,18 +643,16 @@ async fn test_signing_box() { assert_eq!(box_sign.signature, keys_sign.signature); let _: () = client - .request_async( - "crypto.remove_signing_box", - RegisteredSigningBox { handle: external_box.handle }, - ) + .request_async("crypto.remove_signing_box", RegisteredSigningBox { + handle: external_box.handle, + }) .await .unwrap(); let _: () = client - .request_async( - "crypto.remove_signing_box", - RegisteredSigningBox { handle: keys_box_handle.into() }, - ) + .request_async("crypto.remove_signing_box", RegisteredSigningBox { + handle: keys_box_handle.into(), + }) .await .unwrap(); } @@ -820,33 +710,29 @@ async fn test_aes_params(key: &str, data: &str, encrypted: &str) { .handle; let result: ResultOfEncryptionBoxEncrypt = client - .request_async( - "crypto.encryption_box_encrypt", - ParamsOfEncryptionBoxEncrypt { - encryption_box: box_handle.clone(), - data: base64_encode(data.clone()), - }, - ) + .request_async("crypto.encryption_box_encrypt", ParamsOfEncryptionBoxEncrypt { + encryption_box: box_handle.clone(), + data: base64_encode(data.clone()), + }) .await .unwrap(); assert_eq!(result.data, encrypted); let result: ResultOfEncryptionBoxDecrypt = client - .request_async( - "crypto.encryption_box_decrypt", - ParamsOfEncryptionBoxDecrypt { encryption_box: box_handle.clone(), data: encrypted }, - ) + .request_async("crypto.encryption_box_decrypt", ParamsOfEncryptionBoxDecrypt { + encryption_box: box_handle.clone(), + data: encrypted, + }) .await .unwrap(); assert_eq!(base64_decode(&result.data).unwrap()[..data.len()], data); let _: () = client - .request_async( - "crypto.remove_encryption_box", - RegisteredEncryptionBox { handle: box_handle }, - ) + .request_async("crypto.remove_encryption_box", RegisteredEncryptionBox { + handle: box_handle, + }) .await .unwrap(); } @@ -894,47 +780,40 @@ async fn test_chacha20_encryption_box() { let decrypted: String = base64_encode("Message"); let result: ResultOfEncryptionBoxEncrypt = client - .request_async( - "crypto.encryption_box_encrypt", - ParamsOfEncryptionBoxEncrypt { - encryption_box: box_handle.clone(), - data: decrypted.clone(), - }, - ) + .request_async("crypto.encryption_box_encrypt", ParamsOfEncryptionBoxEncrypt { + encryption_box: box_handle.clone(), + data: decrypted.clone(), + }) .await .unwrap(); assert_eq!(result.data, "w5QOGsJodQ=="); let result: ResultOfEncryptionBoxDecrypt = client - .request_async( - "crypto.encryption_box_decrypt", - ParamsOfEncryptionBoxDecrypt { encryption_box: box_handle.clone(), data: result.data }, - ) + .request_async("crypto.encryption_box_decrypt", ParamsOfEncryptionBoxDecrypt { + encryption_box: box_handle.clone(), + data: result.data, + }) .await .unwrap(); assert_eq!(result.data, decrypted); let result: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: box_handle }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: box_handle, + }) .await .unwrap(); - assert_eq!( - result.info, - EncryptionBoxInfo { - hdpath: None, - algorithm: Some("ChaCha20".to_string()), - options: Some(json!({ - "nonce": nonce, - })), - public: None, - }, - ); + assert_eq!(result.info, EncryptionBoxInfo { + hdpath: None, + algorithm: Some("ChaCha20".to_string()), + options: Some(json!({ + "nonce": nonce, + })), + public: None, + },); } #[tokio::test] @@ -965,48 +844,41 @@ async fn test_nacl_encryption_box() { let decrypted: String = base64_encode("Test Message"); let result: ResultOfEncryptionBoxEncrypt = client - .request_async( - "crypto.encryption_box_encrypt", - ParamsOfEncryptionBoxEncrypt { - encryption_box: box_handle.clone(), - data: decrypted.clone(), - }, - ) + .request_async("crypto.encryption_box_encrypt", ParamsOfEncryptionBoxEncrypt { + encryption_box: box_handle.clone(), + data: decrypted.clone(), + }) .await .unwrap(); assert_eq!(result.data, "yPi4Xsgg2FCwpKiaNguf/DDHepE9aKbDCGla6A=="); let result: ResultOfEncryptionBoxDecrypt = client - .request_async( - "crypto.encryption_box_decrypt", - ParamsOfEncryptionBoxDecrypt { encryption_box: box_handle.clone(), data: result.data }, - ) + .request_async("crypto.encryption_box_decrypt", ParamsOfEncryptionBoxDecrypt { + encryption_box: box_handle.clone(), + data: result.data, + }) .await .unwrap(); assert_eq!(result.data, decrypted); let result: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: box_handle }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: box_handle, + }) .await .unwrap(); - assert_eq!( - result.info, - EncryptionBoxInfo { - hdpath: None, - algorithm: Some("NaclBox".to_string()), - options: Some(json!({ - "their_public": THEIR_PUBLIC.to_string(), - "nonce": NONCE, - })), - public: Some(PUBLIC.into()), - }, - ); + assert_eq!(result.info, EncryptionBoxInfo { + hdpath: None, + algorithm: Some("NaclBox".to_string()), + options: Some(json!({ + "their_public": THEIR_PUBLIC.to_string(), + "nonce": NONCE, + })), + public: Some(PUBLIC.into()), + },); } #[tokio::test] @@ -1033,47 +905,40 @@ async fn test_nacl_secret_encryption_box() { let decrypted: String = base64_encode("Test Message"); let result: ResultOfEncryptionBoxEncrypt = client - .request_async( - "crypto.encryption_box_encrypt", - ParamsOfEncryptionBoxEncrypt { - encryption_box: box_handle.clone(), - data: decrypted.clone(), - }, - ) + .request_async("crypto.encryption_box_encrypt", ParamsOfEncryptionBoxEncrypt { + encryption_box: box_handle.clone(), + data: decrypted.clone(), + }) .await .unwrap(); assert_eq!(result.data, "JL7ejKWe2KXmrsns41yfXoQF0t/C1Q8RGyzQ2A=="); let result: ResultOfEncryptionBoxDecrypt = client - .request_async( - "crypto.encryption_box_decrypt", - ParamsOfEncryptionBoxDecrypt { encryption_box: box_handle.clone(), data: result.data }, - ) + .request_async("crypto.encryption_box_decrypt", ParamsOfEncryptionBoxDecrypt { + encryption_box: box_handle.clone(), + data: result.data, + }) .await .unwrap(); assert_eq!(result.data, decrypted); let result: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: box_handle }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: box_handle, + }) .await .unwrap(); - assert_eq!( - result.info, - EncryptionBoxInfo { - hdpath: None, - algorithm: Some("NaclSecretBox".to_string()), - options: Some(json!({ - "nonce": NONCE, - })), - public: None, - }, - ); + assert_eq!(result.info, EncryptionBoxInfo { + hdpath: None, + algorithm: Some("NaclSecretBox".to_string()), + options: Some(json!({ + "nonce": NONCE, + })), + public: None, + },); } fn password_provider( @@ -1096,15 +961,12 @@ fn password_provider( let keypair: KeyPair = client.request_no_params("crypto.nacl_box_keypair").unwrap(); let ResultOfNaclBox { encrypted } = client - .request_async( - "crypto.nacl_box", - ParamsOfNaclBox { - decrypted: base64_encode(hex::decode(password_hash.as_ref()).unwrap()), - nonce: encryption_public_key[..48].to_string(), - their_public: encryption_public_key, - secret: keypair.secret.clone(), - }, - ) + .request_async("crypto.nacl_box", ParamsOfNaclBox { + decrypted: base64_encode(hex::decode(password_hash.as_ref()).unwrap()), + nonce: encryption_public_key[..48].to_string(), + their_public: encryption_public_key, + secret: keypair.secret.clone(), + }) .await .unwrap(); @@ -1148,14 +1010,11 @@ async fn test_crypto_boxes() -> tvm_types::Result<()> { .await?; let verify_result: ResultOfMnemonicVerify = client - .request( - "crypto.mnemonic_verify", - ParamsOfMnemonicVerify { - phrase: seed_phrase.phrase.clone(), - dictionary: Some(MnemonicDictionary::Ton), - word_count: Some(12), - }, - ) + .request("crypto.mnemonic_verify", ParamsOfMnemonicVerify { + phrase: seed_phrase.phrase.clone(), + dictionary: Some(MnemonicDictionary::Ton), + word_count: Some(12), + }) .unwrap(); assert!(verify_result.valid); @@ -1249,20 +1108,18 @@ async fn test_crypto_box_signing_boxes() -> tvm_types::Result<()> { assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 1); let ResultOfSigningBoxGetPublicKey { pubkey } = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: signing_box.handle.clone() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: signing_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 2); assert_eq!(pubkey.len(), 64); let _: ResultOfSigningBoxGetPublicKey = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: signing_box.handle.clone() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: signing_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 3); @@ -1282,30 +1139,27 @@ async fn test_crypto_box_signing_boxes() -> tvm_types::Result<()> { for _ in 0..3 { let _: ResultOfSigningBoxGetPublicKey = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: signing_box.handle.clone() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: signing_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 4); } client - .request_async( - "crypto.clear_crypto_box_secret_cache", - RegisteredCryptoBox { handle: crypto_box.handle }, - ) + .request_async("crypto.clear_crypto_box_secret_cache", RegisteredCryptoBox { + handle: crypto_box.handle, + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 4); for _ in 0..3 { let _: ResultOfSigningBoxGetPublicKey = client - .request_async( - "crypto.signing_box_get_public_key", - RegisteredSigningBox { handle: signing_box.handle.clone() }, - ) + .request_async("crypto.signing_box_get_public_key", RegisteredSigningBox { + handle: signing_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 5); @@ -1361,31 +1215,26 @@ async fn test_crypto_box_encryption_boxes() -> tvm_types::Result<()> { assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 1); let result: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: encryption_box.handle.clone() }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: encryption_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 2); - assert_eq!( - result.info, - EncryptionBoxInfo { - hdpath: None, - algorithm: Some("ChaCha20".to_string()), - options: Some(json!({ - "nonce": nonce, - })), - public: None, - }, - ); + assert_eq!(result.info, EncryptionBoxInfo { + hdpath: None, + algorithm: Some("ChaCha20".to_string()), + options: Some(json!({ + "nonce": nonce, + })), + public: None, + },); let _: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: encryption_box.handle.clone() }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: encryption_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 3); @@ -1408,30 +1257,27 @@ async fn test_crypto_box_encryption_boxes() -> tvm_types::Result<()> { for _ in 0..3 { let _: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: encryption_box.handle.clone() }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: encryption_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 4); } client - .request_async( - "crypto.clear_crypto_box_secret_cache", - RegisteredCryptoBox { handle: crypto_box.handle }, - ) + .request_async("crypto.clear_crypto_box_secret_cache", RegisteredCryptoBox { + handle: crypto_box.handle, + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 4); for _ in 0..3 { let _: ResultOfEncryptionBoxGetInfo = client - .request_async( - "crypto.encryption_box_get_info", - ParamsOfEncryptionBoxGetInfo { encryption_box: encryption_box.handle.clone() }, - ) + .request_async("crypto.encryption_box_get_info", ParamsOfEncryptionBoxGetInfo { + encryption_box: encryption_box.handle.clone(), + }) .await?; assert_eq!(callback_calls_counter.load(Ordering::Relaxed), 5); diff --git a/tvm_client/src/debot/action.rs b/tvm_client/src/debot/action.rs index 69f479458..5a1ea2008 100644 --- a/tvm_client/src/debot/action.rs +++ b/tvm_client/src/debot/action.rs @@ -1,7 +1,7 @@ -use serde::de; use serde::Deserialize; use serde::Deserializer; use serde::Serializer; +use serde::de; use super::context::from_abi_num; use super::context::from_hex_to_utf8_str; diff --git a/tvm_client/src/debot/base64_interface.rs b/tvm_client/src/debot/base64_interface.rs index f63091d82..d7a44c921 100644 --- a/tvm_client/src/debot/base64_interface.rs +++ b/tvm_client/src/debot/base64_interface.rs @@ -2,10 +2,10 @@ use serde_json::Value; use tvm_types::base64_decode; use tvm_types::base64_encode; -use super::dinterface::decode_answer_id; -use super::dinterface::get_arg; use super::dinterface::DebotInterface; use super::dinterface::InterfaceResult; +use super::dinterface::decode_answer_id; +use super::dinterface::get_arg; use crate::abi::Abi; const ABI: &str = r#" diff --git a/tvm_client/src/debot/browser.rs b/tvm_client/src/debot/browser.rs index b03f0458d..19b469708 100644 --- a/tvm_client/src/debot/browser.rs +++ b/tvm_client/src/debot/browser.rs @@ -1,5 +1,5 @@ -use super::action::DAction; use super::DebotActivity; +use super::action::DAction; use crate::crypto::SigningBoxHandle; use crate::error::ClientResult; diff --git a/tvm_client/src/debot/calltype.rs b/tvm_client/src/debot/calltype.rs index 9d2644c05..7404ff7f6 100644 --- a/tvm_client/src/debot/calltype.rs +++ b/tvm_client/src/debot/calltype.rs @@ -8,35 +8,35 @@ use tvm_types::BuilderData; use tvm_types::IBitstring; use tvm_types::SliceData; -use super::errors::Error; -use super::helpers::build_internal_message; use super::BrowserCallbacks; use super::DebotActivity; use super::Spending; use super::TonClient; +use super::errors::Error; +use super::helpers::build_internal_message; use crate::abi::Signer; +use crate::boc::ParamsOfGetBocHash; +use crate::boc::ParamsOfParse; use crate::boc::get_boc_hash; use crate::boc::internal::deserialize_object_from_base64; use crate::boc::internal::serialize_object_to_base64; use crate::boc::parse_message; -use crate::boc::ParamsOfGetBocHash; -use crate::boc::ParamsOfParse; use crate::crypto::SigningBoxHandle; use crate::encoding::decode_abi_number; use crate::error::ClientError; use crate::error::ClientResult; -use crate::net::query_transaction_tree; use crate::net::ParamsOfQueryTransactionTree; -use crate::processing::send_message; -use crate::processing::wait_for_transaction; +use crate::net::query_transaction_tree; use crate::processing::ParamsOfSendMessage; use crate::processing::ParamsOfWaitForTransaction; use crate::processing::ProcessingEvent; -use crate::tvm::run_executor; -use crate::tvm::run_tvm; +use crate::processing::send_message; +use crate::processing::wait_for_transaction; use crate::tvm::AccountForExecutor; use crate::tvm::ParamsOfRunExecutor; use crate::tvm::ParamsOfRunTvm; +use crate::tvm::run_executor; +use crate::tvm::run_tvm; const SUPPORTED_ABI_VERSION: u8 = 2; const ABI_2_3: u8 = 0x32; @@ -302,17 +302,14 @@ impl ContractCall { } async fn run_get_method(&self, func_id: u32, fixed_msg: String) -> ClientResult { - let result = run_tvm( - self.ton.clone(), - ParamsOfRunTvm { - account: self.target_state.clone(), - message: fixed_msg, - abi: None, - execution_options: None, - boc_cache: None, - return_updated_account: Some(true), - }, - ) + let result = run_tvm(self.ton.clone(), ParamsOfRunTvm { + account: self.target_state.clone(), + message: fixed_msg, + abi: None, + execution_options: None, + boc_cache: None, + return_updated_account: Some(true), + }) .await .map_err(Error::get_method_failed); @@ -399,11 +396,12 @@ impl ContractCall { .await; match result { Ok(res) => { - let result = query_transaction_tree( - self.ton.clone(), - ParamsOfQueryTransactionTree { in_msg: msg_id, ..Default::default() }, - ) - .await; + let result = + query_transaction_tree(self.ton.clone(), ParamsOfQueryTransactionTree { + in_msg: msg_id, + ..Default::default() + }) + .await; if let Err(e) = result { return self.build_error_answer_msg(e); } @@ -540,14 +538,11 @@ async fn emulate_transaction( target_state: String, signer: Signer, ) -> ClientResult { - let result = run_executor( - client.clone(), - ParamsOfRunExecutor { - message: msg.clone(), - account: AccountForExecutor::Account { boc: target_state, unlimited_balance: None }, - ..Default::default() - }, - ) + let result = run_executor(client.clone(), ParamsOfRunExecutor { + message: msg.clone(), + account: AccountForExecutor::Account { boc: target_state, unlimited_balance: None }, + ..Default::default() + }) .await?; let exit_code = diff --git a/tvm_client/src/debot/context.rs b/tvm_client/src/debot/context.rs index 1ebc402bb..3459e21f6 100644 --- a/tvm_client/src/debot/context.rs +++ b/tvm_client/src/debot/context.rs @@ -1,9 +1,9 @@ use std::fmt::Display; use std::str::FromStr; -use serde::de; use serde::Deserialize; use serde::Deserializer; +use serde::de; use super::action::DAction; use crate::encoding::decode_abi_number; diff --git a/tvm_client/src/debot/dengine.rs b/tvm_client/src/debot/dengine.rs index fa67aa544..85ab25e74 100644 --- a/tvm_client/src/debot/dengine.rs +++ b/tvm_client/src/debot/dengine.rs @@ -3,17 +3,21 @@ use std::sync::Arc; use tvm_abi::Contract; +use super::DEBOT_WC; +use super::DInfo; +use super::JsonValue; +use super::TonClient; use super::action::AcType; use super::action::DAction; use super::browser::BrowserCallbacks; use super::calltype::ContractCall; use super::calltype::DebotCallType; -use super::context::str_hex_to_utf8; use super::context::DContext; use super::context::STATE_CURRENT; use super::context::STATE_EXIT; use super::context::STATE_PREV; use super::context::STATE_ZERO; +use super::context::str_hex_to_utf8; use super::debot_abi::DEBOT_ABI; use super::dinterface::BuiltinInterfaces; use super::dinterface::DebotInterfaceExecutor; @@ -25,13 +29,8 @@ use super::json_interface::JsonInterface; use super::msg_interface::MsgInterface; use super::routines; use super::run_output::RunOutput; -use super::DInfo; -use super::JsonValue; -use super::TonClient; -use super::DEBOT_WC; -use crate::abi::decode_message_body; -use crate::abi::encode_message; -use crate::abi::encode_message_body; +use crate::ClientConfig; +use crate::ClientContext; use crate::abi::Abi; use crate::abi::CallSet; use crate::abi::DeploySet; @@ -40,24 +39,25 @@ use crate::abi::ParamsOfDecodeMessageBody; use crate::abi::ParamsOfEncodeMessage; use crate::abi::ParamsOfEncodeMessageBody; use crate::abi::Signer; +use crate::abi::decode_message_body; +use crate::abi::encode_message; +use crate::abi::encode_message_body; use crate::boc::internal::deserialize_cell_from_base64; -use crate::crypto::remove_signing_box; use crate::crypto::RegisteredSigningBox; use crate::crypto::SigningBoxHandle; +use crate::crypto::remove_signing_box; use crate::encoding::decode_abi_number; use crate::encoding::slice_from_cell; use crate::error::ClientError; use crate::error::ClientResult; -use crate::net::query_collection; use crate::net::NetworkConfig; use crate::net::ParamsOfQueryCollection; -use crate::processing::process_message; +use crate::net::query_collection; use crate::processing::ParamsOfProcessMessage; use crate::processing::ProcessingEvent; -use crate::tvm::run_tvm; +use crate::processing::process_message; use crate::tvm::ParamsOfRunTvm; -use crate::ClientConfig; -use crate::ClientContext; +use crate::tvm::run_tvm; const EMPTY_CELL: &str = "te6ccgEBAQEAAgAAAA=="; @@ -302,16 +302,13 @@ impl DEngine { } async fn send_to_debot(&mut self, msg: String) -> ClientResult { - let run_result = run_tvm( - self.ton.clone(), - ParamsOfRunTvm { - account: self.state.clone(), - message: msg, - abi: Some(self.abi.clone()), - return_updated_account: Some(true), - ..Default::default() - }, - ) + let run_result = run_tvm(self.ton.clone(), ParamsOfRunTvm { + account: self.state.clone(), + message: msg, + abi: Some(self.abi.clone()), + return_updated_account: Some(true), + ..Default::default() + }) .await?; let mut run_output = RunOutput::new( run_result.account, @@ -357,10 +354,9 @@ impl DEngine { if a.misc != EMPTY_CELL { Some(json!({ "misc": a.misc })) } else { None }; let result = self.run_sendmsg(&a.name, args, signer.clone()).await?; if let Some(signing_box) = signer { - let _ = remove_signing_box( - self.ton.clone(), - RegisteredSigningBox { handle: signing_box }, - ); + let _ = remove_signing_box(self.ton.clone(), RegisteredSigningBox { + handle: signing_box, + }); } self.browser.log("Transaction succeeded.".to_string()).await; result.map(|r| self.browser.log(format!("Result: {}", r))); @@ -417,10 +413,9 @@ impl DEngine { }; let args = self.call_routine(&a.name, &args, signer.clone()).await?; if let Some(signing_box) = signer { - let _ = remove_signing_box( - self.ton.clone(), - RegisteredSigningBox { handle: signing_box }, - ); + let _ = remove_signing_box(self.ton.clone(), RegisteredSigningBox { + handle: signing_box, + }); } let setter = a.func_attr().ok_or("routine callback is not specified".to_owned())?; self.run_debot_external(&setter, Some(args)).await?; @@ -566,15 +561,12 @@ impl DEngine { load_abi(self.target_abi.as_ref().ok_or("target abi is undefined".to_string())?)? }; - let res = decode_message_body( - self.ton.clone(), - ParamsOfDecodeMessageBody { - abi: abi.clone(), - body: body.to_string(), - is_internal: true, - ..Default::default() - }, - ) + let res = decode_message_body(self.ton.clone(), ParamsOfDecodeMessageBody { + abi: abi.clone(), + body: body.to_string(), + is_internal: true, + ..Default::default() + }) .map_err(|e| format!("failed to decode msg body: {}", e))?; debug!("calling {} at address {}", res.name, dest); @@ -604,18 +596,15 @@ impl DEngine { } pub(crate) async fn load_state(ton: TonClient, addr: String) -> Result { - let account_request = query_collection( - ton, - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(serde_json::json!({ - "id": { "eq": addr } - })), - result: "boc".to_owned(), - limit: Some(1), - order: None, - }, - ) + let account_request = query_collection(ton, ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(serde_json::json!({ + "id": { "eq": addr } + })), + result: "boc".to_owned(), + limit: Some(1), + order: None, + }) .await; let acc = account_request.map_err(|e| format!("failed to query account: {}", e))?; if acc.result.is_empty() { @@ -704,16 +693,13 @@ impl DEngine { let result = encode_message(ton.clone(), msg_params).await?; - let result = run_tvm( - ton.clone(), - ParamsOfRunTvm { - account: state, - message: result.message, - abi: Some(abi), - return_updated_account: Some(true), - ..Default::default() - }, - ) + let result = run_tvm(ton.clone(), ParamsOfRunTvm { + account: state, + message: result.message, + abi: Some(abi), + return_updated_account: Some(true), + ..Default::default() + }) .await; match result { diff --git a/tvm_client/src/debot/dinterface.rs b/tvm_client/src/debot/dinterface.rs index e96a47cb9..8ecf7eb29 100644 --- a/tvm_client/src/debot/dinterface.rs +++ b/tvm_client/src/debot/dinterface.rs @@ -4,25 +4,25 @@ use std::sync::Arc; use num_traits::cast::NumCast; use serde_json::Value; +use super::JsonValue; use super::base64_interface::Base64Interface; use super::hex_interface::HexInterface; use super::json_lib_utils::bypass_json; use super::network_interface::NetworkInterface; use super::query_interface::QueryInterface; use super::sdk_interface::SdkInterface; -use super::JsonValue; use crate::abi::Abi; use crate::abi::Error; -use crate::boc::parse_message; use crate::boc::ParamsOfParse; +use crate::boc::parse_message; use crate::debot::TonClient; use crate::encoding::decode_abi_number; use crate::encoding::slice_from_cell; use crate::error::ClientResult; pub type InterfaceResult = Result<(u32, Value), String>; -use tvm_abi::token::Detokenizer; use tvm_abi::Contract; use tvm_abi::ParamType; +use tvm_abi::token::Detokenizer; use tvm_sdk::AbiContract; use crate::boc::internal::deserialize_cell_from_boc; diff --git a/tvm_client/src/debot/hex_interface.rs b/tvm_client/src/debot/hex_interface.rs index 55841a3f0..11bf13b79 100644 --- a/tvm_client/src/debot/hex_interface.rs +++ b/tvm_client/src/debot/hex_interface.rs @@ -1,9 +1,9 @@ use serde_json::Value; -use super::dinterface::decode_answer_id; -use super::dinterface::get_arg; use super::dinterface::DebotInterface; use super::dinterface::InterfaceResult; +use super::dinterface::decode_answer_id; +use super::dinterface::get_arg; use crate::abi::Abi; const ABI: &str = r#" diff --git a/tvm_client/src/debot/info.rs b/tvm_client/src/debot/info.rs index 152424302..9ac0f2286 100644 --- a/tvm_client/src/debot/info.rs +++ b/tvm_client/src/debot/info.rs @@ -1,14 +1,14 @@ use serde::Deserialize; use serde::Deserializer; -use super::context::str_hex_to_utf8; use super::Error; use super::JsonValue; use super::TonClient; -use crate::boc::get_compiler_version; -use crate::boc::parse_account; +use super::context::str_hex_to_utf8; use crate::boc::ParamsOfGetCompilerVersion; use crate::boc::ParamsOfParse; +use crate::boc::get_compiler_version; +use crate::boc::parse_account; use crate::encoding::account_decode; use crate::error::ClientResult; diff --git a/tvm_client/src/debot/json_interface.rs b/tvm_client/src/debot/json_interface.rs index 68339bae3..215be6613 100644 --- a/tvm_client/src/debot/json_interface.rs +++ b/tvm_client/src/debot/json_interface.rs @@ -2,10 +2,10 @@ use serde_json::Value as JsonValue; use tvm_abi::Contract; use tvm_abi::ParamType; -use super::dinterface::decode_answer_id; -use super::dinterface::get_arg; use super::dinterface::DebotInterface; use super::dinterface::InterfaceResult; +use super::dinterface::decode_answer_id; +use super::dinterface::get_arg; use super::json_lib_utils::bypass_json; use crate::abi::Abi; use crate::debot::json_lib_utils::pack; diff --git a/tvm_client/src/debot/json_lib_utils.rs b/tvm_client/src/debot/json_lib_utils.rs index 3facf88d6..d7fd370d9 100644 --- a/tvm_client/src/debot/json_lib_utils.rs +++ b/tvm_client/src/debot/json_lib_utils.rs @@ -4,11 +4,11 @@ use serde_json::Value as JsonValue; use serde_repr::Deserialize_repr; use serde_repr::Serialize_repr; use sha2::Digest; -use tvm_abi::contract::ABI_VERSION_2_0; -use tvm_abi::token::Tokenizer; use tvm_abi::Param; use tvm_abi::ParamType; use tvm_abi::TokenValue; +use tvm_abi::contract::ABI_VERSION_2_0; +use tvm_abi::token::Tokenizer; use crate::boc::internal::deserialize_cell_from_base64; use crate::boc::internal::serialize_cell_to_base64; diff --git a/tvm_client/src/debot/mod.rs b/tvm_client/src/debot/mod.rs index cbb4c2efa..04986e0be 100644 --- a/tvm_client/src/debot/mod.rs +++ b/tvm_client/src/debot/mod.rs @@ -55,8 +55,8 @@ pub use errors::ErrorCode; use info::DInfo; use tokio::sync::Mutex; -use crate::error::ClientResult; use crate::ClientContext; +use crate::error::ClientResult; pub const DEBOT_WC: i8 = -31; // 0xDB diff --git a/tvm_client/src/debot/msg_interface.rs b/tvm_client/src/debot/msg_interface.rs index 21056aa7c..3eac17593 100644 --- a/tvm_client/src/debot/msg_interface.rs +++ b/tvm_client/src/debot/msg_interface.rs @@ -4,17 +4,17 @@ use serde_json::Value; use tvm_abi::Contract; use super::calltype::ContractCall; -use super::dinterface::get_arg; use super::dinterface::DebotInterface; use super::dinterface::InterfaceResult; -use crate::abi::decode_message; +use super::dinterface::get_arg; use crate::abi::Abi; use crate::abi::ParamsOfDecodeMessage; use crate::abi::Signer; -use crate::boc::parse_message; +use crate::abi::decode_message; use crate::boc::ParamsOfParse; -use crate::crypto::get_signing_box; +use crate::boc::parse_message; use crate::crypto::KeyPair; +use crate::crypto::get_signing_box; use crate::debot::BrowserCallbacks; use crate::debot::DEngine; use crate::debot::TonClient; @@ -100,14 +100,11 @@ impl MsgInterface { .map_err(|e| format!("{}", e))?; let answer_msg = callobj.execute(true).await.map_err(|e| format!("{}", e))?; - let result = decode_message( - self.ton.clone(), - ParamsOfDecodeMessage { - abi: self.debot_abi.clone(), - message: answer_msg, - ..Default::default() - }, - ) + let result = decode_message(self.ton.clone(), ParamsOfDecodeMessage { + abi: self.debot_abi.clone(), + message: answer_msg, + ..Default::default() + }) .map_err(|e| format!("failed to decode message: {}", e))?; let abi_str = self.debot_abi.json_string().unwrap(); let contract = Contract::load(abi_str.as_bytes()).map_err(|e| format!("{}", e))?; @@ -138,14 +135,11 @@ impl MsgInterface { .map_err(|e| format!("{}", e))?; let answer_msg = callobj.execute(false).await.map_err(|e| format!("{}", e))?; - let result = decode_message( - self.ton.clone(), - ParamsOfDecodeMessage { - abi: self.debot_abi.clone(), - message: answer_msg, - ..Default::default() - }, - ) + let result = decode_message(self.ton.clone(), ParamsOfDecodeMessage { + abi: self.debot_abi.clone(), + message: answer_msg, + ..Default::default() + }) .map_err(|e| format!("failed to decode message: {}", e))?; let abi_str = self.debot_abi.json_string().unwrap(); let contract = Contract::load(abi_str.as_bytes()).map_err(|e| format!("{}", e))?; diff --git a/tvm_client/src/debot/network_interface.rs b/tvm_client/src/debot/network_interface.rs index f8b111b1f..5d190623e 100644 --- a/tvm_client/src/debot/network_interface.rs +++ b/tvm_client/src/debot/network_interface.rs @@ -2,12 +2,12 @@ use std::collections::HashMap; use serde_json::Value; +use super::TonClient; +use super::dinterface::DebotInterface; +use super::dinterface::InterfaceResult; use super::dinterface::decode_answer_id; use super::dinterface::get_arg; use super::dinterface::get_array_strings; -use super::dinterface::DebotInterface; -use super::dinterface::InterfaceResult; -use super::TonClient; use crate::abi::Abi; use crate::client::FetchMethod; diff --git a/tvm_client/src/debot/query_interface.rs b/tvm_client/src/debot/query_interface.rs index 109237391..b5c41f14e 100644 --- a/tvm_client/src/debot/query_interface.rs +++ b/tvm_client/src/debot/query_interface.rs @@ -1,22 +1,22 @@ use serde_json::Value as JsonValue; +use super::TonClient; +use super::dinterface::DebotInterface; +use super::dinterface::InterfaceResult; use super::dinterface::decode_answer_id; use super::dinterface::get_arg; use super::dinterface::get_num_arg; -use super::dinterface::DebotInterface; -use super::dinterface::InterfaceResult; -use super::TonClient; use crate::abi::Abi; -use crate::debot::json_lib_utils::pack; use crate::debot::json_lib_utils::Value; -use crate::net::query; -use crate::net::query_collection; -use crate::net::wait_for_collection; +use crate::debot::json_lib_utils::pack; use crate::net::OrderBy; use crate::net::ParamsOfQuery; use crate::net::ParamsOfQueryCollection; use crate::net::ParamsOfWaitForCollection; use crate::net::SortDirection; +use crate::net::query; +use crate::net::query_collection; +use crate::net::wait_for_collection; const ABI: &str = r#" { @@ -145,16 +145,13 @@ impl QueryInterface { ) -> Result, QueryStatus> { let filter: Option = Some(serde_json::from_str(&filter).map_err(|_| QueryStatus::FilterError)?); - let result = query_collection( - self.ton.clone(), - ParamsOfQueryCollection { - collection, - filter, - result, - order: Some(vec![order_by]), - limit: Some(limit), - }, - ) + let result = query_collection(self.ton.clone(), ParamsOfQueryCollection { + collection, + filter, + result, + order: Some(vec![order_by]), + limit: Some(limit), + }) .await .map_err(|_| QueryStatus::NetworkError)?; Ok(result.result) @@ -177,10 +174,12 @@ impl QueryInterface { ) -> Result { let filter: Option = Some(serde_json::from_str(&filter).map_err(|_| QueryStatus::FilterError)?); - let result = wait_for_collection( - self.ton.clone(), - ParamsOfWaitForCollection { collection, filter, result, timeout: Some(timeout) }, - ) + let result = wait_for_collection(self.ton.clone(), ParamsOfWaitForCollection { + collection, + filter, + result, + timeout: Some(timeout), + }) .await .map_err(|_| QueryStatus::NetworkError)?; Ok(result.result) diff --git a/tvm_client/src/debot/routines.rs b/tvm_client/src/debot/routines.rs index 418b881e7..810f85168 100644 --- a/tvm_client/src/debot/routines.rs +++ b/tvm_client/src/debot/routines.rs @@ -4,21 +4,21 @@ use tvm_types::base64_decode; use tvm_types::base64_encode; use super::TonClient; -use crate::boc::parse_account; use crate::boc::ParamsOfParse; -use crate::crypto::generate_random_bytes; -use crate::crypto::nacl_box_keypair_from_secret_key; -use crate::crypto::signing_box_sign; +use crate::boc::parse_account; use crate::crypto::KeyPair; use crate::crypto::ParamsOfGenerateRandomBytes; use crate::crypto::ParamsOfNaclBox; use crate::crypto::ParamsOfNaclBoxKeyPairFromSecret; use crate::crypto::ParamsOfSigningBoxSign; use crate::crypto::SigningBoxHandle; +use crate::crypto::generate_random_bytes; +use crate::crypto::nacl_box_keypair_from_secret_key; +use crate::crypto::signing_box_sign; use crate::encoding::decode_abi_bigint; use crate::encoding::decode_abi_number; -use crate::net::query_collection; use crate::net::ParamsOfQueryCollection; +use crate::net::query_collection; #[derive(Serialize, Deserialize, Clone)] pub(super) struct ResultOfGetAccountState { @@ -200,13 +200,10 @@ pub(super) async fn sign_hash( ) -> Result { let hash_str = arg_json["hash"].as_str().ok_or(r#""hash" argument not found"#.to_string())?; let hash_as_bigint = decode_abi_bigint(hash_str).map_err(|err| err.to_string())?; - let result = signing_box_sign( - ton, - ParamsOfSigningBoxSign { - unsigned: base64_encode(&hash_as_bigint.to_bytes_be().1), - signing_box: signer, - }, - ) + let result = signing_box_sign(ton, ParamsOfSigningBoxSign { + unsigned: base64_encode(&hash_as_bigint.to_bytes_be().1), + signing_box: signer, + }) .await .map_err(|err| format!("Can not sign hash: {}", err))?; Ok(result.signature) @@ -228,15 +225,12 @@ fn get_arg(args: &serde_json::Value, name: &str) -> Result { pub(super) fn nacl_box(ton: TonClient, args: serde_json::Value) -> Result { let public = decode_abi_bigint(&get_arg(&args, "publicKey")?).map_err(|e| e.to_string())?; let secret = decode_abi_bigint(&get_arg(&args, "secretKey")?).map_err(|e| e.to_string())?; - let result = crate::crypto::nacl_box( - ton, - ParamsOfNaclBox { - decrypted: base64_encode(get_arg(&args, "decrypted")?), - nonce: get_arg(&args, "nonce")?, - their_public: hex::encode(public.to_bytes_be().1), - secret: hex::encode(secret.to_bytes_be().1), - }, - ) + let result = crate::crypto::nacl_box(ton, ParamsOfNaclBox { + decrypted: base64_encode(get_arg(&args, "decrypted")?), + nonce: get_arg(&args, "nonce")?, + their_public: hex::encode(public.to_bytes_be().1), + secret: hex::encode(secret.to_bytes_be().1), + }) .map_err(|e| format!(" failed to encrypt with nacl box: {}", e))?; Ok(result.encrypted) } @@ -246,10 +240,9 @@ pub(super) fn nacl_box_gen_keypair( args: serde_json::Value, ) -> Result { let secret = decode_abi_bigint(&get_arg(&args, "secret")?).map_err(|e| e.to_string())?; - let result = nacl_box_keypair_from_secret_key( - ton, - ParamsOfNaclBoxKeyPairFromSecret { secret: hex::encode(secret.to_bytes_be().1) }, - ) + let result = nacl_box_keypair_from_secret_key(ton, ParamsOfNaclBoxKeyPairFromSecret { + secret: hex::encode(secret.to_bytes_be().1), + }) .map_err(|e| format!(" failed to generate keypair from secret: {}", e))?; Ok(result) } @@ -278,18 +271,15 @@ pub(super) async fn get_account( args: &serde_json::Value, ) -> Result { let addr = get_arg(args, "addr")?.to_lowercase(); - let mut accounts = query_collection( - ton.clone(), - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({ - "id": { "eq": addr } - })), - result: "boc".to_owned(), - order: None, - limit: Some(1), - }, - ) + let mut accounts = query_collection(ton.clone(), ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({ + "id": { "eq": addr } + })), + result: "boc".to_owned(), + order: None, + limit: Some(1), + }) .await .map_err(|e| format!("account query failed: {}", e))? .result; diff --git a/tvm_client/src/debot/run_output.rs b/tvm_client/src/debot/run_output.rs index 10515edfc..c03050120 100644 --- a/tvm_client/src/debot/run_output.rs +++ b/tvm_client/src/debot/run_output.rs @@ -3,10 +3,10 @@ use std::collections::VecDeque; use tvm_block::Message; use tvm_block::MsgAddressInt; +use super::DEBOT_WC; +use super::JsonValue; use super::action::DAction; use super::calltype::DebotCallType; -use super::JsonValue; -use super::DEBOT_WC; use crate::boc::internal::deserialize_object_from_base64; use crate::boc::internal::serialize_object_to_base64; use crate::encoding::account_decode; diff --git a/tvm_client/src/debot/sdk_interface.rs b/tvm_client/src/debot/sdk_interface.rs index eab44c992..bf6daa068 100644 --- a/tvm_client/src/debot/sdk_interface.rs +++ b/tvm_client/src/debot/sdk_interface.rs @@ -2,33 +2,15 @@ use serde_json::Value; use tvm_types::base64_decode; use tvm_types::base64_encode; +use super::TonClient; +use super::dinterface::DebotInterface; +use super::dinterface::InterfaceResult; use super::dinterface::decode_answer_id; use super::dinterface::get_arg; use super::dinterface::get_bool_arg; use super::dinterface::get_num_arg; -use super::dinterface::DebotInterface; -use super::dinterface::InterfaceResult; use super::routines; -use super::TonClient; use crate::abi::Abi; -use crate::crypto::chacha20; -use crate::crypto::encryption_box_decrypt; -use crate::crypto::encryption_box_encrypt; -use crate::crypto::encryption_box_get_info; -use crate::crypto::hdkey_derive_from_xprv; -use crate::crypto::hdkey_derive_from_xprv_path; -use crate::crypto::hdkey_public_from_xprv; -use crate::crypto::hdkey_secret_from_xprv; -use crate::crypto::hdkey_xprv_from_mnemonic; -use crate::crypto::mnemonic_derive_sign_keys; -use crate::crypto::mnemonic_from_random; -use crate::crypto::mnemonic_verify; -use crate::crypto::nacl_box; -use crate::crypto::nacl_box_keypair_from_secret_key; -use crate::crypto::nacl_box_open; -use crate::crypto::nacl_sign_keypair_from_secret_key; -use crate::crypto::signing_box_get_public_key; -use crate::crypto::signing_box_sign; use crate::crypto::EncryptionBoxHandle; use crate::crypto::EncryptionBoxInfo; use crate::crypto::ParamsOfChaCha20; @@ -49,11 +31,29 @@ use crate::crypto::ParamsOfNaclBoxOpen; use crate::crypto::ParamsOfNaclSignKeyPairFromSecret; use crate::crypto::ParamsOfSigningBoxSign; use crate::crypto::RegisteredSigningBox; +use crate::crypto::chacha20; +use crate::crypto::encryption_box_decrypt; +use crate::crypto::encryption_box_encrypt; +use crate::crypto::encryption_box_get_info; +use crate::crypto::hdkey_derive_from_xprv; +use crate::crypto::hdkey_derive_from_xprv_path; +use crate::crypto::hdkey_public_from_xprv; +use crate::crypto::hdkey_secret_from_xprv; +use crate::crypto::hdkey_xprv_from_mnemonic; +use crate::crypto::mnemonic_derive_sign_keys; +use crate::crypto::mnemonic_from_random; +use crate::crypto::mnemonic_verify; +use crate::crypto::nacl_box; +use crate::crypto::nacl_box_keypair_from_secret_key; +use crate::crypto::nacl_box_open; +use crate::crypto::nacl_sign_keypair_from_secret_key; +use crate::crypto::signing_box_get_public_key; +use crate::crypto::signing_box_sign; use crate::encoding::decode_abi_bigint; -use crate::net::query_collection; use crate::net::OrderBy; use crate::net::ParamsOfQueryCollection; use crate::net::SortDirection; +use crate::net::query_collection; const ABI: &str = r#" { @@ -437,10 +437,10 @@ impl SdkInterface { .try_into() .map_err(|err: ClientError| err.to_string())?; let word_count = get_num_arg::(args, "wordCount")?; - let result = mnemonic_from_random( - self.ton.clone(), - ParamsOfMnemonicFromRandom { dictionary: Some(dict), word_count: Some(word_count) }, - ) + let result = mnemonic_from_random(self.ton.clone(), ParamsOfMnemonicFromRandom { + dictionary: Some(dict), + word_count: Some(word_count), + }) .map_err(|e| format!("{}", e))?; Ok((answer_id, json!({ "phrase": result.phrase }))) } @@ -449,15 +449,12 @@ impl SdkInterface { let answer_id = decode_answer_id(args)?; let phrase = get_arg(args, "phrase")?; let path = get_arg(args, "path")?; - let keypair = mnemonic_derive_sign_keys( - self.ton.clone(), - ParamsOfMnemonicDeriveSignKeys { - phrase, - path: if path.is_empty() { None } else { Some(path) }, - dictionary: None, - word_count: None, - }, - ) + let keypair = mnemonic_derive_sign_keys(self.ton.clone(), ParamsOfMnemonicDeriveSignKeys { + phrase, + path: if path.is_empty() { None } else { Some(path) }, + dictionary: None, + word_count: None, + }) .map_err(|e| format!("{}", e))?; Ok(( @@ -472,10 +469,11 @@ impl SdkInterface { fn mnemonic_verify(&self, args: &Value) -> InterfaceResult { let answer_id = decode_answer_id(args)?; let phrase = get_arg(args, "phrase")?; - let result = mnemonic_verify( - self.ton.clone(), - ParamsOfMnemonicVerify { phrase, dictionary: None, word_count: None }, - ) + let result = mnemonic_verify(self.ton.clone(), ParamsOfMnemonicVerify { + phrase, + dictionary: None, + word_count: None, + }) .map_err(|e| format!("{}", e))?; Ok((answer_id, json!({ "valid": result.valid }))) } @@ -483,10 +481,11 @@ impl SdkInterface { fn hdkey_xprv_from_mnemonic(&self, args: &Value) -> InterfaceResult { let answer_id = decode_answer_id(args)?; let phrase = get_arg(args, "phrase")?; - let result = hdkey_xprv_from_mnemonic( - self.ton.clone(), - ParamsOfHDKeyXPrvFromMnemonic { phrase, dictionary: None, word_count: None }, - ) + let result = hdkey_xprv_from_mnemonic(self.ton.clone(), ParamsOfHDKeyXPrvFromMnemonic { + phrase, + dictionary: None, + word_count: None, + }) .map_err(|e| format!("{}", e))?; Ok((answer_id, json!({ "xprv": result.xprv }))) } @@ -504,10 +503,11 @@ impl SdkInterface { let xprv = get_arg(args, "inXprv")?; let child_index = get_num_arg::(args, "childIndex")?; let hardened = get_bool_arg(args, "hardened")?; - let result = hdkey_derive_from_xprv( - self.ton.clone(), - ParamsOfHDKeyDeriveFromXPrv { xprv, child_index, hardened }, - ) + let result = hdkey_derive_from_xprv(self.ton.clone(), ParamsOfHDKeyDeriveFromXPrv { + xprv, + child_index, + hardened, + }) .map_err(|e| format!("{}", e))?; Ok((answer_id, json!({ "xprv": result.xprv }))) } @@ -516,11 +516,12 @@ impl SdkInterface { let answer_id = decode_answer_id(args)?; let xprv = get_arg(args, "inXprv")?; let path = get_arg(args, "path")?; - let result = hdkey_derive_from_xprv_path( - self.ton.clone(), - ParamsOfHDKeyDeriveFromXPrvPath { xprv, path }, - ) - .map_err(|e| format!("{}", e))?; + let result = + hdkey_derive_from_xprv_path(self.ton.clone(), ParamsOfHDKeyDeriveFromXPrvPath { + xprv, + path, + }) + .map_err(|e| format!("{}", e))?; Ok((answer_id, json!({ "xprv": result.xprv }))) } @@ -575,15 +576,12 @@ impl SdkInterface { let nonce = get_arg(args, "nonce")?; let public = decode_abi_bigint(&get_arg(args, "publicKey")?).map_err(|e| e.to_string())?; let secret = decode_abi_bigint(&get_arg(args, "secretKey")?).map_err(|e| e.to_string())?; - let result = nacl_box( - self.ton.clone(), - ParamsOfNaclBox { - decrypted, - nonce, - their_public: format!("{:064x}", public), - secret: format!("{:064x}", secret), - }, - ) + let result = nacl_box(self.ton.clone(), ParamsOfNaclBox { + decrypted, + nonce, + their_public: format!("{:064x}", public), + secret: format!("{:064x}", secret), + }) .map_err(|e| format!("{}", e))?; Ok(( answer_id, @@ -598,15 +596,12 @@ impl SdkInterface { let nonce = get_arg(args, "nonce")?; let public = decode_abi_bigint(&get_arg(args, "publicKey")?).map_err(|e| e.to_string())?; let secret = decode_abi_bigint(&get_arg(args, "secretKey")?).map_err(|e| e.to_string())?; - let result = nacl_box_open( - self.ton.clone(), - ParamsOfNaclBoxOpen { - encrypted, - nonce, - their_public: format!("{:064x}", public), - secret: format!("{:064x}", secret), - }, - ) + let result = nacl_box_open(self.ton.clone(), ParamsOfNaclBoxOpen { + encrypted, + nonce, + their_public: format!("{:064x}", public), + secret: format!("{:064x}", secret), + }) .map_err(|e| format!("{}", e))?; Ok(( answer_id, @@ -617,11 +612,11 @@ impl SdkInterface { fn nacl_box_keypair_from_secret_key(&self, args: &Value) -> InterfaceResult { let answer_id = decode_answer_id(args)?; let secret = decode_abi_bigint(&get_arg(args, "secret")?).map_err(|e| format!("{}", e))?; - let result = nacl_box_keypair_from_secret_key( - self.ton.clone(), - ParamsOfNaclBoxKeyPairFromSecret { secret: format!("{:064x}", secret) }, - ) - .map_err(|e| format!("{}", e))?; + let result = + nacl_box_keypair_from_secret_key(self.ton.clone(), ParamsOfNaclBoxKeyPairFromSecret { + secret: format!("{:064x}", secret), + }) + .map_err(|e| format!("{}", e))?; Ok(( answer_id, json!({ @@ -643,10 +638,9 @@ impl SdkInterface { let answer_id = decode_answer_id(args)?; let encryption_box = EncryptionBoxHandle(get_num_arg::(args, "boxHandle")?); - let result = encryption_box_get_info( - self.ton.clone(), - ParamsOfEncryptionBoxGetInfo { encryption_box }, - ) + let result = encryption_box_get_info(self.ton.clone(), ParamsOfEncryptionBoxGetInfo { + encryption_box, + }) .await .map_err(|e| e.code) .map(|x| x.info); @@ -666,18 +660,18 @@ impl SdkInterface { let data = base64_encode(hex::decode(get_arg(args, "data")?).map_err(|e| format!("{}", e))?); let result = if encrypt { - encryption_box_encrypt( - self.ton.clone(), - ParamsOfEncryptionBoxEncrypt { encryption_box, data }, - ) + encryption_box_encrypt(self.ton.clone(), ParamsOfEncryptionBoxEncrypt { + encryption_box, + data, + }) .await .map_err(|e| e.code) .map(|x| x.data) } else { - encryption_box_decrypt( - self.ton.clone(), - ParamsOfEncryptionBoxDecrypt { encryption_box, data }, - ) + encryption_box_decrypt(self.ton.clone(), ParamsOfEncryptionBoxDecrypt { + encryption_box, + data, + }) .await .map_err(|e| e.code) .map(|x| x.data) @@ -708,19 +702,16 @@ impl SdkInterface { let code_hash = decode_abi_bigint(&code_hash) .map_err(|e| format!("failed to parse integer \"{}\": {}", code_hash, e))?; - let accounts = query_collection( - self.ton.clone(), - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({ - "code_hash": { "eq": format!("{:064x}", code_hash) }, - "id": {"gt": gt_addr } - })), - result: result.to_owned(), - order: Some(vec![OrderBy { path: "id".to_owned(), direction: SortDirection::ASC }]), - limit: None, - }, - ) + let accounts = query_collection(self.ton.clone(), ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({ + "code_hash": { "eq": format!("{:064x}", code_hash) }, + "id": {"gt": gt_addr } + })), + result: result.to_owned(), + order: Some(vec![OrderBy { path: "id".to_owned(), direction: SortDirection::ASC }]), + limit: None, + }) .await .map_err(|e| format!("account query failed: {}", e))? .result; @@ -739,10 +730,9 @@ impl SdkInterface { async fn get_signing_box_info(&self, args: &Value) -> InterfaceResult { let answer_id = decode_answer_id(args)?; let box_handle = get_num_arg::(args, "boxHandle")?; - let result = signing_box_get_public_key( - self.ton.clone(), - RegisteredSigningBox { handle: box_handle.into() }, - ) + let result = signing_box_get_public_key(self.ton.clone(), RegisteredSigningBox { + handle: box_handle.into(), + }) .await; let (result, key) = match result { @@ -758,13 +748,10 @@ impl SdkInterface { let sign_int = decode_abi_bigint(&get_arg(args, "hash")?).map_err(|e| e.to_string())?; let sign_hash = hex::decode(format!("{:064x}", sign_int)).map_err(|e| e.to_string())?; - let signature = signing_box_sign( - self.ton.clone(), - ParamsOfSigningBoxSign { - signing_box: box_handle.into(), - unsigned: base64_encode(sign_hash.as_slice()), - }, - ) + let signature = signing_box_sign(self.ton.clone(), ParamsOfSigningBoxSign { + signing_box: box_handle.into(), + unsigned: base64_encode(sign_hash.as_slice()), + }) .await .map_err(|e| format!("{}", e))? .signature; diff --git a/tvm_client/src/debot/tests.rs b/tvm_client/src/debot/tests.rs index 2749c34ef..ab61f49d6 100644 --- a/tvm_client/src/debot/tests.rs +++ b/tvm_client/src/debot/tests.rs @@ -42,9 +42,9 @@ use crate::json_interface::debot::*; use crate::json_interface::interop::ResponseType; use crate::net::ParamsOfQueryCollection; use crate::net::ResultOfQueryCollection; -use crate::tests::TestClient; use crate::tests::TEST_DEBOT; use crate::tests::TEST_DEBOT_TARGET; +use crate::tests::TestClient; use crate::tvm::ParamsOfRunTvm; use crate::tvm::ResultOfRunTvm; @@ -172,10 +172,9 @@ impl TestBrowser { if call_start { let _: () = client - .request_async( - "debot.start", - ParamsOfStart { debot_handle: handle.debot_handle.clone() }, - ) + .request_async("debot.start", ParamsOfStart { + debot_handle: handle.debot_handle.clone(), + }) .await .unwrap(); } @@ -195,10 +194,10 @@ impl TestBrowser { }; log::info!("Executing action: {:#?}", action); let _: () = client - .request_async( - "debot.execute", - ParamsOfExecute { debot_handle: handle.debot_handle.clone(), action }, - ) + .request_async("debot.execute", ParamsOfExecute { + debot_handle: handle.debot_handle.clone(), + action, + }) .await .unwrap(); @@ -422,15 +421,12 @@ impl TestBrowser { panic!("unsupported interface"); }; let decoded: DecodedMessageBody = client - .request_async( - "abi.decode_message_body", - ParamsOfDecodeMessageBody { - abi, - body, - is_internal: true, - ..Default::default() - }, - ) + .request_async("abi.decode_message_body", ParamsOfDecodeMessageBody { + abi, + body, + is_internal: true, + ..Default::default() + }) .await .unwrap(); let (func, args) = (decoded.name, decoded.value.unwrap()); @@ -486,19 +482,16 @@ async fn encode_internal_message( call_set: Option, ) -> String { let r: ResultOfEncodeInternalMessage = client - .request_async( - "abi.encode_internal_message", - ParamsOfEncodeInternalMessage { - abi: Some(Abi::Contract(serde_json::from_str(abi).unwrap())), - address: Some(addr), - src_address: None, - deploy_set: None, - call_set, - value: "1000000000000000".to_owned(), - bounce: None, - enable_ihr: None, - }, - ) + .request_async("abi.encode_internal_message", ParamsOfEncodeInternalMessage { + abi: Some(Abi::Contract(serde_json::from_str(abi).unwrap())), + address: Some(addr), + src_address: None, + deploy_set: None, + call_set, + value: "1000000000000000".to_owned(), + bounce: None, + enable_ihr: None, + }) .await .unwrap(); r.message @@ -832,18 +825,15 @@ async fn init_hello_debot(client: Arc) -> DebotData { async fn count_accounts_by_codehash(client: Arc, code_hash: String) -> u32 { let res: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({ - "code_hash": { "eq": code_hash} - })), - result: "id".to_owned(), - limit: None, - order: None, - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({ + "code_hash": { "eq": code_hash} + })), + result: "id".to_owned(), + limit: None, + order: None, + }) .await .unwrap(); @@ -853,10 +843,9 @@ async fn count_accounts_by_codehash(client: Arc, code_hash: String) async fn get_code_hash_from_tvc(client: Arc, name: &str) -> String { let debot_tvc = TestClient::tvc(name, Some(2)); let result: ResultOfGetCodeFromTvc = client - .request_async( - "boc.get_code_from_tvc", - ParamsOfGetCodeFromTvc { tvc: debot_tvc.unwrap_or_default() }, - ) + .request_async("boc.get_code_from_tvc", ParamsOfGetCodeFromTvc { + tvc: debot_tvc.unwrap_or_default(), + }) .await .unwrap(); @@ -1077,11 +1066,9 @@ async fn test_debot_inner_interfaces() { let DebotData { debot_addr, target_addr: _, keys, abi } = init_debot3(client.clone()).await; let steps = serde_json::from_value(json!([])).unwrap(); - let mut info = build_info( - abi, - 0, - vec![format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3")], - ); + let mut info = build_info(abi, 0, vec![format!( + "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3" + )]); info.name = Some("TestSdk".to_string()); info.version = Some("0.4.0".to_string()); info.caption = Some("Test for SDK interface".to_string()); @@ -1281,7 +1268,7 @@ async fn test_debot_getinfo() { dabi: Some(abi), icon: Some(icon), interfaces: vec![ - "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned() + "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), ], dabi_version: "2.0".to_string(), }, @@ -1296,14 +1283,10 @@ async fn test_debot_approve() { let client = Arc::new(TestClient::new()); let DebotData { debot_addr, target_addr: _, keys, abi } = init_simple_debot(client.clone(), "testDebot6").await; - let mut info = build_info( - abi, - 6, - vec![ - "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), - "0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a".to_owned(), - ], - ); + let mut info = build_info(abi, 6, vec![ + "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), + "0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a".to_owned(), + ]); info.caption = Some("Test for approve callback and signing handle".to_string()); info.name = Some("testDebot6".to_string()); info.hello = Some("testDebot6".to_string()); @@ -1332,10 +1315,10 @@ async fn test_debot_approve() { }, ExpectedTransaction { dst: debot_addr.clone(), - out: vec![ - Spending { amount: 2200000000, dst: debot_addr.clone() }, - Spending { amount: 3500000000, dst: format!("0:{:064}", 0) }, - ], + out: vec![Spending { amount: 2200000000, dst: debot_addr.clone() }, Spending { + amount: 3500000000, + dst: format!("0:{:064}", 0), + }], setcode: false, signkey: keys.public.clone(), approved: true, @@ -1395,15 +1378,11 @@ async fn test_debot_network_interface() { keys, steps, vec![], - build_info( - abi, - 8, - vec![ - "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), - "0xe38aed5884dc3e4426a87c083faaf4fa08109189fbc0c79281112f52e062d8ee".to_owned(), - "0x442288826041d564ccedc579674f17c1b0a3452df799656a9167a41ab270ec19".to_owned(), - ], - ), + build_info(abi, 8, vec![ + "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), + "0xe38aed5884dc3e4426a87c083faaf4fa08109189fbc0c79281112f52e062d8ee".to_owned(), + "0x442288826041d564ccedc579674f17c1b0a3452df799656a9167a41ab270ec19".to_owned(), + ]), vec![], ) .await; @@ -1422,11 +1401,9 @@ async fn test_debot_transaction_chain() { keys, steps, vec![format!("Test passed")], - build_info( - abi, - 9, - vec!["0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned()], - ), + build_info(abi, 9, vec![ + "0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3".to_owned(), + ]), vec![], ) .await; @@ -1445,14 +1422,10 @@ async fn test_debot_encryption_box() { keys, steps, vec![format!("Encryption Box Handle: 3"), format!("Test passed")], - build_info( - abi, - 10, - vec![ - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - format!("0x5b5f76b54d976d72f1ada3063d1af2e5352edaf1ba86b3b311170d4d81056d61"), - ], - ), + build_info(abi, 10, vec![ + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + format!("0x5b5f76b54d976d72f1ada3063d1af2e5352edaf1ba86b3b311170d4d81056d61"), + ]), vec![], ) .await; @@ -1471,14 +1444,10 @@ async fn test_debot_encryption_box_get_info() { keys, steps, vec![], - build_info( - abi, - 11, - vec![ - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - format!("0x5b5f76b54d976d72f1ada3063d1af2e5352edaf1ba86b3b311170d4d81056d61"), - ], - ), + build_info(abi, 11, vec![ + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + format!("0x5b5f76b54d976d72f1ada3063d1af2e5352edaf1ba86b3b311170d4d81056d61"), + ]), vec![], ) .await; @@ -1497,14 +1466,10 @@ async fn test_debot_signing_box_get_info() { keys, steps, vec![], - build_info( - abi, - 12, - vec![ - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), - ], - ), + build_info(abi, 12, vec![ + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), + ]), vec![], ) .await; @@ -1522,14 +1487,10 @@ async fn test_debot_query() { keys, vec![], vec![], - build_info( - abi, - 14, - vec![ - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - format!("0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811"), - ], - ), + build_info(abi, 14, vec![ + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + format!("0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811"), + ]), vec![], ) .await; @@ -1541,14 +1502,10 @@ async fn test_debot_json_parse() { let client = Arc::new(TestClient::new()); let DebotData { debot_addr, target_addr: _, keys, abi } = init_simple_debot(client.clone(), "testDebot15").await; - let mut info = build_info( - abi, - 15, - vec![ - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - format!("0x442288826041d564ccedc579674f17c1b0a3452df799656a9167a41ab270ec19"), - ], - ); + let mut info = build_info(abi, 15, vec![ + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + format!("0x442288826041d564ccedc579674f17c1b0a3452df799656a9167a41ab270ec19"), + ]); info.dabi_version = "2.2".to_string(); TestBrowser::execute_with_details( client.clone(), @@ -1586,14 +1543,10 @@ async fn test_debot_custom_header() { // deploy debot let DebotData { debot_addr, target_addr: _, keys, abi } = init_simple_debot(client.clone(), "testDebot20").await; - let info = build_info_abi2_2( - abi, - 20, - vec![ - format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - ], - ); + let info = build_info_abi2_2(abi, 20, vec![ + format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + ]); // set address of CustomReplayProtection to DeBot let debot_abi = TestClient::abi("testDebot20", Some(2)); let _ = client @@ -1652,14 +1605,10 @@ async fn test_debot_msg_sendasync_and_waitforcollection() { keys, steps, vec![], - build_info( - abi, - 17, - vec![ - "0x475a5d1729acee4601c2a8cb67240e4da5316cc90a116e1b181d905e79401c51".to_owned(), - "0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811".to_owned(), - ], - ), + build_info(abi, 17, vec![ + "0x475a5d1729acee4601c2a8cb67240e4da5316cc90a116e1b181d905e79401c51".to_owned(), + "0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811".to_owned(), + ]), vec![], ) .await; @@ -1678,11 +1627,9 @@ async fn test_debot_query_query() { keys, steps, vec![], - build_info( - abi, - 18, - vec!["0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811".to_owned()], - ), + build_info(abi, 18, vec![ + "0x5c6fd81616cdfb963632109c42144a3a885c8d0f2e8deb5d8e15872fb92f2811".to_owned(), + ]), vec![], ) .await; @@ -1700,14 +1647,10 @@ async fn test_debot_transaction_result() { keys, vec![], vec![], - build_info( - abi, - 19, - vec![ - format!("0x475a5d1729acee4601c2a8cb67240e4da5316cc90a116e1b181d905e79401c51"), - format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), - ], - ), + build_info(abi, 19, vec![ + format!("0x475a5d1729acee4601c2a8cb67240e4da5316cc90a116e1b181d905e79401c51"), + format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), + ]), vec![], ) .await; @@ -1726,14 +1669,10 @@ async fn test_debot_sign_hash() { keys, steps, vec![], - build_info_abi2_2( - abi, - 21, - vec![ - format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), - format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), - ], - ), + build_info_abi2_2(abi, 21, vec![ + format!("0xc13024e101c95e71afb1f5fa6d72f633d51e721de0320d73dfd6121a54e4d40a"), + format!("0x8796536366ee21852db56dccb60bc564598b618c865fc50c8b1ab740bba128e3"), + ]), vec![], ) .await; @@ -1782,18 +1721,15 @@ fn build_info_abi2_2(abi: String, n: u32, interfaces: Vec) -> DebotInfo async fn download_account(client: &Arc, addr: &str) -> Option { let client = client.clone(); let accounts: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "accounts".to_string(), - filter: Some(json!({ - "id": { "eq": addr } - })), - result: "boc".to_string(), - limit: Some(1), - order: None, - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "accounts".to_string(), + filter: Some(json!({ + "id": { "eq": addr } + })), + result: "boc".to_string(), + limit: Some(1), + order: None, + }) .await .unwrap(); @@ -1824,17 +1760,14 @@ async fn assert_get_method( let message = client.encode_message(call_params).await.unwrap().message; let result: ResultOfRunTvm = client - .request_async( - "tvm.run_tvm", - ParamsOfRunTvm { - account: acc_boc, - message, - abi: Some(abi.clone()), - execution_options: None, - boc_cache: None, - return_updated_account: Some(true), - }, - ) + .request_async("tvm.run_tvm", ParamsOfRunTvm { + account: acc_boc, + message, + abi: Some(abi.clone()), + execution_options: None, + boc_cache: None, + return_updated_account: Some(true), + }) .await .unwrap(); diff --git a/tvm_client/src/debot/tests_interfaces.rs b/tvm_client/src/debot/tests_interfaces.rs index 87e997db7..42df93c22 100644 --- a/tvm_client/src/debot/tests_interfaces.rs +++ b/tvm_client/src/debot/tests_interfaces.rs @@ -12,20 +12,20 @@ use std::sync::Arc; use serde_json::Value; +use crate::ClientContext; use crate::client::ParamsOfAppRequest; -use crate::crypto::boxes::encryption_box::EncryptionBox; use crate::crypto::EncryptionBoxHandle; use crate::crypto::EncryptionBoxInfo; use crate::crypto::KeyPair; use crate::crypto::RegisteredEncryptionBox; use crate::crypto::RegisteredSigningBox; use crate::crypto::SigningBoxHandle; +use crate::crypto::boxes::encryption_box::EncryptionBox; use crate::encoding::decode_abi_number; use crate::error::ClientResult; use crate::json_interface::crypto::*; use crate::json_interface::interop::ResponseType; use crate::tests::TestClient; -use crate::ClientContext; // use super::*; pub const SUPPORTED_INTERFACES: &[&str] = &[ diff --git a/tvm_client/src/encoding.rs b/tvm_client/src/encoding.rs index d60b89ed4..ee572e898 100644 --- a/tvm_client/src/encoding.rs +++ b/tvm_client/src/encoding.rs @@ -106,11 +106,7 @@ fn encode_base64( let result = tvm_types::base64_encode(&vec); - if as_url { - Ok(result.replace('/', "_").replace('+', "-")) - } else { - Ok(result) - } + if as_url { Ok(result.replace('/', "_").replace('+', "-")) } else { Ok(result) } } else { Err(client::Error::invalid_address("Non-std address", &address.to_string())) } diff --git a/tvm_client/src/error.rs b/tvm_client/src/error.rs index ca8b9f171..df124b5d0 100644 --- a/tvm_client/src/error.rs +++ b/tvm_client/src/error.rs @@ -86,11 +86,7 @@ impl AddNetworkUrl for ClientError { impl Display for ClientError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if f.alternate() { - write!(f, "{:#}", json!(self)) - } else { - write!(f, "{}", self.message) - } + if f.alternate() { write!(f, "{:#}", json!(self)) } else { write!(f, "{}", self.message) } } } diff --git a/tvm_client/src/json_interface/crypto.rs b/tvm_client/src/json_interface/crypto.rs index 908ce0a20..8981f3106 100644 --- a/tvm_client/src/json_interface/crypto.rs +++ b/tvm_client/src/json_interface/crypto.rs @@ -17,16 +17,16 @@ use tvm_types::base64_encode; use crate::client::AppObject; use crate::client::ClientContext; use crate::client::Error; +use crate::crypto::EncryptionBoxInfo; +use crate::crypto::RegisteredEncryptionBox; +use crate::crypto::RegisteredSigningBox; +use crate::crypto::SigningBox; use crate::crypto::boxes::crypto_box::AppPasswordProvider; use crate::crypto::boxes::crypto_box::ParamsOfCreateCryptoBox; use crate::crypto::boxes::crypto_box::RegisteredCryptoBox; use crate::crypto::boxes::crypto_box::ResultOfGetPassword; use crate::crypto::boxes::encryption_box::EncryptionBox; use crate::crypto::internal::hex_decode_secret_const; -use crate::crypto::EncryptionBoxInfo; -use crate::crypto::RegisteredEncryptionBox; -use crate::crypto::RegisteredSigningBox; -use crate::crypto::SigningBox; use crate::encoding::base64_decode; use crate::error::ClientResult; diff --git a/tvm_client/src/json_interface/handlers.rs b/tvm_client/src/json_interface/handlers.rs index 643eadc37..66780f3af 100644 --- a/tvm_client/src/json_interface/handlers.rs +++ b/tvm_client/src/json_interface/handlers.rs @@ -17,8 +17,8 @@ use api_info::ApiType; use api_info::Field; use api_info::Type; use futures::Future; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use serde_json::Value; use super::request::Request; diff --git a/tvm_client/src/json_interface/interop.rs b/tvm_client/src/json_interface/interop.rs index b1022755d..657b53b80 100644 --- a/tvm_client/src/json_interface/interop.rs +++ b/tvm_client/src/json_interface/interop.rs @@ -178,11 +178,7 @@ pub unsafe extern "C" fn tc_destroy_string(string: *const String) { #[no_mangle] pub unsafe extern "C" fn tc_read_string(string: *const String) -> StringData { - if string.is_null() { - StringData::default() - } else { - StringData::new(&*string) - } + if string.is_null() { StringData::default() } else { StringData::new(&*string) } } #[repr(C)] diff --git a/tvm_client/src/json_interface/net.rs b/tvm_client/src/json_interface/net.rs index 85d814659..bb3ccbbbd 100644 --- a/tvm_client/src/json_interface/net.rs +++ b/tvm_client/src/json_interface/net.rs @@ -13,10 +13,10 @@ use super::request::Request; use crate::client::ClientContext; use crate::error::ClientResult; -use crate::net::subscriptions::ParamsOfSubscribe; use crate::net::ParamsOfSubscribeCollection; use crate::net::ResultOfSubscribeCollection; use crate::net::ResultOfSubscription; +use crate::net::subscriptions::ParamsOfSubscribe; /// Creates a collection subscription /// diff --git a/tvm_client/src/json_interface/registrar.rs b/tvm_client/src/json_interface/registrar.rs index 8c7e30cc0..31cdfedc6 100644 --- a/tvm_client/src/json_interface/registrar.rs +++ b/tvm_client/src/json_interface/registrar.rs @@ -16,8 +16,8 @@ use std::sync::Arc; use api_info::ApiModule; use api_info::ApiType; use api_info::Module; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use super::handlers::CallHandler; use super::handlers::CallNoArgsHandler; diff --git a/tvm_client/src/json_interface/request.rs b/tvm_client/src/json_interface/request.rs index 42cc4d923..9e709950e 100644 --- a/tvm_client/src/json_interface/request.rs +++ b/tvm_client/src/json_interface/request.rs @@ -16,14 +16,14 @@ use std::sync::atomic::Ordering; use serde::Serialize; -use crate::error::ClientError; -use crate::error::ClientResult; use crate::CResponseHandler; use crate::CResponseHandlerPtr; use crate::ResponseHandler; use crate::ResponseHandlerPtr; use crate::ResponseType; use crate::StringData; +use crate::error::ClientError; +use crate::error::ClientResult; enum ResponseHandlerImpl { Rust(u32, ResponseHandler), diff --git a/tvm_client/src/json_interface/runtime.rs b/tvm_client/src/json_interface/runtime.rs index 92a242f14..322bf160c 100644 --- a/tvm_client/src/json_interface/runtime.rs +++ b/tvm_client/src/json_interface/runtime.rs @@ -15,16 +15,16 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::MutexGuard; -use api_info::Module; use api_info::API; +use api_info::Module; use super::modules::register_modules; use super::request::Request; +use crate::ContextHandle; use crate::client::ClientConfig; use crate::client::ClientContext; use crate::client::Error; use crate::error::ClientResult; -use crate::ContextHandle; pub(crate) trait SyncHandler { fn handle(&self, context: Arc, params_json: &str) -> ClientResult; diff --git a/tvm_client/src/json_interface/utils.rs b/tvm_client/src/json_interface/utils.rs index 1e09e5b2a..d5b53cb31 100644 --- a/tvm_client/src/json_interface/utils.rs +++ b/tvm_client/src/json_interface/utils.rs @@ -12,8 +12,8 @@ use tvm_types::base64_decode; use tvm_types::base64_encode; -use crate::error::ClientResult; use crate::ClientContext; +use crate::error::ClientResult; #[derive(Serialize, Deserialize, ApiType, Default, Debug)] pub struct ParamsOfCompressZstd { diff --git a/tvm_client/src/net/endpoint.rs b/tvm_client/src/net/endpoint.rs index aa905829e..55f080b80 100644 --- a/tvm_client/src/net/endpoint.rs +++ b/tvm_client/src/net/endpoint.rs @@ -19,10 +19,10 @@ use std::sync::atomic::Ordering; use serde_json::Value; -use crate::client::binding_config; -use crate::client::core_version; use crate::client::ClientEnv; use crate::client::FetchMethod; +use crate::client::binding_config; +use crate::client::core_version; use crate::error::ClientResult; use crate::net::Error; use crate::net::NetworkConfig; @@ -92,11 +92,7 @@ impl Endpoint { }; base_url = format!("{}{}", protocol, base_url); }; - if base_url.ends_with("/graphql") { - base_url - } else { - format!("{}/graphql", base_url) - } + if base_url.ends_with("/graphql") { base_url } else { format!("{}/graphql", base_url) } } async fn fetch_info_with_url( diff --git a/tvm_client/src/net/errors.rs b/tvm_client/src/net/errors.rs index 37fab445c..0e6eb10bf 100644 --- a/tvm_client/src/net/errors.rs +++ b/tvm_client/src/net/errors.rs @@ -3,8 +3,8 @@ use std::fmt::Display; use serde_json::Value; use crate::client::FetchResult; -use crate::error::format_time; use crate::error::ClientError; +use crate::error::format_time; #[derive(ApiType)] pub enum ErrorCode { diff --git a/tvm_client/src/net/iterators/block.rs b/tvm_client/src/net/iterators/block.rs index bc50f8f0b..2363cd83b 100644 --- a/tvm_client/src/net/iterators/block.rs +++ b/tvm_client/src/net/iterators/block.rs @@ -13,17 +13,17 @@ use std::fmt; use std::sync::Arc; -use serde::de::Error; use serde::Serializer; +use serde::de::Error; use serde_json::Value; use tvm_block::ShardIdent; +use crate::ClientContext; use crate::error::ClientResult; -use crate::net::query_collection; use crate::net::OrderBy; use crate::net::ParamsOfQueryCollection; use crate::net::SortDirection; -use crate::ClientContext; +use crate::net::query_collection; pub const BLOCK_TRAVERSE_FIELDS: &str = r#" id @@ -299,16 +299,13 @@ impl MasterBlock { limit: u32, fields: &str, ) -> ClientResult> { - query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - filter: Some(filter), - order: Some(vec![OrderBy { path: "gen_utime".to_string(), direction }]), - result: format!("{} {}", BLOCK_MASTER_FIELDS, fields), - limit: Some(limit), - }, - ) + query_collection(context.clone(), ParamsOfQueryCollection { + collection: "blocks".to_string(), + filter: Some(filter), + order: Some(vec![OrderBy { path: "gen_utime".to_string(), direction }]), + result: format!("{} {}", BLOCK_MASTER_FIELDS, fields), + limit: Some(limit), + }) .await .map(|x| x.result) } diff --git a/tvm_client/src/net/iterators/block_iterator/branch.rs b/tvm_client/src/net/iterators/block_iterator/branch.rs index 17ca63c74..c5c041991 100644 --- a/tvm_client/src/net/iterators/block_iterator/branch.rs +++ b/tvm_client/src/net/iterators/block_iterator/branch.rs @@ -15,11 +15,11 @@ use std::sync::Arc; use serde_json::Value; use tvm_block::ShardIdent; +use crate::ClientContext; use crate::error::ClientResult; use crate::net::iterators::block::BlockFields; -use crate::net::iterators::block_iterator::filter::Filter; use crate::net::iterators::block_iterator::NextLink; -use crate::ClientContext; +use crate::net::iterators::block_iterator::filter::Filter; #[derive(Serialize, Deserialize, Clone)] pub struct Branch { diff --git a/tvm_client/src/net/iterators/block_iterator/filter.rs b/tvm_client/src/net/iterators/block_iterator/filter.rs index 20ea75d8c..dee8364bc 100644 --- a/tvm_client/src/net/iterators/block_iterator/filter.rs +++ b/tvm_client/src/net/iterators/block_iterator/filter.rs @@ -14,8 +14,8 @@ use serde_json::Value; use tvm_block::ShardIdent; use crate::error::ClientResult; -use crate::net::iterators::block::shard_ident_parse; use crate::net::iterators::block::BlockFields; +use crate::net::iterators::block::shard_ident_parse; use crate::net::iterators::block_iterator::ParamsOfCreateBlockIterator; #[derive(Clone)] diff --git a/tvm_client/src/net/iterators/block_iterator/mod.rs b/tvm_client/src/net/iterators/block_iterator/mod.rs index 3240ec42a..876ee7543 100644 --- a/tvm_client/src/net/iterators/block_iterator/mod.rs +++ b/tvm_client/src/net/iterators/block_iterator/mod.rs @@ -23,20 +23,20 @@ use tvm_block::ShardIdent; use crate::client::ClientContext; use crate::error::ClientResult; -use crate::net::iterators::block::shard_ident_parse; -use crate::net::iterators::block::shard_ident_to_string; +use crate::net::ChainIterator; +use crate::net::ParamsOfQueryCollection; +use crate::net::RegisteredIterator; +use crate::net::iterators::ResultOfIteratorNext; +use crate::net::iterators::block::BLOCK_TRAVERSE_FIELDS; use crate::net::iterators::block::BlockFields; use crate::net::iterators::block::MasterBlock; use crate::net::iterators::block::RefFields; -use crate::net::iterators::block::BLOCK_TRAVERSE_FIELDS; +use crate::net::iterators::block::shard_ident_parse; +use crate::net::iterators::block::shard_ident_to_string; use crate::net::iterators::block_iterator::state::StateBuilder; use crate::net::iterators::query_by_ids; use crate::net::iterators::register_iterator; -use crate::net::iterators::ResultOfIteratorNext; use crate::net::query_collection; -use crate::net::ChainIterator; -use crate::net::ParamsOfQueryCollection; -use crate::net::RegisteredIterator; mod branch; mod filter; @@ -211,18 +211,15 @@ impl BlockIterator { let by_prev_ids = prev_ids_by(NextLink::ByPrev); let by_prev_alt_ids = prev_ids_by(NextLink::ByPrevAlt); - let mut blocks = query_collection( - context.clone(), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - filter: Some(json!({ - "prev_ref": { "root_hash": { "in": by_prev_ids } }, - "OR": { "prev_alt_ref": { "root_hash": { "in": by_prev_alt_ids } } }, - })), - result: format!("{} {}", BLOCK_TRAVERSE_FIELDS, self.filter.result_fields), - ..Default::default() - }, - ) + let mut blocks = query_collection(context.clone(), ParamsOfQueryCollection { + collection: "blocks".to_string(), + filter: Some(json!({ + "prev_ref": { "root_hash": { "in": by_prev_ids } }, + "OR": { "prev_alt_ref": { "root_hash": { "in": by_prev_alt_ids } } }, + })), + result: format!("{} {}", BLOCK_TRAVERSE_FIELDS, self.filter.result_fields), + ..Default::default() + }) .await? .result; diff --git a/tvm_client/src/net/iterators/block_iterator/state.rs b/tvm_client/src/net/iterators/block_iterator/state.rs index b02f04d33..3698101cb 100644 --- a/tvm_client/src/net/iterators/block_iterator/state.rs +++ b/tvm_client/src/net/iterators/block_iterator/state.rs @@ -16,9 +16,9 @@ use serde_json::Value; use crate::error::ClientResult; use crate::net::iterators::block::BlockFields; +use crate::net::iterators::block_iterator::NextLink; use crate::net::iterators::block_iterator::branch::Branch; use crate::net::iterators::block_iterator::filter::Filter; -use crate::net::iterators::block_iterator::NextLink; #[derive(Clone)] pub(crate) struct State { diff --git a/tvm_client/src/net/iterators/mod.rs b/tvm_client/src/net/iterators/mod.rs index dc2bbbfe2..71ac2b14c 100644 --- a/tvm_client/src/net/iterators/mod.rs +++ b/tvm_client/src/net/iterators/mod.rs @@ -27,8 +27,8 @@ use tokio::sync::Mutex; use crate::client::ClientContext; use crate::error::ClientResult; -use crate::net::query_collection; use crate::net::ParamsOfQueryCollection; +use crate::net::query_collection; #[async_trait::async_trait] pub trait ChainIterator { @@ -173,15 +173,12 @@ pub(crate) async fn query_by_ids( let mut query_queue: HashSet = head_ids.iter().cloned().collect(); while !query_queue.is_empty() { let portion_ids: Vec = query_queue.iter().cloned().collect(); - let portion = query_collection( - client.clone(), - ParamsOfQueryCollection { - collection: collection.to_string(), - filter: Some(json!({ "id": { "in": portion_ids } })), - result: result_fields.to_string(), - ..Default::default() - }, - ) + let portion = query_collection(client.clone(), ParamsOfQueryCollection { + collection: collection.to_string(), + filter: Some(json!({ "id": { "in": portion_ids } })), + result: result_fields.to_string(), + ..Default::default() + }) .await? .result; for item in portion { diff --git a/tvm_client/src/net/iterators/tests.rs b/tvm_client/src/net/iterators/tests.rs index 73916d492..23eff6838 100644 --- a/tvm_client/src/net/iterators/tests.rs +++ b/tvm_client/src/net/iterators/tests.rs @@ -13,17 +13,14 @@ async fn query_ids_in_range( let mut start_time = start_time; while start_time < end_time { let items: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: collection.to_string(), - filter: Some(json!({ - time_field: { "eq": start_time }, - })), - result: format!("id {}", time_field), - ..Default::default() - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: collection.to_string(), + filter: Some(json!({ + time_field: { "eq": start_time }, + })), + result: format!("id {}", time_field), + ..Default::default() + }) .await .unwrap(); for item in items.result { diff --git a/tvm_client/src/net/iterators/transaction_iterator/mod.rs b/tvm_client/src/net/iterators/transaction_iterator/mod.rs index 1749f2a15..d94b1b38b 100644 --- a/tvm_client/src/net/iterators/transaction_iterator/mod.rs +++ b/tvm_client/src/net/iterators/transaction_iterator/mod.rs @@ -18,17 +18,17 @@ use serde_json::Value; use crate::client::ClientContext; use crate::error::ClientResult; -use crate::net::iterators::block::BlockFields; +use crate::net::ChainIterator; +use crate::net::ParamsOfCreateBlockIterator; +use crate::net::RegisteredIterator; +use crate::net::iterators::ResultOfIteratorNext; use crate::net::iterators::block::BLOCK_TRANSACTIONS_FIELDS; +use crate::net::iterators::block::BlockFields; use crate::net::iterators::block_iterator::BlockIterator; use crate::net::iterators::query_by_ids; use crate::net::iterators::register_iterator; -use crate::net::iterators::transaction::TransactionFields; use crate::net::iterators::transaction::TRANSACTION_FIELDS; -use crate::net::iterators::ResultOfIteratorNext; -use crate::net::ChainIterator; -use crate::net::ParamsOfCreateBlockIterator; -use crate::net::RegisteredIterator; +use crate::net::iterators::transaction::TransactionFields; #[derive(Serialize, Deserialize)] pub(crate) struct ResumeState { @@ -53,15 +53,12 @@ impl TransactionIterator { context: &Arc, params: ParamsOfCreateTransactionIterator, ) -> ClientResult { - let blocks = BlockIterator::new( - context, - ParamsOfCreateBlockIterator { - start_time: params.start_time, - end_time: params.end_time, - result: Some(BLOCK_TRANSACTIONS_FIELDS.to_string()), - shard_filter: params.shard_filter, - }, - ) + let blocks = BlockIterator::new(context, ParamsOfCreateBlockIterator { + start_time: params.start_time, + end_time: params.end_time, + result: Some(BLOCK_TRANSACTIONS_FIELDS.to_string()), + shard_filter: params.shard_filter, + }) .await?; Ok(Self { blocks, diff --git a/tvm_client/src/net/mod.rs b/tvm_client/src/net/mod.rs index e98bc600c..2686dacdd 100644 --- a/tvm_client/src/net/mod.rs +++ b/tvm_client/src/net/mod.rs @@ -9,56 +9,56 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -pub use batch::batch_query; pub use batch::ParamsOfBatchQuery; pub use batch::ResultOfBatchQuery; +pub use batch::batch_query; pub(crate) use endpoint::Endpoint; pub use errors::Error; pub use errors::ErrorCode; -pub use iterators::block_iterator::create_block_iterator; -pub use iterators::block_iterator::resume_block_iterator; +pub use iterators::ChainIterator; +pub use iterators::ParamsOfIteratorNext; +pub use iterators::RegisteredIterator; +pub use iterators::ResultOfIteratorNext; pub use iterators::block_iterator::ParamsOfCreateBlockIterator; pub use iterators::block_iterator::ParamsOfResumeBlockIterator; +pub use iterators::block_iterator::create_block_iterator; +pub use iterators::block_iterator::resume_block_iterator; pub use iterators::iterator_next; pub use iterators::remove_iterator; -pub use iterators::transaction_iterator::create_transaction_iterator; -pub use iterators::transaction_iterator::resume_transaction_iterator; pub use iterators::transaction_iterator::ParamsOfCreateTransactionIterator; pub use iterators::transaction_iterator::ParamsOfResumeTransactionIterator; -pub use iterators::ChainIterator; -pub use iterators::ParamsOfIteratorNext; -pub use iterators::RegisteredIterator; -pub use iterators::ResultOfIteratorNext; -pub use network_params::get_signature_id; +pub use iterators::transaction_iterator::create_transaction_iterator; +pub use iterators::transaction_iterator::resume_transaction_iterator; pub use network_params::ResultOfGetSignatureId; -pub use queries::aggregate_collection; -pub use queries::query; -pub use queries::query_collection; -pub use queries::query_counterparties; -pub use queries::wait_for_collection; +pub use network_params::get_signature_id; pub use queries::ParamsOfQuery; pub use queries::ParamsOfWaitForCollection; pub use queries::ResultOfAggregateCollection; pub use queries::ResultOfQuery; pub use queries::ResultOfQueryCollection; pub use queries::ResultOfWaitForCollection; +pub use queries::aggregate_collection; +pub use queries::query; +pub use queries::query_collection; +pub use queries::query_counterparties; +pub use queries::wait_for_collection; pub(crate) use server_link::EndpointStat; +pub(crate) use server_link::MAX_TIMEOUT; pub(crate) use server_link::NetworkState; pub(crate) use server_link::ServerLink; -pub(crate) use server_link::MAX_TIMEOUT; -pub use subscriptions::subscribe; -pub use subscriptions::subscribe_collection; -pub use subscriptions::unsubscribe; pub use subscriptions::ParamsOfSubscribe; pub use subscriptions::ParamsOfSubscribeCollection; pub use subscriptions::ResultOfSubscribeCollection; pub use subscriptions::ResultOfSubscription; pub use subscriptions::SubscriptionResponseType; -pub use transaction_tree::query_transaction_tree; +pub use subscriptions::subscribe; +pub use subscriptions::subscribe_collection; +pub use subscriptions::unsubscribe; pub use transaction_tree::MessageNode; pub use transaction_tree::ParamsOfQueryTransactionTree; pub use transaction_tree::ResultOfQueryTransactionTree; pub use transaction_tree::TransactionNode; +pub use transaction_tree::query_transaction_tree; pub use tvm_gql::AggregationFn; pub use tvm_gql::FieldAggregation; pub use tvm_gql::GraphQLQueryEvent; @@ -69,11 +69,11 @@ pub use tvm_gql::ParamsOfQueryCounterparties; pub use tvm_gql::ParamsOfQueryOperation; pub use tvm_gql::PostRequest; pub use tvm_gql::SortDirection; -pub use types::NetworkConfig; -pub use types::NetworkQueriesProtocol; pub use types::ACCOUNTS_COLLECTION; pub use types::BLOCKS_COLLECTION; pub use types::MESSAGES_COLLECTION; +pub use types::NetworkConfig; +pub use types::NetworkQueriesProtocol; pub use types::TRANSACTIONS_COLLECTION; use crate::client::ClientContext; diff --git a/tvm_client/src/net/network.rs b/tvm_client/src/net/network.rs index 8d53f5156..df7f1dd9d 100644 --- a/tvm_client/src/net/network.rs +++ b/tvm_client/src/net/network.rs @@ -6,9 +6,9 @@ use std::sync::Arc; use futures::FutureExt; use futures::StreamExt; use rand::RngCore; -use tokio::sync::mpsc; use tokio::sync::Mutex; use tokio::sync::RwLock; +use tokio::sync::mpsc; use tvm_types::UInt256; use crate::client; @@ -16,13 +16,13 @@ use crate::client::ClientEnv; use crate::error::AddNetworkUrl; use crate::error::ClientResult; use crate::net; -use crate::net::queries::deserialize_result; -use crate::net::subscriptions::SubscriptionAction; use crate::net::ChainIterator; use crate::net::ParamsOfQueryCollection; use crate::net::ResultOfQueryCollection; use crate::net::ResultOfSubscription; use crate::net::ServerLink; +use crate::net::queries::deserialize_result; +use crate::net::subscriptions::SubscriptionAction; use crate::utils::json::JsonHelper; #[derive(Debug)] diff --git a/tvm_client/src/net/queries.rs b/tvm_client/src/net/queries.rs index fa97fb083..fe674bb09 100644 --- a/tvm_client/src/net/queries.rs +++ b/tvm_client/src/net/queries.rs @@ -146,8 +146,8 @@ pub async fn wait_for_collection( use serde::de::DeserializeOwned; -use crate::net::tvm_gql::GraphQLQuery; use crate::net::ParamsOfAggregateCollection; +use crate::net::tvm_gql::GraphQLQuery; #[derive(Serialize, Deserialize, ApiType, Default, Clone)] pub struct ResultOfAggregateCollection { diff --git a/tvm_client/src/net/server_link.rs b/tvm_client/src/net/server_link.rs index 6e64f590d..920181e21 100644 --- a/tvm_client/src/net/server_link.rs +++ b/tvm_client/src/net/server_link.rs @@ -14,21 +14,21 @@ use std::cmp::min; use std::collections::HashMap; use std::collections::HashSet; use std::pin::Pin; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; use futures::Future; use futures::Stream; use futures::StreamExt; use rand::seq::SliceRandom; use serde_json::Value; -use tokio::sync::watch; use tokio::sync::Mutex; use tokio::sync::RwLock; -use tvm_types::base64_encode; +use tokio::sync::watch; use tvm_types::UInt256; +use tvm_types::base64_encode; use super::ErrorCode; use crate::client::ClientEnv; @@ -36,10 +36,6 @@ use crate::client::FetchMethod; use crate::error::AddNetworkUrl; use crate::error::ClientError; use crate::error::ClientResult; -use crate::net::endpoint::Endpoint; -use crate::net::tvm_gql::GraphQLQuery; -use crate::net::types::NetworkQueriesProtocol; -use crate::net::websocket_link::WebsocketLink; use crate::net::Error; use crate::net::GraphQLQueryEvent; use crate::net::NetworkConfig; @@ -49,6 +45,10 @@ use crate::net::ParamsOfQueryCounterparties; use crate::net::ParamsOfQueryOperation; use crate::net::ParamsOfWaitForCollection; use crate::net::PostRequest; +use crate::net::endpoint::Endpoint; +use crate::net::tvm_gql::GraphQLQuery; +use crate::net::types::NetworkQueriesProtocol; +use crate::net::websocket_link::WebsocketLink; pub const MAX_TIMEOUT: u32 = i32::MAX as u32; pub const MIN_RESUME_TIMEOUT: u32 = 500; diff --git a/tvm_client/src/net/tests.rs b/tvm_client/src/net/tests.rs index d5ec58a49..447360744 100644 --- a/tvm_client/src/net/tests.rs +++ b/tvm_client/src/net/tests.rs @@ -6,6 +6,7 @@ use serde_json::Value; use tokio::sync::Mutex; use super::*; +use crate::ClientConfig; use crate::abi::CallSet; use crate::abi::DeploySet; use crate::abi::ParamsOfEncodeMessage; @@ -15,9 +16,8 @@ use crate::error::ClientError; // use crate::net::subscriptions::ParamsOfSubscribe; use crate::net::tvm_gql::GraphQLQuery; use crate::processing::ParamsOfProcessMessage; -use crate::tests::TestClient; use crate::tests::HELLO; -use crate::ClientConfig; +use crate::tests::TestClient; #[ignore] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -29,10 +29,10 @@ async fn bad_request() { })); let result = client - .request_async::<_, ResultOfQuery>( - "net.query", - ParamsOfQuery { query: r#"query { accounts { id }"#.to_string(), variables: None }, - ) + .request_async::<_, ResultOfQuery>("net.query", ParamsOfQuery { + query: r#"query { accounts { id }"#.to_string(), + variables: None, + }) .await; if let Err(err) = result { @@ -193,36 +193,33 @@ async fn batch_query() { let client = TestClient::new(); let batch: ResultOfBatchQuery = client - .request_async( - "net.batch_query", - ParamsOfBatchQuery { - operations: vec![ - ParamsOfQueryOperation::QueryCollection(ParamsOfQueryCollection { - collection: "blocks_signatures".to_owned(), - filter: None, - result: "id".to_owned(), - limit: Some(1), - order: None, - }), - ParamsOfQueryOperation::AggregateCollection(ParamsOfAggregateCollection { - collection: "accounts".to_owned(), - filter: None, - fields: Some(vec![FieldAggregation { - field: "".into(), - aggregation_fn: AggregationFn::COUNT, - }]), - }), - ParamsOfQueryOperation::WaitForCollection(ParamsOfWaitForCollection { - collection: "transactions".to_owned(), - filter: Some(json!({ - "now": { "gt": 20 } - })), - result: "id now".to_owned(), - timeout: None, - }), - ], - }, - ) + .request_async("net.batch_query", ParamsOfBatchQuery { + operations: vec![ + ParamsOfQueryOperation::QueryCollection(ParamsOfQueryCollection { + collection: "blocks_signatures".to_owned(), + filter: None, + result: "id".to_owned(), + limit: Some(1), + order: None, + }), + ParamsOfQueryOperation::AggregateCollection(ParamsOfAggregateCollection { + collection: "accounts".to_owned(), + filter: None, + fields: Some(vec![FieldAggregation { + field: "".into(), + aggregation_fn: AggregationFn::COUNT, + }]), + }), + ParamsOfQueryOperation::WaitForCollection(ParamsOfWaitForCollection { + collection: "transactions".to_owned(), + filter: Some(json!({ + "now": { "gt": 20 } + })), + result: "id now".to_owned(), + timeout: None, + }), + ], + }) .await .unwrap(); @@ -234,10 +231,10 @@ async fn query() { let client = TestClient::new(); let info: ResultOfQuery = client - .request_async( - "net.query", - ParamsOfQuery { query: "query{info{version}}".to_owned(), variables: None }, - ) + .request_async("net.query", ParamsOfQuery { + query: "query{info{version}}".to_owned(), + variables: None, + }) .await .unwrap(); @@ -250,19 +247,19 @@ fn query_sync() { let client = TestClient::new(); let info: ResultOfQuery = client - .request( - "net.query", - ParamsOfQuery { query: "query{info{version}}".to_owned(), variables: None }, - ) + .request("net.query", ParamsOfQuery { + query: "query{info{version}}".to_owned(), + variables: None, + }) .unwrap(); let version = info.result["data"]["info"]["version"].as_str().unwrap(); assert_eq!(version.split('.').count(), 3); - let result: ClientResult = client.request( - "net.query", - ParamsOfQuery { query: "query{info111{version}}".to_owned(), variables: None }, - ); + let result: ClientResult = client.request("net.query", ParamsOfQuery { + query: "query{info111{version}}".to_owned(), + variables: None, + }); assert!(result.is_err()); } @@ -272,16 +269,13 @@ async fn block_signatures() { let client = TestClient::new(); let _: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "blocks_signatures".to_owned(), - filter: Some(json!({})), - result: "id".to_owned(), - limit: Some(1), - order: None, - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "blocks_signatures".to_owned(), + filter: Some(json!({})), + result: "id".to_owned(), + limit: Some(1), + order: None, + }) .await .unwrap(); } @@ -291,16 +285,13 @@ async fn all_accounts() { let client = TestClient::new(); let accounts: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({})), - result: "id balance".to_owned(), - limit: None, - order: None, - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({})), + result: "id balance".to_owned(), + limit: None, + order: None, + }) .await .unwrap(); @@ -312,17 +303,14 @@ async fn aggregates() { let client = TestClient::new(); let result: ResultOfAggregateCollection = client - .request_async( - "net.aggregate_collection", - ParamsOfAggregateCollection { - collection: "accounts".to_owned(), - filter: Some(json!({})), - fields: Some(vec![FieldAggregation { - field: "".into(), - aggregation_fn: AggregationFn::COUNT, - }]), - }, - ) + .request_async("net.aggregate_collection", ParamsOfAggregateCollection { + collection: "accounts".to_owned(), + filter: Some(json!({})), + fields: Some(vec![FieldAggregation { + field: "".into(), + aggregation_fn: AggregationFn::COUNT, + }]), + }) .await .unwrap(); @@ -335,18 +323,15 @@ async fn ranges() { let client = TestClient::new(); let accounts: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "messages".to_owned(), - filter: Some(json!({ - "created_at": { "gt": 1562342740 } - })), - result: "body created_at".to_owned(), - limit: None, - order: None, - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "messages".to_owned(), + filter: Some(json!({ + "created_at": { "gt": 1562342740 } + })), + result: "body created_at".to_owned(), + limit: None, + order: None, + }) .await .unwrap(); @@ -360,17 +345,14 @@ async fn wait_for() { let request = tokio::spawn(async move { let client = TestClient::new(); let transactions: ResultOfWaitForCollection = client - .request_async( - "net.wait_for_collection", - ParamsOfWaitForCollection { - collection: "transactions".to_owned(), - filter: Some(json!({ - "now": { "gt": now } - })), - result: "id now".to_owned(), - timeout: None, - }, - ) + .request_async("net.wait_for_collection", ParamsOfWaitForCollection { + collection: "transactions".to_owned(), + filter: Some(json!({ + "now": { "gt": now } + })), + result: "id now".to_owned(), + timeout: None, + }) .await .unwrap(); assert!(transactions.result["now"].as_u64().unwrap() > now as u64); @@ -666,10 +648,9 @@ async fn find_last_shard_block() { let client = TestClient::new(); let block: ResultOfFindLastShardBlock = client - .request_async( - "net.find_last_shard_block", - ParamsOfFindLastShardBlock { address: client.giver_address().await }, - ) + .request_async("net.find_last_shard_block", ParamsOfFindLastShardBlock { + address: client.giver_address().await, + }) .await .unwrap(); @@ -729,15 +710,12 @@ async fn test_query_counterparties() { let account = client.giver_address().await; let counterparties1: ResultOfQueryCollection = client - .request_async( - "net.query_counterparties", - ParamsOfQueryCounterparties { - account: account.clone(), - first: Some(5), - after: None, - result: "counterparty last_message_id cursor".to_owned(), - }, - ) + .request_async("net.query_counterparties", ParamsOfQueryCounterparties { + account: account.clone(), + first: Some(5), + after: None, + result: "counterparty last_message_id cursor".to_owned(), + }) .await .unwrap(); @@ -745,15 +723,12 @@ async fn test_query_counterparties() { if counterparties1.result.len() == 5 { let counterparties2: ResultOfQueryCollection = client - .request_async( - "net.query_counterparties", - ParamsOfQueryCounterparties { - account: account.clone(), - first: Some(5), - after: Some(counterparties1.result[4]["cursor"].as_str().unwrap().to_owned()), - result: "counterparty last_message_id cursor".to_owned(), - }, - ) + .request_async("net.query_counterparties", ParamsOfQueryCounterparties { + account: account.clone(), + first: Some(5), + after: Some(counterparties1.result[4]["cursor"].as_str().unwrap().to_owned()), + result: "counterparty last_message_id cursor".to_owned(), + }) .await .unwrap(); @@ -762,14 +737,11 @@ async fn test_query_counterparties() { } async fn query_block_id(client: &Arc) -> ClientResult { - crate::net::query_collection( - client.clone(), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "id".to_string(), - ..Default::default() - }, - ) + crate::net::query_collection(client.clone(), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "id".to_string(), + ..Default::default() + }) .await .map(|result| result.result[0]["id"].as_str().unwrap().to_string()) } @@ -1064,14 +1036,11 @@ async fn querying_endpoint_selection() { .unwrap(), ); NetworkMock::build().url("a").delay(100).repeat(3).network_err().reset_client(&client).await; - let result = crate::net::query_collection( - client.clone(), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "id id".to_string(), - ..Default::default() - }, - ) + let result = crate::net::query_collection(client.clone(), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "id id".to_string(), + ..Default::default() + }) .await; assert_eq!( @@ -1288,28 +1257,23 @@ async fn transaction_tree() { let abi_registry = vec![abi]; let result: ResultOfQueryTransactionTree = client - .request_async( - "net.query_transaction_tree", - ParamsOfQueryTransactionTree { - in_msg: run_result.transaction["in_msg"].as_str().unwrap().to_string(), - abi_registry: Some(abi_registry.clone()), - transaction_max_count: Some(0), - ..Default::default() - }, - ) + .request_async("net.query_transaction_tree", ParamsOfQueryTransactionTree { + in_msg: run_result.transaction["in_msg"].as_str().unwrap().to_string(), + abi_registry: Some(abi_registry.clone()), + transaction_max_count: Some(0), + ..Default::default() + }) .await .unwrap(); let messages: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "messages".to_owned(), - filter: Some(json!({ - "id": { "eq": run_result.transaction["in_msg"].as_str() }, - "msg_type": { "eq": 1 }, - })), - result: r#" + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "messages".to_owned(), + filter: Some(json!({ + "id": { "eq": run_result.transaction["in_msg"].as_str() }, + "msg_type": { "eq": 1 }, + })), + result: r#" id dst dst_transaction { id aborted out_messages { id dst msg_type_name @@ -1322,11 +1286,10 @@ async fn transaction_tree() { } } "# - .to_string(), - limit: None, - order: None, - }, - ) + .to_string(), + limit: None, + order: None, + }) .await .unwrap(); @@ -1358,16 +1321,13 @@ async fn transaction_tree() { assert!(has_decoded_bodies); let result: ResultOfQueryTransactionTree = client - .request_async( - "net.query_transaction_tree", - ParamsOfQueryTransactionTree { - in_msg: messages.result[0]["id"].as_str().unwrap().to_string(), - abi_registry: Some(abi_registry.clone()), - transaction_max_count: Some(2), - timeout: Some(0), - ..Default::default() - }, - ) + .request_async("net.query_transaction_tree", ParamsOfQueryTransactionTree { + in_msg: messages.result[0]["id"].as_str().unwrap().to_string(), + abi_registry: Some(abi_registry.clone()), + transaction_max_count: Some(2), + timeout: Some(0), + ..Default::default() + }) .await .unwrap(); @@ -1387,18 +1347,21 @@ async fn order_by_fallback() { ) .unwrap(); assert_eq!(params.order.unwrap()[0].path, "id"); - assert!(serde_json::from_str::( - r#" + assert!( + serde_json::from_str::( + r#" { "collection": "messages", "result": "id", "orderBy": [{"path": "id", "direction": "ASC"}] } "#, - ) - .is_err()); - assert!(serde_json::from_str::( - r#" + ) + .is_err() + ); + assert!( + serde_json::from_str::( + r#" { "collection": "messages", "result": "id", @@ -1410,8 +1373,9 @@ async fn order_by_fallback() { ] } "#, - ) - .is_err()); + ) + .is_err() + ); let client = TestClient::new(); let result: ClientResult = client @@ -1533,29 +1497,23 @@ async fn query_using_ws() { })); let accounts: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({})), - result: "id".to_owned(), - ..Default::default() - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({})), + result: "id".to_owned(), + ..Default::default() + }) .await .unwrap(); assert!(!accounts.result.is_empty()); let messages: ResultOfQueryCollection = client - .request_async( - "net.query_collection", - ParamsOfQueryCollection { - collection: "messages".to_owned(), - filter: Some(json!({})), - result: "id".to_owned(), - ..Default::default() - }, - ) + .request_async("net.query_collection", ParamsOfQueryCollection { + collection: "messages".to_owned(), + filter: Some(json!({})), + result: "id".to_owned(), + ..Default::default() + }) .await .unwrap(); diff --git a/tvm_client/src/net/transaction_tree.rs b/tvm_client/src/net/transaction_tree.rs index b4721ce55..44c382bc0 100644 --- a/tvm_client/src/net/transaction_tree.rs +++ b/tvm_client/src/net/transaction_tree.rs @@ -15,15 +15,15 @@ use std::sync::Arc; use serde_json::Value; -use crate::abi::decode_message_body; use crate::abi::Abi; use crate::abi::DecodedMessageBody; use crate::abi::ParamsOfDecodeMessageBody; +use crate::abi::decode_message_body; use crate::client::ClientContext; use crate::error::ClientResult; +use crate::net::MESSAGES_COLLECTION; use crate::net::ParamsOfQueryCollection; use crate::net::ServerLink; -use crate::net::MESSAGES_COLLECTION; const DEFAULT_WAITING_TIMEOUT: u32 = 60000; const DEFAULT_TRANSACTION_MAX_COUNT: u32 = 50; @@ -137,15 +137,14 @@ impl MessageNode { if let Some(body) = message["body"].as_str() { let is_internal = message["msg_type"].as_u64().unwrap_or(0) == 0; for abi in abi_registry { - if let Ok(result) = decode_message_body( - client.clone(), - ParamsOfDecodeMessageBody { + if let Ok(result) = + decode_message_body(client.clone(), ParamsOfDecodeMessageBody { body: body.to_string(), abi: abi.clone(), is_internal, ..Default::default() - }, - ) { + }) + { return Some(result); } } diff --git a/tvm_client/src/net/tvm_gql.rs b/tvm_client/src/net/tvm_gql.rs index f42380380..230cf9c84 100644 --- a/tvm_client/src/net/tvm_gql.rs +++ b/tvm_client/src/net/tvm_gql.rs @@ -10,15 +10,15 @@ // limitations under the License. // -use serde::de::Error; use serde::Deserialize; use serde::Deserializer; +use serde::de::Error; use serde_json::Value; use crate::error::ClientError; use crate::error::ClientResult; -use crate::net::gql::GraphQLMessageFromClient; use crate::net::ParamsOfWaitForCollection; +use crate::net::gql::GraphQLMessageFromClient; const COUNTERPARTIES_COLLECTION: &str = "counterparties"; const FETCH_ADDITIONAL_TIMEOUT: u32 = 5000; diff --git a/tvm_client/src/net/websocket_link.rs b/tvm_client/src/net/websocket_link.rs index 83134cebd..2afb2e321 100644 --- a/tvm_client/src/net/websocket_link.rs +++ b/tvm_client/src/net/websocket_link.rs @@ -14,15 +14,15 @@ use std::collections::HashMap; use std::pin::Pin; use std::sync::Arc; -use futures::stream::Fuse; -use futures::stream::FusedStream; use futures::Sink; use futures::SinkExt; use futures::StreamExt; +use futures::stream::Fuse; +use futures::stream::FusedStream; use serde_json::Value; -use tokio::sync::mpsc::channel; use tokio::sync::mpsc::Receiver; use tokio::sync::mpsc::Sender; +use tokio::sync::mpsc::channel; use tokio_stream::wrappers::ReceiverStream; use crate::client::ClientEnv; @@ -30,14 +30,14 @@ use crate::client::WebSocket; use crate::error::AddNetworkUrl; use crate::error::ClientError; use crate::error::ClientResult; +use crate::net::Error; +use crate::net::NetworkConfig; use crate::net::endpoint::Endpoint; use crate::net::gql::GraphQLMessageFromClient; use crate::net::gql::GraphQLMessageFromServer; use crate::net::server_link::NetworkState; use crate::net::tvm_gql::GraphQLQuery; use crate::net::tvm_gql::GraphQLQueryEvent; -use crate::net::Error; -use crate::net::NetworkConfig; type WSSender = Pin + Send>>; diff --git a/tvm_client/src/processing/blocks_walking.rs b/tvm_client/src/processing/blocks_walking.rs index 2c4ea9d31..3c4c32cdc 100644 --- a/tvm_client/src/processing/blocks_walking.rs +++ b/tvm_client/src/processing/blocks_walking.rs @@ -11,18 +11,18 @@ use std::sync::Arc; -use tvm_block::MsgAddressInt; use tvm_block::MASTERCHAIN_ID; +use tvm_block::MsgAddressInt; use super::Error; use crate::client::ClientContext; use crate::error::ClientResult; +use crate::net::BLOCKS_COLLECTION; use crate::net::Endpoint; use crate::net::OrderBy; use crate::net::ParamsOfQueryCollection; use crate::net::ParamsOfWaitForCollection; use crate::net::SortDirection; -use crate::net::BLOCKS_COLLECTION; pub const BLOCK_FIELDS: &str = r#" id diff --git a/tvm_client/src/processing/errors.rs b/tvm_client/src/processing/errors.rs index 739ddc48a..ded3f017b 100644 --- a/tvm_client/src/processing/errors.rs +++ b/tvm_client/src/processing/errors.rs @@ -13,8 +13,8 @@ use serde_json::Value; use tvm_block::MsgAddressInt; -use crate::error::format_time; use crate::error::ClientError; +use crate::error::format_time; #[derive(ApiType)] pub enum ErrorCode { diff --git a/tvm_client/src/processing/fetching.rs b/tvm_client/src/processing/fetching.rs index 0fecb7ea3..cba6e0926 100644 --- a/tvm_client/src/processing/fetching.rs +++ b/tvm_client/src/processing/fetching.rs @@ -9,19 +9,19 @@ use crate::boc::internal::deserialize_object_from_base64; use crate::client::ClientContext; use crate::error::AddNetworkUrl; use crate::error::ClientResult; -use crate::net::wait_for_collection; -use crate::net::ParamsOfWaitForCollection; use crate::net::MAX_TIMEOUT; +use crate::net::ParamsOfWaitForCollection; use crate::net::TRANSACTIONS_COLLECTION; +use crate::net::wait_for_collection; +use crate::processing::Error; +use crate::processing::ParamsOfWaitForTransaction; +use crate::processing::ProcessingEvent; +use crate::processing::ResultOfProcessMessage; use crate::processing::blocks_walking::wait_next_block; use crate::processing::internal::can_retry_network_error; use crate::processing::internal::resolve_error; use crate::processing::parsing::decode_output; use crate::processing::parsing::parse_transaction_boc; -use crate::processing::Error; -use crate::processing::ParamsOfWaitForTransaction; -use crate::processing::ProcessingEvent; -use crate::processing::ResultOfProcessMessage; use crate::tvm::check_transaction::calc_transaction_fees; use crate::tvm::check_transaction::extract_error; @@ -94,17 +94,14 @@ impl TransactionBoc { context: &Arc, transaction_id: &str, ) -> ClientResult { - Ok(wait_for_collection( - context.clone(), - ParamsOfWaitForCollection { - collection: TRANSACTIONS_COLLECTION.into(), - filter: Some(json!({ - "id": { "eq": transaction_id.to_string() } - })), - result: "boc out_messages { boc }".into(), - timeout: Some(MAX_TIMEOUT), - }, - ) + Ok(wait_for_collection(context.clone(), ParamsOfWaitForCollection { + collection: TRANSACTIONS_COLLECTION.into(), + filter: Some(json!({ + "id": { "eq": transaction_id.to_string() } + })), + result: "boc out_messages { boc }".into(), + timeout: Some(MAX_TIMEOUT), + }) .await? .result) } @@ -114,18 +111,15 @@ impl TransactionBoc { message_id: &str, block_id: &str, ) -> ClientResult { - Ok(wait_for_collection( - context.clone(), - ParamsOfWaitForCollection { - collection: TRANSACTIONS_COLLECTION.into(), - filter: Some(json!({ - "in_msg": { "eq": message_id }, - "block_id": { "eq": block_id }, - })), - result: "boc out_messages { boc }".into(), - timeout: Some(MAX_TIMEOUT), - }, - ) + Ok(wait_for_collection(context.clone(), ParamsOfWaitForCollection { + collection: TRANSACTIONS_COLLECTION.into(), + filter: Some(json!({ + "in_msg": { "eq": message_id }, + "block_id": { "eq": block_id }, + })), + result: "boc out_messages { boc }".into(), + timeout: Some(MAX_TIMEOUT), + }) .await? .result) } diff --git a/tvm_client/src/processing/internal.rs b/tvm_client/src/processing/internal.rs index 98998e4b7..389400fd9 100644 --- a/tvm_client/src/processing/internal.rs +++ b/tvm_client/src/processing/internal.rs @@ -4,8 +4,8 @@ use tvm_block::MsgAddressInt; use tvm_sdk::Block; use tvm_sdk::MessageId; -use super::fetching::fetch_account; use super::ErrorCode; +use super::fetching::fetch_account; use crate::abi::Abi; use crate::abi::ParamsOfDecodeMessage; use crate::client::ClientContext; @@ -62,14 +62,11 @@ pub(crate) fn get_message_expiration_time( message: &str, ) -> ClientResult> { let header = match abi { - Some(abi) => crate::abi::decode_message( - context.clone(), - ParamsOfDecodeMessage { - abi: abi.clone(), - message: message.to_string(), - ..Default::default() - }, - ) + Some(abi) => crate::abi::decode_message(context.clone(), ParamsOfDecodeMessage { + abi: abi.clone(), + message: message.to_string(), + ..Default::default() + }) .map(|x| x.header) .unwrap_or_default(), None => None, diff --git a/tvm_client/src/processing/message_monitor.rs b/tvm_client/src/processing/message_monitor.rs index 2a3dac209..dda167e4c 100644 --- a/tvm_client/src/processing/message_monitor.rs +++ b/tvm_client/src/processing/message_monitor.rs @@ -5,8 +5,8 @@ use tvm_client_processing::MessageMonitoringResult; use tvm_client_processing::MonitorFetchWaitMode; use tvm_client_processing::MonitoringQueueInfo; -use crate::error::ClientResult; use crate::ClientContext; +use crate::error::ClientResult; #[derive(Deserialize, Default, ApiType)] pub struct ParamsOfMonitorMessages { diff --git a/tvm_client/src/processing/message_monitor_sdk_services.rs b/tvm_client/src/processing/message_monitor_sdk_services.rs index f36ca55a5..497bab601 100644 --- a/tvm_client/src/processing/message_monitor_sdk_services.rs +++ b/tvm_client/src/processing/message_monitor_sdk_services.rs @@ -1,7 +1,7 @@ use std::future::Future; +use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use async_trait::async_trait; use serde_json::Value; @@ -88,9 +88,9 @@ impl MessageMonitorSdkServices for SdkServices { &self, messages: Vec, callback: impl Fn(tvm_client_processing::Result>) -> F - + Send - + Sync - + 'static, + + Send + + Sync + + 'static, ) -> tvm_client_processing::Result { // We have to wrap callback into Arc because it will move out of closure scope let callback = Arc::new(callback); diff --git a/tvm_client/src/processing/mod.rs b/tvm_client/src/processing/mod.rs index 91d399c72..22445455f 100644 --- a/tvm_client/src/processing/mod.rs +++ b/tvm_client/src/processing/mod.rs @@ -29,6 +29,11 @@ pub(crate) mod wait_for_transaction; pub use errors::Error; pub use errors::ErrorCode; +pub use message_monitor::ParamsOfCancelMonitor; +pub use message_monitor::ParamsOfFetchNextMonitorResults; +pub use message_monitor::ParamsOfGetMonitorInfo; +pub use message_monitor::ParamsOfMonitorMessages; +pub use message_monitor::ResultOfFetchNextMonitorResults; pub use message_monitor::cancel_monitor; pub use message_monitor::cancel_monitor_api; pub use message_monitor::fetch_next_monitor_results; @@ -37,22 +42,17 @@ pub use message_monitor::get_monitor_info; pub use message_monitor::get_monitor_info_api; pub use message_monitor::monitor_messages; pub use message_monitor::monitor_messages_api; -pub use message_monitor::ParamsOfCancelMonitor; -pub use message_monitor::ParamsOfFetchNextMonitorResults; -pub use message_monitor::ParamsOfGetMonitorInfo; -pub use message_monitor::ParamsOfMonitorMessages; -pub use message_monitor::ResultOfFetchNextMonitorResults; pub(crate) use message_monitor_sdk_services::SdkServices; -pub use process_message::process_message; pub use process_message::ParamsOfProcessMessage; -pub use send_message::send_message; +pub use process_message::process_message; pub use send_message::ParamsOfSendMessage; pub use send_message::ResultOfSendMessage; -pub use send_messages::send_messages; -pub use send_messages::send_messages_api; +pub use send_message::send_message; pub use send_messages::MessageSendingParams; pub use send_messages::ParamsOfSendMessages; pub use send_messages::ResultOfSendMessages; +pub use send_messages::send_messages; +pub use send_messages::send_messages_api; pub use tvm_client_processing::MessageMonitoringParams; pub use tvm_client_processing::MessageMonitoringResult; pub use tvm_client_processing::MessageMonitoringStatus; @@ -65,5 +65,5 @@ pub use types::DecodedOutput; pub use types::ProcessingEvent; pub use types::ProcessingResponseType; pub use types::ResultOfProcessMessage; -pub use wait_for_transaction::wait_for_transaction; pub use wait_for_transaction::ParamsOfWaitForTransaction; +pub use wait_for_transaction::wait_for_transaction; diff --git a/tvm_client/src/processing/parsing.rs b/tvm_client/src/processing/parsing.rs index 43f99063e..d8eceda4a 100644 --- a/tvm_client/src/processing/parsing.rs +++ b/tvm_client/src/processing/parsing.rs @@ -2,12 +2,12 @@ use std::sync::Arc; use serde_json::Value; -use crate::abi::decode_message; use crate::abi::Abi; use crate::abi::MessageBodyType; use crate::abi::ParamsOfDecodeMessage; -use crate::boc::parse_transaction; +use crate::abi::decode_message; use crate::boc::ParamsOfParse; +use crate::boc::parse_transaction; use crate::client::ClientContext; use crate::error::ClientResult; use crate::processing::fetching::TransactionBoc; @@ -32,10 +32,11 @@ pub(crate) fn decode_output( let mut out_messages = Vec::new(); let mut output = None; for message in messages { - let decode_result = decode_message( - context.clone(), - ParamsOfDecodeMessage { message, abi: abi.clone(), ..Default::default() }, - ); + let decode_result = decode_message(context.clone(), ParamsOfDecodeMessage { + message, + abi: abi.clone(), + ..Default::default() + }); let decoded = match decode_result { Ok(decoded) => { if decoded.body_type == MessageBodyType::Output { diff --git a/tvm_client/src/processing/process_message.rs b/tvm_client/src/processing/process_message.rs index b4b00502a..22e20c330 100644 --- a/tvm_client/src/processing/process_message.rs +++ b/tvm_client/src/processing/process_message.rs @@ -4,15 +4,15 @@ use crate::abi::ParamsOfEncodeMessage; use crate::client::ClientContext; use crate::error::AddNetworkUrl; use crate::error::ClientResult; -use crate::processing::internal::can_retry_expired_message; -use crate::processing::send_message; -use crate::processing::wait_for_transaction; use crate::processing::ErrorCode; use crate::processing::ParamsOfSendMessage; use crate::processing::ParamsOfWaitForTransaction; use crate::processing::ProcessingEvent; use crate::processing::ResultOfProcessMessage; use crate::processing::ResultOfSendMessage; +use crate::processing::internal::can_retry_expired_message; +use crate::processing::send_message; +use crate::processing::wait_for_transaction; use crate::tvm::StdContractError; #[derive(Serialize, Deserialize, ApiType, Default, Debug)] diff --git a/tvm_client/src/processing/send_message.rs b/tvm_client/src/processing/send_message.rs index 98696a03f..34d5bbac2 100644 --- a/tvm_client/src/processing/send_message.rs +++ b/tvm_client/src/processing/send_message.rs @@ -17,17 +17,17 @@ use tvm_block::MsgAddressInt; use super::blocks_walking::find_last_shard_block; use crate::abi::Abi; -use crate::boc::internal::deserialize_object_from_boc; use crate::boc::internal::DeserializedObject; +use crate::boc::internal::deserialize_object_from_boc; use crate::client::ClientContext; use crate::encoding::base64_decode; use crate::encoding::hex_decode; use crate::error::AddNetworkUrl; use crate::error::ClientResult; use crate::net::EndpointStat; +use crate::processing::Error; use crate::processing::internal::get_message_expiration_time; use crate::processing::types::ProcessingEvent; -use crate::processing::Error; #[derive(Serialize, Deserialize, ApiType, Default, Debug, Clone)] pub struct ParamsOfSendMessage { diff --git a/tvm_client/src/processing/tests.rs b/tvm_client/src/processing/tests.rs index 41ab1e36a..ede8c39e1 100644 --- a/tvm_client/src/processing/tests.rs +++ b/tvm_client/src/processing/tests.rs @@ -16,17 +16,17 @@ use crate::boc::tvc::resolve_state_init_cell; use crate::json_interface::modules::ProcessingModule; use crate::net::ParamsOfQuery; use crate::net::ResultOfQuery; -use crate::processing::types::DecodedOutput; use crate::processing::ErrorCode; use crate::processing::ParamsOfProcessMessage; use crate::processing::ParamsOfSendMessage; use crate::processing::ParamsOfWaitForTransaction; use crate::processing::ProcessingEvent; use crate::processing::ProcessingResponseType; -use crate::tests::TestClient; +use crate::processing::types::DecodedOutput; use crate::tests::EVENTS_OLD; use crate::tests::GIVER_V2; use crate::tests::HELLO; +use crate::tests::TestClient; use crate::tvm::AccountForExecutor; use crate::tvm::ErrorCode as TvmErrorCode; use crate::tvm::ParamsOfRunExecutor; @@ -92,10 +92,10 @@ fn assert_events(events: &[ProcessingEvent], remp_enabled: bool) { async fn remp_enabled(client: &TestClient) -> bool { let info: ResultOfQuery = client - .request_async( - "net.query", - ParamsOfQuery { query: "query{info{rempEnabled}}".to_owned(), variables: None }, - ) + .request_async("net.query", ParamsOfQuery { + query: "query{info{rempEnabled}}".to_owned(), + variables: None, + }) .await .unwrap_or_default(); @@ -559,14 +559,11 @@ async fn test_fees() { let message = client.encode_message(params.clone()).await.unwrap(); let local_result: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - account: AccountForExecutor::Account { boc: account, unlimited_balance: None }, - message: message.message, - ..Default::default() - }, - ) + .request_async("tvm.run_executor", ParamsOfRunExecutor { + account: AccountForExecutor::Account { boc: account, unlimited_balance: None }, + message: message.message, + ..Default::default() + }) .await .unwrap(); diff --git a/tvm_client/src/processing/wait_for_transaction.rs b/tvm_client/src/processing/wait_for_transaction.rs index 6e0d2ef87..9e43d7cd7 100644 --- a/tvm_client/src/processing/wait_for_transaction.rs +++ b/tvm_client/src/processing/wait_for_transaction.rs @@ -15,13 +15,13 @@ use crate::error::AddNetworkUrl; use crate::error::ClientResult; use crate::net::EndpointStat; use crate::net::ResultOfSubscription; +use crate::processing::Error; +use crate::processing::ProcessingEvent; +use crate::processing::ResultOfProcessMessage; use crate::processing::fetching; use crate::processing::internal; use crate::processing::internal::get_message_expiration_time; use crate::processing::internal::resolve_error; -use crate::processing::Error; -use crate::processing::ProcessingEvent; -use crate::processing::ResultOfProcessMessage; //--------------------------------------------------------------------------- wait_for_transaction diff --git a/tvm_client/src/proofs/engine.rs b/tvm_client/src/proofs/engine.rs index c47f3f44c..c8d2ccdd6 100644 --- a/tvm_client/src/proofs/engine.rs +++ b/tvm_client/src/proofs/engine.rs @@ -13,21 +13,21 @@ use tvm_block::ShardStateUnsplit; use tvm_types::Result; use tvm_types::UInt256; +use crate::ClientContext; use crate::boc::internal::get_boc_hash; use crate::client::storage::InMemoryKeyValueStorage; use crate::client::storage::KeyValueStorage; use crate::encoding::base64_decode; use crate::error::ClientResult; -use crate::net::query_collection; use crate::net::OrderBy; use crate::net::ParamsOfQueryCollection; use crate::net::SortDirection; -use crate::proofs::resolve_initial_trusted_key_block; +use crate::net::query_collection; use crate::proofs::BlockProof; use crate::proofs::Error; use crate::proofs::ProofHelperEngine; +use crate::proofs::resolve_initial_trusted_key_block; use crate::utils::json::JsonHelper; -use crate::ClientContext; const ZEROSTATE_KEY: &str = "zerostate"; const ZEROSTATE_RIGHT_BOUND_KEY: &str = "zs_right_boundary_seq_no"; @@ -255,15 +255,12 @@ impl ProofHelperEngineImpl { } pub(crate) async fn query_zerostate_boc(&self) -> Result> { - let zerostates = query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "zerostates".to_string(), - result: "boc".to_string(), - limit: Some(1), - ..Default::default() - }, - ) + let zerostates = query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "zerostates".to_string(), + result: "boc".to_string(), + limit: Some(1), + ..Default::default() + }) .await? .result; @@ -282,16 +279,13 @@ impl ProofHelperEngineImpl { ) -> Result> { mc_seq_no += 1; let blocks = Self::preprocess_query_result( - query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "seq_no gen_utime prev_ref{file_hash}".to_string(), - filter: Some(Self::filter_for_mc_block(mc_seq_no)), - order: Some(Self::sorting_by_seq_no()), - ..Default::default() - }, - ) + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "seq_no gen_utime prev_ref{file_hash}".to_string(), + filter: Some(Self::filter_for_mc_block(mc_seq_no)), + order: Some(Self::sorting_by_seq_no()), + ..Default::default() + }) .await? .result, )?; @@ -307,16 +301,13 @@ impl ProofHelperEngineImpl { if let Some(boc) = self.read_block(root_hash).await? { Ok(boc) } else { - let blocks = query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "seq_no gen_utime boc".to_string(), - filter: Some(Self::filter_for_block(root_hash)), - limit: Some(1), - ..Default::default() - }, - ) + let blocks = query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "seq_no gen_utime boc".to_string(), + filter: Some(Self::filter_for_block(root_hash)), + limit: Some(1), + ..Default::default() + }) .await? .result; @@ -357,16 +348,13 @@ impl ProofHelperEngineImpl { pub(crate) async fn query_mc_block_proof(&self, mc_seq_no: u32) -> Result { let mut blocks = Self::preprocess_query_result( - query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: PROOF_QUERY_RESULT.to_string(), - filter: Some(Self::filter_for_mc_block(mc_seq_no)), - order: Some(Self::sorting_by_seq_no()), - ..Default::default() - }, - ) + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: PROOF_QUERY_RESULT.to_string(), + filter: Some(Self::filter_for_mc_block(mc_seq_no)), + order: Some(Self::sorting_by_seq_no()), + ..Default::default() + }) .await? .result, )?; @@ -436,27 +424,24 @@ impl ProofHelperEngineImpl { return Ok(result); } - let key_blocks = query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: PROOF_QUERY_RESULT.to_string(), - filter: Some(json!({ - "workchain_id": { - "eq": -1, - }, - "key_block": { - "eq": true, - }, - "seq_no": { - "ge": mc_seq_no_range.start, - "lt": mc_seq_no_range.end, - } - })), - order: Some(Self::sorting_by_seq_no()), - ..Default::default() - }, - ) + let key_blocks = query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: PROOF_QUERY_RESULT.to_string(), + filter: Some(json!({ + "workchain_id": { + "eq": -1, + }, + "key_block": { + "eq": true, + }, + "seq_no": { + "ge": mc_seq_no_range.start, + "lt": mc_seq_no_range.end, + } + })), + order: Some(Self::sorting_by_seq_no()), + ..Default::default() + }) .await? .result; @@ -475,25 +460,22 @@ impl ProofHelperEngineImpl { ) -> Result<()> { while !proofs_sorted.is_empty() { let mut blocks = Self::preprocess_query_result( - query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "seq_no gen_utime prev_ref{file_hash}".to_string(), - filter: Some(json!({ - "workchain_id": { - "eq": -1, - }, - "seq_no": { - "in": proofs_sorted.iter() - .map(|(seq_no, _value)| *seq_no + 1) - .collect::>(), - } - })), - order: Some(Self::sorting_by_seq_no()), - ..Default::default() - }, - ) + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "seq_no gen_utime prev_ref{file_hash}".to_string(), + filter: Some(json!({ + "workchain_id": { + "eq": -1, + }, + "seq_no": { + "in": proofs_sorted.iter() + .map(|(seq_no, _value)| *seq_no + 1) + .collect::>(), + } + })), + order: Some(Self::sorting_by_seq_no()), + ..Default::default() + }) .await? .result, )?; @@ -625,11 +607,9 @@ impl ProofHelperEngineImpl { ) -> Result> { loop { let blocks = Self::preprocess_query_result( - query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "\ + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "\ seq_no \ gen_utime \ master { \ @@ -642,16 +622,15 @@ impl ProofHelperEngineImpl { }\ }\ }" - .to_string(), - filter: Some(json!({ - "workchain_id": { "eq": -1 }, - "seq_no": { "ge": *first_mc_seq_no }, - })), - order: Some(Self::sorting_by_seq_no()), - limit: Some(10), - ..Default::default() - }, - ) + .to_string(), + filter: Some(json!({ + "workchain_id": { "eq": -1 }, + "seq_no": { "ge": *first_mc_seq_no }, + })), + order: Some(Self::sorting_by_seq_no()), + limit: Some(10), + ..Default::default() + }) .await? .result, )?; @@ -682,26 +661,23 @@ impl ProofHelperEngineImpl { seq_no_range: Range, ) -> Result>> { let blocks = Self::preprocess_query_result( - query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "blocks".to_string(), - result: "\ + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "blocks".to_string(), + result: "\ seq_no \ gen_utime \ id \ boc \ " - .to_string(), - filter: Some(json!({ - "workchain_id": { "eq": shard.workchain_id() }, - "shard": { "eq": shard.shard_prefix_as_str_with_tag() }, - "seq_no": { "in": seq_no_range.clone().collect::>() }, - })), - order: Some(Self::sorting_by_seq_no()), - ..Default::default() - }, - ) + .to_string(), + filter: Some(json!({ + "workchain_id": { "eq": shard.workchain_id() }, + "shard": { "eq": shard.shard_prefix_as_str_with_tag() }, + "seq_no": { "in": seq_no_range.clone().collect::>() }, + })), + order: Some(Self::sorting_by_seq_no()), + ..Default::default() + }) .await? .result, )?; @@ -867,9 +843,8 @@ impl ProofHelperEngineImpl { } pub(crate) async fn query_transaction_data(&self, id: &str, fields: &str) -> Result { - let mut transactions = query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { + let mut transactions = + query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { collection: "transactions".to_string(), result: fields.to_string(), filter: Some(json!({ @@ -879,10 +854,9 @@ impl ProofHelperEngineImpl { })), limit: Some(1), ..Default::default() - }, - ) - .await? - .result; + }) + .await? + .result; if transactions.is_empty() { tvm_types::fail!("Unable to download transaction data from DApp server"); @@ -892,20 +866,17 @@ impl ProofHelperEngineImpl { } pub(crate) async fn query_message_data(&self, id: &str, fields: &str) -> Result { - let mut messages = query_collection( - Arc::clone(&self.context), - ParamsOfQueryCollection { - collection: "messages".to_string(), - result: fields.to_string(), - filter: Some(json!({ - "id": { - "eq": id, - }, - })), - limit: Some(1), - ..Default::default() - }, - ) + let mut messages = query_collection(Arc::clone(&self.context), ParamsOfQueryCollection { + collection: "messages".to_string(), + result: fields.to_string(), + filter: Some(json!({ + "id": { + "eq": id, + }, + })), + limit: Some(1), + ..Default::default() + }) .await? .result; diff --git a/tvm_client/src/proofs/mod.rs b/tvm_client/src/proofs/mod.rs index 80d514307..747be893e 100644 --- a/tvm_client/src/proofs/mod.rs +++ b/tvm_client/src/proofs/mod.rs @@ -25,6 +25,7 @@ use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use crate::ClientContext; use crate::boc::internal::deserialize_object_from_base64; use crate::boc::internal::deserialize_object_from_boc_bin; use crate::encoding::base64_decode; @@ -34,7 +35,6 @@ use crate::proofs::errors::Error; use crate::proofs::validators::calc_subset_for_workchain; use crate::proofs::validators::check_crypto_signatures; use crate::utils::json::JsonHelper; -use crate::ClientContext; mod engine; pub mod errors; diff --git a/tvm_client/src/proofs/tests/mod.rs b/tvm_client/src/proofs/tests/mod.rs index df72807be..3c17a7d0b 100644 --- a/tvm_client/src/proofs/tests/mod.rs +++ b/tvm_client/src/proofs/tests/mod.rs @@ -12,17 +12,23 @@ use tvm_block::Block; use tvm_block::BlockIdExt; use tvm_block::Deserializable; use tvm_block::InRefValue; +use tvm_block::MASTERCHAIN_ID; use tvm_block::ShardHashes; use tvm_block::ShardIdent; use tvm_block::ShardStateUnsplit; -use tvm_block::MASTERCHAIN_ID; -use tvm_types::base64_decode; use tvm_types::Result; use tvm_types::UInt256; +use tvm_types::base64_decode; +use crate::ClientContext; use crate::client::storage::InMemoryKeyValueStorage; -use crate::net::query_collection; use crate::net::ParamsOfQueryCollection; +use crate::net::query_collection; +use crate::proofs::BlockProof; +use crate::proofs::INITIAL_TRUSTED_KEY_BLOCKS; +use crate::proofs::ParamsOfProofBlockData; +use crate::proofs::ParamsOfProofMessageData; +use crate::proofs::ParamsOfProofTransactionData; use crate::proofs::engine::ProofHelperEngineImpl; use crate::proofs::is_transaction_refers_to_message; use crate::proofs::message_get_required_data; @@ -33,13 +39,7 @@ use crate::proofs::transaction_get_required_data; use crate::proofs::validators::calc_subset_for_workchain; use crate::proofs::validators::calc_workchain_id; use crate::proofs::validators::calc_workchain_id_by_adnl_id; -use crate::proofs::BlockProof; -use crate::proofs::ParamsOfProofBlockData; -use crate::proofs::ParamsOfProofMessageData; -use crate::proofs::ParamsOfProofTransactionData; -use crate::proofs::INITIAL_TRUSTED_KEY_BLOCKS; use crate::tests::TestClient; -use crate::ClientContext; const GQL_SCHEMA: &str = include_str!("data/schema.graphql"); @@ -471,17 +471,21 @@ async fn test_extract_top_shard_block() -> Result<()> { .await?; let block = Block::construct_from_bytes(&boc)?; - assert!(ProofHelperEngineImpl::extract_top_shard_block( - &block, - &ShardIdent::with_tagged_prefix(0, 0x8000000000000000)?, - ) - .is_err()); + assert!( + ProofHelperEngineImpl::extract_top_shard_block( + &block, + &ShardIdent::with_tagged_prefix(0, 0x8000000000000000)?, + ) + .is_err() + ); - assert!(ProofHelperEngineImpl::extract_top_shard_block( - &block, - &ShardIdent::with_tagged_prefix(1, 0x2000000000000000)?, - ) - .is_err()); + assert!( + ProofHelperEngineImpl::extract_top_shard_block( + &block, + &ShardIdent::with_tagged_prefix(1, 0x2000000000000000)?, + ) + .is_err() + ); assert_eq!( ProofHelperEngineImpl::extract_top_shard_block( @@ -536,8 +540,7 @@ async fn test_query_closest_mc_block_for_shard_block() -> Result<()> { Ok(()) } -const SHARD_BLOCK_0_A000000000000000_99_BOC: &str = - "te6ccuECEQEAArkAABwAxADeAXACBAKgAzwDRgNYA6QECgQiBCoE9AVkBWwFcwQQEe9VqgAAACoBAgMEAqCbx6\ +const SHARD_BLOCK_0_A000000000000000_99_BOC: &str = "te6ccuECEQEAArkAABwAxADeAXACBAKgAzwDRgNYA6QECgQiBCoE9AVkBWwFcwQQEe9VqgAAACoBAgMEAqCbx6\ mHAAAAAIQBAAAAYwAAAAACAAAAAIAAAAAAAAAAXrQHmgAAAAAG6gUAAAAAAAbqBQGyfCu9AAAAAgAAAFMAAAAAx\ AAAAAMAAAAAAAAALgUGAhG45I37QO5rKAQHCAqKBGFR1tD1H1YJuvT+AeffTPjAYu+ZO8nWZmHsiOcBjgwT+aoe\ 0gsBG0P0h0luP4GaSgcCgYy5IjwTqZXSIYYyFU8AAgACCQoDiUoz9v0VXplWHvmULzKidbstN+VVAHO6e3HYwO8\ @@ -550,8 +553,7 @@ const SHARD_BLOCK_0_A000000000000000_99_BOC: &str = kyULAB6NgIjmhTkRuAtJVIIbgsceAUzOrk7wzgAa7BQAAAAAAAAAAAAACmAAAAAA1Z+Af//////////////////\ ////////////////////////wAADACAAAQL5eHt0"; -const SHARD_BLOCK_0_A000000000000000_101_BOC: &str = - "te6ccuECEQEAArkAABwAxADeAXACBAKgAzwDRgNYA6QECgQiBCoE9AVkBWwFcwQQEe9VqgAAACoBAgMEAqCbx6\ +const SHARD_BLOCK_0_A000000000000000_101_BOC: &str = "te6ccuECEQEAArkAABwAxADeAXACBAKgAzwDRgNYA6QECgQiBCoE9AVkBWwFcwQQEe9VqgAAACoBAgMEAqCbx6\ mHAAAAAIQBAAAAZQAAAAACAAAAAIAAAAAAAAAAXrQHngAAAAAHCImAAAAAAAcIiYGyfCu9AAAAAgAAAFUAAAAAx\ AAAAAMAAAAAAAAALgUGAhG45I37QO5rKAQHCAqKBO5sAcF2Ymt7CdQz/5dUOh0WyFdnKDN0tgG6P6udwTloEhUx\ yRwpTzXcIqlKUPMO1c8qSnjjb5j9+2wRS/PnHCoAAgACCQoDiUoz9v17zLkiB8uYo0dn+vy/FUZwk6AL+dQyhFY\ @@ -614,22 +616,30 @@ async fn test_check_mc_proof() -> Result<()> { ) .await?; - assert!(engine - .check_mc_block_proof( - 101, - &UInt256::from_str("01872c85facaa85405518a759dfac2625bc94b9e85b965cf3875d2331db9ad95")?, - ) - .await - .is_err(),); + assert!( + engine + .check_mc_block_proof( + 101, + &UInt256::from_str( + "01872c85facaa85405518a759dfac2625bc94b9e85b965cf3875d2331db9ad95" + )?, + ) + .await + .is_err(), + ); // From cache: - assert!(engine - .check_mc_block_proof( - 100, - &UInt256::from_str("1111111111111111111111111111111111111111111111111111111111111111")?, - ) - .await - .is_err(),); + assert!( + engine + .check_mc_block_proof( + 100, + &UInt256::from_str( + "1111111111111111111111111111111111111111111111111111111111111111" + )?, + ) + .await + .is_err(), + ); Ok(()) } @@ -640,20 +650,17 @@ async fn query_data( id: &str, result: &str, ) -> Result { - Ok(query_collection( - context, - ParamsOfQueryCollection { - collection: collection.to_string(), - result: result.to_string(), - filter: Some(json!({ - "id": { - "eq": id, - }, - })), - limit: Some(1), - ..Default::default() - }, - ) + Ok(query_collection(context, ParamsOfQueryCollection { + collection: collection.to_string(), + result: result.to_string(), + filter: Some(json!({ + "id": { + "eq": id, + }, + })), + limit: Some(1), + ..Default::default() + }) .await? .result .remove(0)) @@ -752,42 +759,42 @@ async fn test_proof_block_data() -> Result<()> { .await?; client - .request_async( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json.clone() }, - ) + .request_async("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json.clone(), + }) .await?; block_json["boc"] = Value::Null; client - .request_async( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json.clone() }, - ) + .request_async("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json.clone(), + }) .await?; block_json["boc"] = SHARD_BLOCK_0_A000000000000000_99_BOC.into(); - assert!(client - .request_async::<_, ()>( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json.clone() }, - ) - .await - .is_err()); + assert!( + client + .request_async::<_, ()>("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json.clone() + },) + .await + .is_err() + ); block_json["boc"] = Value::Null; block_json["prev_ref"]["root_hash"] = "0000000000000000000000000000000000000000000000000000000000000000".into(); - assert!(client - .request_async::<_, ()>( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json }, - ) - .await - .is_err()); + assert!( + client + .request_async::<_, ()>("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json + },) + .await + .is_err() + ); let proof_json = query_block_data( client.context(), @@ -815,13 +822,14 @@ async fn test_proof_block_data() -> Result<()> { ) .await?; - assert!(client - .request_async::<_, ()>( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: proof_json }, - ) - .await - .is_err()); + assert!( + client + .request_async::<_, ()>("proofs.proof_block_data", ParamsOfProofBlockData { + block: proof_json + },) + .await + .is_err() + ); let decimal_fields = r#" id @@ -955,10 +963,9 @@ async fn test_proof_block_data() -> Result<()> { .await?; client - .request_async( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json.clone() }, - ) + .request_async("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json.clone(), + }) .await?; // Shardchain block @@ -970,10 +977,9 @@ async fn test_proof_block_data() -> Result<()> { .await?; client - .request_async( - "proofs.proof_block_data", - ParamsOfProofBlockData { block: block_json.clone() }, - ) + .request_async("proofs.proof_block_data", ParamsOfProofBlockData { + block: block_json.clone(), + }) .await?; Ok(()) @@ -1035,10 +1041,9 @@ async fn test_proof_transaction_data() -> Result<()> { ) .await?; - proof_transaction_data( - client.context(), - ParamsOfProofTransactionData { transaction: transaction_json }, - ) + proof_transaction_data(client.context(), ParamsOfProofTransactionData { + transaction: transaction_json, + }) .await?; let transaction_json = query_transaction_data( @@ -1062,10 +1067,9 @@ async fn test_proof_transaction_data() -> Result<()> { "#, ).await?; - proof_transaction_data( - client.context(), - ParamsOfProofTransactionData { transaction: transaction_json }, - ) + proof_transaction_data(client.context(), ParamsOfProofTransactionData { + transaction: transaction_json, + }) .await?; Ok(()) diff --git a/tvm_client/src/proofs/validators.rs b/tvm_client/src/proofs/validators.rs index 5d53967bb..3174ab55f 100644 --- a/tvm_client/src/proofs/validators.rs +++ b/tvm_client/src/proofs/validators.rs @@ -10,8 +10,8 @@ use tvm_block::ValidatorDescr; use tvm_block::ValidatorSet; use tvm_block::WorkchainDescr; use tvm_block::Workchains; -use tvm_types::base64_encode; use tvm_types::Result; +use tvm_types::base64_encode; use crate::proofs::Signatures; diff --git a/tvm_client/src/tests/common.rs b/tvm_client/src/tests/common.rs index 77cac62ce..e2a795f85 100644 --- a/tvm_client/src/tests/common.rs +++ b/tvm_client/src/tests/common.rs @@ -31,16 +31,13 @@ fn test_parallel_requests() { let query = |client: &TestClient| { let _: ResultOfQueryCollection = client - .request( - "net.query_collection", - ParamsOfQueryCollection { - collection: "accounts".to_owned(), - filter: Some(json!({})), - result: "id".to_owned(), - limit: Some(1), - order: None, - }, - ) + .request("net.query_collection", ParamsOfQueryCollection { + collection: "accounts".to_owned(), + filter: Some(json!({})), + result: "id".to_owned(), + limit: Some(1), + order: None, + }) .unwrap(); }; diff --git a/tvm_client/src/tests/mod.rs b/tvm_client/src/tests/mod.rs index 14905755b..e80cd9753 100644 --- a/tvm_client/src/tests/mod.rs +++ b/tvm_client/src/tests/mod.rs @@ -16,32 +16,33 @@ use std::sync::Arc; use api_info::ApiModule; use futures::Future; use num_traits::FromPrimitive; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use serde_json::Value; -use tokio::sync::oneshot::channel; -use tokio::sync::oneshot::Sender; use tokio::sync::Mutex; +use tokio::sync::oneshot::Sender; +use tokio::sync::oneshot::channel; use tvm_types::base64_encode; use super::tc_destroy_string; use super::tc_read_string; use super::tc_request; use super::tc_request_sync; -use crate::abi::encode_message; +use crate::ContextHandle; use crate::abi::Abi; use crate::abi::CallSet; use crate::abi::DeploySet; use crate::abi::ParamsOfEncodeMessage; use crate::abi::ResultOfEncodeMessage; use crate::abi::Signer; +use crate::abi::encode_message; use crate::client::*; -use crate::crypto::internal::hex_decode_secret_const; -use crate::crypto::mnemonic::ed25519_keys_from_secret_bytes; use crate::crypto::KeyPair; use crate::crypto::ParamsOfNaclSignDetached; use crate::crypto::ParamsOfNaclSignKeyPairFromSecret; use crate::crypto::ResultOfNaclSignDetached; +use crate::crypto::internal::hex_decode_secret_const; +use crate::crypto::mnemonic::ed25519_keys_from_secret_bytes; use crate::error::ClientError; use crate::error::ClientResult; use crate::json_interface::interop::ResponseType; @@ -57,7 +58,6 @@ use crate::processing::ParamsOfProcessMessage; use crate::processing::ResultOfProcessMessage; use crate::tc_create_context; use crate::tc_destroy_context; -use crate::ContextHandle; mod common; @@ -371,11 +371,7 @@ impl TestClient { pub fn queries_protocol() -> Option { let protocol = env::queries_protocol().trim().to_string(); - if protocol.is_empty() { - None - } else { - Some(protocol) - } + if protocol.is_empty() { None } else { Some(protocol) } } pub fn node_se() -> bool { @@ -548,15 +544,12 @@ impl TestClient { let mut runtime = TEST_RUNTIME.lock().await; let id = runtime.gen_request_id(); let (sender, receiver) = channel(); - runtime.requests.insert( - id, - RequestData { - sender: Some(sender), - callback: Box::new(callback), /* as Box Pin + Send + Sync>> + Send + - * Sync> */ - }, - ); + runtime.requests.insert(id, RequestData { + sender: Some(sender), + callback: Box::new(callback), /* as Box Pin + Send + Sync>> + Send + + * Sync> */ + }); (id, receiver) }; unsafe { @@ -702,10 +695,8 @@ impl TestClient { value: Option, ) -> ResultOfProcessMessage { let giver_exists: ResultOfQuery = self - .request_async( - "net.query", - ParamsOfQuery { - query: r#"query($addr: String!) { + .request_async("net.query", ParamsOfQuery { + query: r#"query($addr: String!) { blockchain { account(address: $addr) { info { @@ -714,10 +705,9 @@ impl TestClient { } } }"# - .to_string(), - variables: Some(json!({"addr": self.giver_address().await})), - }, - ) + .to_string(), + variables: Some(json!({"addr": self.giver_address().await})), + }) .await .unwrap_or_default(); @@ -764,13 +754,10 @@ impl TestClient { // wait for tokens reception let _: ResultOfQueryTransactionTree = self - .request_async( - "net.query_transaction_tree", - ParamsOfQueryTransactionTree { - in_msg: run_result.transaction["in_msg"].as_str().unwrap().to_string(), - ..Default::default() - }, - ) + .request_async("net.query_transaction_tree", ParamsOfQueryTransactionTree { + in_msg: run_result.transaction["in_msg"].as_str().unwrap().to_string(), + ..Default::default() + }) .await .unwrap(); @@ -818,25 +805,19 @@ impl TestClient { ) .unwrap(); let result: ResultOfNaclSignDetached = self - .request( - "crypto.nacl_sign_detached", - ParamsOfNaclSignDetached { - unsigned: data.into(), - secret: sign_keys.secret.clone(), - }, - ) + .request("crypto.nacl_sign_detached", ParamsOfNaclSignDetached { + unsigned: data.into(), + secret: sign_keys.secret.clone(), + }) .unwrap(); result.signature } pub async fn resolve_app_request(&self, app_request_id: u32, result: impl Serialize) { - self.request_async::<_, ()>( - "client.resolve_app_request", - ParamsOfResolveAppRequest { - app_request_id, - result: AppRequestResult::Ok { result: json!(result) }, - }, - ) + self.request_async::<_, ()>("client.resolve_app_request", ParamsOfResolveAppRequest { + app_request_id, + result: AppRequestResult::Ok { result: json!(result) }, + }) .await .unwrap(); } diff --git a/tvm_client/src/tvm/call_tvm.rs b/tvm_client/src/tvm/call_tvm.rs index 780b6484d..8a4e0c881 100644 --- a/tvm_client/src/tvm/call_tvm.rs +++ b/tvm_client/src/tvm/call_tvm.rs @@ -24,12 +24,12 @@ use tvm_types::Cell; use tvm_types::HashmapType; use tvm_types::SliceData; use tvm_types::UInt256; -use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::executor::Engine; -use tvm_vm::stack::integer::IntegerData; -use tvm_vm::stack::savelist::SaveList; +use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; +use tvm_vm::stack::integer::IntegerData; +use tvm_vm::stack::savelist::SaveList; use super::types::ResolvedExecutionOptions; use crate::encoding::slice_from_cell; diff --git a/tvm_client/src/tvm/errors.rs b/tvm_client/src/tvm/errors.rs index 45101b5d7..52432c512 100644 --- a/tvm_client/src/tvm/errors.rs +++ b/tvm_client/src/tvm/errors.rs @@ -461,10 +461,6 @@ impl StdContractError { StdContractError::NoKeyInData => "Contract is probably deployed incorrectly", _ => "", }; - if !tip.is_empty() { - Some(tip) - } else { - None - } + if !tip.is_empty() { Some(tip) } else { None } } } diff --git a/tvm_client/src/tvm/mod.rs b/tvm_client/src/tvm/mod.rs index a69fcd4c2..f322d596f 100644 --- a/tvm_client/src/tvm/mod.rs +++ b/tvm_client/src/tvm/mod.rs @@ -24,16 +24,16 @@ mod tests; pub use errors::Error; pub use errors::ErrorCode; pub use errors::StdContractError; -pub use run_get::run_get; pub use run_get::ParamsOfRunGet; pub use run_get::ResultOfRunGet; -pub use run_message::run_executor; -pub(crate) use run_message::run_executor_internal; -pub use run_message::run_tvm; +pub use run_get::run_get; pub use run_message::AccountForExecutor; pub use run_message::ParamsOfRunExecutor; pub use run_message::ParamsOfRunTvm; pub use run_message::ResultOfRunExecutor; pub use run_message::ResultOfRunTvm; +pub use run_message::run_executor; +pub(crate) use run_message::run_executor_internal; +pub use run_message::run_tvm; pub use tvm_sdk::TransactionFees; pub use types::ExecutionOptions; diff --git a/tvm_client/src/tvm/run_get.rs b/tvm_client/src/tvm/run_get.rs index 7db67b2f8..6816b0982 100644 --- a/tvm_client/src/tvm/run_get.rs +++ b/tvm_client/src/tvm/run_get.rs @@ -12,9 +12,9 @@ use std::sync::Arc; use serde_json::Value; -use tvm_vm::stack::integer::IntegerData; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; +use tvm_vm::stack::integer::IntegerData; use super::stack; use super::types::ExecutionOptions; diff --git a/tvm_client/src/tvm/run_message.rs b/tvm_client/src/tvm/run_message.rs index 8a546b2db..f702de1de 100644 --- a/tvm_client/src/tvm/run_message.rs +++ b/tvm_client/src/tvm/run_message.rs @@ -10,8 +10,8 @@ // limitations under the License. // -use std::sync::atomic::AtomicU64; use std::sync::Arc; +use std::sync::atomic::AtomicU64; use serde_json::Value; use tvm_block::Account; @@ -32,6 +32,7 @@ use super::stack::serialize_item; use super::types::ExecutionOptions; use super::types::ResolvedExecutionOptions; use crate::abi::Abi; +use crate::boc::BocCacheType; use crate::boc::internal::deserialize_cell_from_boc; use crate::boc::internal::deserialize_object_from_boc; use crate::boc::internal::deserialize_object_from_cell; @@ -39,13 +40,12 @@ use crate::boc::internal::serialize_cell_to_boc; use crate::boc::internal::serialize_object_to_base64; use crate::boc::internal::serialize_object_to_boc; use crate::boc::internal::serialize_object_to_cell; -use crate::boc::BocCacheType; use crate::client::ClientContext; use crate::error::ClientResult; -use crate::processing::parsing::decode_output; use crate::processing::DecodedOutput; -use crate::tvm::check_transaction::calc_transaction_fees; +use crate::processing::parsing::decode_output; use crate::tvm::Error; +use crate::tvm::check_transaction::calc_transaction_fees; #[derive(Serialize, Deserialize, ApiType, Debug, Clone)] #[serde(tag = "type")] @@ -207,10 +207,9 @@ fn parse_transaction( context: &Arc, transaction: &Transaction, ) -> ClientResult { - Ok(crate::boc::parse_transaction( - context.clone(), - crate::boc::ParamsOfParse { boc: serialize_object_to_base64(transaction, "transaction")? }, - )? + Ok(crate::boc::parse_transaction(context.clone(), crate::boc::ParamsOfParse { + boc: serialize_object_to_base64(transaction, "transaction")?, + })? .parsed) } diff --git a/tvm_client/src/tvm/stack.rs b/tvm_client/src/tvm/stack.rs index 2d67d3b02..4a0ed2ca3 100644 --- a/tvm_client/src/tvm/stack.rs +++ b/tvm_client/src/tvm/stack.rs @@ -15,9 +15,9 @@ use std::slice::Iter; use serde_json::Value; use tvm_types::BuilderData; +use tvm_vm::stack::StackItem; use tvm_vm::stack::continuation::ContinuationData; use tvm_vm::stack::integer::IntegerData; -use tvm_vm::stack::StackItem; use crate::boc::internal::deserialize_cell_from_base64; use crate::boc::internal::serialize_cell_to_base64; diff --git a/tvm_client/src/tvm/tests.rs b/tvm_client/src/tvm/tests.rs index dcc9fe241..bf0420513 100644 --- a/tvm_client/src/tvm/tests.rs +++ b/tvm_client/src/tvm/tests.rs @@ -18,16 +18,15 @@ use tvm_block::ConfigParam8; use tvm_block::ConfigParamEnum; use tvm_block::GlobalCapabilities; use tvm_block::Serializable; -use tvm_types::base64_encode; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::SliceData; -use tvm_vm::stack::continuation::ContinuationData; +use tvm_types::base64_encode; use tvm_vm::stack::StackItem; +use tvm_vm::stack::continuation::ContinuationData; use super::types::resolve_network_params; use super::*; -use crate::abi::encode_account::ParamsOfEncodeAccount; use crate::abi::Abi; use crate::abi::CallSet; use crate::abi::DeploySet; @@ -35,24 +34,25 @@ use crate::abi::FunctionHeader; use crate::abi::ParamsOfEncodeMessage; use crate::abi::ResultOfEncodeMessage; use crate::abi::Signer; -use crate::boc::internal::deserialize_object_from_base64; -use crate::boc::internal::serialize_cell_to_base64; +use crate::abi::encode_account::ParamsOfEncodeAccount; use crate::boc::BocCacheType; use crate::boc::ParamsOfEncodeStateInit; +use crate::boc::internal::deserialize_object_from_base64; +use crate::boc::internal::serialize_cell_to_base64; use crate::error::ClientResult; use crate::json_interface::modules::AbiModule; use crate::json_interface::modules::BocModule; use crate::json_interface::modules::TvmModule; -use crate::net::network_params::offline_config; use crate::net::ParamsOfQueryCollection; use crate::net::ResultOfQueryCollection; +use crate::net::network_params::offline_config; use crate::processing::ParamsOfProcessMessage; use crate::processing::ResultOfProcessMessage; -use crate::tests::TestClient; use crate::tests::EXCEPTION; use crate::tests::GIVER_V2; use crate::tests::HELLO; use crate::tests::SUBSCRIBE; +use crate::tests::TestClient; const ELECTOR_ADDRESS: &str = "-1:3333333333333333333333333333333333333333333333333333333333333333"; const ELECTOR_CODE: &str = "te6ccgECXgEAD04AART/APSkE/S88sgLAQIBIAMCAFGl//8YdqJoegJ6AhE3Sqz4FXkgTio4EPgS+SAs+BR5IHF4E3kgeBSYQAIBSBcEEgGvDuDKmc/+c4wU4tUC3b34gbdFp4dI3KGnJ9xALfcqyQAGIAoFAgEgCQYCAVgIBwAzs+A7UTQ9AQx9AQwgwf0Dm+hk/oAMJIwcOKABbbCle1E0PQFIG6SMG3g2zwQJl8GbYT/jhsigwf0fm+lIJ0C+gAwUhBvAlADbwICkTLiAbPmMDGBUAUm5h12zwQNV8Fgx9tjhRREoAg9H5vpTIhlVIDbwIC3gGzEuZsIYXQIBIBALAgJyDQwBQqss7UTQ9AUgbpJbcODbPBAmXwaDB/QOb6GT+gAwkjBw4lQCAWoPDgGHuq7UTQ9AUgbpgwcFRwAG1TEeDbPG2E/44nJIMH9H5vpSCOGAL6ANMfMdMf0//T/9FvBFIQbwJQA28CApEy4gGz5jAzhUACO4ftRND0BSBukjBwlNDXCx/igCASAUEQIBWBMSAl+vS22eCBqvgsGPtsdPqIlAEHo/N9KQR0cBbZ43g6kIN4EoAbeBAUiZcQDZiXM2EMBdWwInrA6A7Z5Bg/oHN9DHQW2eSRg28UAWFQJTtkhbZ5Cf7bHTqiJQYP6PzfSkEdGAW2eKQg3gSgBt4EBSJlxANmJczYQwFhUCSts8bYMfjhIkgBD0fm+lMiGVUgNvAgLeAbPmMDMD0Ns8bwgDbwREQQIo2zwQNV8FgCD0Dm+hkjBt4ds8bGFdWwICxRkYASqqgjGCEE5Db2SCEM5Db2RZcIBA2zxWAgHJMRoSAW4a85Q1ufW1LEXymEEC7IZbucuD3mjLjoAesLeX8QB6AAhIIRsCAUgdHAHdQxgCT4M26SW3Dhcfgz0NcL//go+kQBpAK9sZJbcOCAIvgzIG6TXwNw4PANMDIC0IAo1yHXCx/4I1EToVy5k18GcOBcocE8kTGRMOKAEfgz0PoAMAOgUgKhcG0QNBAjcHDbPMj0APQAAc8Wye1Uf4UwIBIB8eA3k2zx/jzIkgCD0fG+lII8jAtMfMPgju1MUvbCPFTFUFUTbPBSgVHYTVHNY2zwDUFRwAd6RMuIBs+ZsYW6zgXUhcA5MAds8bFGTXwNw4QL0BFExgCD0Dm+hk18EcOGAQNch1wv/gCL4MyHbPIAk+DNY2zyxjhNwyMoAEvQA9AABzxbJ7VTwJjB/4F8DcIFQgIAAYIW6SW3CVAfkAAbriAgEgMCICASAlIwOnTbPIAi+DP5AFMBupNfB3DgIo4vUySAIPQOb6GOINMfMSDTH9P/MFAEuvK5+CNQA6DIyx9YzxZABIAg9EMCkxNfA+KSbCHif4rmIG6SMHDeAds8f4XSRcAJYjgCD0fG+lII48AtM/0/9TFbqOLjQD9AT6APoAKKsCUZmhUCmgBMjLPxbL/xL0AAH6AgH6AljPFlQgBYAg9EMDcAGSXwPikTLiAbMCASApJgP1AHbPDT4IyW5k18IcOBw+DNulF8I8CLggBH4M9D6APoA+gDTH9FTYbmUXwzwIuAElF8L8CLgBpNfCnDgIxBJUTJQd/AkIMAAILMrBhBbEEoQOU3d2zwjjhAxbFLI9AD0AAHPFsntVPAi4fANMvgjAaCmxCm2CYAQ+DPQgVFMnArqAENch1wsPUnC2CFMToIASyMsHUjDLH8sfGMsPF8sPGss/E/QAyXD4M9DXC/9TGNs8CfQEUFOgKKAJ+QAQSRA4QGVwbds8QDWAIPRDA8j0ABL0ABL0AAHPFsntVH8oWgBGghBOVlNUcIIAxP/IyxAVy/+DHfoCFMtqE8sfEss/zMlx+wAD9yAEPgz0NMP0w8x0w/RcbYJcG1/jkEpgwf0fG+lII4yAvoA0x/TH9P/0//RA6MEyMt/FMofUkDL/8nQURq2CMjLHxPL/8v/QBSBAaD0QQOkQxORMuIBs+YwNFi2CFMBuZdfB21wbVMR4G2K5jM0pVySbxHkcCCK5jY2WyKAvLSoBXsAAUkO5ErGXXwRtcG1TEeBTAaWSbxHkbxBvEHBTAG1tiuY0NDQ2UlW68rFQREMTKwH+Bm8iAW8kUx2DB/QOb6HyvfoAMdM/MdcL/1OcuY5dUTqoqw9SQLYIUUShJKo7LqkEUZWgUYmgghCOgSeKI5KAc5KAU+LIywfLH1JAy/9SoMs/I5QTy/8CkTPiVCKogBD0Q3AkyMv/Gss/UAX6AhjKAEAagwf0QwgQRRMUkmwx4iwBIiGOhUwA2zwKkVviBKQkbhUXSwFIAm8iAW8QBKRTSL6OkFRlBts8UwK8lGwiIgKRMOKRNOJTNr4TLgA0cAKOEwJvIiFvEAJvESSoqw8StggSoFjkMDEAZAOBAaD0km+lII4hAdN/URm2CAHTHzHXC/8D0x/T/zHXC/9BMBRvBFAFbwIEkmwh4rMUAANpwhIB6YZp0CmGybF0xQ4xcJ/WJasNDpUScmQJHtHvtlFfVnQACSA3MgTjpwF9IgDSSa+Bv/AQ67JBg19Jr4G+8G2eCBqvgoFpj6mJwBB6BzfQya+DP3CQa4WP/BHQkGCAya+DvnARbZ42ERn8Ee2eBcGF/KGZQYTQLFQA0wEoBdQNUCgD1CgEUBBBjtAoBlzJr4W98CoKAaoc25PAXUE2MwSk2zzJAts8UbODB/QOb6GUXw6A+uGBAUDXIfoAMFIIqbQfGaBSB7yUXwyA+eBRW7uUXwuA+OBtcFMHVSDbPAb5AEYJgwf0U5RfCoD34UZQEDcQJzVbQzQDIts8AoAg9EPbPDMQRRA0WNs8Wl1cADSAvMjKBxjL/xbMFMsfEssHy/8B+gIB+gLLHwA8gA34MyBuljCDI3GDCJ/Q0wcBwBryifoA+gD6ANHiAgEgOTgAHbsAH/BnoaQ/pD+kP64UPwR/2A6GmBgLjYSS+B8H0gGBDjgEdCGIDtnnAA6Y+Q4ABHQi2A7Z5waZ+RQQgnObol3UdCmQgR7Z5wEUEII7K6El1FdXTjoUeju2wtfKSxXibKZ8Z1s63gQ/coRQXeBsJHrAnPPrB7PzAAaOhDQT2zzgIoIQTkNvZLqPGDRUUkTbPJaCEM5Db2SShB/iQDNwgEDbPOAighDudk9LuiOCEO52T2+6UhCxTUxWOwSWjoYzNEMA2zzgMCKCEFJnQ3C6jqZUQxXwHoBAIaMiwv+XW3T7AnCDBpEy4gGCEPJnY1CgA0REcAHbPOA0IYIQVnRDcLrjAjMggx6wR1Y9PAEcjomEH0AzcIBA2zzhXwNWA6IDgwjXGCDTH9MP0x/T/9EDghBWdENQuvKlIds8MNMHgCCzErDAU/Kp0x8BghCOgSeKuvKp0//TPzBFZvkR8qJVAts8ghDWdFJAoEAzcIBA2zxFPlYEUNs8U5OAIPQOb6E7CpNfCn7hCds8NFtsIkk3GNs8MiHBAZMYXwjgIG5dW0I/AiqSMDSOiUNQ2zwxFaBQROJFE0RG2zxAXAKa0Ns8NDQ0U0WDB/QOb6GTXwZw4dP/0z/6ANIA0VIWqbQfFqBSULYIUVWhAsjL/8s/AfoCEsoAQEWDB/RDI6sCAqoCErYIUTOhREPbPFlBSwAu0gcBwLzyidP/1NMf0wfT//oA+gDTH9EDvlMjgwf0Dm+hlF8EbX/h2zwwAfkAAts8UxW9mV8DbQJzqdQAApI0NOJTUIAQ9A5voTGUXwdtcOD4I8jLH0BmgBD0Q1QgBKFRM7IkUDME2zxANIMH9EMBwv+TMW1x4AFyRkRDAByALcjLBxTMEvQAy//KPwAe0wcBwC3yidT0BNP/0j/RARjbPDJZgBD0Dm+hMAFGACyAIvgzINDTBwHAEvKogGDXIdM/9ATRAqAyAvpEcPgz0NcL/+1E0PQEBKRavbEhbrGSXwTg2zxsUVIVvQSzFLGSXwPg+AABkVuOnfQE9AT6AEM02zxwyMoAE/QA9ABZoPoCAc8Wye1U4lRIA0QBgCD0Zm+hkjBw4ds8MGwzIMIAjoQQNNs8joUwECPbPOISW0pJAXJwIH+OrSSDB/R8b6Ugjp4C0//TPzH6ANIA0ZQxUTOgjodUGIjbPAcD4lBDoAORMuIBs+YwMwG68rtLAZhwUwB/jrcmgwf0fG+lII6oAtP/0z8x+gDSANGUMVEzoI6RVHcIqYRRZqBSF6BLsNs8CQPiUFOgBJEy4gGz5jA1A7pTIbuw8rsSoAGhSwAyUxKDB/QOb6GU+gAwoJEw4sgB+gICgwf0QwBucPgzIG6TXwRw4NDXC/8j+kQBpAK9sZNfA3Dg+AAB1CH7BCDHAJJfBJwB0O0e7VMB8QaC8gDifwLWMSH6RAGkjo4wghD////+QBNwgEDbPODtRND0BPQEUDODB/Rmb6GOj18EghD////+QBNwgEDbPOE2BfoA0QHI9AAV9AABzxbJ7VSCEPlvcyRwgBjIywVQBM8WUAT6AhLLahLLH8s/yYBA+wBWVhTEphKDVdBJFPEW0/xcbn16xYfvSOeP/puknaDtlqylDccABSP6RO1E0PQEIW4EpBSxjocQNV8FcNs84ATT/9Mf0x/T/9QB0IMI1xkB0YIQZUxQdMjLH1JAyx9SMMsfUmDL/1Igy//J0FEV+RGOhxBoXwhx2zzhIYMPuY6HEGhfCHbbPOAHVVVVTwRW2zwxDYIQO5rKAKEgqgsjuY6HEL1fDXLbPOBRIqBRdb2OhxCsXwxz2zzgDFRVVVAEwI6HEJtfC3DbPOBTa4MH9A5voSCfMPoAWaAB0z8x0/8wUoC9kTHijocQm18LdNs84FMBuY6HEJtfC3XbPOAg8qz4APgjyFj6AssfFMsfFsv/GMv/QDiDB/RDEEVBMBZwcFVVVVECJts8yPQAWM8Wye1UII6DcNs84FtTUgEgghDzdEhMWYIQO5rKAHLbPFYAKgbIyx8Vyx9QA/oCAfoC9ADKAMoAyQAg0NMf0x/6APoA9ATSANIA0QEYghDub0VMWXCAQNs8VgBEcIAYyMsFUAfPFlj6AhXLahPLH8s/IcL/kssfkTHiyQH7AARU2zwH+kQBpLEhwACxjogFoBA1VRLbPOBTAoAg9A5voZQwBaAB4w0QNUFDXVxZWAEE2zxcAiDbPAygVQUL2zxUIFOAIPRDW1oAKAbIyx8Vyx8Ty//0AAH6AgH6AvQAAB7TH9Mf0//0BPoA+gD0BNEAKAXI9AAU9AAS9AAB+gLLH8v/ye1UACDtRND0BPQE9AT6ANMf0//R"; @@ -554,25 +554,22 @@ fn test_stack_serialization() { let stack_items = stack::deserialize_items(input.as_array().unwrap().iter()).unwrap(); - assert_eq!( - stack_items, - vec![ - StackItem::None, - StackItem::nan(), - StackItem::int(123), - StackItem::int(0x456), - StackItem::boolean(true), - StackItem::boolean(false), - StackItem::cell(empty_cell.clone()), - StackItem::builder(BuilderData::new()), - StackItem::continuation(ContinuationData::with_code(SliceData::default())), - StackItem::slice(SliceData::default()), - StackItem::tuple(vec![StackItem::int(123), StackItem::int(456)]), - list.clone(), - list.clone(), - extended_list.clone(), - ] - ); + assert_eq!(stack_items, vec![ + StackItem::None, + StackItem::nan(), + StackItem::int(123), + StackItem::int(0x456), + StackItem::boolean(true), + StackItem::boolean(false), + StackItem::cell(empty_cell.clone()), + StackItem::builder(BuilderData::new()), + StackItem::continuation(ContinuationData::with_code(SliceData::default())), + StackItem::slice(SliceData::default()), + StackItem::tuple(vec![StackItem::int(123), StackItem::int(456)]), + list.clone(), + list.clone(), + extended_list.clone(), + ]); let serialized = stack::serialize_items(Box::new(stack_items.iter()), true).unwrap(); @@ -741,13 +738,10 @@ async fn test_method_error( params: &ParamsOfEncodeMessage, ) -> ClientResult { client - .request_async( - "processing.process_message", - ParamsOfProcessMessage { - message_encode_params: params.clone(), - ..Default::default() - }, - ) + .request_async("processing.process_message", ParamsOfProcessMessage { + message_encode_params: params.clone(), + ..Default::default() + }) .await } @@ -758,15 +752,12 @@ async fn test_method_error( message: &str, ) -> ClientResult { client - .request_async( - "tvm.run_tvm", - ParamsOfRunTvm { - message: message.to_owned(), - account: account_boc.to_owned(), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_tvm", ParamsOfRunTvm { + message: message.to_owned(), + account: account_boc.to_owned(), + abi: Some(abi.clone()), + ..Default::default() + }) .await } @@ -777,18 +768,15 @@ async fn test_method_error( message: &str, ) -> ClientResult { client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: message.to_owned(), - account: AccountForExecutor::Account { - boc: account_boc.to_owned(), - unlimited_balance: None, - }, - abi: Some(abi.clone()), - ..Default::default() + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: message.to_owned(), + account: AccountForExecutor::Account { + boc: account_boc.to_owned(), + unlimited_balance: None, }, - ) + abi: Some(abi.clone()), + ..Default::default() + }) .await } @@ -856,65 +844,53 @@ async fn test_my_code() { let ctor_params = json!({ "pubkey": format!("0x{}", keys.public) }); let deploy_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - call_set: Some(CallSet { - function_name: "constructor".into(), - input: Some(ctor_params), - ..Default::default() - }), - deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), - signer: Signer::Keys { keys: keys.clone() }, + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + call_set: Some(CallSet { + function_name: "constructor".into(), + input: Some(ctor_params), ..Default::default() - }, - ) + }), + deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), + signer: Signer::Keys { keys: keys.clone() }, + ..Default::default() + }) .await .unwrap(); let deployed: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: deploy_message.message.clone(), - account: AccountForExecutor::Uninit, - return_updated_account: Some(true), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: deploy_message.message.clone(), + account: AccountForExecutor::Uninit, + return_updated_account: Some(true), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); let get_my_code_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - address: Some(deploy_message.address.clone()), - call_set: Some(CallSet { - function_name: "getCodeRefs".into(), - input: Some(json!({})), - ..Default::default() - }), - signer: Signer::None, + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + address: Some(deploy_message.address.clone()), + call_set: Some(CallSet { + function_name: "getCodeRefs".into(), + input: Some(json!({})), ..Default::default() - }, - ) + }), + signer: Signer::None, + ..Default::default() + }) .await .unwrap(); let get_my_code: ResultOfRunTvm = client - .request_async( - "tvm.run_tvm", - ParamsOfRunTvm { - message: get_my_code_message.message.clone(), - account: deployed.account.clone(), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_tvm", ParamsOfRunTvm { + message: get_my_code_message.message.clone(), + account: deployed.account.clone(), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); @@ -934,73 +910,58 @@ async fn test_run_executor_fees() { // use correct signature let deploy_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - call_set: Some(CallSet { - function_name: "constructor".into(), - ..Default::default() - }), - deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), - signer: signer.clone(), - ..Default::default() - }, - ) + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + call_set: Some(CallSet { function_name: "constructor".into(), ..Default::default() }), + deploy_set: Some(DeploySet { tvc: tvc.clone(), ..Default::default() }), + signer: signer.clone(), + ..Default::default() + }) .await .unwrap(); let address = deploy_message.address.clone(); let deployed: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: deploy_message.message.clone(), - account: AccountForExecutor::Uninit, - return_updated_account: Some(true), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: deploy_message.message.clone(), + account: AccountForExecutor::Uninit, + return_updated_account: Some(true), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); let send_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - address: Some(address.clone()), - call_set: CallSet::some_with_function_and_input( - "sendTransaction", - json!({ - "dest": address.clone(), - "value": 100_000_000u64, - "bounce": false - }), - ), - signer, - ..Default::default() - }, - ) + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + address: Some(address.clone()), + call_set: CallSet::some_with_function_and_input( + "sendTransaction", + json!({ + "dest": address.clone(), + "value": 100_000_000u64, + "bounce": false + }), + ), + signer, + ..Default::default() + }) .await .unwrap(); // first run - with correct signature let return_value: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: send_message.message.clone(), - account: AccountForExecutor::Account { - boc: deployed.account.clone(), - unlimited_balance: Some(true), - }, - abi: Some(abi.clone()), - ..Default::default() + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: send_message.message.clone(), + account: AccountForExecutor::Account { + boc: deployed.account.clone(), + unlimited_balance: Some(true), }, - ) + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); @@ -1010,63 +971,54 @@ async fn test_run_executor_fees() { // use wrong signature let send_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - address: Some(address.clone()), - call_set: Some(CallSet { - function_name: "sendTransaction".into(), - header: Some(FunctionHeader { pubkey, ..Default::default() }), - input: Some(json!({ - "dest": address.clone(), - "value": 100_000_000u64, - "bounce": false - })), - ..Default::default() - }), - signer: bad_signer, + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + address: Some(address.clone()), + call_set: Some(CallSet { + function_name: "sendTransaction".into(), + header: Some(FunctionHeader { pubkey, ..Default::default() }), + input: Some(json!({ + "dest": address.clone(), + "value": 100_000_000u64, + "bounce": false + })), ..Default::default() - }, - ) + }), + signer: bad_signer, + ..Default::default() + }) .await .unwrap(); // second run - with wrong signature let _err = client - .request_async::<_, ResultOfRunExecutor>( - "tvm.run_executor", - ParamsOfRunExecutor { - message: send_message.message.clone(), - account: AccountForExecutor::Account { - boc: deployed.account.clone(), - unlimited_balance: Some(true), - }, - abi: Some(abi.clone()), - ..Default::default() + .request_async::<_, ResultOfRunExecutor>("tvm.run_executor", ParamsOfRunExecutor { + message: send_message.message.clone(), + account: AccountForExecutor::Account { + boc: deployed.account.clone(), + unlimited_balance: Some(true), }, - ) + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap_err(); // third run - with wrong signature and with skipped signature checking let return_value: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: send_message.message.clone(), - account: AccountForExecutor::Account { - boc: deployed.account.clone(), - unlimited_balance: Some(true), - }, - execution_options: Some(ExecutionOptions { - chksig_always_succeed: Some(true), - ..Default::default() - }), - abi: Some(abi.clone()), - ..Default::default() + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: send_message.message.clone(), + account: AccountForExecutor::Account { + boc: deployed.account.clone(), + unlimited_balance: Some(true), }, - ) + execution_options: Some(ExecutionOptions { + chksig_always_succeed: Some(true), + ..Default::default() + }), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); @@ -1084,76 +1036,61 @@ async fn test_gosh() { let signer = Signer::Keys { keys }; let deploy_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - call_set: CallSet::some_with_function("constructor"), - deploy_set: DeploySet::some_with_tvc(tvc.clone()), - signer: signer.clone(), - ..Default::default() - }, - ) + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + call_set: CallSet::some_with_function("constructor"), + deploy_set: DeploySet::some_with_tvc(tvc.clone()), + signer: signer.clone(), + ..Default::default() + }) .await .unwrap(); let address = deploy_message.address.clone(); let deployed: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: deploy_message.message, - account: AccountForExecutor::Uninit, - return_updated_account: Some(true), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: deploy_message.message, + account: AccountForExecutor::Uninit, + return_updated_account: Some(true), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); for function in abi.abi().unwrap().functions().keys().filter(|f| *f != "constructor") { let call_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - address: Some(address.clone()), - call_set: CallSet::some_with_function(function.as_str()), - signer: signer.clone(), - ..Default::default() - }, - ) + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + address: Some(address.clone()), + call_set: CallSet::some_with_function(function.as_str()), + signer: signer.clone(), + ..Default::default() + }) .await .unwrap(); let _: ResultOfRunExecutor = client - .request_async( - "tvm.run_executor", - ParamsOfRunExecutor { - message: call_message.message.clone(), - account: AccountForExecutor::Account { - boc: deployed.account.clone(), - unlimited_balance: Some(true), - }, - abi: Some(abi.clone()), - ..Default::default() + .request_async("tvm.run_executor", ParamsOfRunExecutor { + message: call_message.message.clone(), + account: AccountForExecutor::Account { + boc: deployed.account.clone(), + unlimited_balance: Some(true), }, - ) + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); let _: ResultOfRunTvm = client - .request_async( - "tvm.run_tvm", - ParamsOfRunTvm { - message: call_message.message, - account: deployed.account.clone(), - abi: Some(abi.clone()), - ..Default::default() - }, - ) + .request_async("tvm.run_tvm", ParamsOfRunTvm { + message: call_message.message, + account: deployed.account.clone(), + abi: Some(abi.clone()), + ..Default::default() + }) .await .unwrap(); } @@ -1176,54 +1113,45 @@ async fn test_signature_id() { let orig_config = base64_encode(orig_config.raw_config().write_to_bytes().unwrap()); let deploy_message: ResultOfEncodeMessage = client - .request_async( - "abi.encode_message", - ParamsOfEncodeMessage { - abi: abi.clone(), - call_set: CallSet::some_with_function("constructor"), - deploy_set: DeploySet::some_with_tvc(tvc.clone()), - signer: signer.clone(), - signature_id: Some(global_id), - ..Default::default() - }, - ) + .request_async("abi.encode_message", ParamsOfEncodeMessage { + abi: abi.clone(), + call_set: CallSet::some_with_function("constructor"), + deploy_set: DeploySet::some_with_tvc(tvc.clone()), + signer: signer.clone(), + signature_id: Some(global_id), + ..Default::default() + }) .await .unwrap(); client - .request_async::<_, ResultOfRunExecutor>( - "tvm.run_executor", - ParamsOfRunExecutor { - message: deploy_message.message.clone(), - account: AccountForExecutor::Uninit, - abi: Some(abi.clone()), - execution_options: Some(ExecutionOptions { - blockchain_config: Some(config.clone()), - signature_id: Some(global_id), - ..Default::default() - }), + .request_async::<_, ResultOfRunExecutor>("tvm.run_executor", ParamsOfRunExecutor { + message: deploy_message.message.clone(), + account: AccountForExecutor::Uninit, + abi: Some(abi.clone()), + execution_options: Some(ExecutionOptions { + blockchain_config: Some(config.clone()), + signature_id: Some(global_id), ..Default::default() - }, - ) + }), + ..Default::default() + }) .await .unwrap(); // check signature verification is failed if capability is disabled let result = client - .request_async::<_, ResultOfRunExecutor>( - "tvm.run_executor", - ParamsOfRunExecutor { - message: deploy_message.message, - account: AccountForExecutor::Uninit, - abi: Some(abi.clone()), - execution_options: Some(ExecutionOptions { - blockchain_config: Some(orig_config.clone()), - signature_id: Some(global_id), - ..Default::default() - }), + .request_async::<_, ResultOfRunExecutor>("tvm.run_executor", ParamsOfRunExecutor { + message: deploy_message.message, + account: AccountForExecutor::Uninit, + abi: Some(abi.clone()), + execution_options: Some(ExecutionOptions { + blockchain_config: Some(orig_config.clone()), + signature_id: Some(global_id), ..Default::default() - }, - ) + }), + ..Default::default() + }) .await .unwrap_err(); assert_eq!( diff --git a/tvm_client/src/utils/conversion.rs b/tvm_client/src/utils/conversion.rs index 20c194ea5..315005405 100644 --- a/tvm_client/src/utils/conversion.rs +++ b/tvm_client/src/utils/conversion.rs @@ -16,11 +16,11 @@ use tvm_block::MsgAddressInt; use crate::client; use crate::client::ClientContext; +use crate::encoding::AccountAddressType; +use crate::encoding::Base64AddressParams; use crate::encoding::account_decode; use crate::encoding::account_encode_ex; use crate::encoding::decode_std_base64; -use crate::encoding::AccountAddressType; -use crate::encoding::Base64AddressParams; use crate::error::ClientResult; #[derive(Serialize, Deserialize, Debug, ApiType, Clone)] diff --git a/tvm_client/src/utils/mod.rs b/tvm_client/src/utils/mod.rs index e7f04f806..30249a998 100644 --- a/tvm_client/src/utils/mod.rs +++ b/tvm_client/src/utils/mod.rs @@ -20,20 +20,20 @@ pub(crate) mod conversion; mod errors; pub(crate) mod json; -pub use calc_storage_fee::calc_storage_fee; pub use calc_storage_fee::ParamsOfCalcStorageFee; pub use calc_storage_fee::ResultOfCalcStorageFee; +pub use calc_storage_fee::calc_storage_fee; #[cfg(feature = "include-zstd")] pub use compression::compress_zstd; #[cfg(feature = "include-zstd")] pub use compression::decompress_zstd; -pub use conversion::convert_address; -pub use conversion::get_address_type; pub use conversion::AddressStringFormat; pub use conversion::ParamsOfConvertAddress; pub use conversion::ParamsOfGetAddressType; pub use conversion::ResultOfConvertAddress; pub use conversion::ResultOfGetAddressType; +pub use conversion::convert_address; +pub use conversion::get_address_type; pub use errors::Error; pub use errors::ErrorCode; diff --git a/tvm_client/src/utils/tests.rs b/tvm_client/src/utils/tests.rs index 82ba272c0..d9933dafa 100644 --- a/tvm_client/src/utils/tests.rs +++ b/tvm_client/src/utils/tests.rs @@ -70,13 +70,10 @@ async fn test_calc_storage_fee() { let client = TestClient::new(); let result: ResultOfCalcStorageFee = client - .request_async( - "utils.calc_storage_fee", - ParamsOfCalcStorageFee { - account: base64_encode(include_bytes!("../boc/test_data/account.boc")), - period: 1000, - }, - ) + .request_async("utils.calc_storage_fee", ParamsOfCalcStorageFee { + account: base64_encode(include_bytes!("../boc/test_data/account.boc")), + period: 1000, + }) .await .unwrap(); @@ -95,19 +92,18 @@ fn test_compression() { anim id est laborum."; let compressed: ResultOfCompressZstd = client - .request( - "utils.compress_zstd", - ParamsOfCompressZstd { uncompressed: base64_encode(uncompressed), level: Some(21) }, - ) + .request("utils.compress_zstd", ParamsOfCompressZstd { + uncompressed: base64_encode(uncompressed), + level: Some(21), + }) .unwrap(); assert_ne!(base64_decode(&compressed.compressed).unwrap(), uncompressed); let decompressed: ResultOfDecompressZstd = client - .request( - "utils.decompress_zstd", - ParamsOfDecompressZstd { compressed: compressed.compressed }, - ) + .request("utils.decompress_zstd", ParamsOfDecompressZstd { + compressed: compressed.compressed, + }) .unwrap(); let decompressed = base64_decode(decompressed.decompressed).unwrap(); @@ -133,10 +129,9 @@ fn test_decompression() { anim id est laborum."; let decompressed: ResultOfDecompressZstd = client - .request( - "utils.decompress_zstd", - ParamsOfDecompressZstd { compressed: compressed.to_string() }, - ) + .request("utils.decompress_zstd", ParamsOfDecompressZstd { + compressed: compressed.to_string(), + }) .unwrap(); let decompressed = base64_decode(decompressed.decompressed).unwrap(); @@ -215,9 +210,8 @@ fn get_address_type( address: &'static str, ) -> ClientResult { client - .request::<_, ResultOfGetAddressType>( - "utils.get_address_type", - ParamsOfGetAddressType { address: address.to_string() }, - ) + .request::<_, ResultOfGetAddressType>("utils.get_address_type", ParamsOfGetAddressType { + address: address.to_string(), + }) .map(|result| result.address_type) } diff --git a/tvm_client_processing/src/message_monitor/message.rs b/tvm_client_processing/src/message_monitor/message.rs index 8920a4a67..4518669cc 100644 --- a/tvm_client_processing/src/message_monitor/message.rs +++ b/tvm_client_processing/src/message_monitor/message.rs @@ -1,8 +1,8 @@ use serde_json::Value; use tvm_types::Cell; -use crate::error; use crate::MessageMonitorSdkServices; +use crate::error; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, ApiType)] #[serde(tag = "type")] diff --git a/tvm_client_processing/src/message_monitor/monitor.rs b/tvm_client_processing/src/message_monitor/monitor.rs index b0a9d7521..67733dbc4 100644 --- a/tvm_client_processing/src/message_monitor/monitor.rs +++ b/tvm_client_processing/src/message_monitor/monitor.rs @@ -4,14 +4,14 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::RwLock; +use crate::NetSubscription; use crate::message_monitor::message::MessageMonitoringParams; use crate::message_monitor::message::MessageMonitoringResult; +use crate::message_monitor::monitor_queues::ADDING_TIMEOUT_MS; use crate::message_monitor::monitor_queues::BufferedMessages; use crate::message_monitor::monitor_queues::MonitorQueues; -use crate::message_monitor::monitor_queues::ADDING_TIMEOUT_MS; use crate::message_monitor::queue::BufferedMessage; use crate::sdk_services::MessageMonitorSdkServices; -use crate::NetSubscription; /// The main message monitor object. /// Incorporates and serves all message monitoring queues. diff --git a/tvm_client_processing/src/message_monitor/monitor_queues.rs b/tvm_client_processing/src/message_monitor/monitor_queues.rs index 95b800549..a3835ddd1 100644 --- a/tvm_client_processing/src/message_monitor/monitor_queues.rs +++ b/tvm_client_processing/src/message_monitor/monitor_queues.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use std::collections::HashSet; -use crate::message_monitor::queue::BufferedMessage; -use crate::message_monitor::queue::MonitoringQueue; use crate::MessageMonitoringParams; use crate::MonitoringQueueInfo; +use crate::message_monitor::queue::BufferedMessage; +use crate::message_monitor::queue::MonitoringQueue; pub(crate) const ADDING_TIMEOUT_MS: u64 = 1000; const FETCHING_TIMEOUT_MS: u64 = 5000; @@ -70,11 +70,7 @@ impl MonitorQueues { } } } - if !buffered.messages.is_empty() { - Some(buffered) - } else { - None - } + if !buffered.messages.is_empty() { Some(buffered) } else { None } } pub fn start_resolving(&mut self, now_ms: u64, hashes: HashSet) { diff --git a/tvm_client_processing/src/message_monitor/queue.rs b/tvm_client_processing/src/message_monitor/queue.rs index a99b3b6ea..065868ca4 100644 --- a/tvm_client_processing/src/message_monitor/queue.rs +++ b/tvm_client_processing/src/message_monitor/queue.rs @@ -3,10 +3,10 @@ use std::mem; use serde_json::Value; -use crate::message_monitor::MessageMonitoringResult; use crate::MessageMonitoringParams; use crate::MonitorFetchWaitMode; use crate::MonitoringQueueInfo; +use crate::message_monitor::MessageMonitoringResult; #[derive(Clone)] pub(crate) struct BufferedMessage { @@ -55,10 +55,6 @@ impl MonitoringQueue { self.buffered.is_empty() && self.resolving.is_empty() && !self.results.is_empty() } }; - if is_ready { - Some(mem::take(&mut self.results)) - } else { - None - } + if is_ready { Some(mem::take(&mut self.results)) } else { None } } } diff --git a/tvm_client_processing/src/sdk_services/mock_sdk_services.rs b/tvm_client_processing/src/sdk_services/mock_sdk_services.rs index 64952615f..d3078024d 100644 --- a/tvm_client_processing/src/sdk_services/mock_sdk_services.rs +++ b/tvm_client_processing/src/sdk_services/mock_sdk_services.rs @@ -10,13 +10,13 @@ use std::time::SystemTime; use base64::Engine; use tvm_types::Cell; +use crate::Error; +use crate::MessageMonitorSdkServices; +use crate::NetSubscription; use crate::error; use crate::message_monitor::CellFromBoc; use crate::message_monitor::MessageMonitoringParams; use crate::message_monitor::MessageMonitoringResult; -use crate::Error; -use crate::MessageMonitorSdkServices; -use crate::NetSubscription; #[derive(Clone)] pub struct MockSdkServices { diff --git a/tvm_client_processing/src/tests.rs b/tvm_client_processing/src/tests.rs index b13aa9f9f..6ec0fcf4f 100644 --- a/tvm_client_processing/src/tests.rs +++ b/tvm_client_processing/src/tests.rs @@ -7,6 +7,7 @@ use tvm_block::MsgAddrStd; use tvm_types::AccountId; use tvm_types::UInt256; +use crate::MonitoredMessage; use crate::message_monitor::MessageMonitor; use crate::message_monitor::MessageMonitoringParams; use crate::message_monitor::MessageMonitoringResult; @@ -14,7 +15,6 @@ use crate::message_monitor::MessageMonitoringStatus; use crate::message_monitor::MessageMonitoringTransaction; use crate::message_monitor::MonitorFetchWaitMode; use crate::sdk_services::MockSdkServices; -use crate::MonitoredMessage; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_fetch() { @@ -31,13 +31,10 @@ async fn test_fetch() { msg_res(2, MessageMonitoringStatus::Finalized), ]); let results = mon.fetch_next_monitor_results("1", MonitorFetchWaitMode::All).await.unwrap(); - assert_eq!( - sorted(results, |x| &x.hash), - vec![ - msg_res(1, MessageMonitoringStatus::Finalized), - msg_res(2, MessageMonitoringStatus::Finalized) - ] - ); + assert_eq!(sorted(results, |x| &x.hash), vec![ + msg_res(1, MessageMonitoringStatus::Finalized), + msg_res(2, MessageMonitoringStatus::Finalized) + ]); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -66,13 +63,10 @@ async fn test_fetch_at_least_one() { msg_res(2, MessageMonitoringStatus::Finalized), ]); let results = mon.fetch_next_monitor_results("1", MonitorFetchWaitMode::All).await.unwrap(); - assert_eq!( - sorted(results, |x| &x.hash), - vec![ - msg_res(1, MessageMonitoringStatus::Finalized), - msg_res(2, MessageMonitoringStatus::Finalized) - ] - ); + assert_eq!(sorted(results, |x| &x.hash), vec![ + msg_res(1, MessageMonitoringStatus::Finalized), + msg_res(2, MessageMonitoringStatus::Finalized) + ]); let results = mon.fetch_next_monitor_results("1", MonitorFetchWaitMode::NoWait).await.unwrap(); assert_eq!(results.len(), 0); } @@ -116,13 +110,10 @@ async fn test_fetch_wait_all() { // Check that spawned thread has received all monitoring messages let results = std::mem::take(&mut *fetched.write().unwrap()); - assert_eq!( - sorted(results, |x| &x.hash), - vec![ - msg_res(1, MessageMonitoringStatus::Finalized), - msg_res(2, MessageMonitoringStatus::Finalized) - ] - ); + assert_eq!(sorted(results, |x| &x.hash), vec![ + msg_res(1, MessageMonitoringStatus::Finalized), + msg_res(2, MessageMonitoringStatus::Finalized) + ]); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] diff --git a/tvm_common/rustfmt.toml b/tvm_common/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_common/rustfmt.toml +++ b/tvm_common/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_debugger/src/decode.rs b/tvm_debugger/src/decode.rs index 9aa284705..5a7fae1b1 100644 --- a/tvm_debugger/src/decode.rs +++ b/tvm_debugger/src/decode.rs @@ -12,16 +12,16 @@ use tvm_block::OutAction; use tvm_block::OutActions; use tvm_block::Serializable; use tvm_block::StateInit; -use tvm_types::base64_encode; -use tvm_types::write_boc; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::SliceData; +use tvm_types::base64_encode; +use tvm_types::write_boc; use tvm_vm::stack::StackItem; -use crate::helper::load_abi_as_string; use crate::Args; use crate::ExecutionResult; +use crate::helper::load_abi_as_string; pub(crate) fn decode_body( abi_file: &PathBuf, diff --git a/tvm_debugger/src/execute.rs b/tvm_debugger/src/execute.rs index b36ec527a..1b639756d 100644 --- a/tvm_debugger/src/execute.rs +++ b/tvm_debugger/src/execute.rs @@ -3,16 +3,18 @@ use tvm_block::Serializable; use tvm_block::StateInit; use tvm_types::HashmapE; use tvm_types::SliceData; +use tvm_vm::SmartContractInfo; use tvm_vm::error::tvm_exception; -use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::executor::Engine; +use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::int; -use tvm_vm::stack::integer::IntegerData; -use tvm_vm::stack::savelist::SaveList; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; -use tvm_vm::SmartContractInfo; +use tvm_vm::stack::integer::IntegerData; +use tvm_vm::stack::savelist::SaveList; +use crate::Args; +use crate::ExecutionResult; use crate::decode::decode_actions; use crate::helper::capabilities; use crate::helper::config_params; @@ -22,8 +24,6 @@ use crate::helper::get_now; use crate::helper::load_code_and_data_from_state_init; use crate::helper::trace_callback; use crate::message::generate_message; -use crate::Args; -use crate::ExecutionResult; pub(crate) fn execute(args: &Args, res: &mut ExecutionResult) -> anyhow::Result<()> { let mut contract_state_init = diff --git a/tvm_debugger/src/message.rs b/tvm_debugger/src/message.rs index 33f9f4017..476ed6028 100644 --- a/tvm_debugger/src/message.rs +++ b/tvm_debugger/src/message.rs @@ -2,9 +2,9 @@ use std::path::PathBuf; use std::str::FromStr; +use serde_json::Value; #[cfg(test)] use serde_json::json; -use serde_json::Value; use tvm_abi::encode_function_call; use tvm_block::CurrencyCollection; use tvm_block::ExternalInboundMessageHeader; @@ -15,14 +15,14 @@ use tvm_block::Message; use tvm_block::MsgAddressExt; use tvm_block::MsgAddressInt; use tvm_block::VarUInteger32; -use tvm_types::ed25519_create_private_key; use tvm_types::SliceData; +use tvm_types::ed25519_create_private_key; +use crate::Args; use crate::helper::get_dest_address; use crate::helper::get_now; use crate::helper::load_abi_as_string; use crate::helper::read_keys; -use crate::Args; pub(crate) fn generate_message(args: &Args) -> anyhow::Result<(Message, SliceData)> { let body = generate_message_body(args)?; diff --git a/tvm_debugger/src/result.rs b/tvm_debugger/src/result.rs index 79f0a39f8..163a2007a 100644 --- a/tvm_debugger/src/result.rs +++ b/tvm_debugger/src/result.rs @@ -1,5 +1,5 @@ -use serde_json::json; use serde_json::Value; +use serde_json::json; use tvm_block::CommonMsgInfo; use tvm_block::Message; use tvm_block::Serializable; diff --git a/tvm_executor/rustfmt.toml b/tvm_executor/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_executor/rustfmt.toml +++ b/tvm_executor/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_executor/src/blockchain_config.rs b/tvm_executor/src/blockchain_config.rs index fd985cbf4..56fc9d0f7 100644 --- a/tvm_executor/src/blockchain_config.rs +++ b/tvm_executor/src/blockchain_config.rs @@ -284,11 +284,7 @@ impl BlockchainConfig { /// Get `MsgForwardPrices` for message forward fee calculation pub fn get_fwd_prices(&self, is_masterchain: bool) -> &MsgForwardPrices { - if is_masterchain { - &self.fwd_prices_mc - } else { - &self.fwd_prices_wc - } + if is_masterchain { &self.fwd_prices_mc } else { &self.fwd_prices_wc } } /// Calculate gas fee for account @@ -298,11 +294,7 @@ impl BlockchainConfig { /// Get `GasLimitsPrices` for account gas fee calculation pub fn get_gas_config(&self, is_masterchain: bool) -> &GasLimitsPrices { - if is_masterchain { - &self.gas_prices_mc - } else { - &self.gas_prices_wc - } + if is_masterchain { &self.gas_prices_mc } else { &self.gas_prices_wc } } /// Calculate forward fee diff --git a/tvm_executor/src/ordinary_transaction.rs b/tvm_executor/src/ordinary_transaction.rs index ac5dc5d8b..9c8c5faf0 100644 --- a/tvm_executor/src/ordinary_transaction.rs +++ b/tvm_executor/src/ordinary_transaction.rs @@ -24,6 +24,7 @@ use tvm_block::AddSub; use tvm_block::CommonMsgInfo; use tvm_block::GlobalCapabilities; use tvm_block::Grams; +use tvm_block::MASTERCHAIN_ID; use tvm_block::Message; use tvm_block::Serializable; use tvm_block::TrBouncePhase; @@ -31,25 +32,24 @@ use tvm_block::TrComputePhase; use tvm_block::Transaction; use tvm_block::TransactionDescr; use tvm_block::TransactionDescrOrdinary; -use tvm_block::MASTERCHAIN_ID; -use tvm_types::error; -use tvm_types::fail; use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; +use tvm_vm::SmartContractInfo; use tvm_vm::boolean; use tvm_vm::int; -use tvm_vm::stack::integer::IntegerData; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; -use tvm_vm::SmartContractInfo; +use tvm_vm::stack::integer::IntegerData; -use crate::blockchain_config::BlockchainConfig; -use crate::error::ExecutorError; use crate::ActionPhaseResult; use crate::ExecuteParams; use crate::TransactionExecutor; use crate::VERSION_BLOCK_REVERT_MESSAGES_WITH_ANYCAST_ADDRESSES; +use crate::blockchain_config::BlockchainConfig; +use crate::error::ExecutorError; pub struct OrdinaryTransactionExecutor { config: BlockchainConfig, diff --git a/tvm_executor/src/tick_tock_transaction.rs b/tvm_executor/src/tick_tock_transaction.rs index 17465eb65..95f147d7f 100644 --- a/tvm_executor/src/tick_tock_transaction.rs +++ b/tvm_executor/src/tick_tock_transaction.rs @@ -21,23 +21,23 @@ use tvm_block::Transaction; use tvm_block::TransactionDescr; use tvm_block::TransactionDescrTickTock; use tvm_block::TransactionTickTock; -use tvm_types::error; -use tvm_types::fail; use tvm_types::HashmapType; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; +use tvm_vm::SmartContractInfo; use tvm_vm::boolean; use tvm_vm::int; -use tvm_vm::stack::integer::IntegerData; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; -use tvm_vm::SmartContractInfo; +use tvm_vm::stack::integer::IntegerData; -use crate::blockchain_config::BlockchainConfig; -use crate::error::ExecutorError; use crate::ActionPhaseResult; use crate::ExecuteParams; use crate::TransactionExecutor; +use crate::blockchain_config::BlockchainConfig; +use crate::error::ExecutorError; pub struct TickTockTransactionExecutor { pub config: BlockchainConfig, diff --git a/tvm_executor/src/transaction_executor.rs b/tvm_executor/src/transaction_executor.rs index 8c9630f72..1bce1464f 100644 --- a/tvm_executor/src/transaction_executor.rs +++ b/tvm_executor/src/transaction_executor.rs @@ -12,16 +12,17 @@ use std::cmp::min; use std::collections::LinkedList; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Mutex; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; use tvm_block::AccStatusChange; use tvm_block::Account; use tvm_block::AccountState; use tvm_block::AccountStatus; use tvm_block::AddSub; +use tvm_block::BASE_WORKCHAIN_ID; use tvm_block::CommonMsgInfo; use tvm_block::ComputeSkipReason; use tvm_block::CopyleftReward; @@ -33,10 +34,22 @@ use tvm_block::GetRepresentationHash; use tvm_block::GlobalCapabilities; use tvm_block::Grams; use tvm_block::HashUpdate; +use tvm_block::MASTERCHAIN_ID; use tvm_block::Message; use tvm_block::MsgAddressInt; use tvm_block::OutAction; use tvm_block::OutActions; +use tvm_block::RESERVE_ALL_BUT; +use tvm_block::RESERVE_IGNORE_ERROR; +use tvm_block::RESERVE_PLUS_ORIG; +use tvm_block::RESERVE_REVERSE; +use tvm_block::RESERVE_VALID_MODES; +use tvm_block::SENDMSG_ALL_BALANCE; +use tvm_block::SENDMSG_DELETE_IF_EMPTY; +use tvm_block::SENDMSG_IGNORE_ERROR; +use tvm_block::SENDMSG_PAY_FEE_SEPARATELY; +use tvm_block::SENDMSG_REMAINING_MSG_BALANCE; +use tvm_block::SENDMSG_VALID_FLAGS; use tvm_block::Serializable; use tvm_block::StateInit; use tvm_block::StorageUsedShort; @@ -49,21 +62,6 @@ use tvm_block::TrStoragePhase; use tvm_block::Transaction; use tvm_block::VarUInteger32; use tvm_block::WorkchainFormat; -use tvm_block::BASE_WORKCHAIN_ID; -use tvm_block::MASTERCHAIN_ID; -use tvm_block::RESERVE_ALL_BUT; -use tvm_block::RESERVE_IGNORE_ERROR; -use tvm_block::RESERVE_PLUS_ORIG; -use tvm_block::RESERVE_REVERSE; -use tvm_block::RESERVE_VALID_MODES; -use tvm_block::SENDMSG_ALL_BALANCE; -use tvm_block::SENDMSG_DELETE_IF_EMPTY; -use tvm_block::SENDMSG_IGNORE_ERROR; -use tvm_block::SENDMSG_PAY_FEE_SEPARATELY; -use tvm_block::SENDMSG_REMAINING_MSG_BALANCE; -use tvm_block::SENDMSG_VALID_FLAGS; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::Cell; use tvm_types::ExceptionCode; @@ -73,21 +71,23 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; use tvm_vm::error::tvm_exception; +use tvm_vm::executor::BehaviorModifiers; +use tvm_vm::executor::IndexProvider; use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::executor::token::ECC_SHELL_KEY; use tvm_vm::executor::token::INFINITY_CREDIT; -use tvm_vm::executor::BehaviorModifiers; -use tvm_vm::executor::IndexProvider; use tvm_vm::smart_contract_info::SmartContractInfo; use tvm_vm::stack::Stack; +use crate::VERSION_BLOCK_NEW_CALCULATION_BOUNCED_STORAGE; use crate::blockchain_config::BlockchainConfig; use crate::blockchain_config::CalcMsgFwdFees; use crate::error::ExecutorError; use crate::vmsetup::VMSetup; use crate::vmsetup::VMSetupContext; -use crate::VERSION_BLOCK_NEW_CALCULATION_BOUNCED_STORAGE; const RESULT_CODE_ACTIONLIST_INVALID: i32 = 32; const RESULT_CODE_TOO_MANY_ACTIONS: i32 = 33; @@ -377,11 +377,7 @@ pub trait TransactionExecutor { Some(due_payment_remaining) }); tr.total_fees_mut().grams.add(&collected)?; - if collected.is_zero() { - None - } else { - Some(collected) - } + if collected.is_zero() { None } else { Some(collected) } } else { None }; @@ -512,15 +508,12 @@ pub trait TransactionExecutor { if let Some(init_code_hash) = result_acc.init_code_hash() { smc_info.set_init_code_hash(init_code_hash.clone()); } - let mut vm = VMSetup::with_context( - SliceData::load_cell(code)?, - VMSetupContext { - capabilities: self.config().capabilites(), - block_version: params.block_version, - #[cfg(feature = "signature_with_id")] - signature_id: params.signature_id, - }, - ) + let mut vm = VMSetup::with_context(SliceData::load_cell(code)?, VMSetupContext { + capabilities: self.config().capabilites(), + block_version: params.block_version, + #[cfg(feature = "signature_with_id")] + signature_id: params.signature_id, + }) .set_smart_contract_info(smc_info)? .set_stack(stack) .set_data(data)? diff --git a/tvm_executor/src/vmsetup.rs b/tvm_executor/src/vmsetup.rs index 92b1b6ca7..8b9dec004 100644 --- a/tvm_executor/src/vmsetup.rs +++ b/tvm_executor/src/vmsetup.rs @@ -17,12 +17,12 @@ use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::Result; use tvm_types::SliceData; -use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::executor::Engine; +use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::smart_contract_info::SmartContractInfo; -use tvm_vm::stack::savelist::SaveList; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; +use tvm_vm::stack::savelist::SaveList; use crate::BlockchainConfig; diff --git a/tvm_sdk/src/block.rs b/tvm_sdk/src/block.rs index d907271f8..4432320d1 100644 --- a/tvm_sdk/src/block.rs +++ b/tvm_sdk/src/block.rs @@ -9,10 +9,10 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use crate::contract::ShardDescr; -use crate::types::BlockId; use crate::MessageId; use crate::TransactionId; +use crate::contract::ShardDescr; +use crate::types::BlockId; #[derive(Deserialize, Debug, Clone)] pub struct MsgDescr { diff --git a/tvm_sdk/src/contract.rs b/tvm_sdk/src/contract.rs index 678f320dc..4ae9acf6b 100644 --- a/tvm_sdk/src/contract.rs +++ b/tvm_sdk/src/contract.rs @@ -14,8 +14,8 @@ use std::io::Seek; use chrono::prelude::Utc; use serde_json::Value; -use tvm_abi::json_abi::DecodedMessage; use tvm_abi::PublicKeyData; +use tvm_abi::json_abi::DecodedMessage; use tvm_block::AccountIdPrefixFull; use tvm_block::CurrencyCollection; use tvm_block::Deserializable; @@ -27,18 +27,18 @@ use tvm_block::MsgAddressInt; use tvm_block::Serializable; use tvm_block::ShardIdent; use tvm_block::StateInit; -use tvm_types::error; -use tvm_types::fail; use tvm_types::AccountId; use tvm_types::BocReader; use tvm_types::Ed25519PrivateKey; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; -use crate::error::SdkError; -use crate::json_helper; use crate::AbiContract; use crate::MessageId; +use crate::error::SdkError; +use crate::json_helper; pub struct Contract {} diff --git a/tvm_sdk/src/json_helper.rs b/tvm_sdk/src/json_helper.rs index 972693d43..7db3cd382 100644 --- a/tvm_sdk/src/json_helper.rs +++ b/tvm_sdk/src/json_helper.rs @@ -18,8 +18,8 @@ use tvm_block::AccountStatus; use tvm_block::ComputeSkipReason; use tvm_block::MsgAddressInt; use tvm_block::TransactionProcessingStatus; -use tvm_types::base64_decode; use tvm_types::Cell; +use tvm_types::base64_decode; use crate::MessageType; diff --git a/tvm_sdk/src/lib.rs b/tvm_sdk/src/lib.rs index e5f8404f5..52223ca27 100644 --- a/tvm_sdk/src/lib.rs +++ b/tvm_sdk/src/lib.rs @@ -16,10 +16,10 @@ extern crate api_info; #[macro_use] extern crate api_derive; -pub use tvm_abi::json_abi; pub use tvm_abi::Contract as AbiContract; pub use tvm_abi::Event as AbiEvent; pub use tvm_abi::Function as AbiFunction; +pub use tvm_abi::json_abi; mod error; pub use error::SdkError; diff --git a/tvm_sdk/src/message.rs b/tvm_sdk/src/message.rs index 30039def1..eafc54bda 100644 --- a/tvm_sdk/src/message.rs +++ b/tvm_sdk/src/message.rs @@ -17,8 +17,8 @@ use tvm_types::Result; use tvm_types::SliceData; use crate::json_helper; -use crate::types::grams_to_u64; use crate::types::StringId; +use crate::types::grams_to_u64; #[derive(Deserialize, Debug, PartialEq, Clone, Default)] pub enum MessageType { diff --git a/tvm_sdk/src/transaction.rs b/tvm_sdk/src/transaction.rs index d0b3f60a3..4a7619e00 100644 --- a/tvm_sdk/src/transaction.rs +++ b/tvm_sdk/src/transaction.rs @@ -17,12 +17,12 @@ use tvm_block::TransactionDescr; use tvm_block::TransactionProcessingStatus; use tvm_types::Result; +use crate::Message; +use crate::MessageId; use crate::error::SdkError; use crate::json_helper; -use crate::types::grams_to_u64; use crate::types::StringId; -use crate::Message; -use crate::MessageId; +use crate::types::grams_to_u64; #[derive(Deserialize, Default, Debug)] #[serde(default)] diff --git a/tvm_sdk/src/types.rs b/tvm_sdk/src/types.rs index f4f06b830..176af7726 100644 --- a/tvm_sdk/src/types.rs +++ b/tvm_sdk/src/types.rs @@ -12,9 +12,9 @@ use std::fmt; use num_traits::cast::ToPrimitive; -use tvm_types::base64_encode; use tvm_types::Result; use tvm_types::UInt256; +use tvm_types::base64_encode; use crate::error::SdkError; diff --git a/tvm_struct/rustfmt.toml b/tvm_struct/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_struct/rustfmt.toml +++ b/tvm_struct/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_tests/src/test_framework.rs b/tvm_tests/src/test_framework.rs index 8742eef5f..fcbc7b07b 100644 --- a/tvm_tests/src/test_framework.rs +++ b/tvm_tests/src/test_framework.rs @@ -2,19 +2,19 @@ use std::convert::Into; use std::sync::Arc; -use tvm_assembler::compile_code; use tvm_assembler::CompileError; +use tvm_assembler::compile_code; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::Result; use tvm_types::SliceData; -use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::executor::BehaviorModifiers; use tvm_vm::executor::Engine; use tvm_vm::executor::IndexProvider; -use tvm_vm::stack::savelist::SaveList; +use tvm_vm::executor::gas::gas_state::Gas; use tvm_vm::stack::Stack; +use tvm_vm::stack::savelist::SaveList; pub type Bytecode = SliceData; diff --git a/tvm_tests/src/test_zk.rs b/tvm_tests/src/test_zk.rs index 776c69b8f..b0cb46022 100644 --- a/tvm_tests/src/test_zk.rs +++ b/tvm_tests/src/test_zk.rs @@ -6,8 +6,8 @@ mod tests { use std::time::Instant; use ark_ff::biginteger::BigInteger; - use ark_std::rand::rngs::StdRng; use ark_std::rand::SeedableRng; + use ark_std::rand::rngs::StdRng; use base64::decode; use base64ct::Encoding as bEncoding; use ed25519_dalek::Signer; @@ -17,10 +17,10 @@ mod tests { use fastcrypto_zkp::bn254::utils::gen_address_seed; use fastcrypto_zkp::bn254::utils::get_zk_login_address; use fastcrypto_zkp::bn254::zk_login::CanonicalSerialize; + use fastcrypto_zkp::bn254::zk_login::JWK; use fastcrypto_zkp::bn254::zk_login::JwkId; use fastcrypto_zkp::bn254::zk_login::OIDCProvider; use fastcrypto_zkp::bn254::zk_login::ZkLoginInputs; - use fastcrypto_zkp::bn254::zk_login::JWK; use fastcrypto_zkp::zk_login_utils::Bn254FrElement; use num_bigint::BigUint; use num_traits::Zero; @@ -33,14 +33,14 @@ mod tests { use tvm_types::SliceData; use tvm_vm::executor::zk_stuff::error::ZkCryptoError; use tvm_vm::int; - use tvm_vm::stack::integer::IntegerData; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; + use tvm_vm::stack::integer::IntegerData; use tvm_vm::utils::pack_data_to_cell; use tvm_vm::utils::pack_string_to_cell; - use crate::test_framework::test_case_with_refs; use crate::test_framework::Expects; + use crate::test_framework::test_case_with_refs; pub const SUI_DATA_FROM_REACT_1: &str = "{\"jwt\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjMyM2IyMTRhZTY5NzVhMGYwMzRlYTc3MzU0ZGMwYzI1ZDAzNjQyZGMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIyMzI2MjQwODUxOTEtdjF0cTIwZmcxa2RoaGd2YXQ2c2FqN2pmMGhkODIzM3IuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIyMzI2MjQwODUxOTEtdjF0cTIwZmcxa2RoaGd2YXQ2c2FqN2pmMGhkODIzM3IuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTI4OTc0Njg2MjY3MTY2MjYxMDMiLCJub25jZSI6ImJ4bW5KVzMxcnV6S01HaXIwMVlQR1lMMHhEWSIsIm5iZiI6MTcxNTY4NzAzNiwiaWF0IjoxNzE1Njg3MzM2LCJleHAiOjE3MTU2OTA5MzYsImp0aSI6IjliNjAxZDI1ZjAwMzY0MGMyODg5YTJhMDQ3Nzg5MzgyY2IxY2ZlODcifQ.rTa9KA9HoYm04Agj71D0kDkvsCZ35SeeihBGbABYckBRxaUlCy6LQ-sEaVOTgvnL_DgVn7hx8g3sSmnhJ9kHzj5e6gtUoxoWAe8PuGyK2bmqhmPrQMeEps9f6m2EToQCIA_Id4fGCjSCktjJBi47QHT_Dhe6isHdKk1pgSshOyvCF1VjIvyyeGY5iWQ4cIRBMQNlNBT11o6T01SY6B9DtiiFN_0-ok5taIjQgtMNG6Cwr3tCnqXftuGGQrHlx15y8VgCPODYi-wOtvUbzI2yfx53PmRD_L8O50cMNCrCRE3yYR5MNOu1LlQ_EACy5UFsCJR35xRz84nv-6Iyrufx1g\",\"user_pass_to_int_format\":\"981021191041055255531141165751\",\"ephemeral_key_pair\":{\"keypair\":{\"public_key\":{\"0\":155,\"1\":147,\"2\":37,\"3\":82,\"4\":183,\"5\":109,\"6\":227,\"7\":144,\"8\":85,\"9\":248,\"10\":20,\"11\":45,\"12\":92,\"13\":103,\"14\":160,\"15\":221,\"16\":101,\"17\":44,\"18\":30,\"19\":86,\"20\":96,\"21\":85,\"22\":24,\"23\":224,\"24\":106,\"25\":63,\"26\":13,\"27\":130,\"28\":8,\"29\":119,\"30\":247,\"31\":67},\"secret_key\":{\"0\":192,\"1\":16,\"2\":35,\"3\":54,\"4\":100,\"5\":14,\"6\":88,\"7\":217,\"8\":164,\"9\":21,\"10\":154,\"11\":233,\"12\":248,\"13\":208,\"14\":188,\"15\":4,\"16\":52,\"17\":244,\"18\":125,\"19\":103,\"20\":99,\"21\":26,\"22\":225,\"23\":60,\"24\":140,\"25\":75,\"26\":228,\"27\":157,\"28\":137,\"29\":220,\"30\":1,\"31\":65,\"32\":155,\"33\":147,\"34\":37,\"35\":82,\"36\":183,\"37\":109,\"38\":227,\"39\":144,\"40\":85,\"41\":248,\"42\":20,\"43\":45,\"44\":92,\"45\":103,\"46\":160,\"47\":221,\"48\":101,\"49\":44,\"50\":30,\"51\":86,\"52\":96,\"53\":85,\"54\":24,\"55\":224,\"56\":106,\"57\":63,\"58\":13,\"59\":130,\"60\":8,\"61\":119,\"62\":247,\"63\":67}}},\"zk_addr\":\"0x290623ea2fe67e77502c931e015e910720b59cf99994bfe872da851245a6adb8\",\"zk_proofs\":{\"proofPoints\":{\"a\":[\"4240296169193969312736577528388333411353554120022978085193148043577551744781\",\"5805161066003598301896048908428560240907086333477483881772048922050706263054\",\"1\"],\"b\":[[\"12834391737669124973917765536412427456985620342194191639017091262766903638891\",\"17565396762846717347409742387259908749145765976354144805005547481529916658455\"],[\"10704310067924910937030159163683742097178285875135929496314190235513445131794\",\"5158907077493606386023392148737817037260820737072162547798816810512684527243\"],[\"1\",\"0\"]],\"c\":[\"1422540522119231707130773229384414857146368773886805969586218853559909475064\",\"8843079196273712399340537238369227864378150337693574970239878271571912585171\",\"1\"]},\"issBase64Details\":{\"value\":\"yJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLC\",\"indexMod4\":1},\"headerBase64\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjMyM2IyMTRhZTY5NzVhMGYwMzRlYTc3MzU0ZGMwYzI1ZDAzNjQyZGMiLCJ0eXAiOiJKV1QifQ\"},\"extended_ephemeral_public_key\":\"AJuTJVK3beOQVfgULVxnoN1lLB5WYFUY4Go/DYIId/dD\"}"; pub const SUI_DATA_FROM_REACT_2: &str = "{\"jwt\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjMyM2IyMTRhZTY5NzVhMGYwMzRlYTc3MzU0ZGMwYzI1ZDAzNjQyZGMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiIyMzI2MjQwODUxOTEtdjF0cTIwZmcxa2RoaGd2YXQ2c2FqN2pmMGhkODIzM3IuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiIyMzI2MjQwODUxOTEtdjF0cTIwZmcxa2RoaGd2YXQ2c2FqN2pmMGhkODIzM3IuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTI4OTc0Njg2MjY3MTY2MjYxMDMiLCJub25jZSI6IjJKd0VMbjJfUV9Rd0VsTC1rWTFPRnFqdXZCMCIsIm5iZiI6MTcxNTY4NzAyOSwiaWF0IjoxNzE1Njg3MzI5LCJleHAiOjE3MTU2OTA5MjksImp0aSI6ImU2YjM1ZjJmNmFkNjIzOWEwMDAxMTJiMWI5YWI2MWQ0MjRkMGM1OTIifQ.QcrEDE9qmPZKX83nU3Tx2BN8fsinb_mmXkO1Qf7Uv1QTd0NjirSeu7C4Vn9WDNWDaIR-BgCfhOlkwMQPljcahqC4AN43N_66tvbEsXjtEdFejslXrGG4D_BEKvtmD7_WkW388LyU2PxKgtdDfpYFgmuT6wTM2TO5dTbrGrDyn88q3pkPfefC5a8Wi1V6zECfFdSV-pKQlxtPaImi7s3CKAUMDu1n-jcT-Ho2aTgrWKAzhXE56tgEWOpXQO06eJsWCSOqoZSLYtatTrZr4d38U7QRQiNlH-ydHv4zXt1tixLLJ0wvPx-dQaCnCl1kW1orYkJGFfHgjx6A9z5Ol4afuw\",\"user_pass_to_int_format\":\"101119106102103\",\"ephemeral_key_pair\":{\"keypair\":{\"public_key\":{\"0\":194,\"1\":38,\"2\":203,\"3\":255,\"4\":219,\"5\":127,\"6\":105,\"7\":129,\"8\":234,\"9\":222,\"10\":71,\"11\":169,\"12\":108,\"13\":94,\"14\":28,\"15\":48,\"16\":111,\"17\":221,\"18\":113,\"19\":110,\"20\":5,\"21\":226,\"22\":19,\"23\":230,\"24\":232,\"25\":67,\"26\":255,\"27\":179,\"28\":6,\"29\":10,\"30\":209,\"31\":63},\"secret_key\":{\"0\":44,\"1\":32,\"2\":251,\"3\":184,\"4\":109,\"5\":252,\"6\":105,\"7\":67,\"8\":208,\"9\":111,\"10\":86,\"11\":214,\"12\":192,\"13\":135,\"14\":169,\"15\":48,\"16\":162,\"17\":36,\"18\":216,\"19\":145,\"20\":232,\"21\":64,\"22\":17,\"23\":14,\"24\":29,\"25\":56,\"26\":39,\"27\":118,\"28\":143,\"29\":250,\"30\":31,\"31\":66,\"32\":194,\"33\":38,\"34\":203,\"35\":255,\"36\":219,\"37\":127,\"38\":105,\"39\":129,\"40\":234,\"41\":222,\"42\":71,\"43\":169,\"44\":108,\"45\":94,\"46\":28,\"47\":48,\"48\":111,\"49\":221,\"50\":113,\"51\":110,\"52\":5,\"53\":226,\"54\":19,\"55\":230,\"56\":232,\"57\":67,\"58\":255,\"59\":179,\"60\":6,\"61\":10,\"62\":209,\"63\":63}}},\"zk_addr\":\"0x9d28c04a423b33d6901065b2e23440d80c963e2d8cf60619aed131cf302a3345\",\"zk_proofs\":{\"proofPoints\":{\"a\":[\"10113442204684515220664612836724727112601024759319365467272456423129044788607\",\"1622056145268645528934658046911045406324940175278473377024147189407527440953\",\"1\"],\"b\":[[\"16638441944380099215425740101953753038808466958852552979180365845498468757656\",\"15160836857346434734063515954042830497610079883703780011464867547889770445695\"],[\"18562910453341688699790780964434211467815845944672185772065803860963710445937\",\"8200691834141582017549140597895023392490964486044036655696113278873832146838\"],[\"1\",\"0\"]],\"c\":[\"4229037146526046139176767312447148765936834700862335953317784850097077554287\",\"14155516063621997063825085002662503289554536312724791903045026922766401869119\",\"1\"]},\"issBase64Details\":{\"value\":\"yJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLC\",\"indexMod4\":1},\"headerBase64\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6IjMyM2IyMTRhZTY5NzVhMGYwMzRlYTc3MzU0ZGMwYzI1ZDAzNjQyZGMiLCJ0eXAiOiJKV1QifQ\"},\"extended_ephemeral_public_key\":\"AMImy//bf2mB6t5HqWxeHDBv3XFuBeIT5uhD/7MGCtE/\"}"; @@ -262,10 +262,12 @@ mod tests { println!("code : {code}"); - test_case_with_refs( - code.as_str(), - vec![modulus_cell.clone(), iss_base_64_cell, header_base_64_cell, zk_seed_cell], - ) + test_case_with_refs(code.as_str(), vec![ + modulus_cell.clone(), + iss_base_64_cell, + header_base_64_cell, + zk_seed_cell, + ]) .expect_stack(Stack::new().push(StackItem::Cell(public_inputs_cell.clone()))); //.expect_success(); @@ -280,7 +282,7 @@ mod tests { let proof_cell = pack_data_to_cell(&proof_as_bytes, &mut 0).unwrap(); let verification_key_id: u32 = 0; // valid key id - // let verification_key_id: u32 = 1; //invalid key id + // let verification_key_id: u32 = 1; //invalid key id let mut code = "PUSHREF \n".to_string(); code = code + "PUSHREF \n"; @@ -392,10 +394,12 @@ mod tests { println!("code : {code}"); - test_case_with_refs( - code.as_str(), - vec![modulus_cell, iss_base_64_cell, header_base_64_cell, zk_seed_cell], - ) + test_case_with_refs(code.as_str(), vec![ + modulus_cell, + iss_base_64_cell, + header_base_64_cell, + zk_seed_cell, + ]) .expect_success(); println!("====== Start Vergrth16 ========"); @@ -513,8 +517,8 @@ mod tests { let jwt_string_1 = String::from_utf8(jwt_data_1).expect("UTF-8 conversion failed"); println!("jwt_string_1 is {:?}", jwt_string_1); // jwt_string_1 is - // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" - // typ\":\"JWT\"}" + // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" + // typ\":\"JWT\"}" // JwtDataDecodedPart1 let jwt_data_decoded1: JwtDataDecodedPart1 = @@ -582,8 +586,8 @@ mod tests { // Generate an ephemeral key pair. let ephemeral_kp = Ed25519KeyPair::from_bytes(&secret_key).unwrap(); // Ed25519KeyPair::generate(&mut StdRng::from_seed([0; 32])); let mut eph_pubkey = Vec::new(); // vec![0x00]; - // replace by Alina's data (ephemeral public key place to byte array ), depends - // on iteration + // replace by Alina's data (ephemeral public key place to byte array ), depends + // on iteration eph_pubkey.extend(ephemeral_kp.public().as_ref()); println!("eph_pubkey: {:?}", eph_pubkey); println!("eph_pubkey: {:?}", hex::encode(eph_pubkey.clone())); @@ -674,7 +678,7 @@ mod tests { let public_inputs_cell = pack_data_to_cell(&public_inputs_as_bytes, &mut 0).unwrap(); let verification_key_id: u32 = 0; // valid key id - // let verification_key_id: u32 = 1; //invalid key id + // let verification_key_id: u32 = 1; //invalid key id let mut code = "PUSHREF \n".to_string(); code = code + "PUSHREF \n"; @@ -928,16 +932,13 @@ mod tests { println!("code : {code}"); - test_case_with_refs( - code.as_str(), - vec![ - modulus_cell, - // &iss_and_header_base64details_cell - iss_base_64_cell, - header_base_64_cell, - zk_seed_cell, - ], - ) + test_case_with_refs(code.as_str(), vec![ + modulus_cell, + // &iss_and_header_base64details_cell + iss_base_64_cell, + header_base_64_cell, + zk_seed_cell, + ]) .expect_success(); } @@ -1111,7 +1112,7 @@ mod tests { // Generate an ephemeral key pair. let ephemeral_kp = Ed25519KeyPair::from_bytes(&secret_key).unwrap(); // Ed25519KeyPair::generate(&mut StdRng::from_seed([0; 32])); let mut eph_pubkey = Vec::new(); // vec![0x00]; // replace by Alina's data (ephemeral public key place to byte - // array ), depends on iteration + // array ), depends on iteration eph_pubkey.extend(ephemeral_kp.public().as_ref()); println!("eph_pubkey: {:?}", hex::encode(eph_pubkey.clone())); @@ -1319,8 +1320,8 @@ mod tests { let jwt_string_1 = String::from_utf8(jwt_data_1).expect("UTF-8 conversion failed"); println!("jwt_string_1 is {:?}", jwt_string_1); // jwt_string_1 is - // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" - // typ\":\"JWT\"}" + // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" + // typ\":\"JWT\"}" // JwtDataDecodedPart1 let jwt_data_decoded1: JwtDataDecodedPart1 = @@ -1489,8 +1490,8 @@ mod tests { let jwt_string_1 = String::from_utf8(jwt_data_1).expect("UTF-8 conversion failed"); println!("jwt_string_1 is {:?}", jwt_string_1); // jwt_string_1 is - // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" - // typ\":\"JWT\"}" + // "{\"alg\":\"RS256\",\"kid\":\"323b214ae6975a0f034ea77354dc0c25d03642dc\",\" + // typ\":\"JWT\"}" // JwtDataDecodedPart1 let jwt_data_decoded1: JwtDataDecodedPart1 = diff --git a/tvm_tl_codegen/src/lib.rs b/tvm_tl_codegen/src/lib.rs index 359b35d73..ecd2c7c7e 100644 --- a/tvm_tl_codegen/src/lib.rs +++ b/tvm_tl_codegen/src/lib.rs @@ -38,18 +38,18 @@ use proc_macro2::Spacing; use proc_macro2::Span; use proc_macro2::TokenStream as Tokens; use proc_macro2::TokenStream; -use quote::quote; use quote::TokenStreamExt; +use quote::quote; use serde_derive::Deserialize; pub mod parser { use std::cmp::Ordering; + use pom::Parser; use pom::char_class::alphanum; use pom::char_class::digit; use pom::char_class::hex_digit; use pom::parser::*; - use pom::Parser; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum Type { @@ -1129,35 +1129,19 @@ impl TypeIR { } fn field_type(&self) -> Tokens { - if self.is_unit() { - quote!(bool) - } else { - self.boxed() - } + if self.is_unit() { quote!(bool) } else { self.boxed() } } fn ref_prefix(&self) -> Tokens { - if self.is_unit() { - quote!() - } else { - quote!(ref) - } + if self.is_unit() { quote!() } else { quote!(ref) } } fn reference_prefix(&self) -> Tokens { - if self.is_unit() { - quote!() - } else { - quote!(&) - } + if self.is_unit() { quote!() } else { quote!(&) } } fn local_reference_prefix(&self) -> Tokens { - if self.is_unit() { - quote!(&) - } else { - quote!() - } + if self.is_unit() { quote!(&) } else { quote!() } } fn field_reference_type(&self) -> Tokens { diff --git a/tvm_types/benches/benchmarks.rs b/tvm_types/benches/benchmarks.rs index e35ab94b1..0b37b6773 100644 --- a/tvm_types/benches/benchmarks.rs +++ b/tvm_types/benches/benchmarks.rs @@ -1,11 +1,8 @@ +use criterion::Criterion; use criterion::criterion_group; use criterion::criterion_main; -use criterion::Criterion; use pprof::criterion::Output; use pprof::criterion::PProfProfiler; -use tvm_types::error; -use tvm_types::fail; -use tvm_types::read_single_root_boc; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::GasConsumer; @@ -13,6 +10,9 @@ use tvm_types::HashmapE; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::Status; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::read_single_root_boc; // fn read_boc(filename: &str) -> Vec { // let mut bytes = Vec::new(); diff --git a/tvm_types/rustfmt.toml b/tvm_types/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_types/rustfmt.toml +++ b/tvm_types/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_types/src/bls.rs b/tvm_types/src/bls.rs index bcd198dff..1b5e6e974 100644 --- a/tvm_types/src/bls.rs +++ b/tvm_types/src/bls.rs @@ -17,8 +17,8 @@ use blst::*; use rand::Rng; use rand::RngCore; -use crate::fail; use crate::Result; +use crate::fail; // Constants diff --git a/tvm_types/src/boc.rs b/tvm_types/src/boc.rs index 9cc56b7cc..50b404f53 100644 --- a/tvm_types/src/boc.rs +++ b/tvm_types/src/boc.rs @@ -8,9 +8,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use std::collections::hash_map; use std::collections::HashMap; use std::collections::HashSet; +use std::collections::hash_map; use std::fmt::Debug; use std::fs::File; use std::io::Cursor; @@ -25,9 +25,18 @@ use std::sync::Arc; use smallvec::SmallVec; +use crate::ByteOrderRead; +use crate::CellImpl; +use crate::CellType; +use crate::Crc32; +use crate::MAX_BIG_DATA_BYTES; +use crate::MAX_REFERENCES_COUNT; +use crate::Result; +use crate::Status; +use crate::UInt256; use crate::cell::Cell; -use crate::cell::DataCell; use crate::cell::DEPTH_SIZE; +use crate::cell::DataCell; use crate::cell::MAX_DATA_BYTES; use crate::cell::MAX_SAFE_DEPTH; use crate::cell::SHA256_SIZE; @@ -36,15 +45,6 @@ use crate::crc32_digest; use crate::error; use crate::fail; use crate::full_len; -use crate::ByteOrderRead; -use crate::CellImpl; -use crate::CellType; -use crate::Crc32; -use crate::Result; -use crate::Status; -use crate::UInt256; -use crate::MAX_BIG_DATA_BYTES; -use crate::MAX_REFERENCES_COUNT; const BOC_INDEXED_TAG: u32 = 0x68ff65f3; // deprecated, is used only for read const BOC_INDEXED_CRC32_TAG: u32 = 0xacc3a728; // deprecated, is used only for read @@ -444,9 +444,9 @@ impl<'a, S: OrderedCellsStorage> BocWriter<'a, S> { } else { boc.traverse(root_cell)?; boc.roots_indexes_rev.push(boc.cells_count - 1); // root must be - // added into - // `sorted_rev` - // back + // added into + // `sorted_rev` + // back } } @@ -1153,8 +1153,8 @@ impl<'a> BocReader<'a> { MAX_DATA_BYTES + MAX_REFERENCES_COUNT * ref_size; let min_cell_size = 2; // descr bytes only - // every raw cell except roots must be referenced at least once, hence the - // formula + // every raw cell except roots must be referenced at least once, hence the + // formula let tot_cells_size_minimal = (cells_count - big_cells_count) * (min_cell_size + ref_size) - ref_size * roots_count; if tot_cells_size - big_cells_size < tot_cells_size_minimal { diff --git a/tvm_types/src/cell/builder.rs b/tvm_types/src/cell/builder.rs index 33e909ef6..9f4d3261e 100644 --- a/tvm_types/src/cell/builder.rs +++ b/tvm_types/src/cell/builder.rs @@ -14,15 +14,15 @@ use std::fmt; use smallvec::SmallVec; pub(super) type SmallData = SmallVec<[u8; 128]>; -use crate::cell::append_tag; -use crate::cell::find_tag; use crate::cell::Cell; use crate::cell::CellType; use crate::cell::DataCell; use crate::cell::LevelMask; -use crate::cell::SliceData; use crate::cell::MAX_DATA_BITS; use crate::cell::MAX_SAFE_DEPTH; +use crate::cell::SliceData; +use crate::cell::append_tag; +use crate::cell::find_tag; use crate::error; use crate::fail; use crate::types::ExceptionCode; diff --git a/tvm_types/src/cell/builder_operations.rs b/tvm_types/src/cell/builder_operations.rs index bc6edba9b..3788e7c71 100644 --- a/tvm_types/src/cell/builder_operations.rs +++ b/tvm_types/src/cell/builder_operations.rs @@ -9,11 +9,11 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use crate::cell::find_tag; use crate::cell::BuilderData; -use crate::cell::SliceData; use crate::cell::MAX_DATA_BITS; use crate::cell::MAX_REFERENCES_COUNT; +use crate::cell::SliceData; +use crate::cell::find_tag; use crate::error; use crate::fail; use crate::types::ExceptionCode; @@ -134,11 +134,7 @@ impl IBitstring for BuilderData { } fn append_bit_bool(&mut self, bit: bool) -> Result<&mut Self> { - if bit { - self.append_raw(&[0xFF], 1) - } else { - self.append_raw(&[0x00], 1) - } + if bit { self.append_raw(&[0xFF], 1) } else { self.append_raw(&[0x00], 1) } } fn append_bits(&mut self, value: usize, bits: usize) -> Result<&mut Self> { diff --git a/tvm_types/src/cell/mod.rs b/tvm_types/src/cell/mod.rs index b15f91344..076a7a422 100644 --- a/tvm_types/src/cell/mod.rs +++ b/tvm_types/src/cell/mod.rs @@ -21,21 +21,21 @@ use std::io::Write; use std::ops::BitOr; use std::ops::BitOrAssign; use std::ops::Deref; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Weak; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; use num::FromPrimitive; use num::ToPrimitive; +use crate::Sha256; use crate::error; use crate::fail; use crate::types::ByteOrderRead; use crate::types::ExceptionCode; use crate::types::Result; use crate::types::UInt256; -use crate::Sha256; pub const SHA256_SIZE: usize = 32; pub const DEPTH_SIZE: usize = 2; @@ -457,11 +457,7 @@ impl Cell { pub fn to_hex_string(&self, lower: bool) -> String { let bit_length = self.bit_length(); if bit_length % 8 == 0 { - if lower { - hex::encode(self.data()) - } else { - hex::encode_upper(self.data()) - } + if lower { hex::encode(self.data()) } else { hex::encode_upper(self.data()) } } else { to_hex_string(self.data(), self.bit_length(), lower) } @@ -730,8 +726,8 @@ pub(crate) const HASHES_D1_FLAG: u8 = 16; pub(crate) const EXOTIC_D1_FLAG: u8 = 8; pub(crate) const REFS_D1_MASK: u8 = 7; pub(crate) const BIG_CELL_D1: u8 = 13; // 0b0000_1101 - // next byte is desription byte 2 contains data size (in special encoding, see - // cell_data_len) +// next byte is desription byte 2 contains data size (in special encoding, see +// cell_data_len) #[inline(always)] pub(crate) fn calc_d1( @@ -835,11 +831,7 @@ pub(crate) fn bit_len(buf: &[u8]) -> usize { bytes * 8 } else { debug_assert!(buf.len() >= 2); - if buf[1] & 1 == 0 { - (buf[1] >> 1) as usize * 8 - } else { - find_tag(cell_data(buf)) - } + if buf[1] & 1 == 0 { (buf[1] >> 1) as usize * 8 } else { find_tag(cell_data(buf)) } } } @@ -993,11 +985,7 @@ fn build_cell_buf( let level_mask = LevelMask::with_mask(level_mask); let level = level_mask.level(); let hashes_count = if store_hashes { - if cell_type == CellType::PrunedBranch { - 1 - } else { - level as usize + 1 - } + if cell_type == CellType::PrunedBranch { 1 } else { level as usize + 1 } } else { 0 }; diff --git a/tvm_types/src/crypto.rs b/tvm_types/src/crypto.rs index bfd43cc46..7b18ac490 100644 --- a/tvm_types/src/crypto.rs +++ b/tvm_types/src/crypto.rs @@ -17,6 +17,9 @@ use std::sync::Arc; use super::bls::BLS_PUBLIC_KEY_LEN; use super::bls::BLS_SECRET_KEY_LEN; +use crate::Ed25519ExpandedPrivateKey; +use crate::Ed25519PrivateKey; +use crate::Result; use crate::base64_decode; use crate::base64_encode; use crate::ed25519_create_expanded_private_key; @@ -29,9 +32,6 @@ use crate::ed25519_verify; use crate::fail; use crate::sha256_digest_slices; use crate::x25519_shared_secret; -use crate::Ed25519ExpandedPrivateKey; -use crate::Ed25519PrivateKey; -use crate::Result; pub trait KeyOption: Sync + Send + Debug { fn id(&self) -> &Arc; diff --git a/tvm_types/src/dictionary/mod.rs b/tvm_types/src/dictionary/mod.rs index 5f236fc47..89411059b 100644 --- a/tvm_types/src/dictionary/mod.rs +++ b/tvm_types/src/dictionary/mod.rs @@ -13,6 +13,8 @@ use std::marker::PhantomData; pub use self::hashmap::HashmapE; pub use self::pfxhashmap::PfxHashmapE; +use crate::GasConsumer; +use crate::Mask; use crate::cell::BuilderData; use crate::cell::Cell; use crate::cell::IBitstring; @@ -21,8 +23,6 @@ use crate::error; use crate::fail; use crate::types::ExceptionCode; use crate::types::Result; -use crate::GasConsumer; -use crate::Mask; mod hashmap; mod pfxhashmap; @@ -117,11 +117,7 @@ impl LabelReader { while cursor.get_next_bit()? { len += 1; } - if len <= max { - Ok(len) - } else { - fail!(ExceptionCode::CellUnderflow) - } + if len <= max { Ok(len) } else { fail!(ExceptionCode::CellUnderflow) } } fn get_label_long(cursor: &mut SliceData, max: &mut usize) -> Result { @@ -132,11 +128,7 @@ impl LabelReader { fn get_label_long_length(cursor: &mut SliceData, max: usize) -> Result { let len = cursor.get_next_size(max)? as usize; - if len <= max { - Ok(len) - } else { - fail!(ExceptionCode::CellUnderflow) - } + if len <= max { Ok(len) } else { fail!(ExceptionCode::CellUnderflow) } } fn get_label_same( @@ -154,11 +146,7 @@ impl LabelReader { fn get_label_same_length(cursor: &mut SliceData, max: usize) -> Result { cursor.get_next_bit()?; let len = cursor.get_next_size(max)? as usize; - if len <= max { - Ok(len) - } else { - fail!(ExceptionCode::CellUnderflow) - } + if len <= max { Ok(len) } else { fail!(ExceptionCode::CellUnderflow) } } pub fn new(cursor: SliceData) -> Self { @@ -579,11 +567,7 @@ pub trait HashmapType { .ok_or(ExceptionCode::CellUnderflow)?; label = LabelReader::read_label(&mut cursor, bit_len)?; } - if key.is_empty() && Self::is_leaf(&mut cursor) { - Ok(Some(cursor)) - } else { - Ok(None) - } + if key.is_empty() && Self::is_leaf(&mut cursor) { Ok(Some(cursor)) } else { Ok(None) } } fn hashmap_set_with_mode( @@ -732,7 +716,7 @@ pub trait HashmapType { let bit_len = self.bit_len(); if bit_len != other.bit_len() || key.remaining_bits() > bit_len { return Ok(()); // fail!("data in hashmaps do not correspond each - // other or key too long") + // other or key too long") } let cell1 = match self.data() { Some(data) => data.clone(), @@ -1887,11 +1871,7 @@ pub trait HashmapSubtree: HashmapType + Clone + Sized { let mut cursor = LabelReader::new(SliceData::load_cell_ref(root)?); let (_key, remainder_prefix) = down_by_tree::(prefix, &mut cursor, self.bit_len(), &mut 0)?; - if remainder_prefix.is_none() { - Ok(Some(cursor.remainder()?.cell())) - } else { - Ok(None) - } + if remainder_prefix.is_none() { Ok(Some(cursor.remainder()?.cell())) } else { Ok(None) } } else { Ok(None) } diff --git a/tvm_types/src/dictionary/pfxhashmap.rs b/tvm_types/src/dictionary/pfxhashmap.rs index 46ca35006..82bc0831b 100644 --- a/tvm_types/src/dictionary/pfxhashmap.rs +++ b/tvm_types/src/dictionary/pfxhashmap.rs @@ -11,19 +11,19 @@ use std::fmt; -use super::hm_label; +use super::ADD; use super::BuilderData; use super::Cell; use super::HashmapRemover; use super::HashmapType; use super::IBitstring; use super::Leaf; -use super::SliceData; -use super::ADD; use super::REPLACE; -use crate::types::Result; +use super::SliceData; +use super::hm_label; use crate::GasConsumer; use crate::LabelReader; +use crate::types::Result; #[derive(Clone, Debug)] pub struct PfxHashmapE { diff --git a/tvm_types/src/wrappers.rs b/tvm_types/src/wrappers.rs index 5eb64c4ee..ca3125725 100644 --- a/tvm_types/src/wrappers.rs +++ b/tvm_types/src/wrappers.rs @@ -13,24 +13,24 @@ use core::ops::Range; use aes_ctr::cipher::stream::NewStreamCipher; use aes_ctr::cipher::stream::SyncStreamCipher; +use base64::Engine; use base64::engine::general_purpose::STANDARD; use base64::engine::general_purpose::URL_SAFE; -use base64::Engine; -use crc::Crc; use crc::CRC_32_ISCSI; +use crc::Crc; +pub use ed25519_dalek::PUBLIC_KEY_LENGTH as ED25519_PUBLIC_KEY_LENGTH; +pub use ed25519_dalek::SECRET_KEY_LENGTH as ED25519_SECRET_KEY_LENGTH; +pub use ed25519_dalek::SIGNATURE_LENGTH as ED25519_SIGNATURE_LENGTH; use ed25519_dalek::SecretKey; use ed25519_dalek::Signer; use ed25519_dalek::SigningKey; use ed25519_dalek::Verifier; use ed25519_dalek::VerifyingKey; -pub use ed25519_dalek::PUBLIC_KEY_LENGTH as ED25519_PUBLIC_KEY_LENGTH; -pub use ed25519_dalek::SECRET_KEY_LENGTH as ED25519_SECRET_KEY_LENGTH; -pub use ed25519_dalek::SIGNATURE_LENGTH as ED25519_SIGNATURE_LENGTH; use sha2::Digest; +use crate::Result; use crate::error; use crate::fail; -use crate::Result; // AES-CTR -------------------------------------------------------------- diff --git a/tvm_vm/benches/benchmarks.rs b/tvm_vm/benches/benchmarks.rs index 94ee7e285..b6a3ed315 100644 --- a/tvm_vm/benches/benchmarks.rs +++ b/tvm_vm/benches/benchmarks.rs @@ -11,20 +11,20 @@ use std::time::Duration; -use criterion::criterion_group; -use criterion::criterion_main; use criterion::Criterion; use criterion::SamplingMode; +use criterion::criterion_group; +use criterion::criterion_main; use pprof::criterion::Output; use pprof::criterion::PProfProfiler; use tvm_block::Deserializable; use tvm_block::StateInit; use tvm_types::SliceData; use tvm_vm::executor::Engine; -use tvm_vm::stack::continuation::ContinuationData; -use tvm_vm::stack::savelist::SaveList; use tvm_vm::stack::Stack; use tvm_vm::stack::StackItem; +use tvm_vm::stack::continuation::ContinuationData; +use tvm_vm::stack::savelist::SaveList; static DEFAULT_CAPABILITIES: u64 = 0x572e; diff --git a/tvm_vm/rustfmt.toml b/tvm_vm/rustfmt.toml index 0310a2b91..6a9781e9d 100644 --- a/tvm_vm/rustfmt.toml +++ b/tvm_vm/rustfmt.toml @@ -9,7 +9,7 @@ use_try_shorthand = true use_small_heuristics = "Max" -style_edition = "2021" +style_edition = "2024" unstable_features = true # better grepping diff --git a/tvm_vm/src/error.rs b/tvm_vm/src/error.rs index 5513919c2..13c41768b 100644 --- a/tvm_vm/src/error.rs +++ b/tvm_vm/src/error.rs @@ -10,10 +10,10 @@ // limitations under the License. use thiserror::Error; -use tvm_types::error; -use tvm_types::fail; use tvm_types::ExceptionCode; use tvm_types::Result; +use tvm_types::error; +use tvm_types::fail; use crate::types::Exception; diff --git a/tvm_vm/src/executor/accounts.rs b/tvm_vm/src/executor/accounts.rs index 64a6cdfa4..6a1aa3020 100644 --- a/tvm_vm/src/executor/accounts.rs +++ b/tvm_vm/src/executor/accounts.rs @@ -9,8 +9,8 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use std::cmp::min; use std::cmp::Ordering; +use std::cmp::min; use std::collections::HashMap; use std::sync::Arc; @@ -33,8 +33,6 @@ use tvm_block::ShardAccount; use tvm_block::SigPubKey; use tvm_block::ValidatorDescr; use tvm_block::ValidatorSet; -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::ExceptionCode; @@ -44,9 +42,11 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use tvm_types::fail; -use super::engine::storage::fetch_stack; use super::engine::IndexProvider; +use super::engine::storage::fetch_stack; use super::types::Instruction; use crate::error::TvmError; use crate::executor::engine::Engine; diff --git a/tvm_vm/src/executor/blockchain.rs b/tvm_vm/src/executor/blockchain.rs index 64cb7b445..b0f458451 100644 --- a/tvm_vm/src/executor/blockchain.rs +++ b/tvm_vm/src/executor/blockchain.rs @@ -9,34 +9,34 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use num::bigint::Sign; use num::BigInt; -use tvm_block::Deserializable; -use tvm_block::GlobalCapabilities; -use tvm_block::MsgAddressInt; +use num::bigint::Sign; use tvm_block::ACTION_CHANGE_LIB; use tvm_block::ACTION_COPYLEFT; use tvm_block::ACTION_RESERVE; use tvm_block::ACTION_SEND_MSG; use tvm_block::ACTION_SET_CODE; -use tvm_types::error; -use tvm_types::types::ExceptionCode; +use tvm_block::Deserializable; +use tvm_block::GlobalCapabilities; +use tvm_block::MsgAddressInt; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::GasConsumer; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::types::ExceptionCode; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::serialize_currency_collection; use crate::executor::types::Instruction; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::OperationBehavior; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/config.rs b/tvm_vm/src/executor/config.rs index 6c2166699..7bccb387f 100644 --- a/tvm_vm/src/executor/config.rs +++ b/tvm_vm/src/executor/config.rs @@ -11,12 +11,12 @@ use tvm_block::GlobalCapabilities; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Status; fn execute_config_param(engine: &mut Engine, name: &'static str, opt: bool) -> Status { diff --git a/tvm_vm/src/executor/continuation.rs b/tvm_vm/src/executor/continuation.rs index c372bf76e..e789c4fde 100644 --- a/tvm_vm/src/executor/continuation.rs +++ b/tvm_vm/src/executor/continuation.rs @@ -18,6 +18,8 @@ use tvm_types::fail; use tvm_types::types::ExceptionCode; use crate::error::TvmError; +use crate::executor::Mask; +use crate::executor::engine::Engine; use crate::executor::engine::data::convert; use crate::executor::engine::storage::apply_savelist; use crate::executor::engine::storage::apply_savelist_excluding_c0_c1; @@ -27,7 +29,6 @@ use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::storage::pop_all; use crate::executor::engine::storage::pop_range; use crate::executor::engine::storage::swap; -use crate::executor::engine::Engine; use crate::executor::microcode::CC; use crate::executor::microcode::CELL; use crate::executor::microcode::CONTINUATION; @@ -38,13 +39,12 @@ use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; use crate::executor::types::InstructionParameter; -use crate::executor::Mask; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; use crate::stack::continuation::ContinuationType; -use crate::stack::integer::behavior::Signaling; use crate::stack::integer::IntegerData; +use crate::stack::integer::behavior::Signaling; use crate::stack::savelist::SaveList; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; @@ -774,11 +774,7 @@ fn execute_ifbit_mask(engine: &mut Engine, name: &'static str, how: u8) -> Statu let test_bit_mask = IntegerData::from_u32(1 << nbit); x.and::(&test_bit_mask)?.is_zero() }; - if is_zero ^ how.bit(INV) { - Ok(()) - } else { - jmpx(engine, how.bit(REF)) - } + if is_zero ^ how.bit(INV) { Ok(()) } else { jmpx(engine, how.bit(REF)) } } // (x continuation - x), switch if n's bit of x is set diff --git a/tvm_vm/src/executor/crypto.rs b/tvm_vm/src/executor/crypto.rs index d4920238f..bbea0ac25 100644 --- a/tvm_vm/src/executor/crypto.rs +++ b/tvm_vm/src/executor/crypto.rs @@ -15,19 +15,19 @@ use ed25519::Signature; use ed25519_dalek::Verifier; use ed25519_dalek::VerifyingKey; use tvm_block::GlobalCapabilities; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::GasConsumer; use tvm_types::UInt256; +use tvm_types::error; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; -use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/currency.rs b/tvm_vm/src/executor/currency.rs index 82eac6de2..604d01ad3 100644 --- a/tvm_vm/src/executor/currency.rs +++ b/tvm_vm/src/executor/currency.rs @@ -10,17 +10,17 @@ // limitations under the License. use tvm_block::GlobalCapabilities; -use tvm_types::error; -use tvm_types::types::ExceptionCode; use tvm_types::BuilderData; use tvm_types::IBitstring; +use tvm_types::error; +use tvm_types::types::ExceptionCode; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/deserialization.rs b/tvm_vm/src/executor/deserialization.rs index 7dd6eb228..a3df3a245 100644 --- a/tvm_vm/src/executor/deserialization.rs +++ b/tvm_vm/src/executor/deserialization.rs @@ -12,32 +12,32 @@ use std::collections::HashSet; use tvm_block::GlobalCapabilities; -use tvm_types::error; use tvm_types::CellType; use tvm_types::ExceptionCode; use tvm_types::GasConsumer; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; use crate::error::TvmError; +use crate::executor::Mask; +use crate::executor::engine::Engine; use crate::executor::engine::data::convert; use crate::executor::engine::storage::fetch_stack; -use crate::executor::engine::Engine; use crate::executor::microcode::CELL; use crate::executor::microcode::SLICE; use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::executor::Mask; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; +use crate::stack::integer::IntegerData; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::SignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::SignedIntegerLittleEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerLittleEndianEncoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/dictionary.rs b/tvm_vm/src/executor/dictionary.rs index 60ae2f63c..56a0e2f6d 100644 --- a/tvm_vm/src/executor/dictionary.rs +++ b/tvm_vm/src/executor/dictionary.rs @@ -9,9 +9,6 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; -use tvm_types::fail; -use tvm_types::types::ExceptionCode; use tvm_types::BuilderData; use tvm_types::GasConsumer; use tvm_types::HashmapE; @@ -19,23 +16,26 @@ use tvm_types::HashmapSubtree; use tvm_types::PfxHashmapE; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; +use tvm_types::fail; +use tvm_types::types::ExceptionCode; use crate::error::TvmError; +use crate::executor::Mask; use crate::executor::continuation::callx; use crate::executor::continuation::switch; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::executor::Mask; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; +use crate::stack::integer::IntegerData; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::SignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/diff.rs b/tvm_vm/src/executor/diff.rs index 37e450357..a4e8cb06c 100644 --- a/tvm_vm/src/executor/diff.rs +++ b/tvm_vm/src/executor/diff.rs @@ -15,18 +15,18 @@ use std::time::Duration; use std::time::Instant; use tvm_block::GlobalCapabilities; -use tvm_types::error; use tvm_types::ExceptionCode; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; -use crate::error::tvm_exception_code; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; +use crate::error::tvm_exception_code; +use crate::executor::Mask; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::gas::gas_state::Gas; use crate::executor::types::Instruction; -use crate::executor::Mask; use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; @@ -249,11 +249,7 @@ fn execute_patch_with_options(name: &'static str, engine: &mut Engine, how: u8) })() }; - if how.bit(IGNORE_ERROR) { - ignore_error(engine, result) - } else { - result - } + if how.bit(IGNORE_ERROR) { ignore_error(engine, result) } else { result } } /// ZIP (s – c), zip string diff --git a/tvm_vm/src/executor/dump.rs b/tvm_vm/src/executor/dump.rs index 742a63f1e..e1739dc23 100644 --- a/tvm_vm/src/executor/dump.rs +++ b/tvm_vm/src/executor/dump.rs @@ -17,10 +17,10 @@ use tvm_types::error; use tvm_types::types::ExceptionCode; use crate::error::TvmError; +use crate::executor::Mask; use crate::executor::engine::Engine; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::executor::Mask; use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/engine/core.rs b/tvm_vm/src/executor/engine/core.rs index 2dea51fc5..a6ae05e54 100644 --- a/tvm_vm/src/executor/engine/core.rs +++ b/tvm_vm/src/executor/engine/core.rs @@ -18,7 +18,6 @@ use std::sync::Mutex; use tvm_block::Deserializable; use tvm_block::GlobalCapabilities; use tvm_block::ShardAccount; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::CellType; @@ -29,10 +28,11 @@ use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; use tvm_types::UInt256; +use tvm_types::error; +use crate::error::TvmError; use crate::error::tvm_exception_full; use crate::error::update_error_description; -use crate::error::TvmError; use crate::executor::continuation::switch; use crate::executor::continuation::switch_to_c0; use crate::executor::engine::handlers::Handlers; @@ -49,12 +49,12 @@ use crate::executor::types::RegisterPair; use crate::executor::types::RegisterTrio; use crate::executor::types::WhereToGetParams; use crate::smart_contract_info::SmartContractInfo; +use crate::stack::Stack; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; use crate::stack::continuation::ContinuationType; use crate::stack::integer::IntegerData; use crate::stack::savelist::SaveList; -use crate::stack::Stack; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::ResultMut; use crate::types::ResultOpt; diff --git a/tvm_vm/src/executor/engine/data.rs b/tvm_vm/src/executor/engine/data.rs index 870e781aa..31a8b7454 100644 --- a/tvm_vm/src/executor/engine/data.rs +++ b/tvm_vm/src/executor/engine/data.rs @@ -9,8 +9,8 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::fail; use tvm_types::GasConsumer; +use tvm_types::fail; use crate::executor::engine::Engine; use crate::executor::microcode::BUILDER; @@ -18,8 +18,8 @@ use crate::executor::microcode::CELL; use crate::executor::microcode::CONTINUATION; use crate::executor::microcode::SLICE; use crate::executor::microcode::VAR; -use crate::stack::continuation::ContinuationData; use crate::stack::StackItem; +use crate::stack::continuation::ContinuationData; use crate::types::Status; // Utilities ****************************************************************** diff --git a/tvm_vm/src/executor/engine/handlers.rs b/tvm_vm/src/executor/engine/handlers.rs index fcc86f184..f9684e6fd 100644 --- a/tvm_vm/src/executor/engine/handlers.rs +++ b/tvm_vm/src/executor/engine/handlers.rs @@ -12,9 +12,9 @@ use std::fmt; use std::ops::Range; +use tvm_types::Result; use tvm_types::error; use tvm_types::types::ExceptionCode; -use tvm_types::Result; use crate::error::TvmError; use crate::executor::accounts::*; @@ -28,9 +28,9 @@ use crate::executor::dictionary::*; #[cfg(feature = "gosh")] use crate::executor::diff::*; use crate::executor::dump::*; +use crate::executor::engine::Engine; use crate::executor::engine::core::ExecuteHandler; use crate::executor::engine::storage::fetch_stack; -use crate::executor::engine::Engine; use crate::executor::exceptions::*; use crate::executor::gas::*; use crate::executor::globals::*; diff --git a/tvm_vm/src/executor/engine/storage.rs b/tvm_vm/src/executor/engine/storage.rs index 5761d73ab..2ffa88980 100644 --- a/tvm_vm/src/executor/engine/storage.rs +++ b/tvm_vm/src/executor/engine/storage.rs @@ -12,10 +12,10 @@ use std::mem; use std::ops::Range; +use tvm_types::Result; use tvm_types::error; use tvm_types::fail; use tvm_types::types::ExceptionCode; -use tvm_types::Result; use crate::error::TvmError; use crate::executor::engine::Engine; @@ -27,9 +27,9 @@ use crate::executor::microcode::CTRL_SAVELIST; use crate::executor::microcode::STACK; use crate::executor::microcode::VAR; use crate::executor::microcode::VAR_SAVELIST; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; use crate::stack::savelist::SaveList; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::ResultMut; use crate::types::ResultRef; @@ -330,11 +330,7 @@ pub(in crate::executor) fn pop_all(engine: &mut Engine, dst: u16) -> Status { } else { nargs as usize }; - if drop > 0 { - pop_range(engine, 0..drop, dst) - } else { - Ok(()) - } + if drop > 0 { pop_range(engine, 0..drop, dst) } else { Ok(()) } } // dst.stack.push(CC.stack[range]) diff --git a/tvm_vm/src/executor/exceptions.rs b/tvm_vm/src/executor/exceptions.rs index 8327afa40..664d16605 100644 --- a/tvm_vm/src/executor/exceptions.rs +++ b/tvm_vm/src/executor/exceptions.rs @@ -18,20 +18,20 @@ use tvm_types::types::ExceptionCode; use crate::error::TvmError; use crate::executor::continuation::callx; +use crate::executor::engine::Engine; use crate::executor::engine::storage::copy_to_var; use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::storage::swap; -use crate::executor::engine::Engine; use crate::executor::microcode::CC; use crate::executor::microcode::CTRL; use crate::executor::microcode::SAVELIST; use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; use crate::stack::continuation::ContinuationType; use crate::stack::integer::IntegerData; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; @@ -126,11 +126,7 @@ fn execute_throwif_throwifnot( .set_opts(InstructionOptions::Integer(range)), )?; fetch_stack(engine, 1)?; - if reverse_condition ^ engine.cmd.var(0).as_bool()? { - do_throw(engine, -1, -1) - } else { - Ok(()) - } + if reverse_condition ^ engine.cmd.var(0).as_bool()? { do_throw(engine, -1, -1) } else { Ok(()) } } pub(super) fn execute_throwif_short(engine: &mut Engine) -> Status { @@ -157,11 +153,7 @@ fn execute_throwanyif_throwanyifnot(engine: &mut Engine, reverse_condition: bool "THROWANYIF" }))?; fetch_stack(engine, 2)?; - if reverse_condition ^ engine.cmd.var(0).as_bool()? { - do_throw(engine, 1, -1) - } else { - Ok(()) - } + if reverse_condition ^ engine.cmd.var(0).as_bool()? { do_throw(engine, 1, -1) } else { Ok(()) } } // (n f, f!=0 => throw 0 n) @@ -205,11 +197,7 @@ fn execute_throwarganyif_throwarganyifnot(engine: &mut Engine, reverse_condition "THROWARGANYIF" }))?; fetch_stack(engine, 3)?; - if reverse_condition ^ engine.cmd.var(0).as_bool()? { - do_throw(engine, 1, 2) - } else { - Ok(()) - } + if reverse_condition ^ engine.cmd.var(0).as_bool()? { do_throw(engine, 1, 2) } else { Ok(()) } } // (x n f, f!=0 => throw x n) @@ -229,11 +217,7 @@ fn execute_throwargif_throwargifnot(engine: &mut Engine, reverse_condition: bool .set_opts(InstructionOptions::Integer(0..2048)), )?; fetch_stack(engine, 2)?; - if reverse_condition ^ engine.cmd.var(0).as_bool()? { - do_throw(engine, -1, 1) - } else { - Ok(()) - } + if reverse_condition ^ engine.cmd.var(0).as_bool()? { do_throw(engine, -1, 1) } else { Ok(()) } } // (x f, f!=0 => throw x n) diff --git a/tvm_vm/src/executor/gas/gas_state.rs b/tvm_vm/src/executor/gas/gas_state.rs index 7a9916e8a..0840089be 100644 --- a/tvm_vm/src/executor/gas/gas_state.rs +++ b/tvm_vm/src/executor/gas/gas_state.rs @@ -12,9 +12,9 @@ use std::cmp::max; use std::cmp::min; +use tvm_types::Result; use tvm_types::error; use tvm_types::types::ExceptionCode; -use tvm_types::Result; use crate::error::TvmError; use crate::types::Exception; @@ -165,11 +165,7 @@ impl Gas { /// Compute exception cost pub const fn load_cell_price(first: bool) -> i64 { - if first { - CELL_LOAD_GAS_PRICE - } else { - CELL_RELOAD_GAS_PRICE - } + if first { CELL_LOAD_GAS_PRICE } else { CELL_RELOAD_GAS_PRICE } } pub fn consume_load_cell(&mut self, first: bool) -> i64 { @@ -301,10 +297,6 @@ impl Gas { } pub const fn get_gas_used(&self) -> i64 { - if self.gas_remaining > 0 { - self.gas_base - self.gas_remaining - } else { - self.gas_base - } + if self.gas_remaining > 0 { self.gas_base - self.gas_remaining } else { self.gas_base } } } diff --git a/tvm_vm/src/executor/gas/mod.rs b/tvm_vm/src/executor/gas/mod.rs index b59b929a1..c7843062f 100644 --- a/tvm_vm/src/executor/gas/mod.rs +++ b/tvm_vm/src/executor/gas/mod.rs @@ -10,19 +10,19 @@ // limitations under the License. use tvm_block::GlobalCapabilities; +use tvm_types::Result; use tvm_types::error; use tvm_types::types::ExceptionCode; -use tvm_types::Result; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::Quiet; use crate::stack::integer::conversion::FromInt; use crate::stack::integer::math::Round; -use crate::stack::integer::IntegerData; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/globals.rs b/tvm_vm/src/executor/globals.rs index 0617d39d0..fdb624a80 100644 --- a/tvm_vm/src/executor/globals.rs +++ b/tvm_vm/src/executor/globals.rs @@ -9,12 +9,12 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use crate::executor::engine::storage::fetch_stack; +use crate::executor::Mask; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::gas::gas_state::Gas; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::executor::Mask; use crate::stack::StackItem; use crate::types::Status; diff --git a/tvm_vm/src/executor/math.rs b/tvm_vm/src/executor/math.rs index b76094802..dc9c1d37c 100644 --- a/tvm_vm/src/executor/math.rs +++ b/tvm_vm/src/executor/math.rs @@ -12,27 +12,27 @@ use std::cmp::Ordering; use std::mem; +use tvm_types::Result; use tvm_types::error; use tvm_types::types::Bitmask; use tvm_types::types::ExceptionCode; -use tvm_types::Result; -use crate::error::tvm_exception_code; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; +use crate::error::tvm_exception_code; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::OperationBehavior; +use crate::stack::integer::math::Round; use crate::stack::integer::math::utils::div_by_shift; use crate::stack::integer::math::utils::divmod; -use crate::stack::integer::math::Round; use crate::stack::integer::utils::binary_op; use crate::stack::integer::utils::construct_double_nan; use crate::stack::integer::utils::process_double_result; use crate::stack::integer::utils::unary_op; -use crate::stack::integer::IntegerData; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; @@ -185,11 +185,7 @@ where macro_rules! boolint { ($val:expr) => { - if $val { - IntegerData::minus_one() - } else { - IntegerData::zero() - } + if $val { IntegerData::minus_one() } else { IntegerData::zero() } }; } diff --git a/tvm_vm/src/executor/null.rs b/tvm_vm/src/executor/null.rs index 2f0705525..8d8c2a86e 100644 --- a/tvm_vm/src/executor/null.rs +++ b/tvm_vm/src/executor/null.rs @@ -9,12 +9,12 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use crate::executor::engine::storage::fetch_stack; +use crate::executor::Mask; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; -use crate::executor::Mask; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Status; pub(super) fn execute_null(engine: &mut Engine) -> Status { diff --git a/tvm_vm/src/executor/rand.rs b/tvm_vm/src/executor/rand.rs index af7c4e7b6..52af01bba 100644 --- a/tvm_vm/src/executor/rand.rs +++ b/tvm_vm/src/executor/rand.rs @@ -9,18 +9,18 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::sha512_digest; use tvm_types::Sha256; +use tvm_types::sha512_digest; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::Signaling; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; -use crate::stack::StackItem; use crate::types::Status; // (x - ) diff --git a/tvm_vm/src/executor/serialization.rs b/tvm_vm/src/executor/serialization.rs index 5eefc2fd9..329dd1dc6 100644 --- a/tvm_vm/src/executor/serialization.rs +++ b/tvm_vm/src/executor/serialization.rs @@ -9,20 +9,21 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::CellType; use tvm_types::ExceptionCode; use tvm_types::GasConsumer; use tvm_types::IBitstring; -use tvm_types::Result; use tvm_types::MAX_LEVEL; +use tvm_types::Result; +use tvm_types::error; use crate::error::TvmError; +use crate::executor::Mask; +use crate::executor::engine::Engine; use crate::executor::engine::data::convert; use crate::executor::engine::storage::fetch_reference; use crate::executor::engine::storage::fetch_stack; -use crate::executor::engine::Engine; use crate::executor::gas::gas_state::Gas; use crate::executor::microcode::BUILDER; use crate::executor::microcode::CC; @@ -30,14 +31,13 @@ use crate::executor::microcode::CELL; use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; -use crate::executor::Mask; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::SignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::SignedIntegerLittleEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerLittleEndianEncoding; -use crate::stack::integer::IntegerData; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/slice_comparison.rs b/tvm_vm/src/executor/slice_comparison.rs index 4881526ba..2f07ca0c0 100644 --- a/tvm_vm/src/executor/slice_comparison.rs +++ b/tvm_vm/src/executor/slice_comparison.rs @@ -11,11 +11,11 @@ use tvm_types::SliceData; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Status; fn unary(engine: &mut Engine, name: &'static str, operation: F) -> Status @@ -90,11 +90,7 @@ pub(super) fn execute_sdlexcmp(engine: &mut Engine) -> Status { int!(if r_s0.is_none() && r_s1.is_none() { 0 } else if r_s0.is_some() && r_s1.is_some() { - if r_s1.unwrap().get_next_bit().unwrap() { - 1 - } else { - -1 - } + if r_s1.unwrap().get_next_bit().unwrap() { 1 } else { -1 } } else if r_s1.is_some() { 1 } else { diff --git a/tvm_vm/src/executor/stack.rs b/tvm_vm/src/executor/stack.rs index 02786b1f0..980e4076f 100644 --- a/tvm_vm/src/executor/stack.rs +++ b/tvm_vm/src/executor/stack.rs @@ -17,12 +17,12 @@ use tvm_types::fail; use tvm_types::types::ExceptionCode; use crate::error::TvmError; +use crate::executor::engine::Engine; use crate::executor::engine::data::convert; use crate::executor::engine::storage::copy_to_var; use crate::executor::engine::storage::fetch_reference; use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::storage::swap; -use crate::executor::engine::Engine; use crate::executor::microcode::CC; use crate::executor::microcode::CELL; use crate::executor::microcode::CONTINUATION; @@ -33,11 +33,11 @@ use crate::executor::microcode::VAR; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; use crate::executor::types::WhereToGetParams; +use crate::stack::StackItem; use crate::stack::continuation::ContinuationData; -use crate::stack::integer::behavior::Signaling; use crate::stack::integer::IntegerData; +use crate::stack::integer::behavior::Signaling; use crate::stack::savelist::SaveList; -use crate::stack::StackItem; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/token.rs b/tvm_vm/src/executor/token.rs index c0da9e6b1..7cc31efaa 100644 --- a/tvm_vm/src/executor/token.rs +++ b/tvm_vm/src/executor/token.rs @@ -1,17 +1,17 @@ +use tvm_block::ACTION_CNVRTSHELLQ; +use tvm_block::ACTION_MINT_SHELL_TOKEN; +use tvm_block::ACTION_MINTECC; use tvm_block::ExtraCurrencyCollection; use tvm_block::Serializable; use tvm_block::VarUInteger32; -use tvm_block::ACTION_CNVRTSHELLQ; -use tvm_block::ACTION_MINTECC; -use tvm_block::ACTION_MINT_SHELL_TOKEN; use tvm_types::BuilderData; use crate::executor::blockchain::add_action; -use crate::executor::engine::storage::fetch_stack; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::types::Instruction; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Status; pub const ECC_NACKL_KEY: u32 = 1; diff --git a/tvm_vm/src/executor/tuple.rs b/tvm_vm/src/executor/tuple.rs index 9d3c8a253..431f36810 100644 --- a/tvm_vm/src/executor/tuple.rs +++ b/tvm_vm/src/executor/tuple.rs @@ -10,20 +10,20 @@ // limitations under the License. use tvm_block::GlobalCapabilities; +use tvm_types::ExceptionCode; use tvm_types::error; use tvm_types::fail; -use tvm_types::ExceptionCode; use crate::error::TvmError; -use crate::executor::engine::storage::fetch_stack; +use crate::executor::Mask; use crate::executor::engine::Engine; +use crate::executor::engine::storage::fetch_stack; use crate::executor::gas::gas_state::Gas; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; use crate::executor::types::WhereToGetParams; -use crate::executor::Mask; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::types::Exception; use crate::types::Status; diff --git a/tvm_vm/src/executor/types.rs b/tvm_vm/src/executor/types.rs index 2dcff5bd4..f5502c497 100644 --- a/tvm_vm/src/executor/types.rs +++ b/tvm_vm/src/executor/types.rs @@ -12,13 +12,13 @@ use std::fmt; use std::ops::Range; -use tvm_types::error; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; use crate::executor::math::DivMode; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; macro_rules! param { ($self:ident, $id:ident) => {{ @@ -331,11 +331,7 @@ impl InstructionExt { Some(InstructionOptions::ControlRegister) => format!(" c{}", self.creg_raw()?), Some(InstructionOptions::DivisionMode) => { let mode = self.division_mode(); - if mode.shift_parameter() { - format!(" {}", self.length()) - } else { - String::new() - } + if mode.shift_parameter() { format!(" {}", self.length()) } else { String::new() } } Some(InstructionOptions::Integer(_)) => format!(" {}", self.integer_raw()?), Some(InstructionOptions::Length(_)) | Some(InstructionOptions::LengthMinusOne(_)) => { diff --git a/tvm_vm/src/executor/zk.rs b/tvm_vm/src/executor/zk.rs index 6f635bf22..fcc5c785b 100644 --- a/tvm_vm/src/executor/zk.rs +++ b/tvm_vm/src/executor/zk.rs @@ -24,21 +24,21 @@ use serde::Deserialize; use serde::Serialize; use tvm_types::SliceData; +use crate::executor::Engine; use crate::executor::engine::storage::fetch_stack; use crate::executor::zk_stuff::bn254::poseidon::poseidon_zk_login; use crate::executor::zk_stuff::curve_utils::Bn254FrElement; use crate::executor::zk_stuff::error::ZkCryptoError; use crate::executor::zk_stuff::utils::split_to_two_frs; -use crate::executor::zk_stuff::zk_login::hash_ascii_str_to_field; -use crate::executor::zk_stuff::zk_login::hash_to_field; use crate::executor::zk_stuff::zk_login::MAX_HEADER_LEN; use crate::executor::zk_stuff::zk_login::MAX_ISS_LEN_B64; use crate::executor::zk_stuff::zk_login::PACK_WIDTH; -use crate::executor::Engine; -use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; +use crate::executor::zk_stuff::zk_login::hash_ascii_str_to_field; +use crate::executor::zk_stuff::zk_login::hash_to_field; use crate::stack::StackItem; use crate::stack::StackItem::Cell; +use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; use crate::types::Status; use crate::utils::pack_data_to_cell; use crate::utils::unpack_data_from_cell; @@ -148,11 +148,7 @@ impl Bn254FrElementWrapper { } // If the value is '0' then just return a slice of length 1 of the final byte - if buf.is_empty() { - &self.0[31..] - } else { - buf - } + if buf.is_empty() { &self.0[31..] } else { buf } } /// Returns the padded version of the field element. This returns with diff --git a/tvm_vm/src/executor/zk_stuff/bn254/api.rs b/tvm_vm/src/executor/zk_stuff/bn254/api.rs index 1bf3cb0e7..a1b9d45ca 100644 --- a/tvm_vm/src/executor/zk_stuff/bn254/api.rs +++ b/tvm_vm/src/executor/zk_stuff/bn254/api.rs @@ -1,7 +1,7 @@ -use crate::executor::zk_stuff::bn254::verifier::PreparedVerifyingKey; use crate::executor::zk_stuff::bn254::FieldElement; use crate::executor::zk_stuff::bn254::Proof; use crate::executor::zk_stuff::bn254::VerifyingKey; +use crate::executor::zk_stuff::bn254::verifier::PreparedVerifyingKey; use crate::executor::zk_stuff::error::ZkCryptoError; /// Size of scalars in the BN254 construction. diff --git a/tvm_vm/src/executor/zk_stuff/bn254/poseidon/constants.rs b/tvm_vm/src/executor/zk_stuff/bn254/poseidon/constants.rs index aa0ea67f9..3cc61eedd 100644 --- a/tvm_vm/src/executor/zk_stuff/bn254/poseidon/constants.rs +++ b/tvm_vm/src/executor/zk_stuff/bn254/poseidon/constants.rs @@ -1,17 +1,9 @@ use ff::PrimeField; +use neptune::Strength; use neptune::hash_type::HashType; use neptune::poseidon::PoseidonConstants; -use neptune::Strength; use once_cell::sync::Lazy; -use typenum::Unsigned; use typenum::U1; -use typenum::U10; -use typenum::U11; -use typenum::U12; -use typenum::U13; -use typenum::U14; -use typenum::U15; -use typenum::U16; use typenum::U2; use typenum::U3; use typenum::U4; @@ -20,6 +12,14 @@ use typenum::U6; use typenum::U7; use typenum::U8; use typenum::U9; +use typenum::U10; +use typenum::U11; +use typenum::U12; +use typenum::U13; +use typenum::U14; +use typenum::U15; +use typenum::U16; +use typenum::Unsigned; use crate::executor::zk_stuff::Fr; diff --git a/tvm_vm/src/executor/zk_stuff/bn254/poseidon/mod.rs b/tvm_vm/src/executor/zk_stuff/bn254/poseidon/mod.rs index 8433682bb..b2c517a70 100644 --- a/tvm_vm/src/executor/zk_stuff/bn254/poseidon/mod.rs +++ b/tvm_vm/src/executor/zk_stuff/bn254/poseidon/mod.rs @@ -5,15 +5,15 @@ use ark_ff::BigInteger; use ark_ff::PrimeField; use byte_slice_cast::AsByteSlice; use ff::PrimeField as OtherPrimeField; -use neptune::poseidon::HashMode::OptimizedStatic; use neptune::Poseidon; +use neptune::poseidon::HashMode::OptimizedStatic; +use crate::executor::zk_stuff::FrRepr; use crate::executor::zk_stuff::bn254::poseidon::constants::*; use crate::executor::zk_stuff::error::ZkCryptoError; use crate::executor::zk_stuff::error::ZkCryptoError::InputTooLong; use crate::executor::zk_stuff::error::ZkCryptoError::InvalidInput; use crate::executor::zk_stuff::error::ZkCryptoResult; -use crate::executor::zk_stuff::FrRepr; /// The output of the Poseidon hash function is a field element in BN254 which /// is 254 bits long, so we need 32 bytes to represent it as an integer. diff --git a/tvm_vm/src/executor/zk_stuff/bn254/verifier.rs b/tvm_vm/src/executor/zk_stuff/bn254/verifier.rs index 84f0fad76..912bbec7b 100644 --- a/tvm_vm/src/executor/zk_stuff/bn254/verifier.rs +++ b/tvm_vm/src/executor/zk_stuff/bn254/verifier.rs @@ -14,10 +14,10 @@ use ark_serialize::CanonicalDeserialize; use ark_serialize::CanonicalSerialize; use ark_snark::SNARK; -use crate::executor::zk_stuff::bn254::api::SCALAR_SIZE; use crate::executor::zk_stuff::bn254::FieldElement; use crate::executor::zk_stuff::bn254::Proof; use crate::executor::zk_stuff::bn254::VerifyingKey; +use crate::executor::zk_stuff::bn254::api::SCALAR_SIZE; use crate::executor::zk_stuff::error::ZkCryptoError; use crate::executor::zk_stuff::error::ZkCryptoResult; diff --git a/tvm_vm/src/executor/zk_stuff/curve_utils.rs b/tvm_vm/src/executor/zk_stuff/curve_utils.rs index ac30be9cc..75f55244a 100644 --- a/tvm_vm/src/executor/zk_stuff/curve_utils.rs +++ b/tvm_vm/src/executor/zk_stuff/curve_utils.rs @@ -80,11 +80,7 @@ impl Bn254FrElement { } // If the value is '0' then just return a slice of length 1 of the final byte - if buf.is_empty() { - &self.0[31..] - } else { - buf - } + if buf.is_empty() { &self.0[31..] } else { buf } } /// Returns the padded version of the field element. This returns with diff --git a/tvm_vm/src/executor/zk_stuff/zk_login.rs b/tvm_vm/src/executor/zk_stuff/zk_login.rs index 23c393186..6e477d7c3 100644 --- a/tvm_vm/src/executor/zk_stuff/zk_login.rs +++ b/tvm_vm/src/executor/zk_stuff/zk_login.rs @@ -19,11 +19,11 @@ use serde_json::Value; use super::utils::split_to_two_frs; use crate::executor::zk_stuff::bn254::poseidon::poseidon_zk_login; -use crate::executor::zk_stuff::curve_utils::g1_affine_from_str_projective; -use crate::executor::zk_stuff::curve_utils::g2_affine_from_str_projective; use crate::executor::zk_stuff::curve_utils::Bn254FrElement; use crate::executor::zk_stuff::curve_utils::CircomG1; use crate::executor::zk_stuff::curve_utils::CircomG2; +use crate::executor::zk_stuff::curve_utils::g1_affine_from_str_projective; +use crate::executor::zk_stuff::curve_utils::g2_affine_from_str_projective; use crate::executor::zk_stuff::error::ZkCryptoError; use crate::executor::zk_stuff::error::ZkCryptoResult; use crate::executor::zk_stuff::jwt_utils::JWTHeader; diff --git a/tvm_vm/src/smart_contract_info.rs b/tvm_vm/src/smart_contract_info.rs index 298eb64e5..679060e2a 100644 --- a/tvm_vm/src/smart_contract_info.rs +++ b/tvm_vm/src/smart_contract_info.rs @@ -11,15 +11,15 @@ use tvm_block::CurrencyCollection; use tvm_block::GlobalCapabilities; -use tvm_types::types::UInt256; use tvm_types::Cell; use tvm_types::HashmapE; use tvm_types::HashmapType; use tvm_types::Sha256; use tvm_types::SliceData; +use tvm_types::types::UInt256; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; // The smart-contract information // structure SmartContractInfo, passed in the first reference of the cell diff --git a/tvm_vm/src/stack/continuation.rs b/tvm_vm/src/stack/continuation.rs index 917f56969..236469a9f 100644 --- a/tvm_vm/src/stack/continuation.rs +++ b/tvm_vm/src/stack/continuation.rs @@ -12,7 +12,6 @@ use std::fmt; use std::mem; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::ExceptionCode; @@ -21,19 +20,20 @@ use tvm_types::HashmapE; use tvm_types::HashmapType; use tvm_types::IBitstring; use tvm_types::Result; +use tvm_types::error; +use super::DeserializeItem; use super::items_deserialize; use super::items_serialize; use super::prepare_cont_serialize_vars; use super::slice_deserialize; use super::slice_serialize; -use super::DeserializeItem; use crate::error::TvmError; use crate::executor::gas::gas_state::Gas; -use crate::stack::savelist::SaveList; use crate::stack::SliceData; use crate::stack::Stack; use crate::stack::StackItem; +use crate::stack::savelist::SaveList; use crate::types::Exception; use crate::types::ResultOpt; diff --git a/tvm_vm/src/stack/integer/behavior.rs b/tvm_vm/src/stack/integer/behavior.rs index c5b2dfe37..4c2617214 100644 --- a/tvm_vm/src/stack/integer/behavior.rs +++ b/tvm_vm/src/stack/integer/behavior.rs @@ -29,23 +29,17 @@ pub struct Quiet {} #[macro_export] macro_rules! on_integer_overflow { - ($T:ident) => {{ - $T::on_integer_overflow(file!(), line!()) - }}; + ($T:ident) => {{ $T::on_integer_overflow(file!(), line!()) }}; } #[macro_export] macro_rules! on_nan_parameter { - ($T:ident) => {{ - $T::on_nan_parameter(file!(), line!()) - }}; + ($T:ident) => {{ $T::on_nan_parameter(file!(), line!()) }}; } #[macro_export] macro_rules! on_range_check_error { - ($T:ident) => {{ - $T::on_range_check_error(file!(), line!()) - }}; + ($T:ident) => {{ $T::on_range_check_error(file!(), line!()) }}; } impl OperationBehavior for Signaling { diff --git a/tvm_vm/src/stack/integer/bitlogics.rs b/tvm_vm/src/stack/integer/bitlogics.rs index 6329e2e86..ef411c2b2 100644 --- a/tvm_vm/src/stack/integer/bitlogics.rs +++ b/tvm_vm/src/stack/integer/bitlogics.rs @@ -11,12 +11,12 @@ use tvm_types::Result; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::OperationBehavior; use crate::stack::integer::utils::binary_op; use crate::stack::integer::utils::construct_single_nan; use crate::stack::integer::utils::process_single_result; use crate::stack::integer::utils::unary_op; -use crate::stack::integer::IntegerData; impl IntegerData { pub fn and(&self, other: &IntegerData) -> Result diff --git a/tvm_vm/src/stack/integer/conversion.rs b/tvm_vm/src/stack/integer/conversion.rs index 6e2ea649d..9d960eb81 100644 --- a/tvm_vm/src/stack/integer/conversion.rs +++ b/tvm_vm/src/stack/integer/conversion.rs @@ -12,16 +12,16 @@ use std::ops::RangeInclusive; use num_traits::Num; +use tvm_types::Result; use tvm_types::error; use tvm_types::types::ExceptionCode; -use tvm_types::Result; use crate::error::TvmError; -use crate::stack::integer::utils::check_overflow; -use crate::stack::integer::utils::twos_complement; use crate::stack::integer::Int; use crate::stack::integer::IntegerData; use crate::stack::integer::IntegerValue; +use crate::stack::integer::utils::check_overflow; +use crate::stack::integer::utils::twos_complement; use crate::types::Exception; impl IntegerData { diff --git a/tvm_vm/src/stack/integer/math.rs b/tvm_vm/src/stack/integer/math.rs index d598df743..941b9c46d 100644 --- a/tvm_vm/src/stack/integer/math.rs +++ b/tvm_vm/src/stack/integer/math.rs @@ -15,6 +15,8 @@ use num_traits::Zero; use tvm_types::Result; use tvm_types::Status; +use crate::stack::integer::IntegerData; +use crate::stack::integer::IntegerValue; use crate::stack::integer::behavior::OperationBehavior; use crate::stack::integer::utils::binary_op; use crate::stack::integer::utils::construct_double_nan; @@ -22,8 +24,6 @@ use crate::stack::integer::utils::construct_single_nan; use crate::stack::integer::utils::process_double_result; use crate::stack::integer::utils::process_single_result; use crate::stack::integer::utils::unary_op; -use crate::stack::integer::IntegerData; -use crate::stack::integer::IntegerValue; // [x / y] -> (q, r) : q*y + r = x : |r| < |y| #[derive(Copy, Clone, Eq, PartialEq)] @@ -179,8 +179,8 @@ pub mod utils { use num_traits::Signed; use num_traits::Zero; - use crate::stack::integer::math::Round; use crate::stack::integer::Int; + use crate::stack::integer::math::Round; #[inline] pub fn divmod(dividend: &Int, divisor: &Int, rounding: Round) -> (Int, Int) { diff --git a/tvm_vm/src/stack/integer/mod.rs b/tvm_vm/src/stack/integer/mod.rs index bebb373fb..da279c6ef 100644 --- a/tvm_vm/src/stack/integer/mod.rs +++ b/tvm_vm/src/stack/integer/mod.rs @@ -16,11 +16,11 @@ use std::cmp::Ordering; use num_traits::One; use num_traits::Signed; use num_traits::Zero; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; use crate::error::TvmError; use crate::stack::integer::behavior::OperationBehavior; diff --git a/tvm_vm/src/stack/integer/serialization/common.rs b/tvm_vm/src/stack/integer/serialization/common.rs index 8cd2f5e62..e7d1ea2ec 100644 --- a/tvm_vm/src/stack/integer/serialization/common.rs +++ b/tvm_vm/src/stack/integer/serialization/common.rs @@ -23,11 +23,7 @@ pub fn calc_excess_bits(length_in_bits: usize) -> usize { #[inline] fn get_fill(is_negative: bool) -> u8 { - if is_negative { - 0xFF - } else { - 0 - } + if is_negative { 0xFF } else { 0 } } /// Extends buffer, if needed (big-endian). diff --git a/tvm_vm/src/stack/integer/serialization/signed_big_endian.rs b/tvm_vm/src/stack/integer/serialization/signed_big_endian.rs index 3370619ea..534d757ab 100644 --- a/tvm_vm/src/stack/integer/serialization/signed_big_endian.rs +++ b/tvm_vm/src/stack/integer/serialization/signed_big_endian.rs @@ -11,16 +11,16 @@ use num::bigint::ToBigInt; use num_traits::Signed; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::Result; +use tvm_types::error; use crate::error::TvmError; +use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::common::calc_excess_bits; use crate::stack::integer::serialization::common::extend_buffer_be; -use crate::stack::integer::serialization::Encoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; use crate::stack::serialization::Serializer; use crate::types::Exception; diff --git a/tvm_vm/src/stack/integer/serialization/signed_little_endian.rs b/tvm_vm/src/stack/integer/serialization/signed_little_endian.rs index 1e419922a..996a9af28 100644 --- a/tvm_vm/src/stack/integer/serialization/signed_little_endian.rs +++ b/tvm_vm/src/stack/integer/serialization/signed_little_endian.rs @@ -9,17 +9,17 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use num::bigint::ToBigInt; use num::Signed; -use tvm_types::error; +use num::bigint::ToBigInt; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::Result; +use tvm_types::error; use crate::error::TvmError; -use crate::stack::integer::serialization::common::extend_buffer_le; -use crate::stack::integer::serialization::Encoding; use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::Encoding; +use crate::stack::integer::serialization::common::extend_buffer_le; use crate::stack::serialization::Deserializer; use crate::stack::serialization::Serializer; use crate::types::Exception; diff --git a/tvm_vm/src/stack/integer/serialization/tests/test_integer_encoding.rs b/tvm_vm/src/stack/integer/serialization/tests/test_integer_encoding.rs index 3cf665000..ac10eee24 100644 --- a/tvm_vm/src/stack/integer/serialization/tests/test_integer_encoding.rs +++ b/tvm_vm/src/stack/integer/serialization/tests/test_integer_encoding.rs @@ -9,13 +9,13 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. +use crate::stack::BuilderData; +use crate::stack::SliceData; +use crate::stack::integer::IntegerData; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::SignedIntegerBigEndianEncoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; use crate::stack::serialization::Serializer; -use crate::stack::BuilderData; -use crate::stack::SliceData; #[test] fn encoding_one_positive_byte() { diff --git a/tvm_vm/src/stack/integer/serialization/tests/test_ser_deser.rs b/tvm_vm/src/stack/integer/serialization/tests/test_ser_deser.rs index c8aa0943d..6849b671c 100644 --- a/tvm_vm/src/stack/integer/serialization/tests/test_ser_deser.rs +++ b/tvm_vm/src/stack/integer/serialization/tests/test_ser_deser.rs @@ -9,13 +9,13 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. +use crate::stack::SliceData; +use crate::stack::integer::IntegerData; use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::SignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::SignedIntegerLittleEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerBigEndianEncoding; use crate::stack::integer::serialization::UnsignedIntegerLittleEndianEncoding; -use crate::stack::integer::IntegerData; -use crate::stack::SliceData; #[test] fn test_signed_big_endian_ser_deser() { diff --git a/tvm_vm/src/stack/integer/serialization/unsigned_big_endian.rs b/tvm_vm/src/stack/integer/serialization/unsigned_big_endian.rs index dede7074f..c07872720 100644 --- a/tvm_vm/src/stack/integer/serialization/unsigned_big_endian.rs +++ b/tvm_vm/src/stack/integer/serialization/unsigned_big_endian.rs @@ -9,18 +9,18 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; use tvm_types::ExceptionCode; use tvm_types::Result; +use tvm_types::error; use crate::error::TvmError; +use crate::stack::BuilderData; +use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::Encoding; use crate::stack::integer::serialization::common::calc_excess_bits; use crate::stack::integer::serialization::common::extend_buffer_be; -use crate::stack::integer::serialization::Encoding; -use crate::stack::integer::IntegerData; use crate::stack::serialization::Deserializer; use crate::stack::serialization::Serializer; -use crate::stack::BuilderData; use crate::types::Exception; pub struct UnsignedIntegerBigEndianEncoding { diff --git a/tvm_vm/src/stack/integer/serialization/unsigned_little_endian.rs b/tvm_vm/src/stack/integer/serialization/unsigned_little_endian.rs index 21384cb63..2039a5b06 100644 --- a/tvm_vm/src/stack/integer/serialization/unsigned_little_endian.rs +++ b/tvm_vm/src/stack/integer/serialization/unsigned_little_endian.rs @@ -9,15 +9,15 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::Result; +use tvm_types::error; use crate::error::TvmError; -use crate::stack::integer::serialization::common::bits_to_bytes; -use crate::stack::integer::serialization::Encoding; use crate::stack::integer::IntegerData; +use crate::stack::integer::serialization::Encoding; +use crate::stack::integer::serialization::common::bits_to_bytes; use crate::stack::serialization::Deserializer; use crate::stack::serialization::Serializer; use crate::types::Exception; diff --git a/tvm_vm/src/stack/integer/tests/test_integer.rs b/tvm_vm/src/stack/integer/tests/test_integer.rs index e59fe5697..0e2a5eaf8 100644 --- a/tvm_vm/src/stack/integer/tests/test_integer.rs +++ b/tvm_vm/src/stack/integer/tests/test_integer.rs @@ -81,11 +81,11 @@ mod test_bitsize { mod test_minus_2_pow_256 { - use tvm_types::types::ExceptionCode; use tvm_types::Result; + use tvm_types::types::ExceptionCode; - use crate::stack::integer::behavior::Signaling; use crate::stack::integer::IntegerData; + use crate::stack::integer::behavior::Signaling; #[test] fn test_2_pow_256_overflows() { @@ -146,9 +146,9 @@ mod test_minus_2_pow_256 { mod test_behavior { + use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::Quiet; use crate::stack::integer::behavior::Signaling; - use crate::stack::integer::IntegerData; #[test] fn add_quiet_vs_signaling() { @@ -166,8 +166,8 @@ mod test_behavior { mod test_bitlogics { - use crate::stack::integer::behavior::Signaling; use crate::stack::integer::IntegerData; + use crate::stack::integer::behavior::Signaling; fn test_and(x: i64, y: i64) { let xdst = IntegerData::from_i64(x); diff --git a/tvm_vm/src/stack/mod.rs b/tvm_vm/src/stack/mod.rs index cad0c6b82..16dabecc4 100644 --- a/tvm_vm/src/stack/mod.rs +++ b/tvm_vm/src/stack/mod.rs @@ -19,7 +19,6 @@ use std::sync::Arc; use integer::serialization::Encoding; use integer::serialization::SignedIntegerBigEndianEncoding; use serialization::Deserializer; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::CellType; @@ -28,10 +27,11 @@ use tvm_types::GasConsumer; use tvm_types::HashmapE; use tvm_types::HashmapType; use tvm_types::IBitstring; -use tvm_types::Result; -use tvm_types::SliceData; use tvm_types::MAX_DATA_BITS; use tvm_types::MAX_REFERENCES_COUNT; +use tvm_types::Result; +use tvm_types::SliceData; +use tvm_types::error; use self::continuation::ContinuationData; use self::integer::IntegerData; @@ -70,11 +70,7 @@ macro_rules! int { #[macro_export] macro_rules! boolean { ($val:expr) => { - if $val { - int!(-1) - } else { - int!(0) - } + if $val { int!(-1) } else { int!(0) } }; } @@ -616,11 +612,7 @@ impl StackItem { }; let d2 = |bits: u32| { let res = ((bits / 8) * 2) as u8; - if bits & 7 != 0 { - res + 1 - } else { - res - } + if bits & 7 != 0 { res + 1 } else { res } }; let start = data.pos(); let end = start + data.remaining_bits(); diff --git a/tvm_vm/src/stack/savelist.rs b/tvm_vm/src/stack/savelist.rs index c7eeea0c0..0a579a447 100644 --- a/tvm_vm/src/stack/savelist.rs +++ b/tvm_vm/src/stack/savelist.rs @@ -11,7 +11,6 @@ use std::fmt; -use tvm_types::error; use tvm_types::BuilderData; use tvm_types::ExceptionCode; use tvm_types::HashmapE; @@ -19,6 +18,7 @@ use tvm_types::HashmapType; use tvm_types::IBitstring; use tvm_types::Result; use tvm_types::SliceData; +use tvm_types::error; use crate::error::TvmError; use crate::executor::gas::gas_state::Gas; @@ -42,11 +42,7 @@ impl SaveList { pub const REGS: [usize; Self::NUMREGS] = [0, 1, 2, 3, 4, 5, 7]; const fn adjust(index: usize) -> usize { - if index == 7 { - 6 - } else { - index - } + if index == 7 { 6 } else { index } } pub fn new() -> Self { diff --git a/tvm_vm/src/tests/test_dump.rs b/tvm_vm/src/tests/test_dump.rs index aa1ae66d2..0a8ebe993 100644 --- a/tvm_vm/src/tests/test_dump.rs +++ b/tvm_vm/src/tests/test_dump.rs @@ -12,6 +12,9 @@ use tvm_types::BuilderData; use tvm_types::SliceData; +use crate::executor::dump::BIN; +use crate::executor::dump::HEX; +use crate::executor::dump::STR; use crate::executor::dump::dump_var; use crate::executor::dump::execute_dump_bin; use crate::executor::dump::execute_dump_hex; @@ -22,13 +25,10 @@ use crate::executor::dump::execute_dump_string; use crate::executor::dump::execute_print_bin; use crate::executor::dump::execute_print_hex; use crate::executor::dump::execute_print_str; -use crate::executor::dump::BIN; -use crate::executor::dump::HEX; -use crate::executor::dump::STR; use crate::executor::engine::Engine; -use crate::stack::integer::IntegerData; use crate::stack::Stack; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; #[test] fn test_dump_var() { diff --git a/tvm_vm/src/tests/test_executor.rs b/tvm_vm/src/tests/test_executor.rs index 1cd7dfac2..c71b2df1f 100644 --- a/tvm_vm/src/tests/test_executor.rs +++ b/tvm_vm/src/tests/test_executor.rs @@ -20,12 +20,12 @@ use crate::executor::math::DivMode; use crate::executor::serialize_currency_collection; use crate::executor::types::Instruction; use crate::executor::types::InstructionOptions; +use crate::stack::Stack; +use crate::stack::StackItem; +use crate::stack::integer::IntegerData; use crate::stack::integer::behavior::OperationBehavior; use crate::stack::integer::behavior::Quiet; use crate::stack::integer::behavior::Signaling; -use crate::stack::integer::IntegerData; -use crate::stack::Stack; -use crate::stack::StackItem; use crate::types::Status; #[test] diff --git a/tvm_vm/src/tests/test_microfunctions.rs b/tvm_vm/src/tests/test_microfunctions.rs index 296268369..e61e8263a 100644 --- a/tvm_vm/src/tests/test_microfunctions.rs +++ b/tvm_vm/src/tests/test_microfunctions.rs @@ -10,17 +10,17 @@ // limitations under the License. use tvm_block::GlobalCapabilities; -use tvm_types::types::ExceptionCode; use tvm_types::Cell; use tvm_types::SliceData; +use tvm_types::types::ExceptionCode; +use crate::executor::Engine; use crate::executor::engine::storage::swap; use crate::executor::microcode::CTRL; use crate::executor::microcode::SAVELIST; use crate::executor::microcode::VAR; -use crate::executor::Engine; -use crate::stack::continuation::ContinuationData; use crate::stack::StackItem; +use crate::stack::continuation::ContinuationData; #[test] fn test_swap_with_any() { diff --git a/tvm_vm/src/types.rs b/tvm_vm/src/types.rs index 59bec2f3d..88add43bb 100644 --- a/tvm_vm/src/types.rs +++ b/tvm_vm/src/types.rs @@ -11,11 +11,11 @@ use std::fmt; -use tvm_types::types::ExceptionCode; use tvm_types::Result; +use tvm_types::types::ExceptionCode; -use crate::stack::integer::IntegerData; use crate::stack::StackItem; +use crate::stack::integer::IntegerData; #[derive(Clone, PartialEq)] enum ExceptionType { @@ -36,19 +36,11 @@ impl ExceptionType { } fn exception_code(&self) -> Option { - if let ExceptionType::System(code) = self { - Some(*code) - } else { - None - } + if let ExceptionType::System(code) = self { Some(*code) } else { None } } fn custom_code(&self) -> Option { - if let ExceptionType::Custom(code) = self { - Some(*code) - } else { - None - } + if let ExceptionType::Custom(code) = self { Some(*code) } else { None } } pub fn exception_or_custom_code(&self) -> i32 { diff --git a/tvm_vm/src/utils.rs b/tvm_vm/src/utils.rs index 73e7c2e3c..ff72698a4 100644 --- a/tvm_vm/src/utils.rs +++ b/tvm_vm/src/utils.rs @@ -9,15 +9,15 @@ // See the License for the specific TON DEV software governing permissions and // limitations under the License. -use tvm_types::error; -use tvm_types::fail; use tvm_types::BuilderData; use tvm_types::Cell; use tvm_types::ExceptionCode; use tvm_types::GasConsumer; +use tvm_types::MAX_DATA_BITS; use tvm_types::Result; use tvm_types::SliceData; -use tvm_types::MAX_DATA_BITS; +use tvm_types::error; +use tvm_types::fail; use crate::error::TvmError; use crate::types::Exception;