Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3618506
Reworked mint helper function to accept minting script instead of jus…
vsubhuman Nov 28, 2021
edbab5f
Fixed test for fee estimation
vsubhuman Nov 28, 2021
b6de84d
Added test that fee-estimation fails when mint scripts are not provided
vsubhuman Nov 29, 2021
276334a
Fixed fee-estimation to add vkey witnesses for each minting policy an…
vsubhuman Nov 29, 2021
91bbbb8
Flowgen update. Warnings fixed. Version bump to beta7
vsubhuman Nov 30, 2021
94460c2
Fixed unique vkey signatures for minting. Version bump to beta8
vsubhuman Dec 1, 2021
ed86ae8
Started changing API for mint-scripts
vsubhuman Dec 6, 2021
d968823
Fixed tests for new minting API
vsubhuman Dec 12, 2021
3db7400
Merge remote-tracking branch 'origin/master' into ruslan/mint-fix
vsubhuman Dec 12, 2021
f1eb5fd
Removed unused functions and variables (after merge)
vsubhuman Dec 12, 2021
2bbe1c4
Flowgen update
vsubhuman Dec 12, 2021
4a65faf
Replaced functions with a new type and `From` implementation
vsubhuman Dec 12, 2021
15bd42e
Removed unused field
vsubhuman Dec 13, 2021
4daf87d
Merge remote-tracking branch 'origin/master' into ruslan/mint-fix
vsubhuman Jan 14, 2022
1409301
lock file updates
vsubhuman Jan 14, 2022
f4aef74
Merge remote-tracking branch 'origin/master' into ruslan/mint-fix
vsubhuman Jan 14, 2022
4ac439a
Added comment to `get_witness_set()`
vsubhuman Jan 15, 2022
2b93da3
Removed unnecessary clone
vsubhuman Jan 15, 2022
97995ed
Commented out a non-critical expensive assert in a critical function
vsubhuman Jan 15, 2022
f4e68c8
Merge branch 'master' into ruslan/mint-fix
vsubhuman Jan 15, 2022
3021134
Disabled some tests for the disabled functionality
vsubhuman Jan 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cardano-serialization-lib",
"version": "9.1.2",
"version": "10.0.0-beta.8",
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
"scripts": {
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack) && npm run js:flowgen",
Expand Down
2 changes: 1 addition & 1 deletion 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 = "cardano-serialization-lib"
version = "9.1.2"
version = "10.0.0-beta.8"
edition = "2018"
authors = ["EMURGO"]
license = "MIT"
Expand Down
43 changes: 33 additions & 10 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -5179,29 +5179,52 @@ declare export class TransactionBuilder {
/**
* Set explicit Mint object to this builder
* it will replace any previously existing mint
* NOTE! If you use `set_mint` manually - you must use `set_mint_scripts`
* to provide matching policy scripts or min-fee calculation will be rejected!
* @param {Mint} mint
*/
set_mint(mint: Mint): void;

/**
* Returns a copy of the current mint state in the builder
* @returns {Mint | void}
*/
get_mint(): Mint | void;

/**
* Set explicit witness set to this builder
* It will replace any previously existing witnesses
* NOTE! Use carefully! If you are using `set_mint` - then you must be using
* this setter as well to be able to calculate fee automatically!
* @param {NativeScripts} mint_scripts
*/
set_mint_scripts(mint_scripts: NativeScripts): void;

/**
* Returns a copy of the current mint witness scripts in the builder
* @returns {NativeScripts | void}
*/
get_mint_scripts(): NativeScripts | void;

/**
* Add a mint entry to this builder using a PolicyID and MintAssets object
* It will be securely added to existing or new Mint in this builder
* It will replace any existing mint assets with the same PolicyID
* @param {ScriptHash} policy_id
* @param {NativeScript} policy_script
* @param {MintAssets} mint_assets
*/
set_mint_asset(policy_id: ScriptHash, mint_assets: MintAssets): void;
set_mint_asset(policy_script: NativeScript, mint_assets: MintAssets): void;

/**
* Add a mint entry to this builder using a PolicyID, AssetName, and Int object for amount
* It will be securely added to existing or new Mint in this builder
* It will replace any previous existing amount same PolicyID and AssetName
* @param {ScriptHash} policy_id
* @param {NativeScript} policy_script
* @param {AssetName} asset_name
* @param {Int} amount
*/
add_mint_asset(
policy_id: ScriptHash,
policy_script: NativeScript,
asset_name: AssetName,
amount: Int
): void;
Expand All @@ -5211,14 +5234,14 @@ declare export class TransactionBuilder {
* Using a PolicyID, AssetName, Int for amount, Address, and Coin (BigNum) objects
* The asset will be securely added to existing or new Mint in this builder
* A new output will be added with the specified Address, the Coin value, and the minted asset
* @param {ScriptHash} policy_id
* @param {NativeScript} policy_script
* @param {AssetName} asset_name
* @param {Int} amount
* @param {Address} address
* @param {BigNum} output_coin
*/
add_mint_asset_and_output(
policy_id: ScriptHash,
policy_script: NativeScript,
asset_name: AssetName,
amount: Int,
address: Address,
Expand All @@ -5231,13 +5254,13 @@ declare export class TransactionBuilder {
* The asset will be securely added to existing or new Mint in this builder
* A new output will be added with the specified Address and the minted asset
* The output will be set to contain the minimum required amount of Coin
* @param {ScriptHash} policy_id
* @param {NativeScript} policy_script
* @param {AssetName} asset_name
* @param {Int} amount
* @param {Address} address
*/
add_mint_asset_and_output_min_required_coin(
policy_id: ScriptHash,
policy_script: NativeScript,
asset_name: AssetName,
amount: Int,
address: Address
Expand Down Expand Up @@ -5300,14 +5323,14 @@ declare export class TransactionBuilder {
/**
* Returns object the body of the new transaction
* Auxiliary data itself is not included
* You can use `get_auxiliary_date` or `build_tx`
* You can use `get_auxiliary_data` or `build_tx`
* @returns {TransactionBody}
*/
build(): TransactionBody;

/**
* Returns full Transaction object with the body and the auxiliary data
* NOTE: witness_set is set to just empty set
* NOTE: witness_set will contain all mint_scripts if any been added or set
* NOTE: is_valid set to true
* @returns {Transaction}
*/
Expand Down
103 changes: 103 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use plutus::*;
use metadata::*;
use utils::*;
use std::cmp::Ordering;
use std::collections::BTreeSet;

type DeltaCoin = Int;

Expand Down Expand Up @@ -2752,6 +2753,35 @@ impl NetworkId {
}
}

pub fn get_all_pubkeys_from_script(script: &NativeScript) -> BTreeSet<Ed25519KeyHash> {
match &script.0 {
NativeScriptEnum::ScriptPubkey(spk) => {
let mut set = BTreeSet::new();
set.insert(spk.addr_keyhash());
set
},
NativeScriptEnum::ScriptAll(all) => {
get_all_pubkeys_from_scripts(&all.native_scripts)
},
NativeScriptEnum::ScriptAny(any) => {
get_all_pubkeys_from_scripts(&any.native_scripts)
},
NativeScriptEnum::ScriptNOfK(ofk) => {
get_all_pubkeys_from_scripts(&ofk.native_scripts)
},
_ => BTreeSet::new(),
}
}

pub fn get_all_pubkeys_from_scripts(scripts: &NativeScripts) -> BTreeSet<Ed25519KeyHash> {
scripts.0.iter().fold(BTreeSet::new(), |mut set, s| {
get_all_pubkeys_from_script(s).iter().for_each(|pk| {
set.insert(pk.clone());
});
set
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -2933,4 +2963,77 @@ mod tests {
assert_eq!(p_ass.get(&name1).unwrap(), amount1);
assert_eq!(n_ass.get(&name1).unwrap(), amount1);
}

fn keyhash(x: u8) -> Ed25519KeyHash {
Ed25519KeyHash::from_bytes(vec![x, 180, 186, 93, 223, 42, 243, 7, 81, 98, 86, 125, 97, 69, 110, 52, 130, 243, 244, 98, 246, 13, 33, 212, 128, 168, 136, 40]).unwrap()
}

fn pkscript(pk: &Ed25519KeyHash) -> NativeScript {
NativeScript::new_script_pubkey(&ScriptPubkey::new(pk))
}

fn scripts_vec(scripts: Vec<&NativeScript>) -> NativeScripts {
NativeScripts(scripts.iter().map(|s| { (*s).clone() }).collect())
}

#[test]
fn native_scripts_get_pubkeys() {
let keyhash1 = keyhash(1);
let keyhash2 = keyhash(2);
let keyhash3 = keyhash(3);

let pks1 = get_all_pubkeys_from_script(&pkscript(&keyhash1));
assert_eq!(pks1.len(), 1);
assert!(pks1.contains(&keyhash1));

let pks2 = get_all_pubkeys_from_script(
&NativeScript::new_timelock_start(
&TimelockStart::new(123),
),
);
assert_eq!(pks2.len(), 0);

let pks3 = get_all_pubkeys_from_script(
&NativeScript::new_script_all(
&ScriptAll::new(&scripts_vec(vec![
&pkscript(&keyhash1),
&pkscript(&keyhash2),
]))
),
);
assert_eq!(pks3.len(), 2);
assert!(pks3.contains(&keyhash1));
assert!(pks3.contains(&keyhash2));

let pks4 = get_all_pubkeys_from_script(
&NativeScript::new_script_any(
&ScriptAny::new(&scripts_vec(vec![
&NativeScript::new_script_n_of_k(&ScriptNOfK::new(
1,
&scripts_vec(vec![
&NativeScript::new_timelock_start(&TimelockStart::new(132)),
&pkscript(&keyhash3),
]),
)),
&NativeScript::new_script_all(&ScriptAll::new(
&scripts_vec(vec![
&NativeScript::new_timelock_expiry(&TimelockExpiry::new(132)),
&pkscript(&keyhash1),
]),
)),
&NativeScript::new_script_any(&ScriptAny::new(
&scripts_vec(vec![
&pkscript(&keyhash1),
&pkscript(&keyhash2),
&pkscript(&keyhash3),
]),
)),
]))
),
);
assert_eq!(pks4.len(), 3);
assert!(pks4.contains(&keyhash1));
assert!(pks4.contains(&keyhash2));
assert!(pks4.contains(&keyhash3));
}
}
Loading