Skip to content

Commit

Permalink
Merge pull request #628 from Emurgo/evgenii/certs_withdrawasl_builders
Browse files Browse the repository at this point in the history
Certificates and withdrawals builders
  • Loading branch information
lisicky authored Aug 30, 2023
2 parents a014d90 + 98f6563 commit 23caa65
Show file tree
Hide file tree
Showing 12 changed files with 1,459 additions and 378 deletions.
272 changes: 234 additions & 38 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,6 @@ declare export function decode_metadatum_to_json_str(
schema: number
): string;

/**
* @param {Transaction} tx
* @param {LinearFee} linear_fee
* @returns {BigNum}
*/
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 @@ -124,6 +97,33 @@ declare export function create_send_all(
config: TransactionBuilderConfig
): TransactionBatchList;

/**
* @param {Transaction} tx
* @param {LinearFee} linear_fee
* @returns {BigNum}
*/
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 {TransactionHash} tx_body_hash
* @param {ByronAddress} addr
Expand Down Expand Up @@ -399,6 +399,14 @@ declare export var MetadataJsonSchema: {|
+DetailedSchema: 2, // 2
|};

/**
*/

declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
|};

/**
*/

Expand All @@ -412,9 +420,9 @@ declare export var CoinSelectionStrategyCIP2: {|
/**
*/

declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
declare export var CborContainerType: {|
+Array: 0, // 0
+Map: 1, // 1
|};

/**
Expand All @@ -426,14 +434,6 @@ declare export var ScriptSchema: {|
+Node: 1, // 1
|};

/**
*/

declare export var CborContainerType: {|
+Array: 0, // 0
+Map: 1, // 1
|};

/**
*/
declare export class Address {
Expand Down Expand Up @@ -1722,6 +1722,11 @@ declare export class Certificate {
* @returns {MoveInstantaneousRewardsCert | void}
*/
as_move_instantaneous_rewards_cert(): MoveInstantaneousRewardsCert | void;

/**
* @returns {boolean}
*/
has_required_script_witness(): boolean;
}
/**
*/
Expand Down Expand Up @@ -1787,6 +1792,75 @@ declare export class Certificates {
*/
add(elem: Certificate): void;
}
/**
*/
declare export class CertificatesBuilder {
free(): void;

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

/**
* @param {Certificate} cert
*/
add(cert: Certificate): void;

/**
* @param {Certificate} cert
* @param {PlutusWitness} witness
*/
add_with_plutus_witness(cert: Certificate, witness: PlutusWitness): void;

/**
* @param {Certificate} cert
* @param {NativeScriptSource} native_script_source
*/
add_with_native_script(
cert: Certificate,
native_script_source: NativeScriptSource
): void;

/**
* @returns {PlutusWitnesses}
*/
get_plutus_witnesses(): PlutusWitnesses;

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

/**
* @returns {NativeScripts}
*/
get_native_scripts(): NativeScripts;

/**
* @param {BigNum} pool_deposit
* @param {BigNum} key_deposit
* @returns {Value}
*/
get_certificates_refund(pool_deposit: BigNum, key_deposit: BigNum): Value;

/**
* @param {BigNum} pool_deposit
* @param {BigNum} key_deposit
* @returns {BigNum}
*/
get_certificates_deposit(pool_deposit: BigNum, key_deposit: BigNum): BigNum;

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

/**
* @returns {Certificates}
*/
build(): Certificates;
}
/**
*/
declare export class ConstrPlutusData {
Expand Down Expand Up @@ -4431,6 +4505,29 @@ declare export class NativeScript {
*/
get_required_signers(): Ed25519KeyHashes;
}
/**
*/
declare export class NativeScriptSource {
free(): void;

/**
* @param {NativeScript} script
* @returns {NativeScriptSource}
*/
static new(script: NativeScript): NativeScriptSource;

/**
* @param {ScriptHash} script_hash
* @param {TransactionInput} input
* @param {Ed25519KeyHashes} required_signers
* @returns {NativeScriptSource}
*/
static new_ref_input(
script_hash: ScriptHash,
input: TransactionInput,
required_signers: Ed25519KeyHashes
): NativeScriptSource;
}
/**
*/
declare export class NativeScripts {
Expand Down Expand Up @@ -7285,6 +7382,11 @@ declare export class StakeCredential {
*/
kind(): number;

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

/**
* @returns {Uint8Array}
*/
Expand Down Expand Up @@ -7449,6 +7551,11 @@ declare export class StakeDelegation {
stake_credential: StakeCredential,
pool_keyhash: Ed25519KeyHash
): StakeDelegation;

/**
* @returns {boolean}
*/
has_script_credentials(): boolean;
}
/**
*/
Expand Down Expand Up @@ -7503,6 +7610,11 @@ declare export class StakeDeregistration {
* @returns {StakeDeregistration}
*/
static new(stake_credential: StakeCredential): StakeDeregistration;

/**
* @returns {boolean}
*/
has_script_credentials(): boolean;
}
/**
*/
Expand Down Expand Up @@ -8401,15 +8513,31 @@ declare export class TransactionBuilder {
set_validity_start_interval_bignum(validity_start_interval: BigNum): void;

/**
* !!! DEPRECATED !!!
* Can emit error if add a cert with script credential.
* Use set_certs_builder instead.
* @param {Certificates} certs
*/
set_certs(certs: Certificates): void;

/**
* @param {CertificatesBuilder} certs
*/
set_certs_builder(certs: CertificatesBuilder): void;

/**
* !!! DEPRECATED !!!
* Can emit error if add a withdrawal with script credential.
* Use set_withdrawals_builder instead.
* @param {Withdrawals} withdrawals
*/
set_withdrawals(withdrawals: Withdrawals): void;

/**
* @param {WithdrawalsBuilder} withdrawals
*/
set_withdrawals_builder(withdrawals: WithdrawalsBuilder): void;

/**
* @returns {AuxiliaryData | void}
*/
Expand Down Expand Up @@ -10545,6 +10673,74 @@ declare export class Withdrawals {
*/
keys(): RewardAddresses;
}
/**
*/
declare export class WithdrawalsBuilder {
free(): void;

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

/**
* @param {RewardAddress} address
* @param {BigNum} coin
*/
add(address: RewardAddress, coin: BigNum): void;

/**
* @param {RewardAddress} address
* @param {BigNum} coin
* @param {PlutusWitness} witness
*/
add_with_plutus_witness(
address: RewardAddress,
coin: BigNum,
witness: PlutusWitness
): void;

/**
* @param {RewardAddress} address
* @param {BigNum} coin
* @param {NativeScriptSource} native_script_source
*/
add_with_native_script(
address: RewardAddress,
coin: BigNum,
native_script_source: NativeScriptSource
): void;

/**
* @returns {PlutusWitnesses}
*/
get_plutus_witnesses(): PlutusWitnesses;

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

/**
* @returns {NativeScripts}
*/
get_native_scripts(): NativeScripts;

/**
* @returns {Value}
*/
get_total_withdrawals(): Value;

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

/**
* @returns {Withdrawals}
*/
build(): Withdrawals;
}
export type AddressJSON = string;
export type AssetNameJSON = string;
export type AssetNamesJSON = string[];
Expand Down
7 changes: 7 additions & 0 deletions rust/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ impl StakeCredential {
}
}

pub fn has_script_hash(&self) -> bool {
match &self.0 {
StakeCredType::Key(_) => false,
StakeCredType::Script(_) => true,
}
}

fn to_raw_bytes(&self) -> Vec<u8> {
match &self.0 {
StakeCredType::Key(hash) => hash.to_bytes(),
Expand Down
Loading

0 comments on commit 23caa65

Please sign in to comment.