Skip to content

Commit

Permalink
Merge pull request #1 from matiwinnetou/ex-budget-support
Browse files Browse the repository at this point in the history
Added support for passing ExBudget / InitialBudget externally
  • Loading branch information
satran004 authored Mar 17, 2023
2 parents 4ba760b + 5593673 commit 4753198
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aiken-jna-wrapper"
version = "0.0.9"
version = "0.1.0"
authors = ["Satya <[email protected]>"]
edition = "2021"

Expand Down
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ extern crate core;
mod transaction;
mod build;

use jni::JNIEnv;
use jni::objects::{JClass, JString};
use jni::sys::jstring;
use std::os::raw::c_char;
use std::ffi::{CStr, CString};
use std::{mem, panic};
Expand All @@ -31,20 +28,30 @@ pub struct InitialBudget {

#[no_mangle]
#[allow(non_snake_case)]
pub fn eval_phase_two(tx_hex: *const c_char, inputs: *const c_char, outputs: *const c_char, cost_mdls: *const c_char, slot_config: SlotConfig) -> *const c_char {
pub fn eval_phase_two(tx_hex: *const c_char,
inputs: *const c_char,
outputs: *const c_char,
cost_mdls: *const c_char,
initial_budget: InitialBudget,
slot_config: SlotConfig) -> *const c_char {
let result = panic::catch_unwind(|| {
let tx_hex = to_string(tx_hex);
let inputs = to_string(inputs);
let outputs = to_string(outputs);
let cost_mdls = to_string(cost_mdls);

let ak_ex_budget = uplc::machine::cost_model::ExBudget {
mem: initial_budget.mem as i64,
cpu: initial_budget.cpu as i64,
};

let ak_slot_config = uplc::tx::script_context::SlotConfig {
zero_time: slot_config.zero_time,
zero_slot: slot_config.zero_slot,
slot_length: slot_config.slot_length,
};

let result = transaction::eval_phase_two(&tx_hex, &inputs, &outputs, &cost_mdls, ak_slot_config);
let result = transaction::eval_phase_two(&tx_hex, &inputs, &outputs, &cost_mdls, ak_ex_budget, ak_slot_config);
match result {
Ok(redeemer) => {
to_ptr(redeemer)
Expand All @@ -57,7 +64,7 @@ pub fn eval_phase_two(tx_hex: *const c_char, inputs: *const c_char, outputs: *co

match result {
Ok(c) => c,
Err(cause) => {
Err(_cause) => {
to_ptr(String::new())
}
}
Expand Down
Loading

0 comments on commit 4753198

Please sign in to comment.