Skip to content

Commit

Permalink
feat: update mesh tx builder naming
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Sep 9, 2024
1 parent 236b28d commit 33303cb
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 267 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ yarn add @sidan-lab/sidan-csl-rs-browser

```rust
use whisky::{
builder::{IMeshTxBuilder, MeshTxBuilder},
builder::TxBuilder,
model::{Asset, UTxO},
};

Expand All @@ -56,7 +56,7 @@ async fn my_first_whisky_tx(
my_address: &str,
inputs: Vec<UTxO>,
) -> String {
let mut mesh = MeshTxBuilder::new_core();
let mut mesh = TxBuilder::new_core();
mesh.tx_out(
&recipient_address,
vec![Asset::new_from_str("lovelace", "1000000")],
Expand Down
70 changes: 29 additions & 41 deletions packages/sidan-csl-rs/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{csl, model::*};
use cardano_serialization_lib::JsError;

#[derive(Clone, Debug)]
pub struct MeshTxBuilderCore {
pub struct TxBuilderCore {
pub mesh_csl: MeshCSL,
pub mesh_tx_builder_body: MeshTxBuilderBody,
pub mesh_tx_builder_body: TxBuilderBody,
pub tx_evaluation_multiplier_percentage: u64,
}

Expand All @@ -22,46 +22,34 @@ pub struct MeshTxBuilderCore {
///
/// * `String` - the built transaction hex
pub fn serialize_tx_body(
mesh_tx_builder_body: MeshTxBuilderBody,
mesh_tx_builder_body: TxBuilderBody,
params: Option<Protocol>,
) -> Result<String, JsError> {
if mesh_tx_builder_body.change_address.is_empty() {
return Err(JsError::from_str("change address cannot be empty"));
}
let mut mesh_csl = MeshCSL::new(params);

MeshTxBuilderCore::add_all_inputs(&mut mesh_csl, mesh_tx_builder_body.inputs.clone())?;
MeshTxBuilderCore::add_all_outputs(&mut mesh_csl, mesh_tx_builder_body.outputs.clone())?;
MeshTxBuilderCore::add_all_collaterals(
&mut mesh_csl,
mesh_tx_builder_body.collaterals.clone(),
)?;
MeshTxBuilderCore::add_all_reference_inputs(
TxBuilderCore::add_all_inputs(&mut mesh_csl, mesh_tx_builder_body.inputs.clone())?;
TxBuilderCore::add_all_outputs(&mut mesh_csl, mesh_tx_builder_body.outputs.clone())?;
TxBuilderCore::add_all_collaterals(&mut mesh_csl, mesh_tx_builder_body.collaterals.clone())?;
TxBuilderCore::add_all_reference_inputs(
&mut mesh_csl,
mesh_tx_builder_body.reference_inputs.clone(),
)?;
MeshTxBuilderCore::add_all_withdrawals(
&mut mesh_csl,
mesh_tx_builder_body.withdrawals.clone(),
)?;
MeshTxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone())?;
MeshTxBuilderCore::add_all_certificates(
&mut mesh_csl,
mesh_tx_builder_body.certificates.clone(),
)?;
MeshTxBuilderCore::add_validity_range(
&mut mesh_csl,
mesh_tx_builder_body.validity_range.clone(),
);
MeshTxBuilderCore::add_all_required_signature(
TxBuilderCore::add_all_withdrawals(&mut mesh_csl, mesh_tx_builder_body.withdrawals.clone())?;
TxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone())?;
TxBuilderCore::add_all_certificates(&mut mesh_csl, mesh_tx_builder_body.certificates.clone())?;
TxBuilderCore::add_validity_range(&mut mesh_csl, mesh_tx_builder_body.validity_range.clone());
TxBuilderCore::add_all_required_signature(
&mut mesh_csl,
&mesh_tx_builder_body
.required_signatures
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>(),
)?;
MeshTxBuilderCore::add_all_metadata(&mut mesh_csl, mesh_tx_builder_body.metadata.clone())?;
TxBuilderCore::add_all_metadata(&mut mesh_csl, mesh_tx_builder_body.metadata.clone())?;

match mesh_tx_builder_body.network {
Some(current_network) => mesh_csl.add_script_hash(current_network)?,
Expand Down Expand Up @@ -139,19 +127,19 @@ pub fn serialize_tx_body(
mesh_csl.build_tx()
}

impl MeshTxBuilderCore {
impl TxBuilderCore {
/// ## Transaction building method
///
/// Create a new MeshTxBuilder instance
/// Create a new TxBuilder instance
///
/// ### Returns
///
/// * `Self` - A new MeshTxBuilder instance
/// * `Self` - A new TxBuilder instance
///
pub fn new_core(params: Option<Protocol>) -> Self {
Self {
mesh_csl: MeshCSL::new(params),
mesh_tx_builder_body: MeshTxBuilderBody {
mesh_tx_builder_body: TxBuilderBody {
inputs: vec![],
outputs: vec![],
collaterals: vec![],
Expand Down Expand Up @@ -194,7 +182,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple signing keys to the MeshTxBuilder instance
/// Add multiple signing keys to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -208,7 +196,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple inputs to the MeshTxBuilder instance
/// Add multiple inputs to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -230,7 +218,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple outputs to the MeshTxBuilder instance
/// Add multiple outputs to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -245,7 +233,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple collaterals to the MeshTxBuilder instance
/// Add multiple collaterals to the TxBuilder instance
///
/// ## Arguments
///
Expand All @@ -265,7 +253,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple reference inputs to the MeshTxBuilder instance
/// Add multiple reference inputs to the TxBuilder instance
///
/// ## Arguments
///
Expand All @@ -283,7 +271,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple withdrawals to the MeshTxBuilder instance
/// Add multiple withdrawals to the TxBuilder instance
///
/// ## Arguments
///
Expand Down Expand Up @@ -314,7 +302,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple mints to the MeshTxBuilder instance
/// Add multiple mints to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -338,7 +326,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple certificates to the MeshTxBuilder instance
/// Add multiple certificates to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -358,7 +346,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add a validity range to the MeshTxBuilder instance
/// Add a validity range to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -375,7 +363,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple required signatures to the MeshTxBuilder instance
/// Add multiple required signatures to the TxBuilder instance
///
/// ### Arguments
///
Expand All @@ -393,7 +381,7 @@ impl MeshTxBuilderCore {

/// ## Internal method
///
/// Add multiple metadata to the MeshTxBuilder instance
/// Add multiple metadata to the TxBuilder instance
///
/// ### Arguments
///
Expand Down Expand Up @@ -429,7 +417,7 @@ impl MeshTxBuilderCore {
// }
}

impl Default for MeshTxBuilderCore {
impl Default for TxBuilderCore {
fn default() -> Self {
Self::new_core(None)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sidan-csl-rs/src/core/tx_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashSet;

use crate::csl;
use crate::model::{
Asset, Datum, LanguageVersion, MeshTxBuilderBody, Output, OutputScriptSource,
Asset, Datum, LanguageVersion, TxBuilderBody, Output, OutputScriptSource,
ProvidedScriptSource, UTxO, UtxoInput, UtxoOutput, ValidityRange,
};

Expand All @@ -15,7 +15,7 @@ pub struct MeshTxParser {
pub tx_hash: String,
pub tx_hex: String,
pub tx_fee_lovelace: u64,
pub tx_body: MeshTxBuilderBody,
pub tx_body: TxBuilderBody,
pub csl_tx_body: csl::TransactionBody,
pub csl_witness_set: csl::TransactionWitnessSet,
}
Expand All @@ -24,7 +24,7 @@ impl MeshTxParser {
// Constructor method
pub fn new(s: &str) -> Result<MeshTxParser, JsError> {
// TODO: Deserialized into the tx_body
let mut tx_body = MeshTxBuilderBody {
let mut tx_body = TxBuilderBody {
inputs: vec![],
outputs: vec![],
collaterals: vec![],
Expand Down
Loading

0 comments on commit 33303cb

Please sign in to comment.