From d4f9875a93bf0a85041a1568112dee016932ce08 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Mon, 19 Aug 2024 07:41:32 +0200 Subject: [PATCH] tari_max_size crate --- Cargo.lock | 19 +++++++++++++++++++ applications/minotari_app_grpc/Cargo.toml | 1 + .../src/conversions/sidechain_feature.rs | 6 ++---- .../minotari_console_wallet/Cargo.toml | 1 + .../src/ui/state/tasks.rs | 3 +-- .../minotari_merge_mining_proxy/Cargo.toml | 1 + .../src/block_template_protocol.rs | 3 ++- .../minotari_merge_mining_proxy/src/error.rs | 2 +- applications/minotari_miner/Cargo.toml | 1 + applications/minotari_miner/src/errors.rs | 2 +- .../minotari_miner/src/stratum/error.rs | 2 +- .../stratum/stratum_controller/controller.rs | 2 +- base_layer/common_types/src/lib.rs | 9 --------- base_layer/contacts/Cargo.toml | 1 + .../contacts/src/chat_client/Cargo.toml | 1 + .../contacts/src/chat_client/src/error.rs | 2 +- .../contacts/src/contacts_service/error.rs | 2 +- .../contacts_service/types/confirmation.rs | 2 +- .../src/contacts_service/types/message.rs | 3 ++- base_layer/core/Cargo.toml | 1 + base_layer/core/src/common/mod.rs | 2 +- base_layer/core/src/covenants/arguments.rs | 6 ++---- base_layer/core/src/covenants/covenant.rs | 2 +- base_layer/core/src/covenants/error.rs | 2 +- .../core/src/proof_of_work/proof_of_work.rs | 2 +- .../core/src/proto/sidechain_feature.rs | 6 ++---- .../transaction_components/encrypted_data.rs | 2 +- .../transaction_components/output_features.rs | 7 ++----- .../side_chain/template_registration.rs | 7 ++----- base_layer/wallet/Cargo.toml | 1 + .../wallet/src/transaction_service/handle.rs | 3 +-- infrastructure/max_size/Cargo.toml | 18 ++++++++++++++++++ infrastructure/max_size/README.md | 14 ++++++++++++++ .../max_size/src}/bytes.rs | 0 .../max_size/src/lib.rs | 0 .../max_size/src}/string.rs | 0 .../max_size/src}/vec.rs | 0 infrastructure/tari_script/Cargo.toml | 1 + infrastructure/tari_script/src/script.rs | 3 +++ 39 files changed, 91 insertions(+), 49 deletions(-) create mode 100644 infrastructure/max_size/Cargo.toml create mode 100644 infrastructure/max_size/README.md rename {base_layer/common_types/src/max_size => infrastructure/max_size/src}/bytes.rs (100%) rename base_layer/common_types/src/max_size/mod.rs => infrastructure/max_size/src/lib.rs (100%) rename {base_layer/common_types/src/max_size => infrastructure/max_size/src}/string.rs (100%) rename {base_layer/common_types/src/max_size => infrastructure/max_size/src}/vec.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index bae53370dcd..2c1de588f72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3241,6 +3241,7 @@ dependencies = [ "tari_core", "tari_crypto", "tari_features", + "tari_max_size", "tari_script", "tari_utilities", "thiserror", @@ -3337,6 +3338,7 @@ dependencies = [ "tari_hashing", "tari_key_manager", "tari_libtor", + "tari_max_size", "tari_p2p", "tari_script", "tari_shutdown", @@ -3414,6 +3416,7 @@ dependencies = [ "tari_core", "tari_features", "tari_key_manager", + "tari_max_size", "tari_utilities", "thiserror", "tokio", @@ -3452,6 +3455,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", + "tari_max_size", "tari_utilities", "thiserror", "tokio", @@ -3571,6 +3575,7 @@ dependencies = [ "tari_core", "tari_crypto", "tari_key_manager", + "tari_max_size", "tari_p2p", "tari_script", "tari_service_framework", @@ -5969,6 +5974,7 @@ dependencies = [ "tari_comms", "tari_comms_dht", "tari_contacts", + "tari_max_size", "tari_p2p", "tari_service_framework", "tari_shutdown", @@ -6169,6 +6175,7 @@ dependencies = [ "tari_comms", "tari_comms_dht", "tari_crypto", + "tari_max_size", "tari_p2p", "tari_service_framework", "tari_shutdown", @@ -6238,6 +6245,7 @@ dependencies = [ "tari_features", "tari_hashing", "tari_key_manager", + "tari_max_size", "tari_metrics", "tari_mmr", "tari_p2p", @@ -6390,6 +6398,16 @@ dependencies = [ "tor-hash-passwd", ] +[[package]] +name = "tari_max_size" +version = "1.2.0-pre.0" +dependencies = [ + "borsh", + "serde", + "tari_utilities", + "thiserror", +] + [[package]] name = "tari_metrics" version = "1.2.0-pre.0" @@ -6472,6 +6490,7 @@ dependencies = [ "sha2 0.10.8", "sha3", "tari_crypto", + "tari_max_size", "tari_utilities", "thiserror", ] diff --git a/applications/minotari_app_grpc/Cargo.toml b/applications/minotari_app_grpc/Cargo.toml index 2da7bc1d679..224c2025284 100644 --- a/applications/minotari_app_grpc/Cargo.toml +++ b/applications/minotari_app_grpc/Cargo.toml @@ -13,6 +13,7 @@ tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core" } tari_crypto = { version = "0.20.3" } tari_script = { path = "../../infrastructure/tari_script" } +tari_max_size = { path = "../../infrastructure/max_size" } tari_utilities = { version = "0.7" } argon2 = { version = "0.4.1", features = ["std", "password-hash"] } diff --git a/applications/minotari_app_grpc/src/conversions/sidechain_feature.rs b/applications/minotari_app_grpc/src/conversions/sidechain_feature.rs index a542b73477f..13a2ec87f9b 100644 --- a/applications/minotari_app_grpc/src/conversions/sidechain_feature.rs +++ b/applications/minotari_app_grpc/src/conversions/sidechain_feature.rs @@ -22,10 +22,7 @@ use std::convert::{TryFrom, TryInto}; -use tari_common_types::{ - types::{PublicKey, Signature}, - MaxSizeString, -}; +use tari_common_types::types::{PublicKey, Signature}; use tari_core::transactions::transaction_components::{ BuildInfo, CodeTemplateRegistration, @@ -35,6 +32,7 @@ use tari_core::transactions::transaction_components::{ ValidatorNodeRegistration, ValidatorNodeSignature, }; +use tari_max_size::MaxSizeString; use tari_utilities::ByteArray; use crate::tari_rpc as grpc; diff --git a/applications/minotari_console_wallet/Cargo.toml b/applications/minotari_console_wallet/Cargo.toml index 8158ed9f741..ab725fededf 100644 --- a/applications/minotari_console_wallet/Cargo.toml +++ b/applications/minotari_console_wallet/Cargo.toml @@ -17,6 +17,7 @@ tari_contacts = { path = "../../base_layer/contacts" } tari_crypto = { version = "0.20.3" } tari_key_manager = { path = "../../base_layer/key_manager" } tari_libtor = { path = "../../infrastructure/libtor", optional = true } +tari_max_size = { path = "../../infrastructure/max_size" } tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } tari_script = { path = "../../infrastructure/tari_script" } tari_shutdown = { path = "../../infrastructure/shutdown" } diff --git a/applications/minotari_console_wallet/src/ui/state/tasks.rs b/applications/minotari_console_wallet/src/ui/state/tasks.rs index 57d056ddcc4..b0fb66f47f2 100644 --- a/applications/minotari_console_wallet/src/ui/state/tasks.rs +++ b/applications/minotari_console_wallet/src/ui/state/tasks.rs @@ -34,8 +34,6 @@ use rand::{random, rngs::OsRng}; use tari_common_types::{ tari_address::TariAddress, types::{PublicKey, Signature}, - MaxSizeBytes, - MaxSizeString, }; use tari_core::{ consensus::DomainSeparatedConsensusHasher, @@ -47,6 +45,7 @@ use tari_core::{ use tari_crypto::{keys::PublicKey as PublicKeyTrait, ristretto::RistrettoPublicKey}; use tari_hashing::TransactionHashDomain; use tari_key_manager::key_manager::KeyManager; +use tari_max_size::{MaxSizeBytes, MaxSizeString}; use tari_utilities::{hex::Hex, ByteArray}; use tokio::sync::{broadcast, watch}; diff --git a/applications/minotari_merge_mining_proxy/Cargo.toml b/applications/minotari_merge_mining_proxy/Cargo.toml index cd70ce9f28b..606f6ca6e69 100644 --- a/applications/minotari_merge_mining_proxy/Cargo.toml +++ b/applications/minotari_merge_mining_proxy/Cargo.toml @@ -20,6 +20,7 @@ tari_common_types = { path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] } +tari_max_size = { path = "../../infrastructure/max_size" } tari_utilities = { version = "0.7" } anyhow = "1.0.53" diff --git a/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs b/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs index 07c1c7526b6..291a4adbdb8 100644 --- a/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs +++ b/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs @@ -26,7 +26,7 @@ use std::{cmp, convert::TryFrom, sync::Arc}; use log::*; use minotari_app_utilities::parse_miner_input::BaseNodeGrpcClient; use minotari_node_grpc_client::grpc; -use tari_common_types::{tari_address::TariAddress, types::FixedHash, MaxSizeBytes}; +use tari_common_types::{tari_address::TariAddress, types::FixedHash}; use tari_core::{ consensus::ConsensusManager, proof_of_work::{monero_rx, monero_rx::FixedByteArray, Difficulty}, @@ -37,6 +37,7 @@ use tari_core::{ }, AuxChainHashes, }; +use tari_max_size::MaxSizeBytes; use tari_utilities::{hex::Hex, ByteArray}; use crate::{ diff --git a/applications/minotari_merge_mining_proxy/src/error.rs b/applications/minotari_merge_mining_proxy/src/error.rs index f17df270322..4aab962b3a2 100644 --- a/applications/minotari_merge_mining_proxy/src/error.rs +++ b/applications/minotari_merge_mining_proxy/src/error.rs @@ -29,13 +29,13 @@ use hyper::header::InvalidHeaderValue; use minotari_app_utilities::parse_miner_input::ParseInputError; use minotari_wallet_grpc_client::BasicAuthError; use tari_common::{ConfigError, ConfigurationError}; -use tari_common_types::{MaxSizeBytesError, MaxSizeVecError}; use tari_core::{ consensus::ConsensusBuilderError, proof_of_work::{monero_rx::MergeMineError, DifficultyError}, transactions::{key_manager::CoreKeyManagerError, CoinbaseBuildError}, }; use tari_key_manager::key_manager_service::KeyManagerServiceError; +use tari_max_size::{MaxSizeBytesError, MaxSizeVecError}; use thiserror::Error; use tonic::{codegen::http::uri::InvalidUri, transport}; diff --git a/applications/minotari_miner/Cargo.toml b/applications/minotari_miner/Cargo.toml index 21da3aaf469..77fc2132dcb 100644 --- a/applications/minotari_miner/Cargo.toml +++ b/applications/minotari_miner/Cargo.toml @@ -12,6 +12,7 @@ tari_core = { path = "../../base_layer/core", default-features = false } tari_common = { path = "../../common" } tari_common_types = { path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } +tari_max_size = { path = "../../infrastructure/max_size" } minotari_app_utilities = { path = "../minotari_app_utilities", features = ["miner_input"] } minotari_app_grpc = { path = "../minotari_app_grpc" } tari_crypto = { version = "0.20.3" } diff --git a/applications/minotari_miner/src/errors.rs b/applications/minotari_miner/src/errors.rs index 3485d15d412..f2342f7a881 100644 --- a/applications/minotari_miner/src/errors.rs +++ b/applications/minotari_miner/src/errors.rs @@ -21,7 +21,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use minotari_app_grpc::authentication::BasicAuthError; use minotari_app_utilities::parse_miner_input::ParseInputError; -use tari_common_types::MaxSizeBytesError; +use tari_max_size::MaxSizeBytesError; use thiserror::Error; use tonic::codegen::http::uri::InvalidUri; diff --git a/applications/minotari_miner/src/stratum/error.rs b/applications/minotari_miner/src/stratum/error.rs index 846aab9833c..29f1ac324f1 100644 --- a/applications/minotari_miner/src/stratum/error.rs +++ b/applications/minotari_miner/src/stratum/error.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use tari_common_types::MaxSizeBytesError; +use tari_max_size::MaxSizeBytesError; use thiserror::Error; #[allow(clippy::enum_variant_names)] diff --git a/applications/minotari_miner/src/stratum/stratum_controller/controller.rs b/applications/minotari_miner/src/stratum/stratum_controller/controller.rs index 2cadf176c27..b19027ef637 100644 --- a/applications/minotari_miner/src/stratum/stratum_controller/controller.rs +++ b/applications/minotari_miner/src/stratum/stratum_controller/controller.rs @@ -25,7 +25,7 @@ use borsh::BorshDeserialize; use futures::stream::StreamExt; use log::*; use minotari_app_grpc::tari_rpc::BlockHeader; -use tari_common_types::MaxSizeBytes; +use tari_max_size::MaxSizeBytes; use tari_utilities::{hex::Hex, ByteArray}; use crate::{ diff --git a/base_layer/common_types/src/lib.rs b/base_layer/common_types/src/lib.rs index d10280e82d3..b0d6c50ca19 100644 --- a/base_layer/common_types/src/lib.rs +++ b/base_layer/common_types/src/lib.rs @@ -31,18 +31,9 @@ pub mod encryption; pub mod epoch; pub mod grpc_authentication; pub mod key_branches; -mod max_size; pub mod serializers; pub mod tari_address; pub mod transaction; mod tx_id; pub mod types; pub mod wallet_types; -pub use max_size::{ - MaxSizeBytes, - MaxSizeBytesError, - MaxSizeString, - MaxSizeStringLengthError, - MaxSizeVec, - MaxSizeVecError, -}; diff --git a/base_layer/contacts/Cargo.toml b/base_layer/contacts/Cargo.toml index 9df65b52293..8c06191858a 100644 --- a/base_layer/contacts/Cargo.toml +++ b/base_layer/contacts/Cargo.toml @@ -13,6 +13,7 @@ tari_common_types = { path = "../../base_layer/common_types", version = "1.2.0-p tari_comms = { path = "../../comms/core", version = "1.2.0-pre.0" } tari_comms_dht = { path = "../../comms/dht", version = "1.2.0-pre.0" } tari_crypto = { version = "0.20.3" } +tari_max_size = { path = "../../infrastructure/max_size" } tari_p2p = { path = "../p2p", features = ["auto-update"], version = "1.2.0-pre.0" } tari_service_framework = { path = "../service_framework", version = "1.2.0-pre.0" } tari_shutdown = { path = "../../infrastructure/shutdown", version = "1.2.0-pre.0" } diff --git a/base_layer/contacts/src/chat_client/Cargo.toml b/base_layer/contacts/src/chat_client/Cargo.toml index 07aa0474052..9f7f555136d 100644 --- a/base_layer/contacts/src/chat_client/Cargo.toml +++ b/base_layer/contacts/src/chat_client/Cargo.toml @@ -15,6 +15,7 @@ tari_common_types = { path = "../../../common_types" } tari_comms = { path = "../../../../comms/core" } tari_comms_dht = { path = "../../../../comms/dht" } tari_contacts = { path = "../../../contacts" } +tari_max_size = { path = "../../../../infrastructure/max_size" } tari_p2p = { path = "../../../p2p" } tari_service_framework= { path = "../../../service_framework" } tari_shutdown = { path = "../../../../infrastructure/shutdown" } diff --git a/base_layer/contacts/src/chat_client/src/error.rs b/base_layer/contacts/src/chat_client/src/error.rs index c5eda9635a8..80adf0f0c4d 100644 --- a/base_layer/contacts/src/chat_client/src/error.rs +++ b/base_layer/contacts/src/chat_client/src/error.rs @@ -25,9 +25,9 @@ use std::io; use diesel::ConnectionError; use minotari_app_utilities::identity_management::IdentityError; use tari_common_sqlite::error::StorageError as SqliteStorageError; -use tari_common_types::MaxSizeBytesError; use tari_comms::peer_manager::PeerManagerError; use tari_contacts::contacts_service::error::ContactsServiceError; +use tari_max_size::MaxSizeBytesError; use tari_p2p::initialization::CommsInitializationError; use tari_storage::lmdb_store::LMDBError; diff --git a/base_layer/contacts/src/contacts_service/error.rs b/base_layer/contacts/src/contacts_service/error.rs index 74c5f226226..332d8a055c9 100644 --- a/base_layer/contacts/src/contacts_service/error.rs +++ b/base_layer/contacts/src/contacts_service/error.rs @@ -22,9 +22,9 @@ use diesel::result::Error as DieselError; use tari_common_sqlite::error::SqliteStorageError; -use tari_common_types::MaxSizeBytesError; use tari_comms::connectivity::ConnectivityError; use tari_comms_dht::outbound::DhtOutboundError; +use tari_max_size::MaxSizeBytesError; use tari_p2p::services::liveness::error::LivenessError; use tari_service_framework::reply_channel::TransportChannelError; use thiserror::Error; diff --git a/base_layer/contacts/src/contacts_service/types/confirmation.rs b/base_layer/contacts/src/contacts_service/types/confirmation.rs index 27af40c2360..faf992d1f0d 100644 --- a/base_layer/contacts/src/contacts_service/types/confirmation.rs +++ b/base_layer/contacts/src/contacts_service/types/confirmation.rs @@ -22,7 +22,7 @@ use std::{convert::TryFrom, fmt::Display}; -use tari_common_types::MaxSizeBytes; +use tari_max_size::MaxSizeBytes; use tari_utilities::ByteArray; use crate::contacts_service::{error::ContactsServiceError, proto, types::MessageId}; diff --git a/base_layer/contacts/src/contacts_service/types/message.rs b/base_layer/contacts/src/contacts_service/types/message.rs index 99ba644483e..2d500337e35 100644 --- a/base_layer/contacts/src/contacts_service/types/message.rs +++ b/base_layer/contacts/src/contacts_service/types/message.rs @@ -25,8 +25,9 @@ use std::{convert::TryFrom, fmt::Display}; use num_derive::FromPrimitive; use num_traits::FromPrimitive; use serde::{Deserialize, Serialize}; -use tari_common_types::{tari_address::TariAddress, MaxSizeBytes}; +use tari_common_types::tari_address::TariAddress; use tari_comms_dht::domain_message::OutboundDomainMessage; +use tari_max_size::MaxSizeBytes; use tari_p2p::tari_message::TariMessageType; use tari_utilities::ByteArray; diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 1b1f2a47a88..9ef6a1753da 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -36,6 +36,7 @@ tari_comms = { path = "../../comms/core", version = "1.2.0-pre.0" } tari_comms_dht = { path = "../../comms/dht", version = "1.2.0-pre.0" } tari_comms_rpc_macros = { path = "../../comms/rpc_macros", version = "1.2.0-pre.0" } tari_crypto = { version = "0.20.3", features = ["borsh"] } +tari_max_size = { path = "../../infrastructure/max_size" } tari_metrics = { path = "../../infrastructure/metrics", optional = true, version = "1.2.0-pre.0" } tari_mmr = { path = "../../base_layer/mmr", optional = true, version = "1.2.0-pre.0" } tari_p2p = { path = "../../base_layer/p2p", version = "1.2.0-pre.0" } diff --git a/base_layer/core/src/common/mod.rs b/base_layer/core/src/common/mod.rs index 29e9054fbb6..dfdd7aa37b2 100644 --- a/base_layer/core/src/common/mod.rs +++ b/base_layer/core/src/common/mod.rs @@ -23,8 +23,8 @@ use blake2::Blake2b; use digest::consts::U64; #[cfg(feature = "base_node")] -use tari_common_types::MaxSizeVec; use tari_hashing::ConfidentialOutputHashDomain; +use tari_max_size::MaxSizeVec; use crate::consensus::DomainSeparatedConsensusHasher; diff --git a/base_layer/core/src/covenants/arguments.rs b/base_layer/core/src/covenants/arguments.rs index 5b271c4c496..1db3ee10c47 100644 --- a/base_layer/core/src/covenants/arguments.rs +++ b/base_layer/core/src/covenants/arguments.rs @@ -27,10 +27,8 @@ use std::{ use borsh::{BorshDeserialize, BorshSerialize}; use integer_encoding::VarIntWriter; -use tari_common_types::{ - types::{Commitment, FixedHash, PublicKey}, - MaxSizeBytes, -}; +use tari_common_types::types::{Commitment, FixedHash, PublicKey}; +use tari_max_size::MaxSizeBytes; use tari_script::TariScript; use tari_utilities::{hex::Hex, ByteArray}; diff --git a/base_layer/core/src/covenants/covenant.rs b/base_layer/core/src/covenants/covenant.rs index 3cb047327d8..d3bad1d4ab4 100644 --- a/base_layer/core/src/covenants/covenant.rs +++ b/base_layer/core/src/covenants/covenant.rs @@ -27,7 +27,7 @@ use std::{ use borsh::{BorshDeserialize, BorshSerialize}; use integer_encoding::{VarIntReader, VarIntWriter}; -use tari_common_types::MaxSizeVec; +use tari_max_size::MaxSizeVec; use super::decoder::CovenantDecodeError; use crate::{ diff --git a/base_layer/core/src/covenants/error.rs b/base_layer/core/src/covenants/error.rs index 51a1a84f94c..bca13bcfe8a 100644 --- a/base_layer/core/src/covenants/error.rs +++ b/base_layer/core/src/covenants/error.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use tari_common_types::MaxSizeVecError; +use tari_max_size::MaxSizeVecError; #[derive(Debug, thiserror::Error)] pub enum CovenantError { diff --git a/base_layer/core/src/proof_of_work/proof_of_work.rs b/base_layer/core/src/proof_of_work/proof_of_work.rs index 7b07ea3c2aa..446246dd19e 100644 --- a/base_layer/core/src/proof_of_work/proof_of_work.rs +++ b/base_layer/core/src/proof_of_work/proof_of_work.rs @@ -25,7 +25,7 @@ use std::fmt::{Display, Error, Formatter}; use borsh::{BorshDeserialize, BorshSerialize}; use bytes::BufMut; use serde::{Deserialize, Serialize}; -use tari_common_types::MaxSizeBytes; +use tari_max_size::MaxSizeBytes; use tari_utilities::hex::Hex; use crate::proof_of_work::PowAlgorithm; diff --git a/base_layer/core/src/proto/sidechain_feature.rs b/base_layer/core/src/proto/sidechain_feature.rs index 997b851602c..a0cc6f744f4 100644 --- a/base_layer/core/src/proto/sidechain_feature.rs +++ b/base_layer/core/src/proto/sidechain_feature.rs @@ -24,10 +24,8 @@ use std::convert::{TryFrom, TryInto}; -use tari_common_types::{ - types::{PublicKey, Signature}, - MaxSizeString, -}; +use tari_common_types::types::{PublicKey, Signature}; +use tari_max_size::MaxSizeString; use tari_utilities::ByteArray; use crate::{ diff --git a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs index 5ad5bef4c42..d986d8f3ee3 100644 --- a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs +++ b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs @@ -47,10 +47,10 @@ use serde::{Deserialize, Serialize}; use tari_common_types::{ tari_address::{TariAddress, TARI_ADDRESS_INTERNAL_DUAL_SIZE, TARI_ADDRESS_INTERNAL_SINGLE_SIZE}, types::{Commitment, PrivateKey}, - MaxSizeBytes, }; use tari_crypto::{hashing::DomainSeparatedHasher, keys::SecretKey}; use tari_hashing::TransactionSecureNonceKdfDomain; +use tari_max_size::MaxSizeBytes; use tari_utilities::{ hex::{from_hex, to_hex, Hex, HexError}, safe_array::SafeArray, diff --git a/base_layer/core/src/transactions/transaction_components/output_features.rs b/base_layer/core/src/transactions/transaction_components/output_features.rs index 06e422a9d3f..cf2230097c7 100644 --- a/base_layer/core/src/transactions/transaction_components/output_features.rs +++ b/base_layer/core/src/transactions/transaction_components/output_features.rs @@ -28,11 +28,8 @@ use std::{ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use tari_common_types::{ - types::{PublicKey, Signature}, - MaxSizeBytes, - MaxSizeString, -}; +use tari_common_types::types::{PublicKey, Signature}; +use tari_max_size::{MaxSizeBytes, MaxSizeString}; use super::OutputFeaturesVersion; use crate::transactions::transaction_components::{ diff --git a/base_layer/core/src/transactions/transaction_components/side_chain/template_registration.rs b/base_layer/core/src/transactions/transaction_components/side_chain/template_registration.rs index 732ef460142..0fe680a55c9 100644 --- a/base_layer/core/src/transactions/transaction_components/side_chain/template_registration.rs +++ b/base_layer/core/src/transactions/transaction_components/side_chain/template_registration.rs @@ -22,11 +22,8 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use tari_common_types::{ - types::{PublicKey, Signature}, - MaxSizeBytes, - MaxSizeString, -}; +use tari_common_types::types::{PublicKey, Signature}; +use tari_max_size::{MaxSizeBytes, MaxSizeString}; #[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)] pub struct CodeTemplateRegistration { diff --git a/base_layer/wallet/Cargo.toml b/base_layer/wallet/Cargo.toml index d217e98eb71..cf5c43316d4 100644 --- a/base_layer/wallet/Cargo.toml +++ b/base_layer/wallet/Cargo.toml @@ -16,6 +16,7 @@ tari_contacts = { path = "../../base_layer/contacts", version = "1.2.0-pre.0" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions", "mempool_proto", "base_node_proto"], version = "1.2.0-pre.0" } tari_crypto = { version = "0.20.3" } tari_key_manager = { path = "../key_manager", features = ["key_manager_service"], version = "1.2.0-pre.0" } +tari_max_size = { path = "../../infrastructure/max_size" } tari_p2p = { path = "../p2p", features = ["auto-update"], version = "1.2.0-pre.0" } tari_script = { path = "../../infrastructure/tari_script", version = "1.2.0-pre.0" } tari_service_framework = { path = "../service_framework", version = "1.2.0-pre.0" } diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index 439e48adaf1..645f997d1cb 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -33,8 +33,6 @@ use tari_common_types::{ tari_address::TariAddress, transaction::{ImportStatus, TxId}, types::{FixedHash, HashOutput, PrivateKey, PublicKey, Signature}, - MaxSizeBytes, - MaxSizeString, }; use tari_comms::types::CommsPublicKey; use tari_core::{ @@ -54,6 +52,7 @@ use tari_core::{ }, }; use tari_crypto::ristretto::pedersen::PedersenCommitment; +use tari_max_size::{MaxSizeBytes, MaxSizeString}; use tari_script::CheckSigSchnorrSignature; use tari_service_framework::reply_channel::SenderService; use tari_utilities::hex::Hex; diff --git a/infrastructure/max_size/Cargo.toml b/infrastructure/max_size/Cargo.toml new file mode 100644 index 00000000000..f177022321e --- /dev/null +++ b/infrastructure/max_size/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "tari_max_size" +version = "1.2.0-pre.0" +edition = "2021" +description = "Tari max size library" +authors = ["The Tari Development Community"] +repository = "https://github.com/tari-project/tari" +categories = ["cryptography"] +homepage = "https://tari.com" +readme = "README.md" +license = "BSD-3-Clause" + +[dependencies] +tari_utilities = { version = "0.7" } + +borsh = "1.2" +serde = { version = "1.0.136", features = ["derive"] } +thiserror = "1.0.30" diff --git a/infrastructure/max_size/README.md b/infrastructure/max_size/README.md new file mode 100644 index 00000000000..e73a0f547e0 --- /dev/null +++ b/infrastructure/max_size/README.md @@ -0,0 +1,14 @@ +# Tari Script +Implementation of `Tari Script` for Tari. + +This crate is part of the [Tari Cryptocurrency](https://tari.com) project. + +For more details see: + +[TariScript for dummies](https://tlu.tarilabs.com/tari/TariScript_for_dummies) explain how Tari script works. + +[Tari script RFC](https://rfc.tari.com/RFC-0201_TariScript.html) + +[Tari Script Opcodes](https://rfc.tari.com/RFC-0202_TariScriptOpcodes.html) + + diff --git a/base_layer/common_types/src/max_size/bytes.rs b/infrastructure/max_size/src/bytes.rs similarity index 100% rename from base_layer/common_types/src/max_size/bytes.rs rename to infrastructure/max_size/src/bytes.rs diff --git a/base_layer/common_types/src/max_size/mod.rs b/infrastructure/max_size/src/lib.rs similarity index 100% rename from base_layer/common_types/src/max_size/mod.rs rename to infrastructure/max_size/src/lib.rs diff --git a/base_layer/common_types/src/max_size/string.rs b/infrastructure/max_size/src/string.rs similarity index 100% rename from base_layer/common_types/src/max_size/string.rs rename to infrastructure/max_size/src/string.rs diff --git a/base_layer/common_types/src/max_size/vec.rs b/infrastructure/max_size/src/vec.rs similarity index 100% rename from base_layer/common_types/src/max_size/vec.rs rename to infrastructure/max_size/src/vec.rs diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index baaa5fe293c..23bc06c58b5 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -12,6 +12,7 @@ license = "BSD-3-Clause" [dependencies] tari_crypto = { version = "0.20.3" } +tari_max_size = { path = "../../infrastructure/max_size" } tari_utilities = { version = "0.7" } blake2 = "0.10" diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index ab07a14323c..1a7c82d9656 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -28,6 +28,7 @@ use tari_crypto::{ keys::PublicKey, ristretto::{RistrettoPublicKey, RistrettoSecretKey}, }; +use tari_max_size::MaxSizeVec; use tari_utilities::{ hex::{from_hex, to_hex, Hex, HexError}, ByteArray, @@ -58,6 +59,8 @@ macro_rules! script { const MAX_MULTISIG_LIMIT: u8 = 32; const MAX_SCRIPT_BYTES: usize = 4096; +pub(crate) type ScriptOpcodes = MaxSizeVec; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct TariScript { script: Vec,