Skip to content

Commit

Permalink
Extract solana-transaction from solana-sdk (#3634)
Browse files Browse the repository at this point in the history
* extract transaction crate

* make serde and bincode optional

* fix frozen-abi support

* missing dep for frozen-abi

* update digest

* fix circular dep

* fmt

* missing feature activation

* add doc_auto_cfg

* add "wasm32-unknown-unknown" to doc targets

* make solana-feature-set optional

* inline some consts

* fix wasm support

* update expected error

* update expected error

* missing #![cfg(feature = "full")]

* update digest

* update digest

* remove solana-program (except for dev deps)

* add wasm32-unknown-unknown to doc targets

* update docs links

* tighten deps

* remove extraneous commit

* use explicit link
  • Loading branch information
kevinheavey authored Dec 4, 2024
1 parent f294b99 commit e4e232c
Show file tree
Hide file tree
Showing 17 changed files with 514 additions and 268 deletions.
40 changes: 40 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 @@ -176,6 +176,7 @@ members = [
"sdk/sysvar",
"sdk/sysvar-id",
"sdk/time-utils",
"sdk/transaction",
"sdk/transaction-context",
"sdk/transaction-error",
"send-transaction-service",
Expand Down Expand Up @@ -573,6 +574,7 @@ solana-sysvar = { path = "sdk/sysvar", version = "=2.2.0" }
solana-sysvar-id = { path = "sdk/sysvar-id", version = "=2.2.0" }
solana-test-validator = { path = "test-validator", version = "=2.2.0" }
solana-thin-client = { path = "thin-client", version = "=2.2.0" }
solana-transaction = { path = "sdk/transaction", version = "=2.2.0" }
solana-transaction-error = { path = "sdk/transaction-error", version = "=2.2.0" }
solana-tpu-client = { path = "tpu-client", version = "=2.2.0", default-features = false }
solana-tpu-client-next = { path = "tpu-client-next", version = "=2.2.0" }
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) const PULL_RESPONSE_MIN_SERIALIZED_SIZE: usize = 161;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "ESDND6D3FcRyA6UTUpDVDcS4AkESc5E6UtZWSbT7G8e8")
frozen_abi(digest = "CBR9G92mpd1WSXEmiH6dAKHziLjJky9aYWPw6S5WmJkG")
)]
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down
27 changes: 27 additions & 0 deletions programs/sbf/Cargo.lock

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

12 changes: 6 additions & 6 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8532,7 +8532,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx58, TransactionBinaryEncoding::Base58)
.unwrap_err(),
Error::invalid_params(format!(
"base58 encoded solana_sdk::transaction::Transaction too large: {tx58_len} bytes (max: encoded/raw {MAX_BASE58_SIZE}/{PACKET_DATA_SIZE})",
"base58 encoded solana_transaction::Transaction too large: {tx58_len} bytes (max: encoded/raw {MAX_BASE58_SIZE}/{PACKET_DATA_SIZE})",
)
));

Expand All @@ -8542,7 +8542,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx64, TransactionBinaryEncoding::Base64)
.unwrap_err(),
Error::invalid_params(format!(
"base64 encoded solana_sdk::transaction::Transaction too large: {tx64_len} bytes (max: encoded/raw {MAX_BASE64_SIZE}/{PACKET_DATA_SIZE})",
"base64 encoded solana_transaction::Transaction too large: {tx64_len} bytes (max: encoded/raw {MAX_BASE64_SIZE}/{PACKET_DATA_SIZE})",
)
));

Expand All @@ -8553,7 +8553,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx58, TransactionBinaryEncoding::Base58)
.unwrap_err(),
Error::invalid_params(format!(
"decoded solana_sdk::transaction::Transaction too large: {too_big} bytes (max: {PACKET_DATA_SIZE} bytes)"
"decoded solana_transaction::Transaction too large: {too_big} bytes (max: {PACKET_DATA_SIZE} bytes)"
))
);

Expand All @@ -8562,7 +8562,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx64, TransactionBinaryEncoding::Base64)
.unwrap_err(),
Error::invalid_params(format!(
"decoded solana_sdk::transaction::Transaction too large: {too_big} bytes (max: {PACKET_DATA_SIZE} bytes)"
"decoded solana_transaction::Transaction too large: {too_big} bytes (max: {PACKET_DATA_SIZE} bytes)"
))
);

