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

add wasm functions to get txid for genesis utxos #372

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions chain/wasm/src/genesis/network_info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::byron::utils::ProtocolMagic;
use cml_core_wasm::impl_wasm_conversions;
use wasm_bindgen::prelude::wasm_bindgen;
use cml_crypto_wasm::TransactionHash;

#[wasm_bindgen]
pub struct NetworkInfo(cml_chain::genesis::network_info::NetworkInfo);
Expand Down Expand Up @@ -43,3 +44,36 @@ impl NetworkInfo {
cml_chain::genesis::network_info::NetworkInfo::sancho_testnet().into()
}
}

#[wasm_bindgen]
pub struct ByronGenesisRedeem(pub (crate) (cml_crypto::TransactionHash, cml_chain::byron::ByronAddress));

#[wasm_bindgen]
impl ByronGenesisRedeem {
pub fn new(txid: &TransactionHash, address: &crate::byron::ByronAddress) -> Self {
ByronGenesisRedeem((txid.clone().into(), address.clone().into()))
}

pub fn txid(&self) -> TransactionHash {
self.0.0.into()
}

pub fn address(&self) -> crate::byron::ByronAddress {
self.0.1.clone().into()
}
}


#[wasm_bindgen]
pub fn genesis_txid_byron(pubkey: &cml_crypto_wasm::PublicKey, protocol_magic: Option<u32>) -> ByronGenesisRedeem {
let redeem = cml_chain::genesis::byron::parse::redeem_pubkey_to_txid(
&pubkey.clone().as_ref().0,
protocol_magic.map(|pm| ProtocolMagic::new(pm).into())
);
ByronGenesisRedeem(redeem)
}

#[wasm_bindgen]
pub fn genesis_txid_shelley(address: &crate::address::Address) -> TransactionHash {
TransactionHash::from(cml_chain::genesis::shelley::parse::redeem_address_to_txid(&address.clone().into()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do address.as_ref() and avoid the clone()/into().

}
Loading