diff --git a/.github/ISSUE_TEMPLATE/-bug.md b/.github/ISSUE_TEMPLATE/-bug.md new file mode 100644 index 0000000..e2a142a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/-bug.md @@ -0,0 +1,32 @@ +--- +name: "[BUG]: Short description of the problem" +about: Create a report to help us improve +title: "" +labels: "" +assignees: "" +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Station (please complete the following information):** + +- OS: [e.g. Windows, Ubuntu] +- Version [e.g. 10, 11, 22.02] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/-docs.md b/.github/ISSUE_TEMPLATE/-docs.md new file mode 100644 index 0000000..e3bf5da --- /dev/null +++ b/.github/ISSUE_TEMPLATE/-docs.md @@ -0,0 +1,16 @@ +--- +name: "[DOCS] Short description of the documentation issue" +about: Suggest documentation improvements +title: "" +labels: "" +assignees: "" +--- + +**Describe the issue with the documentation** +A clear and concise description of what the issue is. + +**Suggest a solution** +Describe how the documentation can be improved or corrected. + +**Additional context** +Add any other context, references, or screenshots that might help clarify the issue. diff --git a/.github/ISSUE_TEMPLATE/-feature.md b/.github/ISSUE_TEMPLATE/-feature.md new file mode 100644 index 0000000..7c1fb5c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/-feature.md @@ -0,0 +1,19 @@ +--- +name: "[FEATURE] Short description of the feature" +about: Suggest an idea for this project +title: "" +labels: "" +assignees: "" +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/pull_request.template.md b/.github/pull_request.template.md new file mode 100644 index 0000000..0691d7c --- /dev/null +++ b/.github/pull_request.template.md @@ -0,0 +1,43 @@ +Thank you for contributing to Whisky! We appreciate your effort and dedication to improving this project. To ensure that your contribution is in line with the project's guidelines and can be reviewed efficiently, please fill out the template below. + +Remember to follow our [Contributing Guide](CONTRIBUTING.md) before submitting your pull request. + +## Summary + +> Please provide a brief, concise summary of the changes in your pull request. Explain the problem you are trying to solve and the solution you have implemented. + +## Type of Change + +> Please mark the relevant option(s) for your pull request: + +### Feature Change + +> Type of feature change: +> +> 1. New feature - non-breaking change which adds functionality +> 2. Breaking change - fix or feature that would cause existing functionality to not work as expected + +- [ ] Rust crate `whisky` - New feature +- [ ] Rust crate `whisky` - Breaking change +- [ ] WASM `sidan-csl-rs` - New feature +- [ ] WASM `sidan-csl-rs` - Breaking change + +### Maintenance + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] Code refactoring (improving code quality without changing its behavior) +- [ ] Documentation update (adding or updating documentation related to the project) + +## Checklist + +> Please ensure that your pull request meets the following criteria: + +- [ ] My code is appropriately commented and includes relevant documentation, if necessary +- [ ] I have added tests to cover my changes, if necessary +- [ ] I have updated the documentation, if necessary +- [ ] All new and existing tests pass +- [ ] Both rust and wasm build pass + +## Additional Information + +> If you have any additional information or context to provide, such as screenshots, relevant issues, or other details, please include them here. diff --git a/packages/Cargo.lock b/packages/Cargo.lock index 609733f..97a8388 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -2644,7 +2644,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.9.1" +version = "0.9.2" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -3258,7 +3258,7 @@ dependencies = [ [[package]] name = "whisky" -version = "0.9.1" +version = "0.9.2" dependencies = [ "async-trait", "cryptoxide", @@ -3283,7 +3283,7 @@ dependencies = [ [[package]] name = "whisky-examples" -version = "0.9.1" +version = "0.9.2" dependencies = [ "actix-cors", "actix-web", diff --git a/packages/Cargo.toml b/packages/Cargo.toml index 5ff39e5..66258ab 100644 --- a/packages/Cargo.toml +++ b/packages/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -version = "0.9.1" +version = "0.9.2" resolver = "2" members = [ "sidan-csl-rs", diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index db991cd..3cab249 100644 --- a/packages/sidan-csl-rs/Cargo.toml +++ b/packages/sidan-csl-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.9.1" +version = "0.9.2" edition = "2021" license = "Apache-2.0" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs" diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index 88e4632..bce8558 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -1,8 +1,4 @@ use pallas_codec::utils::NonEmptyKeyValuePairs; -use pallas_primitives::conway::NativeScript; -use pallas_primitives::conway::PlutusV1Script; -use pallas_primitives::conway::PlutusV2Script; -use pallas_primitives::conway::PlutusV3Script; use pallas_primitives::conway::RedeemerTag as PRedeemerTag; use std::collections::HashMap; use uplc::tx::SlotConfig; @@ -13,12 +9,11 @@ use crate::csl::{Address, JsError}; use crate::model::{Action, Asset, Budget, JsVecString, Network, RedeemerTag, UTxO, UtxoOutput}; use crate::wasm::WasmResult; use crate::*; -use pallas_codec::minicbor::Decoder; use pallas_codec::utils::{Bytes, CborWrap, PositiveCoin}; use pallas_primitives::{ conway::{ AssetName, Coin, CostMdls, DatumOption, PlutusData, PolicyId, PostAlonzoTransactionOutput, - PseudoScript, ScriptRef, TransactionOutput, Value, + ScriptRef, TransactionOutput, Value, }, Fragment, }; @@ -159,7 +154,7 @@ fn to_pallas_utxos(utxos: &Vec) -> Result, JsError> { address: Bytes::from(Address::from_bech32(&utxo.output.address)?.to_bytes()), value: to_pallas_value(&utxo.output.amount)?, datum_option: to_pallas_datum(&utxo.output)?, - script_ref: to_pallas_script_ref(&utxo.output)?, + script_ref: to_pallas_script_ref(&utxo.output.script_ref)?, }), }; resolved_inputs.push(resolved_input); @@ -167,33 +162,17 @@ fn to_pallas_utxos(utxos: &Vec) -> Result, JsError> { Ok(resolved_inputs) } -fn to_pallas_script_ref(utxo_output: &UtxoOutput) -> Result>, JsError> { - if let Some(script_ref) = &utxo_output.script_ref { - let script_bytes = hex::decode(script_ref.script_hex.clone()) +fn to_pallas_script_ref( + script_ref: &Option, +) -> Result>, JsError> { + if let Some(script_ref) = script_ref { + let script_bytes = hex::decode(script_ref) .map_err(|err| JsError::from_str(&format!("Invalid script hex found: {}", err)))?; - let unwrapped_bytes = Decoder::new(&script_bytes) - .bytes() - .map_err(|err| JsError::from_str(&format!("Invalid script hex found: {}", err)))?; + let pallas_script = ScriptRef::decode_fragment(&script_bytes) + .map_err(|err| JsError::from_str(&format!("Invalid script found: {}", err)))?; - match &script_ref.script_version { - Some(version) => match version { - model::LanguageVersion::V1 => Ok(Some(CborWrap(PseudoScript::PlutusV1Script( - PlutusV1Script(unwrapped_bytes.to_vec().into()), - )))), - model::LanguageVersion::V2 => Ok(Some(CborWrap(PseudoScript::PlutusV2Script( - PlutusV2Script(unwrapped_bytes.to_vec().into()), - )))), - model::LanguageVersion::V3 => Ok(Some(CborWrap(PseudoScript::PlutusV3Script( - PlutusV3Script(unwrapped_bytes.to_vec().into()), - )))), - }, - None => Ok(Some(CborWrap(PseudoScript::NativeScript( - NativeScript::decode_fragment(unwrapped_bytes).map_err(|err| { - JsError::from_str(&format!("Invalid native script found: {}", err)) - })?, - )))), - } + Ok(Some(CborWrap(pallas_script))) } else { Ok(None) } @@ -277,7 +256,7 @@ fn to_pallas_multi_asset_value(assets: &Vec) -> Result { mod test { use super::*; use crate::csl; - use model::{LanguageVersion, ScriptRef, UtxoInput}; + use model::UtxoInput; use pallas_codec::minicbor::Decoder; use serde_json::json; @@ -329,7 +308,7 @@ mod test { data_hash: None, plutus_data: None, script_hash: None, - script_ref: Some(ScriptRef { script_hex: "5655010000322223253330054a229309b2b1bad0025735".to_string(), script_version: Some(LanguageVersion::V2)}) + script_ref: Some("82025655010000322223253330054a229309b2b1bad0025735".to_string()) } }], &[], @@ -363,4 +342,54 @@ mod test { decoded_bytes ); } + + #[test] + fn test_v1_script_ref() { + let script_ref = to_pallas_script_ref(&Some( + "82015655010000322223253330054a229309b2b1bad0025735".to_string(), + )) + .unwrap() + .unwrap(); + + match script_ref.0 { + ScriptRef::PlutusV1Script(_) => {} + _ => panic!("Invalid script ref"), + } + } + + #[test] + fn test_v2_script_ref() { + let script_ref = to_pallas_script_ref(&Some( + "82025655010000322223253330054a229309b2b1bad0025735".to_string(), + )) + .unwrap() + .unwrap(); + + match script_ref.0 { + ScriptRef::PlutusV2Script(_) => {} + _ => panic!("Invalid script ref"), + } + } + + #[test] + fn test_v3_script_ref() { + let script_ref = to_pallas_script_ref(&Some( + "82035655010000322223253330054a229309b2b1bad0025735".to_string(), + )) + .unwrap() + .unwrap(); + + match script_ref.0 { + ScriptRef::PlutusV3Script(_) => {} + _ => panic!("Invalid script ref"), + } + } + + #[test] + fn test_invalid_native_script_ref() { + let script_ref = to_pallas_script_ref(&Some( + "82005655010000322223253330054a229309b2b1bad0025735".to_string(), + )); + assert!(script_ref.is_err()); + } } diff --git a/packages/sidan-csl-rs/src/model/tx_builder_types/utxo.rs b/packages/sidan-csl-rs/src/model/tx_builder_types/utxo.rs index 95380b0..692a88d 100644 --- a/packages/sidan-csl-rs/src/model/tx_builder_types/utxo.rs +++ b/packages/sidan-csl-rs/src/model/tx_builder_types/utxo.rs @@ -2,8 +2,6 @@ use serde::{Deserialize, Serialize}; use crate::model::Asset; -use super::LanguageVersion; - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct UtxoInput { @@ -11,13 +9,6 @@ pub struct UtxoInput { pub tx_hash: String, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ScriptRef { - pub script_hex: String, - pub script_version: Option, -} - #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct UtxoOutput { @@ -25,7 +16,7 @@ pub struct UtxoOutput { pub amount: Vec, pub data_hash: Option, pub plutus_data: Option, - pub script_ref: Option, + pub script_ref: Option, pub script_hash: Option, } diff --git a/packages/whisky-examples/Cargo.toml b/packages/whisky-examples/Cargo.toml index 89dbe94..533da32 100644 --- a/packages/whisky-examples/Cargo.toml +++ b/packages/whisky-examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky-examples" -version = "0.9.1" +version = "0.9.2" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -13,4 +13,4 @@ path = "src/server.rs" actix-cors = "0.7.0" actix-web = "4.9.0" serde = "1.0.209" -whisky = { version = "=0.9.1", path = "../whisky" } +whisky = { version = "=0.9.2", path = "../whisky" } diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index d099abb..4553ffb 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky" -version = "0.9.1" +version = "0.9.2" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -24,7 +24,7 @@ pallas-codec = { version = "0.30.2", features = ["num-bigint"] } pallas-primitives = "0.30.2" pallas-traverse = "0.30.2" maestro-rust-sdk = "1.1.3" -sidan-csl-rs = { version = "=0.9.1", path = "../sidan-csl-rs" } +sidan-csl-rs = { version = "=0.9.2", path = "../sidan-csl-rs" } reqwest = "0.12.5" tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }