Skip to content

Commit b596090

Browse files
authored
[hermes] Switch to message structs in pythnet_sdk (#897)
1 parent 4c2dfad commit b596090

File tree

9 files changed

+36
-153
lines changed

9 files changed

+36
-153
lines changed

hermes/Cargo.lock

Lines changed: 8 additions & 127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermes/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ moka = { version = "0.11.0", features = ["future"] }
3939
pyth-sdk = { version = "0.7.0" }
4040

4141
# Parse Wormhole attester price attestations.
42-
pythnet-sdk = { path = "../pythnet/pythnet_sdk/", version = "=1.13.6" }
42+
pythnet-sdk = { path = "../pythnet/pythnet_sdk/", version = "=1.13.6", features = ["strum"] }
4343

4444
rand = { version = "0.8.5" }
4545
reqwest = { version = "0.11.14", features = ["blocking", "json"] }
@@ -61,12 +61,6 @@ tokio = { version = "1.26.0", features = ["full"] }
6161
tower-http = { version = "0.4.0", features = ["cors"] }
6262
wormhole-sdk = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }
6363

64-
# Oracle message types
65-
[dependencies.pyth-oracle]
66-
git = "https://github.com/pyth-network/pyth-client"
67-
rev = "1bdac0d2ee39a5a9f27eb86e4fd01229bd68aa5a"
68-
features = ["library", "strum", "serde"]
69-
7064
[patch.crates-io]
7165
serde_wormhole = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.17.1" }
7266

hermes/src/network/pythnet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use {
2222
borsh::BorshDeserialize,
2323
byteorder::BE,
2424
futures::stream::StreamExt,
25-
pyth_oracle::Message,
25+
pythnet_sdk::messages::Message,
2626
solana_account_decoder::UiAccountEncoding,
2727
solana_client::{
2828
nonblocking::{

hermes/src/store.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ use {
3434
Result,
3535
},
3636
moka::future::Cache,
37-
pyth_oracle::{
38-
Message,
39-
MessageType,
40-
},
4137
pyth_sdk::PriceIdentifier,
42-
pythnet_sdk::wire::v1::{
43-
WormholeMessage,
44-
WormholePayload,
38+
pythnet_sdk::{
39+
messages::{
40+
Message,
41+
MessageType,
42+
},
43+
wire::v1::{
44+
WormholeMessage,
45+
WormholePayload,
46+
},
4547
},
4648
std::{
4749
collections::{

hermes/src/store/proof/wormhole_merkle.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ pub fn construct_message_states_proofs(
7979
let raw_messages = accumulator_messages
8080
.messages
8181
.iter()
82-
.map(|m| m.to_bytes())
83-
.collect::<Vec<Vec<u8>>>();
82+
.map(|m| {
83+
to_vec::<_, byteorder::BE>(m).map_err(|e| anyhow!("Failed to serialize message: {}", e))
84+
})
85+
.collect::<Result<Vec<Vec<u8>>>>()?;
8486

8587
// Check whether the state is valid
8688
let merkle_acc =
@@ -129,11 +131,15 @@ pub fn construct_update_data(mut message_states: Vec<&MessageState>) -> Result<V
129131
vaa: vaa.into(),
130132
updates: messages
131133
.iter()
132-
.map(|message| MerklePriceUpdate {
133-
message: message.message.to_bytes().into(),
134-
proof: message.proof_set.wormhole_merkle_proof.proof.clone(),
134+
.map(|message| {
135+
Ok(MerklePriceUpdate {
136+
message: to_vec::<_, byteorder::BE>(&message.message)
137+
.map_err(|e| anyhow!("Failed to serialize message: {}", e))?
138+
.into(),
139+
proof: message.proof_set.wormhole_merkle_proof.proof.clone(),
140+
})
135141
})
136-
.collect(),
142+
.collect::<Result<_>>()?,
137143
},
138144
))?)
139145
})

hermes/src/store/storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use {
1414
Result,
1515
},
1616
async_trait::async_trait,
17-
pyth_oracle::{
17+
pyth_sdk::PriceIdentifier,
18+
pythnet_sdk::messages::{
1819
Message,
1920
MessageType,
2021
},
21-
pyth_sdk::PriceIdentifier,
2222
};
2323

2424
pub mod local_storage;

hermes/src/store/storage/local_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use {
1717
async_trait::async_trait,
1818
dashmap::DashMap,
1919
moka::sync::Cache,
20-
pyth_oracle::MessageType,
2120
pyth_sdk::PriceIdentifier,
21+
pythnet_sdk::messages::MessageType,
2222
std::{
2323
collections::VecDeque,
2424
sync::Arc,

hermes/src/store/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
super::proof::wormhole_merkle::WormholeMerkleMessageProof,
3-
pyth_oracle::{
3+
pythnet_sdk::messages::{
44
Message,
55
PriceFeedMessage,
66
},

pythnet/pythnet_sdk/src/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use serde::{
2929
strum::EnumIter,
3030
strum::EnumString,
3131
strum::IntoStaticStr,
32-
strum::ToString,
32+
strum::Display,
3333
Serialize,
3434
Deserialize
3535
))

0 commit comments

Comments
 (0)