Skip to content

Commit 5c9453c

Browse files
committed
added serde deserialization
1 parent b3ddc02 commit 5c9453c

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

target_chains/stylus/Cargo.lock

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

target_chains/stylus/contracts/pyth-receiver/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
[package]
2-
name = "stylus-hello-world"
2+
name = "pyth-receiver-stylus"
33
version = "0.1.11"
44
edition = "2021"
5-
license = "MIT OR Apache-2.0"
6-
homepage = "https://github.com/OffchainLabs/stylus-hello-world"
7-
repository = "https://github.com/OffchainLabs/stylus-hello-world"
8-
keywords = ["arbitrum", "ethereum", "stylus", "alloy"]
9-
description = "Stylus hello world example"
5+
homepage = "https://github.com/pyth-network/pyth-crosschain"
6+
repository = "https://github.com/pyth-network/pyth-crosschain"
7+
keywords = ["arbitrum", "ethereum", "stylus", "alloy", "pyth"]
8+
description = "Pyth receiver contract for the Arbitrum networks, built on Arbitrum Stylus"
109

1110
[dependencies]
1211
alloy-primitives = "=0.8.20"
1312
alloy-sol-types = "=0.8.20"
1413
stylus-sdk = "0.9.0"
1514
byteorder = { version = "1.4.3" }
1615
hex = { version = "0.4", default-features = false }
17-
serde = { version = "1.0", features = ["derive"] }
1816
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
1917
pyth-types = { path = "../pyth-types" }
18+
serde = { version = "1.0", features = ["derive"] }
2019
wormhole-vaas = "0.1.1"
2120
wormhole-contract = { path = "../../contracts/wormhole" }
2221

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ impl PythReceiver {
176176
return Err(PythReceiverError::InvalidMerkleProof);
177177
}
178178

179-
// UPDATE STORED PRICE INFO BASED ON THE UPDATES IN THE VAA
180179
let msg = from_slice::<byteorder::BE, Message>(&message_vec)
181180
.map_err(|_| PythReceiverError::InvalidAccumulatorMessage)?;
182181

@@ -263,15 +262,6 @@ impl PythReceiver {
263262

264263
current_u64.saturating_sub(publish_time_u64) <= max_age
265264
}
266-
267-
// Updates the Price Feed only if it is newer than the current one. This function never fails
268-
// and will either update in-place or not update at all. The return value indicates whether
269-
// the update was performed or not.
270-
// fn update_price_feed_if_new(&self, price_id: [u8; 32], price_feed: PriceInfo) -> bool {
271-
272-
// }
273-
274-
275265
}
276266

277267
fn parse_wormhole_proof(vaa: Vaa) -> Result<MerkleRoot<Keccak160>, PythReceiverError> {
@@ -282,5 +272,3 @@ fn parse_wormhole_proof(vaa: Vaa) -> Result<MerkleRoot<Keccak160>, PythReceiverE
282272
});
283273
Ok(root)
284274
}
285-
286-

target_chains/stylus/contracts/pyth-receiver/src/structs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ fn serialize_data_source_to_bytes(chain_id: u16, emitter_address: &[u8; 32]) ->
2222
chain_id,
2323
emitter_address: *emitter_address,
2424
};
25-
25+
2626
let bytes = to_vec::<_, byteorder::BE>(&data_source)?;
2727
if bytes.len() != 34 {
2828
return Err(format!("Expected 34 bytes, got {}", bytes.len()).into());
2929
}
30-
30+
3131
let mut result = [0u8; 34];
3232
result.copy_from_slice(&bytes);
3333
Ok(result)
@@ -50,10 +50,10 @@ impl StorageKey for DataSourceStorage {
5050
fn to_slot(&self, root: B256) -> U256 {
5151
let chain_id: u16 = self.chain_id.get().to::<u16>();
5252
let emitter_address = self.emitter_address.get();
53-
53+
5454
let bytes = serialize_data_source_to_bytes(chain_id, emitter_address.as_slice().try_into().unwrap())
5555
.expect("Failed to serialize DataSource");
56-
56+
5757
keccak256(bytes).to_slot(root)
5858
}
5959
}
@@ -62,10 +62,10 @@ impl StorageKey for DataSource {
6262
fn to_slot(&self, root: B256) -> U256 {
6363
let chain_id: u16 = self.chain_id.to::<u16>();
6464
let emitter_address: [u8; 32] = self.emitter_address.as_slice().try_into().unwrap();
65-
65+
6666
let bytes = serialize_data_source_to_bytes(chain_id, &emitter_address)
6767
.expect("Failed to serialize DataSource");
68-
68+
6969
keccak256(bytes).to_slot(root)
7070
}
7171
}
@@ -143,7 +143,7 @@ mod tests {
143143

144144
let actual_bytes = serialize_data_source_to_bytes(chain_id, &emitter_address)
145145
.expect("Serialization should succeed");
146-
146+
147147
assert_eq!(actual_bytes, expected_bytes, "Serialization should produce identical bytes");
148148
}
149149
}

0 commit comments

Comments
 (0)