diff --git a/src/prd.rs b/src/prd.rs index 52e80d8..e8f6328 100644 --- a/src/prd.rs +++ b/src/prd.rs @@ -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 { let prd: Prd = serde_json::from_slice(plain)?;