@@ -516,7 +516,7 @@ impl PythReceiver {
516
516
price_feeds
517
517
}
518
518
519
- pub fn execute_governance_instruction ( & self , data : Vec < u8 > ) -> Result < ( ) , PythReceiverError > {
519
+ pub fn execute_governance_instruction ( & mut self , data : Vec < u8 > ) -> Result < ( ) , PythReceiverError > {
520
520
let wormhole: IWormholeContract = IWormholeContract :: new ( self . wormhole . get ( ) ) ;
521
521
let config = Call :: new ( ) ;
522
522
wormhole
@@ -526,27 +526,27 @@ impl PythReceiver {
526
526
let vm = Vaa :: read ( & mut Vec :: from ( data. clone ( ) ) . as_slice ( ) )
527
527
. map_err ( |_| PythReceiverError :: VaaVerificationFailed ) ?;
528
528
529
- self . verify_governance_vm ( vm ) ?;
529
+ verify_governance_vm ( self , vm . clone ( ) ) ?;
530
530
531
- let instruction = governance_structs:: parse_instruction ( vm. payload . to_vec ( ) )
531
+ let instruction = governance_structs:: parse_instruction ( vm. body . payload . to_vec ( ) )
532
532
. map_err ( |_| PythReceiverError :: InvalidGovernanceMessage ) ?;
533
533
534
- if instruction. target_chain_id != 0 && instruction. target_chain_id != wormhole . chain_id ( ) {
534
+ if instruction. target_chain_id != 0 && instruction. target_chain_id != self . vm ( ) . chain_id ( ) as u16 {
535
535
return Err ( PythReceiverError :: InvalidGovernanceTarget ) ;
536
536
}
537
537
538
538
match instruction. payload {
539
- SetFee ( payload ) => { }
540
- SetFeeInToken ( payload ) => { }
541
- SetDataSources ( payload ) => { }
542
- SetWormholeAddress ( payload ) => { }
543
- RequestGovernanceDataSourceTransfer ( _) => {
539
+ GovernancePayload :: SetFee ( _payload ) => { }
540
+ GovernancePayload :: SetFeeInToken ( _payload ) => { }
541
+ GovernancePayload :: SetDataSources ( _payload ) => { }
542
+ GovernancePayload :: SetWormholeAddress ( _payload ) => { }
543
+ GovernancePayload :: RequestGovernanceDataSourceTransfer ( _) => {
544
544
// RequestGovernanceDataSourceTransfer can be only part of
545
545
// AuthorizeGovernanceDataSourceTransfer message
546
546
return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
547
547
}
548
- AuthorizeGovernanceDataSourceTransfer ( payload ) => { }
549
- UpgradeContract ( payload) => {
548
+ GovernancePayload :: AuthorizeGovernanceDataSourceTransfer ( _payload ) => { }
549
+ GovernancePayload :: UpgradeContract ( payload) => {
550
550
if instruction. target_chain_id == 0 {
551
551
return Err ( PythReceiverError :: InvalidGovernanceTarget ) ;
552
552
}
@@ -557,31 +557,10 @@ impl PythReceiver {
557
557
Ok ( ( ) )
558
558
}
559
559
560
- fn upgrade_contract ( & self , new_implementation : Address ) {
561
- ! unimplemented ! ( "Upgrade contract not yet implemented" ) ;
560
+ fn upgrade_contract ( & self , _new_implementation : FixedBytes < 32 > ) {
561
+ unimplemented ! ( "Upgrade contract not yet implemented" ) ;
562
562
}
563
563
564
- fn verify_governance_vm ( & self , vm : Vaa ) -> Result < ( ) , PythReceiverError > {
565
- if vm. body . emitter_chain != self . governance_data_source_chain_id . get ( ) . to :: < u16 > ( ) {
566
- return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
567
- }
568
-
569
- if vm. body . emitter_address != self . governance_data_source_emitter_address . get ( ) {
570
- return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
571
- }
572
-
573
- let current_sequence = vm. body . sequence . to :: < u64 > ( ) ;
574
- let last_executed_sequence = self . last_executed_governance_sequence . get ( ) . to :: < u64 > ( ) ;
575
-
576
- if current_sequence <= last_executed_sequence {
577
- return Err ( PythReceiverError :: GovernanceMessageAlreadyExecuted ) ;
578
- }
579
-
580
- self . last_executed_governance_sequence
581
- . set ( U64 :: from ( current_sequence) ) ;
582
-
583
- Ok ( ( ) )
584
- }
585
564
586
565
fn is_no_older_than ( & self , publish_time : U64 , max_age : u64 ) -> bool {
587
566
self . get_current_timestamp ( )
@@ -603,6 +582,28 @@ impl PythReceiver {
603
582
}
604
583
}
605
584
585
+ fn verify_governance_vm ( receiver : & mut PythReceiver , vm : Vaa ) -> Result < ( ) , PythReceiverError > {
586
+ if vm. body . emitter_chain != receiver. governance_data_source_chain_id . get ( ) . to :: < u16 > ( ) {
587
+ return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
588
+ }
589
+
590
+ if vm. body . emitter_address . as_slice ( ) != receiver. governance_data_source_emitter_address . get ( ) . as_slice ( ) {
591
+ return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
592
+ }
593
+
594
+ let current_sequence = vm. body . sequence . to :: < u64 > ( ) ;
595
+ let last_executed_sequence = receiver. last_executed_governance_sequence . get ( ) . to :: < u64 > ( ) ;
596
+
597
+ if current_sequence <= last_executed_sequence {
598
+ return Err ( PythReceiverError :: GovernanceMessageAlreadyExecuted ) ;
599
+ }
600
+
601
+ receiver. last_executed_governance_sequence
602
+ . set ( U64 :: from ( current_sequence) ) ;
603
+
604
+ Ok ( ( ) )
605
+ }
606
+
606
607
fn parse_wormhole_proof ( vaa : Vaa ) -> Result < MerkleRoot < Keccak160 > , PythReceiverError > {
607
608
let message = WormholeMessage :: try_from_bytes ( vaa. body . payload . to_vec ( ) )
608
609
. map_err ( |_| PythReceiverError :: PriceUnavailable ) ?;
0 commit comments