Skip to content

Commit ca6bf73

Browse files
authored
Merge pull request #442 from Emurgo/ruslan/tx-builder-collateral
collateral support in the builder
2 parents 8eb8880 + 3129b3c commit ca6bf73

11 files changed

+1427
-326
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "10.1.0",
3+
"version": "10.2.0-beta.5",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "10.1.0"
3+
version = "10.2.0-beta.5"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"
@@ -27,6 +27,7 @@ cfg-if = "1"
2727
linked-hash-map = "0.5.3"
2828
serde_json = "1.0.57"
2929
num-bigint = "0.4.0"
30+
num-integer = "0.1.45"
3031
# The default can't be compiled to wasm, so it's necessary to use either the 'nightly'
3132
# feature or this one
3233
clear_on_drop = { version = "0.2", features = ["no_cc"] }

rust/pkg/cardano_serialization_lib.js.flow

+248
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ declare export function decode_metadatum_to_json_str(
172172
*/
173173
declare export function min_fee(tx: Transaction, linear_fee: LinearFee): BigNum;
174174

175+
/**
176+
* @param {ExUnits} ex_units
177+
* @param {ExUnitPrices} ex_unit_prices
178+
* @returns {BigNum}
179+
*/
180+
declare export function calculate_ex_units_ceil_cost(
181+
ex_units: ExUnits,
182+
ex_unit_prices: ExUnitPrices
183+
): BigNum;
184+
185+
/**
186+
* @param {Transaction} tx
187+
* @param {ExUnitPrices} ex_unit_prices
188+
* @returns {BigNum}
189+
*/
190+
declare export function min_script_fee(
191+
tx: Transaction,
192+
ex_unit_prices: ExUnitPrices
193+
): BigNum;
194+
175195
/**
176196
* @param {string} password
177197
* @param {string} salt
@@ -648,6 +668,11 @@ declare export class BigInt {
648668
*/
649669
static from_bytes(bytes: Uint8Array): BigInt;
650670

671+
/**
672+
* @returns {boolean}
673+
*/
674+
is_zero(): boolean;
675+
651676
/**
652677
* @returns {BigNum | void}
653678
*/
@@ -663,6 +688,34 @@ declare export class BigInt {
663688
* @returns {string}
664689
*/
665690
to_str(): string;
691+
692+
/**
693+
* @param {BigInt} other
694+
* @returns {BigInt}
695+
*/
696+
add(other: BigInt): BigInt;
697+
698+
/**
699+
* @param {BigInt} other
700+
* @returns {BigInt}
701+
*/
702+
mul(other: BigInt): BigInt;
703+
704+
/**
705+
* @returns {BigInt}
706+
*/
707+
static one(): BigInt;
708+
709+
/**
710+
* @returns {BigInt}
711+
*/
712+
increment(): BigInt;
713+
714+
/**
715+
* @param {BigInt} other
716+
* @returns {BigInt}
717+
*/
718+
div_ceil(other: BigInt): BigInt;
666719
}
667720
/**
668721
*/
@@ -696,6 +749,11 @@ declare export class BigNum {
696749
*/
697750
static zero(): BigNum;
698751

752+
/**
753+
* @returns {BigNum}
754+
*/
755+
static one(): BigNum;
756+
699757
/**
700758
* @returns {boolean}
701759
*/
@@ -1533,6 +1591,11 @@ declare export class Ed25519KeyHashes {
15331591
* @param {Ed25519KeyHash} elem
15341592
*/
15351593
add(elem: Ed25519KeyHash): void;
1594+
1595+
/**
1596+
* @returns {Ed25519KeyHashes | void}
1597+
*/
1598+
to_option(): Ed25519KeyHashes | void;
15361599
}
15371600
/**
15381601
*/
@@ -3052,6 +3115,13 @@ declare export class PlutusData {
30523115
constr_plutus_data: ConstrPlutusData
30533116
): PlutusData;
30543117

3118+
/**
3119+
* Same as `.new_constr_plutus_data` but creates constr with empty data list
3120+
* @param {BigNum} alternative
3121+
* @returns {PlutusData}
3122+
*/
3123+
static new_empty_constr_plutus_data(alternative: BigNum): PlutusData;
3124+
30553125
/**
30563126
* @param {PlutusMap} map
30573127
* @returns {PlutusData}
@@ -4258,6 +4328,11 @@ declare export class Redeemers {
42584328
* @param {Redeemer} elem
42594329
*/
42604330
add(elem: Redeemer): void;
4331+
4332+
/**
4333+
* @returns {ExUnits}
4334+
*/
4335+
total_ex_units(): ExUnits;
42614336
}
42624337
/**
42634338
*/
@@ -5292,6 +5367,16 @@ declare export class TransactionBuilder {
52925367
*/
52935368
add_inputs_from(inputs: TransactionUnspentOutputs, strategy: number): void;
52945369

5370+
/**
5371+
* @param {TxInputsBuilder} inputs
5372+
*/
5373+
set_inputs(inputs: TxInputsBuilder): void;
5374+
5375+
/**
5376+
* @param {TxInputsBuilder} collateral
5377+
*/
5378+
set_collateral(collateral: TxInputsBuilder): void;
5379+
52955380
/**
52965381
* We have to know what kind of inputs these are to know what kind of mock witnesses to create since
52975382
* 1) mock witnesses have different lengths depending on the type which changes the expecting fee
@@ -5684,6 +5769,11 @@ declare export class TransactionBuilder {
56845769
*/
56855770
remove_script_data_hash(): void;
56865771

5772+
/**
5773+
* @param {Ed25519KeyHash} key
5774+
*/
5775+
add_required_signer(key: Ed25519KeyHash): void;
5776+
56875777
/**
56885778
* @returns {number}
56895779
*/
@@ -5754,6 +5844,12 @@ declare export class TransactionBuilderConfigBuilder {
57545844
coins_per_utxo_word: BigNum
57555845
): TransactionBuilderConfigBuilder;
57565846

5847+
/**
5848+
* @param {ExUnitPrices} ex_unit_prices
5849+
* @returns {TransactionBuilderConfigBuilder}
5850+
*/
5851+
ex_unit_prices(ex_unit_prices: ExUnitPrices): TransactionBuilderConfigBuilder;
5852+
57575853
/**
57585854
* @param {BigNum} pool_deposit
57595855
* @returns {TransactionBuilderConfigBuilder}
@@ -6346,6 +6442,158 @@ declare export class TxBuilderConstants {
63466442
*/
63476443
static plutus_default_cost_models(): Costmdls;
63486444
}
6445+
/**
6446+
*/
6447+
declare export class TxInputsBuilder {
6448+
free(): void;
6449+
6450+
/**
6451+
* @returns {TxInputsBuilder}
6452+
*/
6453+
static new(): TxInputsBuilder;
6454+
6455+
/**
6456+
* We have to know what kind of inputs these are to know what kind of mock witnesses to create since
6457+
* 1) mock witnesses have different lengths depending on the type which changes the expecting fee
6458+
* 2) Witnesses are a set so we need to get rid of duplicates to avoid over-estimating the fee
6459+
* @param {Ed25519KeyHash} hash
6460+
* @param {TransactionInput} input
6461+
* @param {Value} amount
6462+
*/
6463+
add_key_input(
6464+
hash: Ed25519KeyHash,
6465+
input: TransactionInput,
6466+
amount: Value
6467+
): void;
6468+
6469+
/**
6470+
* This method adds the input to the builder BUT leaves a missing spot for the witness native script
6471+
*
6472+
* After adding the input with this method, use `.add_required_native_input_scripts`
6473+
* and `.add_required_plutus_input_scripts` to add the witness scripts
6474+
*
6475+
* Or instead use `.add_native_script_input` and `.add_plutus_script_input`
6476+
* to add inputs right along with the script, instead of the script hash
6477+
* @param {ScriptHash} hash
6478+
* @param {TransactionInput} input
6479+
* @param {Value} amount
6480+
*/
6481+
add_script_input(
6482+
hash: ScriptHash,
6483+
input: TransactionInput,
6484+
amount: Value
6485+
): void;
6486+
6487+
/**
6488+
* This method will add the input to the builder and also register the required native script witness
6489+
* @param {NativeScript} script
6490+
* @param {TransactionInput} input
6491+
* @param {Value} amount
6492+
*/
6493+
add_native_script_input(
6494+
script: NativeScript,
6495+
input: TransactionInput,
6496+
amount: Value
6497+
): void;
6498+
6499+
/**
6500+
* This method will add the input to the builder and also register the required plutus witness
6501+
* @param {PlutusWitness} witness
6502+
* @param {TransactionInput} input
6503+
* @param {Value} amount
6504+
*/
6505+
add_plutus_script_input(
6506+
witness: PlutusWitness,
6507+
input: TransactionInput,
6508+
amount: Value
6509+
): void;
6510+
6511+
/**
6512+
* @param {ByronAddress} hash
6513+
* @param {TransactionInput} input
6514+
* @param {Value} amount
6515+
*/
6516+
add_bootstrap_input(
6517+
hash: ByronAddress,
6518+
input: TransactionInput,
6519+
amount: Value
6520+
): void;
6521+
6522+
/**
6523+
* Note that for script inputs this method will use underlying generic `.add_script_input`
6524+
* which leaves a required empty spot for the script witness (or witnesses in case of Plutus).
6525+
* You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness.
6526+
* @param {Address} address
6527+
* @param {TransactionInput} input
6528+
* @param {Value} amount
6529+
*/
6530+
add_input(address: Address, input: TransactionInput, amount: Value): void;
6531+
6532+
/**
6533+
* Returns the number of still missing input scripts (either native or plutus)
6534+
* Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts
6535+
* @returns {number}
6536+
*/
6537+
count_missing_input_scripts(): number;
6538+
6539+
/**
6540+
* Try adding the specified scripts as witnesses for ALREADY ADDED script inputs
6541+
* Any scripts that don't match any of the previously added inputs will be ignored
6542+
* Returns the number of remaining required missing witness scripts
6543+
* Use `.count_missing_input_scripts` to find the number of still missing scripts
6544+
* @param {NativeScripts} scripts
6545+
* @returns {number}
6546+
*/
6547+
add_required_native_input_scripts(scripts: NativeScripts): number;
6548+
6549+
/**
6550+
* Try adding the specified scripts as witnesses for ALREADY ADDED script inputs
6551+
* Any scripts that don't match any of the previously added inputs will be ignored
6552+
* Returns the number of remaining required missing witness scripts
6553+
* Use `.count_missing_input_scripts` to find the number of still missing scripts
6554+
* @param {PlutusWitnesses} scripts
6555+
* @returns {number}
6556+
*/
6557+
add_required_plutus_input_scripts(scripts: PlutusWitnesses): number;
6558+
6559+
/**
6560+
* Returns a copy of the current script input witness scripts in the builder
6561+
* @returns {NativeScripts | void}
6562+
*/
6563+
get_native_input_scripts(): NativeScripts | void;
6564+
6565+
/**
6566+
* Returns a copy of the current plutus input witness scripts in the builder.
6567+
* NOTE: each plutus witness will be cloned with a specific corresponding input index
6568+
* @returns {PlutusWitnesses | void}
6569+
*/
6570+
get_plutus_input_scripts(): PlutusWitnesses | void;
6571+
6572+
/**
6573+
* @returns {number}
6574+
*/
6575+
len(): number;
6576+
6577+
/**
6578+
* @param {Ed25519KeyHash} key
6579+
*/
6580+
add_required_signer(key: Ed25519KeyHash): void;
6581+
6582+
/**
6583+
* @param {Ed25519KeyHashes} keys
6584+
*/
6585+
add_required_signers(keys: Ed25519KeyHashes): void;
6586+
6587+
/**
6588+
* @returns {TransactionInputs}
6589+
*/
6590+
inputs(): TransactionInputs;
6591+
6592+
/**
6593+
* @returns {TransactionInputs | void}
6594+
*/
6595+
inputs_option(): TransactionInputs | void;
6596+
}
63496597
/**
63506598
*/
63516599
declare export class URL {

0 commit comments

Comments
 (0)