Expand All @@ -8572,7 +8572,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx64.clone(), TransactionBinaryEncoding::Base64)
.unwrap_err(),
Error::invalid_params(
"failed to deserialize solana_sdk::transaction::Transaction: invalid value: \
"failed to deserialize solana_transaction::Transaction: invalid value: \
continue signal on byte-three, expected a terminal signal on or before byte-three"
.to_string()
)
Expand All @@ -8590,7 +8590,7 @@ pub mod tests {
decode_and_deserialize::<Transaction>(tx58.clone(), TransactionBinaryEncoding::Base58)
.unwrap_err(),
Error::invalid_params(
"failed to deserialize solana_sdk::transaction::Transaction: invalid value: \
"failed to deserialize solana_transaction::Transaction: invalid value: \
continue signal on byte-three, expected a terminal signal on or before byte-three"
.to_string()
)
Expand Down
11 changes: 10 additions & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ full = [
"dep:solana-seed-derivable",
"dep:solana-seed-phrase",
"dep:solana-signer",
"dep:solana-transaction",
"dep:solana-transaction-error",
]
borsh = [
Expand All @@ -60,6 +61,7 @@ dev-context-only-utils = [
"solana-account/dev-context-only-utils",
"solana-compute-budget-interface/dev-context-only-utils",
"solana-rent-debits/dev-context-only-utils",
"solana-transaction/dev-context-only-utils",
"solana-transaction-context/dev-context-only-utils",
]
frozen-abi = [
Expand All @@ -74,7 +76,8 @@ frozen-abi = [
"solana-reward-info/frozen-abi",
"solana-short-vec/frozen-abi",
"solana-signature/frozen-abi",
"solana-transaction-error/frozen-abi",
"solana-transaction/frozen-abi",
"solana-transaction-error/frozen-abi"
]
# Enables the "vendored" feature of openssl inside of secp256r1-program
openssl-vendored = ["solana-precompiles/openssl-vendored"]
Expand Down Expand Up @@ -173,6 +176,12 @@ solana-signature = { workspace = true, features = [
], optional = true }
solana-signer = { workspace = true, optional = true }
solana-time-utils = { workspace = true }
solana-transaction = { workspace = true, features = [
"blake3",
"precompiles",
"serde",
"verify"
], optional = true }
solana-transaction-context = { workspace = true, features = ["bincode"] }
solana-transaction-error = { workspace = true, features = [
"serde",
Expand Down
7 changes: 6 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub mod rpc_port;
pub mod shred_version;
pub mod signature;
pub mod signer;
pub mod simple_vote_transaction_checker;
pub mod system_transaction;
pub mod transaction;
pub mod transport;
Expand Down Expand Up @@ -203,6 +202,12 @@ pub use solana_serde_varint as serde_varint;
pub use solana_short_vec as short_vec;
#[deprecated(since = "2.2.0", note = "Use `solana-time-utils` crate instead")]
pub use solana_time_utils as timing;
#[cfg(feature = "full")]
#[deprecated(
since = "2.2.0",
note = "Use `solana_transaction::simple_vote_transaction_checker` instead"
)]
pub use solana_transaction::simple_vote_transaction_checker;
#[deprecated(
since = "2.2.0",
note = "Use `solana-transaction-context` crate instead"
Expand Down
21 changes: 21 additions & 0 deletions sdk/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![cfg(feature = "full")]
#[deprecated(since = "2.2.0", note = "Use solana_transaction_error crate instead")]
pub use solana_transaction_error::{
AddressLoaderError, SanitizeMessageError, TransactionError, TransactionResult as Result,
TransportError, TransportResult,
};
#[deprecated(since = "2.2.0", note = "Use solana_transaction crate instead")]
pub use {
solana_program::message::{AddressLoader, SimpleAddressLoader},
solana_transaction::{
sanitized::{
MessageHash, SanitizedTransaction, TransactionAccountLocks, MAX_TX_ACCOUNT_LOCKS,
},
uses_durable_nonce,
versioned::{
sanitized::SanitizedVersionedTransaction, Legacy, TransactionVersion,
VersionedTransaction,
},
Transaction, TransactionVerificationMode,
},
};
57 changes: 3 additions & 54 deletions sdk/src/wasm/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
//! `Transaction` Javascript interface
#![cfg(target_arch = "wasm32")]
#![allow(non_snake_case)]
use {
crate::{hash::Hash, message::Message, signer::keypair::Keypair, transaction::Transaction},
solana_program::{
pubkey::Pubkey,
wasm::{display_to_jsvalue, instructions::Instructions},
},
wasm_bindgen::prelude::*,
};

#[wasm_bindgen]
impl Transaction {
/// Create a new `Transaction`
#[wasm_bindgen(constructor)]
pub fn constructor(instructions: Instructions, payer: Option<Pubkey>) -> Transaction {
let instructions: Vec<_> = instructions.into();
Transaction::new_with_payer(&instructions, payer.as_ref())
}

/// Return a message containing all data that should be signed.
#[wasm_bindgen(js_name = message)]
pub fn js_message(&self) -> Message {
self.message.clone()
}

/// Return the serialized message data to sign.
pub fn messageData(&self) -> Box<[u8]> {
self.message_data().into()
}

/// Verify the transaction
#[wasm_bindgen(js_name = verify)]
pub fn js_verify(&self) -> Result<(), JsValue> {
self.verify().map_err(display_to_jsvalue)
}

pub fn partialSign(&mut self, keypair: &Keypair, recent_blockhash: &Hash) {
self.partial_sign(&[keypair], *recent_blockhash);
}

pub fn isSigned(&self) -> bool {
self.is_signed()
}

pub fn toBytes(&self) -> Box<[u8]> {
bincode::serialize(self).unwrap().into()
}

pub fn fromBytes(bytes: &[u8]) -> Result<Transaction, JsValue> {
bincode::deserialize(bytes).map_err(display_to_jsvalue)
}
}
//! This module is empty but has not yet been removed because that would
//! technically be a breaking change. There was never anything to import
//! from here.
Loading

0 comments on commit e4e232c

Please sign in to comment.