From 6fac201888c286362622439dba6db1ff61dc5033 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sat, 27 Jan 2024 13:32:23 -0500 Subject: [PATCH] chore: add doc strings --- cmd/crates/soroban-rpc/src/txn.rs | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cmd/crates/soroban-rpc/src/txn.rs b/cmd/crates/soroban-rpc/src/txn.rs index b53de682a..1d3d48285 100644 --- a/cmd/crates/soroban-rpc/src/txn.rs +++ b/cmd/crates/soroban-rpc/src/txn.rs @@ -20,17 +20,35 @@ pub struct Assembled { sim_res: SimulateTransactionResponse, } +/// Represents an assembled transaction ready to be signed and submitted to the network. impl Assembled { + /// + /// Creates a new `Assembled` transaction. + /// + /// # Arguments + /// + /// * `txn` - The original transaction. + /// * `client` - The client used for simulation and submission. /// /// # Errors + /// + /// Returns an error if simulation fails or if assembling the transaction fails. pub async fn new(txn: &Transaction, client: &Client) -> Result { let sim_res = Self::simulate(txn, client).await?; let txn = assemble(txn, &sim_res)?; Ok(Self { txn, sim_res }) } + /// + /// Calculates the hash of the assembled transaction. + /// + /// # Arguments + /// + /// * `network_passphrase` - The network passphrase. /// /// # Errors + /// + /// Returns an error if generating the hash fails. pub fn hash(&self, network_passphrase: &str) -> Result<[u8; 32], xdr::Error> { let signature_payload = TransactionSignaturePayload { network_id: Hash(Sha256::digest(network_passphrase).into()), @@ -39,8 +57,17 @@ impl Assembled { Ok(Sha256::digest(signature_payload.to_xdr(Limits::none())?).into()) } + /// + /// Signs the assembled transaction. + /// + /// # Arguments + /// + /// * `key` - The signing key. + /// * `network_passphrase` - The network passphrase. /// /// # Errors + /// + /// Returns an error if signing the transaction fails. pub fn sign( self, key: &ed25519_dalek::SigningKey, @@ -61,8 +88,17 @@ impl Assembled { })) } + /// + /// Simulates the assembled transaction. + /// + /// # Arguments + /// + /// * `tx` - The original transaction. + /// * `client` - The client used for simulation. /// /// # Errors + /// + /// Returns an error if simulation fails. pub async fn simulate( tx: &Transaction, client: &Client, @@ -75,8 +111,18 @@ impl Assembled { .await } + /// + /// Handles the restore process for the assembled transaction. + /// + /// # Arguments + /// + /// * `client` - The client used for submission. + /// * `source_key` - The signing key of the source account. + /// * `network_passphrase` - The network passphrase. /// /// # Errors + /// + /// Returns an error if the restore process fails. pub async fn handle_restore( self, client: &Client, @@ -98,10 +144,12 @@ impl Assembled { } } + /// Returns a reference to the original transaction. pub fn txn(&self) -> &Transaction { &self.txn } + /// Returns a reference to the simulation response. pub fn sim_res(&self) -> &SimulateTransactionResponse { &self.sim_res }