whisky_pallas/wrapper/witness_set/
bootstrap_witness.rs1use std::str::FromStr;
2
3use pallas::codec::utils::Bytes;
4use pallas::ledger::primitives::{conway::BootstrapWitness as PallasBootstrapWitness, Fragment};
5#[derive(Debug, PartialEq, Eq, Clone)]
6pub struct BootstrapWitness {
7 pub inner: PallasBootstrapWitness,
8}
9
10impl BootstrapWitness {
11 pub fn new(
12 public_key: String,
13 signature: String,
14 chain_code: String,
15 attributes: String,
16 ) -> Result<Self, String> {
17 let inner = PallasBootstrapWitness {
18 public_key: Bytes::from_str(&public_key)
19 .expect("Invalid public key in bootstrap witness"),
20 signature: Bytes::from_str(&signature).expect("Invalid signature in bootstrap witness"),
21 chain_code: Bytes::from_str(&chain_code)
22 .expect("Invalid chain code in bootstrap witness"),
23 attributes: Bytes::from_str(&attributes)
24 .expect("Invalid attributes in bootstrap witness"),
25 };
26 Ok(Self { inner })
27 }
28
29 pub fn encode(&self) -> String {
30 hex::encode(
31 self.inner
32 .encode_fragment()
33 .expect("encoding failed at BootstrapWitness"),
34 )
35 }
36
37 pub fn decode_bytes(bytes: &[u8]) -> Result<Self, String> {
38 let inner = PallasBootstrapWitness::decode_fragment(&bytes)
39 .map_err(|e| format!("Fragment decode error: {}", e.to_string()))?;
40 Ok(Self { inner })
41 }
42}