Skip to content

Commit

Permalink
Merge pull request #9 from sidan-lab/feature/update_csl
Browse files Browse the repository at this point in the history
bump cardano serialisation lib version
  • Loading branch information
twwu123 authored May 12, 2024
2 parents dc3bdfc + 8fbe045 commit 35e6226
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 205 deletions.
135 changes: 116 additions & 19 deletions rust/Cargo.lock

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

6 changes: 3 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
getrandom = { version = "0.2", features = ["js"] }
cardano-serialization-lib = "11.5.0"
cardano-serialization-lib = "12.0.0-alpha.30"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -21,15 +21,15 @@ async-trait = "0.1.79"
# non-wasm
[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))'.dependencies]
uplc = "=1.0.26-alpha"
wasm-bindgen = { version = "=0.2.87", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.90", features = ["serde-serialize"] }
rand_os = "0.1"
noop_proc_macro = "0.3.0"
pallas = "0.22.0"

# wasm
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
uplc = "0.0.29"
wasm-bindgen = { version = "=0.2.87", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.90", features = ["serde-serialize"] }
rand_os = { version = "0.1", features = ["wasm-bindgen"] }
js-sys = "=0.3.61"
wasm-bindgen-futures = "=0.4.34"
Expand Down
10 changes: 7 additions & 3 deletions rust/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
self.serialize_tx_body();
self.mesh_csl.tx_builder = build_tx_builder();
self.mesh_csl.tx_inputs_builder =
csl::tx_builder::tx_inputs_builder::TxInputsBuilder::new();
csl::TxInputsBuilder::new();
self
}

Expand Down Expand Up @@ -402,6 +402,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
tx_index: u32,
spending_script_hash: &str,
version: LanguageVersion,
script_size: usize,
) -> &mut Self {
let tx_in_item = self.tx_in_item.take();
if tx_in_item.is_none() {
Expand All @@ -417,6 +418,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
tx_index,
spending_script_hash: spending_script_hash.to_string(),
language_version: version,
script_size,
}));
self.tx_in_item = Some(TxIn::ScriptTxIn(input));
}
Expand Down Expand Up @@ -486,6 +488,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
tx_index: u32,
spending_script_hash: &str,
version: LanguageVersion,
script_size: usize,
) -> &mut Self {
let mint_item = self.mint_item.take();
if mint_item.is_none() {
Expand All @@ -497,6 +500,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
tx_index,
spending_script_hash: spending_script_hash.to_string(),
language_version: version,
script_size,
}));
self.mint_item = Some(mint_item);
self
Expand Down Expand Up @@ -686,7 +690,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
}

fn add_all_collaterals(&mut self, collaterals: Vec<PubKeyTxIn>) {
let mut collateral_builder = csl::tx_builder::tx_inputs_builder::TxInputsBuilder::new();
let mut collateral_builder = csl::TxInputsBuilder::new();
for collateral in collaterals {
self.mesh_csl
.add_collateral(&mut collateral_builder, collateral)
Expand All @@ -701,7 +705,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
}

fn add_all_mints(&mut self, mints: Vec<MintItem>) {
let mut mint_builder = csl::tx_builder::mint_builder::MintBuilder::new();
let mut mint_builder = csl::MintBuilder::new();
for (index, mint) in mints.into_iter().enumerate() {
match mint.type_.as_str() {
"Plutus" => self
Expand Down
4 changes: 4 additions & 0 deletions rust/src/builder/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pub trait IMeshTxBuilderCore {
/// * `tx_index` - The transaction index
/// * `spending_script_hash` - The spending script hash
/// * `version` - The language version
/// * `scrip_size` - Size of the script
///
/// ### Returns
///
Expand All @@ -260,6 +261,7 @@ pub trait IMeshTxBuilderCore {
tx_index: u32,
spending_script_hash: &str,
version: LanguageVersion,
script_size: usize,
) -> &mut Self;

/// ## Transaction building method
Expand Down Expand Up @@ -346,6 +348,7 @@ pub trait IMeshTxBuilderCore {
/// * `tx_index` - The transaction index
/// * `spending_script_hash` - The spending script hash
/// * `version` - The language version
/// * `script_size` - Size of the script
///
/// ### Returns
///
Expand All @@ -356,6 +359,7 @@ pub trait IMeshTxBuilderCore {
tx_index: u32,
spending_script_hash: &str,
version: LanguageVersion,
script_size: usize,
) -> &mut Self;

/// ## Transaction building method
Expand Down
12 changes: 5 additions & 7 deletions rust/src/core/algo/tx_eval.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use cardano_serialization_lib as csl;
use csl::error::JsError;
use csl::JsError;
use pallas::ledger::primitives::alonzo::RedeemerTag as PRedeemerTag;
use pallas::ledger::primitives::conway::PlutusV2Script;
use std::collections::HashMap;
Expand All @@ -11,7 +11,7 @@ use crate::core::constants::{get_v1_cost_models, get_v2_cost_models};
use crate::core::tx_parser::{IMeshTxParser, MeshTxParser};
use crate::model::{Action, Asset, Budget, RedeemerTag, UTxO, UtxoOutput};
use crate::service::IEvaluator;
use cardano_serialization_lib::address::Address;
use csl::Address;
use pallas::codec::minicbor::Decoder;
use pallas::codec::utils::{Bytes, CborWrap, KeyValuePairs};
use pallas::ledger::primitives::babbage::{
Expand Down Expand Up @@ -158,11 +158,9 @@ fn to_pallas_script_ref(utxo_output: &UtxoOutput) -> Result<Option<CborWrap<Scri

fn to_pallas_datum(utxo_output: &UtxoOutput) -> Result<Option<DatumOption>, JsError> {
if let Some(inline_datum) = &utxo_output.plutus_data {
let csl_plutus_data = csl::plutus::PlutusData::from_json(
inline_datum,
csl::plutus::PlutusDatumSchema::DetailedSchema,
)
.map_err(|err| JsError::from_str(&format!("Invalid plutus data found: {}", err)))?;
let csl_plutus_data =
csl::PlutusData::from_json(inline_datum, csl::PlutusDatumSchema::DetailedSchema)
.map_err(|err| JsError::from_str(&format!("Invalid plutus data found: {}", err)))?;

let plutus_data_bytes = csl_plutus_data.to_bytes();
let datum = CborWrap(
Expand Down
Loading

0 comments on commit 35e6226

Please sign in to comment.