1
1
#![ allow( missing_docs) ]
2
2
use crate :: math:: Decimal ;
3
- use solana_program:: { msg , pubkey:: Pubkey } ;
3
+ use solana_program:: pubkey:: Pubkey ;
4
4
use std:: fmt;
5
5
6
- #[ derive( Debug ) ]
7
- enum LogEventType {
6
+ extern crate serde;
7
+ extern crate serde_json;
8
+
9
+ #[ derive( Debug , Serialize ) ]
10
+ pub enum LogEventType {
8
11
PythOraclePriceUpdateType ,
9
12
SwitchboardV1OraclePriceUpdateType ,
10
13
}
@@ -15,49 +18,27 @@ impl fmt::Display for LogEventType {
15
18
}
16
19
}
17
20
18
- pub fn emit_log_event ( e : & dyn LogEvent ) {
19
- msg ! ( "Solend Log Event" ) ;
20
- msg ! ( & e. to_string( ) ) ;
21
- }
22
-
23
- pub trait LogEvent {
24
- fn to_string ( & self ) -> String ;
21
+ #[ macro_export]
22
+ macro_rules! emit_log_event {
23
+ ( $e: expr) => {
24
+ msg!( "solend-event-log" ) ;
25
+ msg!( & serde_json:: to_string( $e) . unwrap( ) ) ;
26
+ } ;
25
27
}
26
28
29
+ #[ derive( Serialize ) ]
27
30
pub struct PythOraclePriceUpdate {
31
+ pub event_type : LogEventType ,
28
32
pub oracle_pubkey : Pubkey ,
29
33
pub price : Decimal ,
30
- pub conf : u64 ,
34
+ pub confidence : u64 ,
31
35
pub published_slot : u64 ,
32
36
}
33
37
34
- impl LogEvent for PythOraclePriceUpdate {
35
- fn to_string ( & self ) -> String {
36
- return format ! (
37
- "{},{},{},{},{}" ,
38
- LogEventType :: PythOraclePriceUpdateType . to_string( ) ,
39
- self . oracle_pubkey. to_string( ) ,
40
- self . price. to_string( ) ,
41
- self . conf. to_string( ) ,
42
- self . published_slot,
43
- ) ;
44
- }
45
- }
46
-
38
+ #[ derive( Serialize ) ]
47
39
pub struct SwitchboardV1OraclePriceUpdate {
40
+ pub event_type : LogEventType ,
48
41
pub oracle_pubkey : Pubkey ,
49
42
pub price : Decimal ,
50
43
pub published_slot : u64 ,
51
44
}
52
-
53
- impl LogEvent for SwitchboardV1OraclePriceUpdate {
54
- fn to_string ( & self ) -> String {
55
- return format ! (
56
- "{},{},{},{}" ,
57
- LogEventType :: SwitchboardV1OraclePriceUpdateType . to_string( ) ,
58
- self . oracle_pubkey. to_string( ) ,
59
- self . price. to_string( ) ,
60
- self . published_slot,
61
- ) ;
62
- }
63
- }
0 commit comments