Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract solana-transaction from solana-sdk #3634

Merged
merged 24 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -172,6 +172,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 @@ -567,6 +568,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
2 changes: 1 addition & 1 deletion sdk/instruction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ serde = [
std = []

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't remember why it happened in this PR but it is a good change, otherwise you can't see the wasm-specific code on docs.rs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible i meant to add it for the solana-transaction crate. But it matters for solana-instruction too

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not needed, let's make the change in a separate PR. That way we can add it to all of the affected crates at once. I put in #3901 for it

all-features = true
rustdoc-args = ["--cfg=docsrs"]

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")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: all of these re-exports except for TransactionResult were already deprecated as of 2.1.0, but it's fine to bump this up for simplicity

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
Loading