redgold 0.1.25

p2p database / compute engine & portfolio target models
use redgold_schema::{error_info, RgResult, SafeOption};
use redgold_schema::structs::{PartySigningValidation, SupportedCurrency};
use crate::core::relay::Relay;
use crate::party::party_stream::PartyEvents;

impl PartyEvents {

    pub async fn validate_event(&self, validator: PartySigningValidation, hash_to_sign: Vec<u8>, r: &Relay) -> RgResult<()> {
        let c = validator.currency();
        if c == SupportedCurrency::Redgold {
            let tx = validator.transaction.safe_get_msg("Missing transaction")?;
            return self.validate_rdg_swap_fulfillment_transaction(tx);
        }
        let payload = validator.json_payload.safe_get_msg("Missing PSBT")?.clone();
        match c {
            SupportedCurrency::Bitcoin => {
                let arc = r.btc_wallet(&self.party_public_key).await?;
                let mut w = arc.lock().await;
                self.validate_btc_fulfillment(payload, hash_to_sign, &mut w)?;
            }
            SupportedCurrency::Ethereum => {
                self.validate_eth_fulfillment(payload, hash_to_sign)?;
            }
            _ => {
                return Err(error_info("Unsupported currency"));
            }
        }
        Ok(())
    }
}