Skip to content

Commit

Permalink
feat: updating apply params to script
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed May 20, 2024
1 parent 9ae9c49 commit 0ec02c1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sidan-csl-rs
# whisky

This is a library for building off-chain code on Cardano. It is a cardano-cli like wrapper on cardano-serialization-lib (equivalent on MeshJS’s lower level APIs), supporting serious DApps’ backend on rust codebase. It has an active [F11 proposal](https://cardano.ideascale.com/c/idea/112172) for supporting the development.

Expand All @@ -7,22 +7,26 @@ This is a library for building off-chain code on Cardano. It is a cardano-cli li
### Rust Library

```sh
cargo add sidan-csl-rs
cargo add whisky
```

### JS / TS WASM Lib

- To be added
```sh
# For nodejs package
yarn add @sidan-lab/sidan-csl-rs-nodejs
# For browser package
yarn add @sidan-lab/sidan-csl-rs-browser
```

## APIs

The APIs of `sidan-csl-rs` consists of 3 parts:
The APIs of `whisky` consists of 3 parts:

### 1. APIs on core CSL logics

| Type | Name | Description |
| ------------------ | -------------------------- | -------------------------------------------------------------------------------------- |
| `MeshCSL` Property | `tx_hex` | This is the transaction hex, used for storing the transaction in hexadecimal format. |
| `MeshCSL` Property | `tx_builder` | This is the transaction builder, used for building transactions. |
| `MeshCSL` Property | `tx_inputs_builder` | This is the transaction inputs builder, used for building the inputs of a transaction. |
| `MeshCSL` Method | `add_tx_in` | This method is used to add a transaction input. |
Expand All @@ -46,10 +50,6 @@ The APIs of `sidan-csl-rs` consists of 3 parts:
| Util Function | `get_v2_script_hash` | To obtain script hash from script cbor |
| Util Function | `calculate_tx_hash` | To calculate the transaction hash from signed or unsigned hex |
| Util Function | `sign_transaction` | To add private key signature to current tx_hex |
| Util Function | `meshToPlutusData` | To be added -To serialize plutus data from mesh data type |
| Util Function | `jsonToPlutusData` | To be added -To serialize plutus data from json |
| Util Function | `cborToPlutusData` | To be added -To serialize plutus data from cbor |
| Util Function | To be added | To be added - A bunch of other methods that need CSL to serialized / deserialized |

### 2. `MeshTxBuilderCore`

Expand Down Expand Up @@ -80,26 +80,27 @@ The APIs of `sidan-csl-rs` consists of 3 parts:
| `MeshTxBuilderCore` User-facing Method | `required_signer_hash` | Sets the required signer of the transaction. |
| `MeshTxBuilderCore` User-facing Method | `tx_in_collateral` | Sets the collateral UTxO for the transaction. |
| `MeshTxBuilderCore` User-facing Method | `change_address` | Configures the address to accept change UTxO. |
| `MeshTxBuilderCore` User-facing Method | `change_output_datum` | [To be implemented] |
| `MeshTxBuilderCore` User-facing Method | `change_output_datum` | Add datum to change output |
| `MeshTxBuilderCore` User-facing Method | `invalid_before` | Sets the transaction valid interval to be valid only after the slot. |
| `MeshTxBuilderCore` User-facing Method | `invalid_hereafter` | Sets the transaction valid interval to be valid only before the slot. |
| `MeshTxBuilderCore` User-facing Method | `metadata_value` | Adds metadata to the transaction. |
| `MeshTxBuilderCore` User-facing Method | `signing_key` | Signs the transaction with the private key. |
| `MeshTxBuilderCore` User-facing Method | `tx_hex` | Obtain the current transaction hex from build |
| `MeshTxBuilderCore` User-facing Method | `reset` | [To be implemented] Resetting the whole MeshTxBuilderCore |
| `MeshTxBuilderCore` User-facing Method | `emptyTxBuilderBody` | [To be implemented] Resetting the body object |
| `MeshTxBuilderCore` User-facing Method | `complete` | Conduct async operation, e.g. updating redeemers, before `complete_sync` |
| `MeshTxBuilderCore` User-facing Method | `complete_sync` | Determine whether using customizedTx, if not queue all last items then serialize the tx |
| `MeshTxBuilderCore` User-facing Method | `complete_signing` | Adding signing keys and return txHex |
| `MeshTxBuilderCore` Internal Method | `serialize_tx_body` | Take the tx object and serialized it to txHex |
| `MeshTxBuilderCore` Internal Method | `updateRedeemer` | [To be implemented] Update SPEND and MINT exUnits |
| `MeshTxBuilderCore` Internal Method | `queue_input` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `queue_mint` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `queue_all_last_item` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_signing_keys` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_inputs` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_outputs` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_collaterals` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_reference_inputs` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `add_all_mints` | [To be implemented] |
| `MeshTxBuilderCore` Internal Method | `updateRedeemer` | Update SPEND and MINT exUnits |
| `MeshTxBuilderCore` Internal Method | `queue_input` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `queue_mint` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `queue_all_last_item` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_required_signature` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_inputs` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_outputs` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_collaterals` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_reference_inputs` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `add_all_mints` | Internal method before building tx |
| `MeshTxBuilderCore` Internal Method | `castRawDataToJsonString` | [To be implemented] Turn object to string, keep string as string |
| `MeshTxBuilderCore` Internal Method | `castDataToPlutusData` | [To be implemented] |
2 changes: 1 addition & 1 deletion core/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 core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sidan-csl-rs"
version = "0.5.0-alpha"
version = "0.5.0-alpha.1"
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
18 changes: 15 additions & 3 deletions core/src/core/utils/aiken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::{
*,
};

use self::model::BuilderDataType;

pub fn apply_double_cbor_encoding(script: &str) -> Result<String, JsError> {
let bytes: Vec<u8> = hex_to_bytes(script).unwrap();

Expand Down Expand Up @@ -37,16 +39,26 @@ fn test_apply_double_cbor_encoding() {

#[wasm_bindgen]
pub fn apply_params_to_script(
params_to_apply: JsVecString,
plutus_script: String,
params_to_apply: JsVecString,
param_type: BuilderDataType,
) -> Result<String, JsError> {
let double_encoded_script = apply_double_cbor_encoding(&plutus_script).unwrap();
let plutus_script =
PlutusScript::from_bytes(hex_to_bytes(&double_encoded_script).unwrap()).unwrap();
let mut plutus_list = PlutusList::new();
for param in params_to_apply {
let plutus_data = PlutusData::from_json(&param, PlutusDatumSchema::DetailedSchema).unwrap();
plutus_list.add(&plutus_data);
match param_type {
BuilderDataType::JSON => {
let plutus_data =
PlutusData::from_json(&param, PlutusDatumSchema::DetailedSchema).unwrap();
plutus_list.add(&plutus_data);
}
BuilderDataType::CBOR => {
let plutus_data = PlutusData::from_hex(&param).unwrap();
plutus_list.add(&plutus_data);
}
}
}
let bytes = apply_params_to_plutus_script(&plutus_list, plutus_script)?.to_bytes();
Ok(bytes_to_hex(&bytes))
Expand Down
8 changes: 8 additions & 0 deletions core/src/model/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::*;

#[wasm_bindgen]
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum BuilderDataType {
JSON,
CBOR,
}
2 changes: 2 additions & 0 deletions core/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod action;
mod asset;
mod data;
mod js_vec;
mod serialized_address;
mod value;
pub use action::*;
pub use asset::*;
pub use data::*;
pub use js_vec::*;
pub use serialized_address::*;
pub use value::*;
Expand Down
7 changes: 5 additions & 2 deletions core/tests/aiken_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mod aiken_tests {
use sidan_csl_rs::{core::utils::apply_params_to_script, model::JsVecString};
use sidan_csl_rs::{
core::utils::apply_params_to_script,
model::{BuilderDataType, JsVecString},
};

#[test]
fn test_apply_params_to_script() {
Expand All @@ -12,7 +15,7 @@ mod aiken_tests {
aiken_params.add(params[0].clone());

assert_eq!(
apply_params_to_script(aiken_params, script.to_string()).unwrap(),
apply_params_to_script(script.to_string(),aiken_params, BuilderDataType::JSON).unwrap(),
"584f584d010000332323232323222533300432323253330073370e900018041baa0011324a2600c0022c60120026012002600600229309b2b118021baa0015734aae7555cf2ba157449801034212340001"
);
}
Expand Down
4 changes: 2 additions & 2 deletions rust/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 rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "whiskey"
version = "0.1.0-alpha"
version = "0.1.0-alpha.1"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand Down

0 comments on commit 0ec02c1

Please sign in to comment.