whisky_csl/utils/
staking.rs

1use cardano_serialization_lib::{self as csl};
2use whisky_common::WError;
3
4pub fn script_hash_to_stake_address(script_hash: &str, network_id: u8) -> Result<String, WError> {
5    let script_hash = csl::ScriptHash::from_hex(script_hash).map_err(WError::from_err(
6        "script_hash_to_stake_address - invalid script hash",
7    ))?;
8    let credential = csl::Credential::from_scripthash(&script_hash);
9    let stake_address = csl::RewardAddress::new(network_id, &credential)
10        .to_address()
11        .to_bech32(None)
12        .map_err(WError::from_err(
13            "script_hash_to_stake_address - failed to convert to bech32",
14        ))?;
15    Ok(stake_address)
16}