Add new_request

This commit is contained in:
NicolasCantu 2025-01-02 12:29:52 +01:00 committed by Nicolas Cantu
parent bfd7c6bcda
commit 129f957214

View File

@ -27,6 +27,7 @@ pub enum PrdType {
Response, // Validate (or disagree) with a prd update
Confirm, // Confirm we received an update
TxProposal, // Send a psbt asking for recipient signature
Request // asks for the prd update for some state,
}
sha256t_hash_newtype! {
@ -51,7 +52,7 @@ impl AnkPrdHash {
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Tsify)]
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[allow(non_camel_case_types)]
pub struct Prd {
@ -138,6 +139,16 @@ impl Prd {
}
}
pub fn new_request(root_commitment: OutPoint, sender: Member, state_ids: Vec<[u8; 32]>) -> Self {
Self {
prd_type: PrdType::Request,
root_commitment: root_commitment.to_string(),
sender: serde_json::to_string(&sender).unwrap(),
payload: serde_json::to_string(&state_ids).unwrap(),
..Default::default()
}
}
pub fn extract_from_message(plain: &[u8], local_address: SilentPaymentAddress) -> Result<Self> {
let prd: Prd = serde_json::from_slice(plain)?;