Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluator fix #96

Merged
merged 5 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/-bug.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/-docs.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/-feature.md
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 43 additions & 0 deletions .github/pull_request.template.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions packages/Cargo.lock

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

2 changes: 1 addition & 1 deletion packages/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
version = "0.9.1"
version = "0.9.2"
resolver = "2"
members = [
"sidan-csl-rs",
Expand Down
2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
95 changes: 62 additions & 33 deletions packages/sidan-csl-rs/src/core/utils/evaluator.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
};
Expand Down Expand Up @@ -159,41 +154,25 @@ fn to_pallas_utxos(utxos: &Vec<UTxO>) -> Result<Vec<ResolvedInput>, 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);
}
Ok(resolved_inputs)
}

fn to_pallas_script_ref(utxo_output: &UtxoOutput) -> Result<Option<CborWrap<ScriptRef>>, 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<String>,
) -> Result<Option<CborWrap<ScriptRef>>, 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)
}
Expand Down Expand Up @@ -277,7 +256,7 @@ fn to_pallas_multi_asset_value(assets: &Vec<Asset>) -> Result<Value, JsError> {
mod test {
use super::*;
use crate::csl;
use model::{LanguageVersion, ScriptRef, UtxoInput};
use model::UtxoInput;
use pallas_codec::minicbor::Decoder;
use serde_json::json;

Expand Down Expand Up @@ -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())
}
}],
&[],
Expand Down Expand Up @@ -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());
}
}
11 changes: 1 addition & 10 deletions packages/sidan-csl-rs/src/model/tx_builder_types/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@ use serde::{Deserialize, Serialize};

use crate::model::Asset;

use super::LanguageVersion;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UtxoInput {
pub output_index: u32,
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<LanguageVersion>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UtxoOutput {
pub address: String,
pub amount: Vec<Asset>,
pub data_hash: Option<String>,
pub plutus_data: Option<String>,
pub script_ref: Option<ScriptRef>,
pub script_ref: Option<String>,
pub script_hash: Option<String>,
}

Expand Down
4 changes: 2 additions & 2 deletions packages/whisky-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
4 changes: 2 additions & 2 deletions packages/whisky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"] }

Expand Down
Loading