use ex3_canister_types::wallet_identifier::WalletIdentifier;
use ex3_node_error::OtherError;
use serde_bytes::ByteBuf;
use crate::{PayloadDecoder, Result};
impl PayloadDecoder {
pub fn decode_to_wallet_identifier(payload: &[u8]) -> Result<WalletIdentifier> {
let payload_str = String::from_utf8(payload.to_vec()).expect("should success");
let hexes = payload_str.split('|').collect::<Vec<&str>>();
if hexes.len() != 1 {
return Err(OtherError::new("Invalid payload").into());
}
let pub_key_bytes = hex::decode(&hexes[0][2..]);
let pub_key = pub_key_bytes.unwrap();
let pub_key: ByteBuf = ByteBuf::from(pub_key);
let wallet_identifier = WalletIdentifier(pub_key);
Ok(wallet_identifier)
}
}