diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..bf379c5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,24 @@ +{ + "name": "RustyContainer1", + "image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye", + "features": { + "ghcr.io/lee-orr/rusty-dev-containers/cargo-watch:0": {} + }, + "mounts": [ + { + "source": "devcontainer-cargo-cache-${devcontainerId}", + "target": "/usr/local/cargo", + "type": "volume" + } + ], + "remoteUser": "root", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer" + ] + } + }, + "postCreateCommand": "rustup install nightly && rustup default nightly" + } + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index e79af45..893c497 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -420,7 +420,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "marlowe_lang" -version = "0.3.1" +version = "0.3.2" dependencies = [ "assert-json-diff", "bech32", diff --git a/Cargo.toml b/Cargo.toml index 8eba6be..3990bff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "marlowe_lang" description = "experimental parser lib for Cardano Marlowe DSL" -version = "0.3.1" +version = "0.3.2" edition = "2021" authors = ["Olof Blomqvist "] repository = "https://github.com/OlofBlomqvist/marlowe_rust" diff --git a/build_npm_packages.ps1 b/build_npm_packages.ps1 index 00bb4fe..c652a72 100644 --- a/build_npm_packages.ps1 +++ b/build_npm_packages.ps1 @@ -29,7 +29,7 @@ if($skipBuild -ne $true) { Remove-Item $latest_dir/ -Recurse -Force -ErrorAction Stop } # Build for NodeJS - wasm-pack build --all-features --release --target nodejs --out-dir $nodejs_dir/pkg + /home/olof/.cargo/bin/wasm-pack build --all-features --release --target nodejs --out-dir $nodejs_dir/pkg $j = Get-Content $nodejs_dir/pkg/package.json |convertfrom-json if($null -ne $version -and $version.Length -gt 1) { $j.version = $version + "-nodejs" @@ -42,7 +42,7 @@ if($skipBuild -ne $true) { # Build for Web - wasm-pack build --all-features --release --target web --out-dir $web_dir/pkg + /home/olof/.cargo/bin/wasm-pack build --all-features --release --target web --out-dir $web_dir/pkg $j = Get-Content $web_dir/pkg/package.json |convertfrom-json if($null -ne $version -and $version.Length -gt 0) { $j.version = $version + "-web" @@ -62,7 +62,7 @@ if($skipBuild -ne $true) { #wasm-pack pack $web_dir # Build bundle - wasm-pack build --all-features --release --target bundler --out-dir $bundle_dir/pkg + /home/olof/.cargo/bin/wasm-pack build --all-features --release --target bundler --out-dir $bundle_dir/pkg $j = Get-Content $bundle_dir/pkg/package.json |convertfrom-json if($null -ne $version -and $version.Length -gt 0) { $j.version = $version + "-bundle" @@ -75,7 +75,7 @@ if($skipBuild -ne $true) { #wasm-pack pack $bundle_dir # Build latest - wasm-pack build --all-features --release --target nodejs --out-dir $latest_dir/pkg + /home/olof/.cargo/bin/wasm-pack build --all-features --release --target nodejs --out-dir $latest_dir/pkg $j = Get-Content $latest_dir/pkg/package.json |convertfrom-json if($null -ne $version -and $version.Length -gt 0) { $j.version = $version @@ -98,14 +98,14 @@ if($skipBuild -ne $true) { if($publish) { write-host -ForegroundColor Green "Publishing web... $web_dir $webv" - wasm-pack publish -t web --tag web $web_dir + /home/olof/.cargo/bin/wasm-pack publish -t web --tag web $web_dir write-host -ForegroundColor Green "Publishing nodejs... $nodejs_dir $njsv" - wasm-pack publish -t nodejs --tag nodejs $nodejs_dir + /home/olof/.cargo/bin/wasm-pack publish -t nodejs --tag nodejs $nodejs_dir write-host -ForegroundColor Green "Publishing bundle... $bundle_dir $bundlev" - wasm-pack publish -t bundler --tag bundle $bundle_dir + /home/olof/.cargo/bin/wasm-pack publish -t bundler --tag bundle $bundle_dir if($publishLatestTag) { write-host -ForegroundColor Green "Publishing latest... $latest_dir $latestlev" - wasm-pack publish -t nodejs --tag latest $latest_dir + /home/olof/.cargo/bin/wasm-pack publish -t nodejs --tag latest $latest_dir } -} \ No newline at end of file +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d5519ef --- /dev/null +++ b/flake.lock @@ -0,0 +1,130 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716220750, + "narHash": "sha256-Lhhrd1ZBNXCbUupWGq6gRPIy1qMKEdcAXcjnwgVqe/U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "641daa314d5bc1bca4b345da8eb08a130b109c79", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1716257780, + "narHash": "sha256-R+NjvJzKEkTVCmdrKRfPE4liX/KMGVqGUwwS5H8ET8A=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "4e5e3d2c5c9b2721bd266f9e43c14e96811b89d2", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..26052e1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + description = "A Rust application using the nightly compiler"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ rust-overlay.overlays.default ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + rustNightly = pkgs.rustChannelOf { + channel = "nightly"; + date = "2024-03-04"; + }; + + in { + + packages.default = pkgs.rustPlatform.buildRustPackage rec { + + pname = "odd-box"; + version = "0.0.10"; + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + #buildNoDefaultFeatures = true; + #buildFeatures = [ "color" "net" ]; + #checkFeatures = [ "color" ]; + + meta = with pkgs.lib; { + description = "dead simple reverse-proxy"; + homepage = "https://github.com/OlofBlomqvist/odd-box"; + license = licenses.mit; + maintainers = ["olof@twnet.se"]; + }; + + buildType = "release"; + buildInputs = [ pkgs.openssl pkgs.pkg-config ]; + + RUSTC = "${rustNightly.default}/bin/rustc"; + CARGO = "${rustNightly.default}/bin/cargo"; + + nativeBuildInputs = [ rustNightly.default ]; + + OPENSSL_DIR = "${pkgs.openssl.dev}"; + OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib"; + + installPhase = '' + mkdir -p $out/bin + cp target/*/release/odd-box $out/bin/ + ''; + + }; + + # DEV THE THING + devShell = pkgs.mkShell { + nativeBuildInputs = [ + rustNightly.default + pkgs.openssl + pkgs.pkg-config + ]; + }; + } + + ); +} diff --git a/pkg_wasi/libmarlowe_lang.rlib b/pkg_wasi/libmarlowe_lang.rlib new file mode 100644 index 0000000..b894e52 Binary files /dev/null and b/pkg_wasi/libmarlowe_lang.rlib differ diff --git a/pkg_wasi/marlowe_lang.wasm b/pkg_wasi/marlowe_lang.wasm old mode 100644 new mode 100755 index 371258a..9e72fb2 Binary files a/pkg_wasi/marlowe_lang.wasm and b/pkg_wasi/marlowe_lang.wasm differ diff --git a/pkg_wasi/marlowe_lang_cli.wasm b/pkg_wasi/marlowe_lang_cli.wasm old mode 100644 new mode 100755 index 0f5e28f..a9db39e Binary files a/pkg_wasi/marlowe_lang_cli.wasm and b/pkg_wasi/marlowe_lang_cli.wasm differ diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..92b36eb --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +cargo-features = ["edition2021"] \ No newline at end of file diff --git a/src/lib/deserialization/json.rs b/src/lib/deserialization/json.rs index 5e04979..8defb08 100644 --- a/src/lib/deserialization/json.rs +++ b/src/lib/deserialization/json.rs @@ -186,12 +186,12 @@ impl<'de> serde::de::Visitor<'de> for InputActionVisitor { }) } - if let Some(a) = input_that_chooses_num && - let Some(b) = for_choice_id + if let Some(chosen_number) = input_that_chooses_num && + let Some(choice_id) = for_choice_id { return Ok(InputAction::Choice { - for_choice_id: Some(a), - input_that_chooses_num: b + for_choice_id: Some(choice_id), + input_that_chooses_num: chosen_number }) } diff --git a/src/lib/extras/js.rs b/src/lib/extras/js.rs index cec1db7..6120650 100644 --- a/src/lib/extras/js.rs +++ b/src/lib/extras/js.rs @@ -1198,4 +1198,12 @@ fn payee_to_wasm(x:&Payee) -> WasmPayee { _ => panic!("cannot convert payee to wasm because it is null.") }; account_id_to_wasm_payee(accid) -} \ No newline at end of file +} + + +#[wasm_bindgen()] +pub fn redeemer_json_to_cbor(list_of_inputs_json:&str) { + let deserialized : Vec = crate::deserialization::json::deserialize(list_of_inputs_json.into()).unwrap(); + let action = deserialized.into_iter().map(PossiblyMerkleizedInput::Action).collect::>(); + crate::serialization::cborhex::serialize(action).unwrap(); +} \ No newline at end of file diff --git a/src/lib/tests/serialization.rs b/src/lib/tests/serialization.rs index 8126149..825f7f1 100644 --- a/src/lib/tests/serialization.rs +++ b/src/lib/tests/serialization.rs @@ -15,7 +15,7 @@ fn json_can_deserialize_choice_id_with_owner_address() { "choice_owner": { "address" : "addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs68faae" } - } + } "#; let choice_id : crate::types::marlowe::ChoiceId = serde_json::from_str(serialized).expect("err unser"); assert!(choice_id.choice_name=="KALLES CHOICE"); @@ -472,3 +472,47 @@ fn serialize_datum_json() { crate::serialization::json::serialize(&original_datum_decoded).unwrap(); } + + +#[test] +fn deserialize_input_action() { + + let j = r##" + { + "for_choice_id": { + "choice_owner": { + "address": "addr1qxfturx55xqdm3pu3vwsrvvz26syajjlmpz0whxvll7cw27r7cz4mu6gh005gdck67p7y9d8s8zsfgjkcdy75mrjh6jqjy687a" + }, + "choice_name": "Amount" + }, + "input_that_chooses_num": 1257743 + } + "##; + + let deserialized : crate::types::marlowe::InputAction = crate::deserialization::json::deserialize(j.into()).unwrap(); + +} + +#[test] +fn input_actions_to_cbor() { + let j = r##" + [{ + "for_choice_id": { + "choice_owner": { + "address": "addr1qxfturx55xqdm3pu3vwsrvvz26syajjlmpz0whxvll7cw27r7cz4mu6gh005gdck67p7y9d8s8zsfgjkcdy75mrjh6jqjy687a" + }, + "choice_name": "Amount" + }, + "input_that_chooses_num": 1257743 + }] + "##; + let deserialized : Vec = crate::deserialization::json::deserialize(j.into()).unwrap(); + let action = deserialized.into_iter().map(PossiblyMerkleizedInput::Action).collect::>(); + let cbor = crate::serialization::cborhex::serialize(action).unwrap(); + + assert!( + &cbor == + "9fd8799fd87a9fd8799f46416d6f756e74d8799fd87a80d8799fd8799f581c92be0cd4a180ddc43c8b1d01b18256a04eca5fd844f75cccfffd872bffd8799fd8799fd8799f581cc3f6055df348bbdf443716d783e215a781c504a256c349ea6c72bea4ffffffffffff1a0013310fffffff" + ) + +} \ No newline at end of file