Skip to content

Commit

Permalink
Merge pull request #1 from mpizenberg/main
Browse files Browse the repository at this point in the history
Update the wasm wrapper of aiken/uplc to the conway era
  • Loading branch information
micahkendall authored Sep 11, 2024
2 parents ef24a59 + cf0002d commit 49602cb
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 74 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Rust

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always
Expand All @@ -20,13 +20,13 @@ jobs:
steps:
- uses: jetli/[email protected]
with:
version: 'latest'
- uses: actions/checkout@v3
version: "latest"
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: ./build.sh
- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: |
pkg-node
pkg-web
pkg-web
108 changes: 66 additions & 42 deletions Cargo.lock

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

26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
[package]
name = "uplc-wrapper"
version = "0.0.1"
name = "uplc-wasm"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
description = "A WebAssembly (wasm) wrapper for the uplc crate"
repository = "https://github.com/mpizenberg/uplc-wasm"
license = "Apache-2.0"
keywords = ["cardano", "wasm", "uplc"]
categories = ["algorithms"]

[lib]
crate-type = ["cdylib"]

[dependencies]
error = "0.1.9"
uplc = { git = "https://github.com/aiken-lang/aiken.git"}
wasm-bindgen = "0.2.89"
k256 = { version = "0.13.0" }
js-sys = "0.3.61"
uplc = { git = "https://github.com/aiken-lang/aiken.git" }
wasm-bindgen = "0.2.93"
js-sys = "0.3.70"
wee_alloc = "0.4.5"
# required for wasm usage of getrandom
getrandom = { version = "0.2", features = ["js"] }

[profile.release]
codegen-units = 1
opt-level = "z"
lto = true
debug = false
debug = false

[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Oz']
10 changes: 4 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
rm -rf pkg
rm -rf pkg-node
rm -rf pkg-web
wasm-pack build -t nodejs
rm -rf pkg pkg-node pkg-web
wasm-pack build --target nodejs
mv pkg pkg-node
wasm-pack build
mv pkg pkg-web
wasm-pack build --target web
mv pkg pkg-web
30 changes: 19 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,37 @@ use js_sys;
use uplc::tx;
use wasm_bindgen::prelude::*;

// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
pub fn eval_phase_two_raw(
tx_bytes: &[u8],
utxos_bytes_x: Vec<js_sys::Uint8Array>,
utxos_bytes_y: Vec<js_sys::Uint8Array>,
utxos_refs_bytes: Vec<js_sys::Uint8Array>,
utxos_outputs_bytes: Vec<js_sys::Uint8Array>,
cost_mdls_bytes: &[u8],
initial_budget_n: u64,
initial_budget_d: u64,
slot_config_x: u64,
slot_config_y: u64,
slot_config_z: u32,
cpu_budget: u64,
mem_budget: u64,
slot_config_zero_time: u64,
slot_config_zero_slot: u64,
slot_config_slot_length: u32,
) -> Result<Vec<js_sys::Uint8Array>, JsValue> {
let utxos_bytes = utxos_bytes_x
let utxos_bytes = utxos_refs_bytes
.into_iter()
.zip(utxos_bytes_y.into_iter())
.zip(utxos_outputs_bytes.into_iter())
.map(|(x, y)| (x.to_vec(), y.to_vec()))
.collect::<Vec<(Vec<u8>, Vec<u8>)>>();
return tx::eval_phase_two_raw(
tx_bytes,
&utxos_bytes,
cost_mdls_bytes,
(initial_budget_n, initial_budget_d),
(slot_config_x, slot_config_y, slot_config_z),
(cpu_budget, mem_budget),
(
slot_config_zero_time,
slot_config_zero_slot,
slot_config_slot_length,
),
false,
|_| (),
)
Expand Down

0 comments on commit 49602cb

Please sign in to comment.