Skip to content

Commit

Permalink
Feature/native script withdrawal (#63)
Browse files Browse the repository at this point in the history
* native script withdrawal

* add support for native and plutus certs

* clean up

* clean up unused imports

* add certificate redeemer logic

* chore: fix minor linting and update action secrets

* feat: bump ver

* fix: fix utxo selection panic

* plutus script certs

* update integration tests

* chore: fix naming and param

---------

Co-authored-by: SIDANWhatever <[email protected]>
  • Loading branch information
twwu123 and HinsonSIDAN authored Aug 8, 2024
1 parent 65bb3dc commit 81d75ae
Show file tree
Hide file tree
Showing 28 changed files with 1,241 additions and 702 deletions.
27 changes: 24 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.6.13"
version = "0.6.14"
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.6.13"
version = "0.6.14"
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
63 changes: 5 additions & 58 deletions packages/sidan-csl-rs/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
Withdrawal::PlutusScriptWithdrawal(plutus_script_withdrawal) => {
mesh_csl.add_plutus_withdrawal(plutus_script_withdrawal)?
}
Withdrawal::SimpleScriptWithdrawal(simple_script_withdrawal) => {
mesh_csl.add_simple_script_withdrawal(simple_script_withdrawal)?
}
}
}
mesh_csl
Expand All @@ -290,7 +293,6 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
}
};
}
println!("6-3");
mesh_csl.tx_builder.set_mint_builder(&mint_builder);
Ok(())
}
Expand All @@ -300,63 +302,8 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
certificates: Vec<Certificate>,
) -> Result<(), JsError> {
let mut certificates_builder = csl::CertificatesBuilder::new();
for cert in certificates {
match cert {
Certificate::RegisterPool(register_pool) => {
mesh_csl.add_register_pool_cert(&mut certificates_builder, register_pool)?
}
Certificate::RegisterStake(register_stake) => {
mesh_csl.add_register_stake_cert(&mut certificates_builder, register_stake)?
}
Certificate::DelegateStake(delegate_stake) => {
mesh_csl.add_delegate_stake_cert(&mut certificates_builder, delegate_stake)?
}
Certificate::DeregisterStake(deregister_stake) => mesh_csl
.add_deregister_stake_cert(&mut certificates_builder, deregister_stake)?,
Certificate::RetirePool(retire_pool) => {
mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool)?
}
Certificate::VoteDelegation(vote_delegation) => {
mesh_csl.add_vote_delegation_cert(&mut certificates_builder, vote_delegation)?
}
Certificate::StakeAndVoteDelegation(stake_and_vote_delegation) => mesh_csl
.add_stake_and_vote_delegation_cert(
&mut certificates_builder,
stake_and_vote_delegation,
)?,
Certificate::StakeRegistrationAndDelegation(stake_registration_and_delegation) => {
mesh_csl.add_stake_registration_and_delegation_cert(
&mut certificates_builder,
stake_registration_and_delegation,
)?
}
Certificate::VoteRegistrationAndDelegation(vote_registration_and_delegation) => {
mesh_csl.add_vote_registration_and_delgation_cert(
&mut certificates_builder,
vote_registration_and_delegation,
)?
}
Certificate::StakeVoteRegistrationAndDelegation(
stake_vote_registration_and_delegation,
) => mesh_csl.add_stake_vote_registration_and_delegation_cert(
&mut certificates_builder,
stake_vote_registration_and_delegation,
)?,
Certificate::CommitteeHotAuth(committee_hot_auth) => mesh_csl
.add_committee_hot_auth_cert(&mut certificates_builder, committee_hot_auth)?,
Certificate::CommitteeColdResign(commitee_cold_resign) => mesh_csl
.add_commitee_cold_resign_cert(
&mut certificates_builder,
commitee_cold_resign,
)?,
Certificate::DRepRegistration(drep_registration) => mesh_csl
.add_drep_registration_cert(&mut certificates_builder, drep_registration)?,
Certificate::DRepDeregistration(drep_deregistration) => mesh_csl
.add_drep_deregistration_cert(&mut certificates_builder, drep_deregistration)?,
Certificate::DRepUpdate(drep_update) => {
mesh_csl.add_drep_update_cert(&mut certificates_builder, drep_update)?
}
}
for (index, cert) in certificates.into_iter().enumerate() {
mesh_csl.add_cert(&mut certificates_builder, cert, index as u64)?
}
mesh_csl.tx_builder.set_certs_builder(&certificates_builder);
Ok(())
Expand Down
17 changes: 10 additions & 7 deletions packages/sidan-csl-rs/src/core/algo/utxo_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ pub fn js_select_utxos(
.expect("Error deserializing required_assets");
let required_value = Value::from_asset_vec(required_assets);

select_utxos(inputs, required_value, threshold.to_string())
select_utxos(&inputs, required_value, threshold)
.map_err(|e| JsError::from_str(&e))
.map(|utxos| serde_json::to_string(&utxos).unwrap())
}

pub fn select_utxos(
inputs: Vec<UTxO>,
inputs: &[UTxO],
required_assets: Value,
threshold: String,
threshold: &str,
) -> Result<Vec<UTxO>, String> {
let mut total_required_assets = required_assets.clone();
total_required_assets.add_asset(Asset::new("lovelace".to_string(), threshold));
total_required_assets.add_asset(Asset::new("lovelace".to_string(), threshold.to_string()));

// Classify the utxos
let mut only_lovelace: Vec<usize> = vec![];
Expand Down Expand Up @@ -103,7 +103,11 @@ pub fn select_utxos(
for unit in required_units.clone() {
if total_required_assets.get(&unit) > 0 {
println!("Total required assets: {:?}", total_required_assets);
return Err("Selection failed".to_string());
return Err(format!(
"Selection failed, {:?} value missing. Reminder, in this selection you required for {:?} extra lovelace as threshold",
total_required_assets,
threshold
));
}
}

Expand Down Expand Up @@ -134,7 +138,6 @@ fn test_basic_selection() {

let mut required_assets: Value = Value::new();
required_assets.add_asset(Asset::new_from_str("lovelace", "5000000"));
let selected_list =
select_utxos(utxo_list.clone(), required_assets, "5000000".to_string()).unwrap();
let selected_list = select_utxos(&utxo_list, required_assets, "5000000").unwrap();
assert_eq!(utxo_list, selected_list);
}
Loading

0 comments on commit 81d75ae

Please sign in to comment.