Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collateral support in the builder #442

Merged
merged 22 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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": "10.1.0",
"version": "10.2.0-beta.5",
"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
7 changes: 4 additions & 3 deletions rust/Cargo.lock

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

3 changes: 2 additions & 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 = "10.1.0"
version = "10.2.0-beta.5"
edition = "2018"
authors = ["EMURGO"]
license = "MIT"
Expand All @@ -27,6 +27,7 @@ cfg-if = "1"
linked-hash-map = "0.5.3"
serde_json = "1.0.57"
num-bigint = "0.4.0"
num-integer = "0.1.45"
# The default can't be compiled to wasm, so it's necessary to use either the 'nightly'
# feature or this one
clear_on_drop = { version = "0.2", features = ["no_cc"] }
Expand Down
248 changes: 248 additions & 0 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ declare export function decode_metadatum_to_json_str(
*/
declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum;

/**
* @param {ExUnits} ex_units
* @param {ExUnitPrices} ex_unit_prices
* @returns {BigNum}
*/
declare export function calculate_ex_units_ceil_cost(
ex_units: ExUnits,
ex_unit_prices: ExUnitPrices
): BigNum;

/**
* @param {Transaction} tx
* @param {ExUnitPrices} ex_unit_prices
* @returns {BigNum}
*/
declare export function min_script_fee(
tx: Transaction,
ex_unit_prices: ExUnitPrices
): BigNum;

/**
* @param {string} password
* @param {string} salt
Expand Down Expand Up @@ -648,6 +668,11 @@ declare export class BigInt {
*/
static from_bytes(bytes: Uint8Array): BigInt;

/**
* @returns {boolean}
*/
is_zero(): boolean;

/**
* @returns {BigNum | void}
*/
Expand All @@ -663,6 +688,34 @@ declare export class BigInt {
* @returns {string}
*/
to_str(): string;

/**
* @param {BigInt} other
* @returns {BigInt}
*/
add(other: BigInt): BigInt;

/**
* @param {BigInt} other
* @returns {BigInt}
*/
mul(other: BigInt): BigInt;

/**
* @returns {BigInt}
*/
static one(): BigInt;

/**
* @returns {BigInt}
*/
increment(): BigInt;

/**
* @param {BigInt} other
* @returns {BigInt}
*/
div_ceil(other: BigInt): BigInt;
}
/**
*/
Expand Down Expand Up @@ -696,6 +749,11 @@ declare export class BigNum {
*/
static zero(): BigNum;

/**
* @returns {BigNum}
*/
static one(): BigNum;

/**
* @returns {boolean}
*/
Expand Down Expand Up @@ -1533,6 +1591,11 @@ declare export class Ed25519KeyHashes {
* @param {Ed25519KeyHash} elem
*/
add(elem: Ed25519KeyHash): void;

/**
* @returns {Ed25519KeyHashes | void}
*/
to_option(): Ed25519KeyHashes | void;
}
/**
*/
Expand Down Expand Up @@ -3052,6 +3115,13 @@ declare export class PlutusData {
constr_plutus_data: ConstrPlutusData
): PlutusData;

/**
* Same as `.new_constr_plutus_data` but creates constr with empty data list
* @param {BigNum} alternative
* @returns {PlutusData}
*/
static new_empty_constr_plutus_data(alternative: BigNum): PlutusData;

/**
* @param {PlutusMap} map
* @returns {PlutusData}
Expand Down Expand Up @@ -4258,6 +4328,11 @@ declare export class Redeemers {
* @param {Redeemer} elem
*/
add(elem: Redeemer): void;

/**
* @returns {ExUnits}
*/
total_ex_units(): ExUnits;
}
/**
*/
Expand Down Expand Up @@ -5292,6 +5367,16 @@ declare export class TransactionBuilder {
*/
add_inputs_from(inputs: TransactionUnspentOutputs, strategy: number): void;

/**
* @param {TxInputsBuilder} inputs
*/
set_inputs(inputs: TxInputsBuilder): void;

/**
* @param {TxInputsBuilder} collateral
*/
set_collateral(collateral: TxInputsBuilder): void;

/**
* We have to know what kind of inputs these are to know what kind of mock witnesses to create since
* 1) mock witnesses have different lengths depending on the type which changes the expecting fee
Expand Down Expand Up @@ -5684,6 +5769,11 @@ declare export class TransactionBuilder {
*/
remove_script_data_hash(): void;

/**
* @param {Ed25519KeyHash} key
*/
add_required_signer(key: Ed25519KeyHash): void;

/**
* @returns {number}
*/
Expand Down Expand Up @@ -5754,6 +5844,12 @@ declare export class TransactionBuilderConfigBuilder {
coins_per_utxo_word: BigNum
): TransactionBuilderConfigBuilder;

/**
* @param {ExUnitPrices} ex_unit_prices
* @returns {TransactionBuilderConfigBuilder}
*/
ex_unit_prices(ex_unit_prices: ExUnitPrices): TransactionBuilderConfigBuilder;

/**
* @param {BigNum} pool_deposit
* @returns {TransactionBuilderConfigBuilder}
Expand Down Expand Up @@ -6346,6 +6442,158 @@ declare export class TxBuilderConstants {
*/
static plutus_default_cost_models(): Costmdls;
}
/**
*/
declare export class TxInputsBuilder {
free(): void;

/**
* @returns {TxInputsBuilder}
*/
static new(): TxInputsBuilder;

/**
* We have to know what kind of inputs these are to know what kind of mock witnesses to create since
* 1) mock witnesses have different lengths depending on the type which changes the expecting fee
* 2) Witnesses are a set so we need to get rid of duplicates to avoid over-estimating the fee
* @param {Ed25519KeyHash} hash
* @param {TransactionInput} input
* @param {Value} amount
*/
add_key_input(
hash: Ed25519KeyHash,
input: TransactionInput,
amount: Value
): void;

/**
* This method adds the input to the builder BUT leaves a missing spot for the witness native script
*
* After adding the input with this method, use `.add_required_native_input_scripts`
* and `.add_required_plutus_input_scripts` to add the witness scripts
*
* Or instead use `.add_native_script_input` and `.add_plutus_script_input`
* to add inputs right along with the script, instead of the script hash
* @param {ScriptHash} hash
* @param {TransactionInput} input
* @param {Value} amount
*/
add_script_input(
hash: ScriptHash,
input: TransactionInput,
amount: Value
): void;

/**
* This method will add the input to the builder and also register the required native script witness
* @param {NativeScript} script
* @param {TransactionInput} input
* @param {Value} amount
*/
add_native_script_input(
script: NativeScript,
input: TransactionInput,
amount: Value
): void;

/**
* This method will add the input to the builder and also register the required plutus witness
* @param {PlutusWitness} witness
* @param {TransactionInput} input
* @param {Value} amount
*/
add_plutus_script_input(
witness: PlutusWitness,
input: TransactionInput,
amount: Value
): void;

/**
* @param {ByronAddress} hash
* @param {TransactionInput} input
* @param {Value} amount
*/
add_bootstrap_input(
hash: ByronAddress,
input: TransactionInput,
amount: Value
): void;

/**
* Note that for script inputs this method will use underlying generic `.add_script_input`
* which leaves a required empty spot for the script witness (or witnesses in case of Plutus).
* You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness.
* @param {Address} address
* @param {TransactionInput} input
* @param {Value} amount
*/
add_input(address: Address, input: TransactionInput, amount: Value): void;

/**
* Returns the number of still missing input scripts (either native or plutus)
* Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts
* @returns {number}
*/
count_missing_input_scripts(): number;

/**
* Try adding the specified scripts as witnesses for ALREADY ADDED script inputs
* Any scripts that don't match any of the previously added inputs will be ignored
* Returns the number of remaining required missing witness scripts
* Use `.count_missing_input_scripts` to find the number of still missing scripts
* @param {NativeScripts} scripts
* @returns {number}
*/
add_required_native_input_scripts(scripts: NativeScripts): number;

/**
* Try adding the specified scripts as witnesses for ALREADY ADDED script inputs
* Any scripts that don't match any of the previously added inputs will be ignored
* Returns the number of remaining required missing witness scripts
* Use `.count_missing_input_scripts` to find the number of still missing scripts
* @param {PlutusWitnesses} scripts
* @returns {number}
*/
add_required_plutus_input_scripts(scripts: PlutusWitnesses): number;

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

/**
* Returns a copy of the current plutus input witness scripts in the builder.
* NOTE: each plutus witness will be cloned with a specific corresponding input index
* @returns {PlutusWitnesses | void}
*/
get_plutus_input_scripts(): PlutusWitnesses | void;

/**
* @returns {number}
*/
len(): number;

/**
* @param {Ed25519KeyHash} key
*/
add_required_signer(key: Ed25519KeyHash): void;

/**
* @param {Ed25519KeyHashes} keys
*/
add_required_signers(keys: Ed25519KeyHashes): void;

/**
* @returns {TransactionInputs}
*/
inputs(): TransactionInputs;

/**
* @returns {TransactionInputs | void}
*/
inputs_option(): TransactionInputs | void;
}
/**
*/
declare export class URL {
Expand Down
Loading