cyfs_base_meta/
event.rs

1use cyfs_base::*;
2use crate::MetaExtensionType;
3
4#[derive(Clone, RawEncode, RawDecode)]
5pub struct RentParam {
6    pub id: ObjectId
7}
8
9#[derive(Clone, RawEncode, RawDecode)]
10pub struct NameRentParam {
11    pub name_id: String
12}
13
14#[derive(Clone, RawEncode, RawDecode)]
15pub struct ChangeNameParam {
16    pub name: String,
17    pub to: NameState
18}
19
20#[derive(Clone, RawEncode, RawDecode)]
21pub struct StopAuctionParam {
22    pub name: String,
23    pub stop_block: i64,
24    pub starting_price: i64
25}
26
27#[derive(Clone, RawEncode, RawDecode)]
28pub struct BidName {
29    pub name: String,
30    pub price: i64,
31    pub bid_id: ObjectId,
32    pub coin_id: u8,
33    pub take_effect_block: i64,
34    pub rent_price: i64,
35}
36
37#[derive(Clone, RawEncode, RawDecode)]
38pub struct UnionWithdraw {
39    pub union_id: ObjectId,
40    pub account_id: ObjectId,
41    pub ctid: CoinTokenId,
42    pub value: i64,
43    pub height: i64,
44}
45
46#[derive(Clone, RawEncode, RawDecode)]
47pub struct ExtensionEvent {
48    pub extension_type: MetaExtensionType,
49    pub data: Vec<u8>,
50}
51
52#[derive(Clone, RawEncode, RawDecode)]
53pub struct NFTStopAuction {
54    pub nft_id: ObjectId,
55}
56
57#[derive(Clone, RawEncode, RawDecode)]
58pub struct NFTStopSell {
59    pub nft_id: ObjectId,
60}
61
62#[derive(Clone, RawEncode, RawDecode)]
63pub struct NFTCancelApplyBuyParam {
64    pub nft_id: ObjectId,
65    pub user_id: ObjectId,
66}
67
68#[repr(u8)]
69#[derive(Clone, Copy, Eq, PartialEq, Hash)]
70pub enum EventType {
71    Rent = 0,
72    ChangeName = 1,
73    NameRent = 2,
74    BidName = 3,
75    StopAuction = 4,
76    UnionWithdraw = 5,
77    Extension = 6,
78    NFTStopAuction = 7,
79    NFTCancelApplyBuy = 8,
80    NFTStopSell = 9,
81}
82
83#[derive(RawEncode, RawDecode, Clone)]
84pub enum Event {
85    Rent(RentParam),
86    NameRent(NameRentParam),
87    ChangeNameEvent(ChangeNameParam),
88    BidName(BidName),
89    StopAuction(StopAuctionParam),
90    UnionWithdraw(UnionWithdraw),
91    Extension(ExtensionEvent),
92    NFTStopAuction(NFTStopAuction),
93    NFTCancelApplyBuy(NFTCancelApplyBuyParam),
94    NFTStopSell(NFTStopSell),
95}
96
97pub const EVENT_RESULT_SUCCESS: u8 = 0;
98pub const EVENT_RESULT_FAILED: u8 = 1;
99
100#[derive(RawEncode, RawDecode, Clone)]
101pub struct EventResult {
102    pub status: u8,
103    pub data: Vec<u8>,
104}
105
106impl EventResult {
107    pub fn new(status: u8, data: Vec<u8>) -> Self {
108        Self {
109            status,
110            data
111        }
112    }
113}
114
115#[derive(RawEncode, RawDecode, Clone)]
116pub struct EventRecord {
117    pub event: Event,
118    pub event_result: EventResult,
119}
120
121impl EventRecord {
122    pub fn new(event: Event, event_result: EventResult) -> Self {
123        Self {
124            event,
125            event_result
126        }
127    }
128}
129
130impl Event {
131    pub fn get_type(&self) -> EventType {
132        match self {
133            Event::Rent(_) => { EventType::Rent },
134            Event::ChangeNameEvent(_) => { EventType::ChangeName },
135            Event::NameRent(_) => { EventType::NameRent },
136            Event::BidName(_) => {EventType::BidName},
137            Event::StopAuction(_) => {EventType::StopAuction},
138            Event::UnionWithdraw(_) => EventType::UnionWithdraw,
139            Event::Extension(_) => EventType::Extension,
140            Event::NFTStopAuction(_) => {EventType::NFTStopAuction},
141            Event::NFTCancelApplyBuy(_) => {EventType::NFTCancelApplyBuy},
142            Event::NFTStopSell(_) => {EventType::NFTStopSell},
143        }
144    }
145
146    pub fn get_content(&self) -> BuckyResult<Vec<u8>> {
147        self.to_vec()
148    }
149}