tap_msg/message/
revert.rs1use serde::{Deserialize, Serialize};
7
8use crate::error::{Error, Result};
9use crate::TapMessage;
10
11#[derive(Debug, Clone, Serialize, Deserialize, TapMessage)]
13#[tap(message_type = "https://tap.rsvp/schema/1.0#Revert")]
14pub struct Revert {
15 #[tap(thread_id)]
17 pub transaction_id: String,
18
19 #[serde(rename = "settlementAddress")]
21 pub settlement_address: String,
22
23 pub reason: String,
25}
26
27impl Revert {
28 pub fn new(transaction_id: &str, settlement_address: &str, reason: &str) -> Self {
30 Self {
31 transaction_id: transaction_id.to_string(),
32 settlement_address: settlement_address.to_string(),
33 reason: reason.to_string(),
34 }
35 }
36}
37
38impl Revert {
39 pub fn validate_revert(&self) -> Result<()> {
41 if self.transaction_id.is_empty() {
42 return Err(Error::Validation(
43 "Transaction ID is required in Revert".to_string(),
44 ));
45 }
46
47 if self.settlement_address.is_empty() {
48 return Err(Error::Validation(
49 "Settlement address is required in Revert".to_string(),
50 ));
51 }
52
53 if self.reason.is_empty() {
54 return Err(Error::Validation(
55 "Reason is required in Revert".to_string(),
56 ));
57 }
58
59 Ok(())
60 }
61}