@@ -8,9 +8,9 @@ use crate::{
8
8
use byteorder:: ByteOrder ;
9
9
use byteorder:: { LittleEndian , ReadBytesExt } ;
10
10
use itertools:: Itertools ;
11
- // use pyth_oracle::PythOracleSerialize;
12
- // use pyth_oracle::{solana_program::account_info::AccountInfo, PriceAccountFlags};
13
- // use pyth_oracle::{PriceAccount, PythAccount};
11
+ use pyth_oracle:: PythOracleSerialize ;
12
+ use pyth_oracle:: { solana_program:: account_info:: AccountInfo , PriceAccountFlags } ;
13
+ use pyth_oracle:: { PriceAccount , PythAccount } ;
14
14
use pythnet_sdk:: {
15
15
accumulators:: { merkle:: MerkleAccumulator , Accumulator } ,
16
16
hashers:: { keccak256_160:: Keccak160 , Hasher } ,
@@ -35,62 +35,23 @@ use std::{io::Read, mem::size_of, sync::Arc};
35
35
//
36
36
// NOTE: This was serialized by hand, but should be replaced with the pythnet-sdk
37
37
// serializer once implemented.
38
- // fn create_message_buffer_bytes(msgs: Vec<Vec<u8>>) -> Vec<u8> {
39
- // let mut buffer = Vec::new();
40
- // let preimage = b"account:MessageBuffer";
41
- // buffer.extend_from_slice(&hashv(&[preimage]).to_bytes()[..8]);
42
- // buffer.extend_from_slice(&[0, 1, 10, 2]);
43
- // let mut sums: Vec<u16> = msgs.iter().map(|m| m.len() as u16).collect();
44
- // sums.resize(255, 0u16);
45
- // buffer.extend(
46
- // sums.into_iter()
47
- // .scan(0, |acc, v| {
48
- // *acc += v;
49
- // Some(if v == 0 { v } else { *acc }.to_le_bytes())
50
- // })
51
- // .flatten(),
52
- // );
53
- // buffer.extend(msgs.into_iter().flatten());
54
- // buffer
55
- // }
56
-
57
- // fn get_acc_sequence_tracker(bank: &Bank) -> AccumulatorSequenceTracker {
58
- // let account = bank
59
- // .get_account(&Pubkey::new_from_array(
60
- // pythnet_sdk::pythnet::ACCUMULATOR_SEQUENCE_ADDR,
61
- // ))
62
- // .unwrap();
63
- // AccumulatorSequenceTracker::try_from_slice(&mut account.data()).unwrap()
64
- // }
65
-
66
- // fn get_wormhole_message_account(bank: &Bank, ring_index: u32) -> AccountSharedData {
67
- // let (wormhole_message_pubkey, _bump) = Pubkey::find_program_address(
68
- // &[b"AccumulatorMessage", &ring_index.to_be_bytes()],
69
- // &Pubkey::new_from_array(pythnet_sdk::pythnet::WORMHOLE_PID),
70
- // );
71
- // bank.get_account(&wormhole_message_pubkey)
72
- // .unwrap_or_default()
73
- // }
74
-
75
- // fn get_accumulator_state(bank: &Bank, ring_index: u32) -> Vec<u8> {
76
- // let (accumulator_state_pubkey, _) = Pubkey::find_program_address(
77
- // &[b"AccumulatorState", &ring_index.to_be_bytes()],
78
- // &solana_sdk::system_program::id(),
79
- // );
80
-
81
- // let account = bank.get_account(&accumulator_state_pubkey).unwrap();
82
- // account.data().to_vec()
83
- // }
84
-
85
- #[ test]
86
- fn test_get_accumulator_state ( ) {
87
- let index = 0 ;
88
- let ( accumulator_state_pubkey, _) = Pubkey :: find_program_address (
89
- & [ b"AccumulatorState" , & ( 2386_u32 ) . to_be_bytes ( ) ] ,
90
- & solana_sdk:: system_program:: id ( ) ,
38
+ fn create_message_buffer_bytes ( msgs : Vec < Vec < u8 > > ) -> Vec < u8 > {
39
+ let mut buffer = Vec :: new ( ) ;
40
+ let preimage = b"account:MessageBuffer" ;
41
+ buffer. extend_from_slice ( & hashv ( & [ preimage] ) . to_bytes ( ) [ ..8 ] ) ;
42
+ buffer. extend_from_slice ( & [ 0 , 1 , 10 , 2 ] ) ;
43
+ let mut sums: Vec < u16 > = msgs. iter ( ) . map ( |m| m. len ( ) as u16 ) . collect ( ) ;
44
+ sums. resize ( 255 , 0u16 ) ;
45
+ buffer. extend (
46
+ sums. into_iter ( )
47
+ . scan ( 0 , |acc, v| {
48
+ * acc += v;
49
+ Some ( if v == 0 { v } else { * acc } . to_le_bytes ( ) )
50
+ } )
51
+ . flatten ( ) ,
91
52
) ;
92
- println ! ( "{:?}" , accumulator_state_pubkey ) ;
93
-
53
+ buffer . extend ( msgs . into_iter ( ) . flatten ( ) ) ;
54
+ buffer
94
55
}
95
56
96
57
#[ test]
0 commit comments