From 6cfb1af0d208296700ddacfcda6fd9cc5cb5ea84 Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Thu, 5 Dec 2024 17:35:19 +0400 Subject: [PATCH] Extract client-traits crate (#3829) * extract solana-client-traits * add required feature after rebase * remove solana-program --- Cargo.lock | 20 +++++++++ Cargo.toml | 2 + programs/sbf/Cargo.lock | 20 +++++++++ sdk/Cargo.toml | 2 + sdk/client-traits/Cargo.toml | 28 +++++++++++++ .../client.rs => client-traits/src/lib.rs} | 41 ++++++++----------- sdk/src/lib.rs | 4 +- svm/examples/Cargo.lock | 20 +++++++++ 8 files changed, 111 insertions(+), 26 deletions(-) create mode 100644 sdk/client-traits/Cargo.toml rename sdk/{src/client.rs => client-traits/src/lib.rs} (89%) diff --git a/Cargo.lock b/Cargo.lock index d4f9121908abe9..aff02a4bba97d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6545,6 +6545,25 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "solana-client-traits" +version = "2.2.0" +dependencies = [ + "solana-account", + "solana-commitment-config", + "solana-epoch-info", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-pubkey", + "solana-signature", + "solana-signer", + "solana-system-interface", + "solana-transaction", + "solana-transaction-error", +] + [[package]] name = "solana-clock" version = "2.2.0" @@ -8520,6 +8539,7 @@ dependencies = [ "siphasher", "solana-account", "solana-bn254", + "solana-client-traits", "solana-cluster-type", "solana-commitment-config", "solana-compute-budget-interface", diff --git a/Cargo.toml b/Cargo.toml index 4b772019b47900..5b9b4e382e5d75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,7 @@ members = [ "sdk/borsh", "sdk/cargo-build-sbf", "sdk/cargo-test-sbf", + "sdk/client-traits", "sdk/clock", "sdk/cluster-type", "sdk/commitment-config", @@ -445,6 +446,7 @@ solana-cli = { path = "cli", version = "=2.2.0" } solana-cli-config = { path = "cli-config", version = "=2.2.0" } solana-cli-output = { path = "cli-output", version = "=2.2.0" } solana-client = { path = "client", version = "=2.2.0" } +solana-client-traits = { path = "sdk/client-traits", version = "=2.2.0" } solana-clock = { path = "sdk/clock", version = "=2.2.0" } solana-cluster-type = { path = "sdk/cluster-type", version = "=2.2.0" } solana-commitment-config = { path = "sdk/commitment-config", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index c7ce89f5001706..9fe538b8649299 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5271,6 +5271,25 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-client-traits" +version = "2.2.0" +dependencies = [ + "solana-account", + "solana-commitment-config", + "solana-epoch-info", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-pubkey", + "solana-signature", + "solana-signer", + "solana-system-interface", + "solana-transaction", + "solana-transaction-error", +] + [[package]] name = "solana-clock" version = "2.2.0" @@ -7219,6 +7238,7 @@ dependencies = [ "siphasher", "solana-account", "solana-bn254", + "solana-client-traits", "solana-cluster-type", "solana-commitment-config", "solana-compute-budget-interface", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 2b42c3a884b3e2..3369c3696fb35e 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -35,6 +35,7 @@ full = [ "solana-commitment-config", "digest", "solana-pubkey/rand", + "dep:solana-client-traits", "dep:solana-cluster-type", "dep:solana-ed25519-program", "dep:solana-compute-budget-interface", @@ -116,6 +117,7 @@ sha3 = { workspace = true, optional = true } siphasher = { workspace = true } solana-account = { workspace = true, features = ["bincode"] } solana-bn254 = { workspace = true } +solana-client-traits = { workspace = true, optional = true } solana-cluster-type = { workspace = true, features = [ "serde", ], optional = true } diff --git a/sdk/client-traits/Cargo.toml b/sdk/client-traits/Cargo.toml new file mode 100644 index 00000000000000..acb85a1a4eefb8 --- /dev/null +++ b/sdk/client-traits/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "solana-client-traits" +description = "Traits for Solana clients" +documentation = "https://docs.rs/solana-client-traits" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +solana-account = { workspace = true } +solana-commitment-config = { workspace = true } +solana-epoch-info = { workspace = true } +solana-hash = { workspace = true } +solana-instruction = { workspace = true } +solana-keypair = { workspace = true } +solana-message = { workspace = true } +solana-pubkey = { workspace = true } +solana-signature = { workspace = true } +solana-signer = { workspace = true } +solana-system-interface = { workspace = true } +solana-transaction = { workspace = true, features = ["bincode"] } +solana-transaction-error = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/src/client.rs b/sdk/client-traits/src/lib.rs similarity index 89% rename from sdk/src/client.rs rename to sdk/client-traits/src/lib.rs index 6b9261a5d1f312..4f4a466413c3f7 100644 --- a/sdk/src/client.rs +++ b/sdk/client-traits/src/lib.rs @@ -7,25 +7,20 @@ //! Asynchronous implementations are expected to create transactions, sign them, and send //! them but without waiting to see if the server accepted it. -#![cfg(feature = "full")] - use { - crate::{ - clock::Slot, - commitment_config::CommitmentConfig, - epoch_info::EpochInfo, - hash::Hash, - instruction::Instruction, - message::Message, - pubkey::Pubkey, - signature::{Keypair, Signature}, - signer::Signer, - signers::Signers, - system_instruction, - transaction::{self, Transaction, VersionedTransaction}, - transport::Result, - }, solana_account::Account, + solana_commitment_config::CommitmentConfig, + solana_epoch_info::EpochInfo, + solana_hash::Hash, + solana_instruction::Instruction, + solana_keypair::Keypair, + solana_message::Message, + solana_pubkey::Pubkey, + solana_signature::Signature, + solana_signer::{signers::Signers, Signer}, + solana_system_interface::instruction::transfer, + solana_transaction::{versioned::VersionedTransaction, Transaction}, + solana_transaction_error::{TransactionResult, TransportResult as Result}, }; pub trait Client: SyncClient + AsyncClient { @@ -84,20 +79,17 @@ pub trait SyncClient { fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> Result; /// Get signature status. - fn get_signature_status( - &self, - signature: &Signature, - ) -> Result>>; + fn get_signature_status(&self, signature: &Signature) -> Result>>; /// Get signature status. Uses explicit commitment configuration. fn get_signature_status_with_commitment( &self, signature: &Signature, commitment_config: CommitmentConfig, - ) -> Result>>; + ) -> Result>>; /// Get last known slot - fn get_slot(&self) -> Result; + fn get_slot(&self) -> Result; /// Get last known slot. Uses explicit commitment configuration. fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result; @@ -200,8 +192,7 @@ pub trait AsyncClient { pubkey: &Pubkey, recent_blockhash: Hash, ) -> Result { - let transfer_instruction = - system_instruction::transfer(&keypair.pubkey(), pubkey, lamports); + let transfer_instruction = transfer(&keypair.pubkey(), pubkey, lamports); self.async_send_instruction(keypair, transfer_instruction, recent_blockhash) } } diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 3076c997b251a5..0421b81ff58515 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -62,7 +62,6 @@ pub use solana_program::{borsh, borsh0_10, borsh1}; #[cfg(feature = "full")] #[deprecated(since = "2.2.0", note = "Use `solana-signer` crate instead")] pub use solana_signer::signers; -pub mod client; pub mod entrypoint; pub mod entrypoint_deprecated; pub mod epoch_rewards_hasher; @@ -108,6 +107,9 @@ pub use solana_account as account; pub use solana_account::state_traits as account_utils; #[deprecated(since = "2.1.0", note = "Use `solana-bn254` crate instead")] pub use solana_bn254 as alt_bn128; +#[cfg(feature = "full")] +#[deprecated(since = "2.2.0", note = "Use `solana-client-traits` crate instead")] +pub use solana_client_traits as client; #[deprecated( since = "2.2.0", note = "Use `solana-compute-budget-interface` crate instead" diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 1cc9d6a4e80fa8..a2c4d65392d5aa 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5122,6 +5122,25 @@ dependencies = [ "tokio", ] +[[package]] +name = "solana-client-traits" +version = "2.2.0" +dependencies = [ + "solana-account", + "solana-commitment-config", + "solana-epoch-info", + "solana-hash", + "solana-instruction", + "solana-keypair", + "solana-message", + "solana-pubkey", + "solana-signature", + "solana-signer", + "solana-system-interface", + "solana-transaction", + "solana-transaction-error", +] + [[package]] name = "solana-clock" version = "2.2.0" @@ -6547,6 +6566,7 @@ dependencies = [ "siphasher", "solana-account", "solana-bn254", + "solana-client-traits", "solana-cluster-type", "solana-commitment-config", "solana-compute-budget-interface",