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 pub settlement_address: String,
21
22 pub reason: String,
24}
25
26impl Revert {
27 pub fn new(transaction_id: &str, settlement_address: &str, reason: &str) -> Self {
29 Self {
30 transaction_id: transaction_id.to_string(),
31 settlement_address: settlement_address.to_string(),
32 reason: reason.to_string(),
33 }
34 }
35}
36
37impl Revert {
38 pub fn validate_revert(&self) -> Result<()> {
40 if self.transaction_id.is_empty() {
41 return Err(Error::Validation(
42 "Transaction ID is required in Revert".to_string(),
43 ));
44 }
45
46 if self.settlement_address.is_empty() {
47 return Err(Error::Validation(
48 "Settlement address is required in Revert".to_string(),
49 ));
50 }
51
52 if self.reason.is_empty() {
53 return Err(Error::Validation(
54 "Reason is required in Revert".to_string(),
55 ));
56 }
57
58 Ok(())
59 }
60}