Skip to content

Commit

Permalink
Extract client-traits crate (#3829)
Browse files Browse the repository at this point in the history
* extract solana-client-traits

* add required feature after rebase

* remove solana-program
  • Loading branch information
kevinheavey authored Dec 5, 2024
1 parent 3069e0c commit 6cfb1af
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 26 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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" }
Expand Down
20 changes: 20 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }
Expand Down
28 changes: 28 additions & 0 deletions sdk/client-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
41 changes: 16 additions & 25 deletions sdk/src/client.rs → sdk/client-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -84,20 +79,17 @@ pub trait SyncClient {
fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> Result<u64>;

/// Get signature status.
fn get_signature_status(
&self,
signature: &Signature,
) -> Result<Option<transaction::Result<()>>>;
fn get_signature_status(&self, signature: &Signature) -> Result<Option<TransactionResult<()>>>;

/// Get signature status. Uses explicit commitment configuration.
fn get_signature_status_with_commitment(
&self,
signature: &Signature,
commitment_config: CommitmentConfig,
) -> Result<Option<transaction::Result<()>>>;
) -> Result<Option<TransactionResult<()>>>;

/// Get last known slot
fn get_slot(&self) -> Result<Slot>;
fn get_slot(&self) -> Result<u64>;

/// Get last known slot. Uses explicit commitment configuration.
fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result<u64>;
Expand Down Expand Up @@ -200,8 +192,7 @@ pub trait AsyncClient {
pubkey: &Pubkey,
recent_blockhash: Hash,
) -> Result<Signature> {
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)
}
}
4 changes: 3 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cfb1af

Please sign in to comment.