Skip to content

Commit

Permalink
chore: add doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jan 27, 2024
1 parent 14da4e5 commit 6fac201
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cmd/crates/soroban-rpc/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Error> {
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()),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
}
Expand Down

0 comments on commit 6fac201

Please sign in to comment.