11#![ allow( missing_docs) ]
22use crate :: math:: Decimal ;
3- use solana_program:: { msg , pubkey:: Pubkey } ;
3+ use solana_program:: pubkey:: Pubkey ;
44use std:: fmt;
55
6- #[ derive( Debug ) ]
7- enum LogEventType {
6+ extern crate serde;
7+ extern crate serde_json;
8+
9+ #[ derive( Debug , Serialize ) ]
10+ pub enum LogEventType {
811 PythOraclePriceUpdateType ,
912 SwitchboardV1OraclePriceUpdateType ,
1013}
@@ -15,49 +18,27 @@ impl fmt::Display for LogEventType {
1518 }
1619}
1720
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+ } ;
2527}
2628
29+ #[ derive( Serialize ) ]
2730pub struct PythOraclePriceUpdate {
31+ pub event_type : LogEventType ,
2832 pub oracle_pubkey : Pubkey ,
2933 pub price : Decimal ,
30- pub conf : u64 ,
34+ pub confidence : u64 ,
3135 pub published_slot : u64 ,
3236}
3337
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 ) ]
4739pub struct SwitchboardV1OraclePriceUpdate {
40+ pub event_type : LogEventType ,
4841 pub oracle_pubkey : Pubkey ,
4942 pub price : Decimal ,
5043 pub published_slot : u64 ,
5144}
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