Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pythnet/pythnet_sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub enum Error {

#[error("Invalid Version")]
InvalidVersion,

#[error("Deserialization error")]
DeserializationError,
}

#[macro_export]
Expand Down
15 changes: 12 additions & 3 deletions pythnet/pythnet_sdk/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod v1 {
major_version: u8,
minor_version: u8,
trailing: Vec<u8>,
proof: Proof,
pub proof: Proof,
}

impl AccumulatorUpdateData {
Expand All @@ -72,7 +72,8 @@ pub mod v1 {
}

pub fn try_from_slice(bytes: &[u8]) -> Result<Self, Error> {
let message = from_slice::<byteorder::BE, Self>(bytes).unwrap();
let message = from_slice::<byteorder::BE, Self>(bytes)
.map_err(|_| Error::DeserializationError)?;
require!(
&message.magic[..] == PYTHNET_ACCUMULATOR_UPDATE_MAGIC,
Error::InvalidMagic
Expand Down Expand Up @@ -109,8 +110,16 @@ pub mod v1 {
pub const ACCUMULATOR_UPDATE_WORMHOLE_VERIFICATION_MAGIC: &[u8; 4] = b"AUWV";

impl WormholeMessage {
pub fn new(payload: WormholePayload) -> Self {
Self {
magic: *ACCUMULATOR_UPDATE_WORMHOLE_VERIFICATION_MAGIC,
payload,
}
}

pub fn try_from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error> {
let message = from_slice::<byteorder::BE, Self>(bytes.as_ref()).unwrap();
let message = from_slice::<byteorder::BE, Self>(bytes.as_ref())
.map_err(|_| Error::DeserializationError)?;
require!(
&message.magic[..] == ACCUMULATOR_UPDATE_WORMHOLE_VERIFICATION_MAGIC,
Error::InvalidMagic
Expand Down
159 changes: 156 additions & 3 deletions target_chains/cosmwasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions target_chains/cosmwasm/contracts/pyth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ byteorder = "1.4.3"
cosmwasm-schema = "1.1.9"
osmosis-std = "0.15.2"
pyth-sdk-cw = { path = "../../sdk/rust" }
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }

[dev-dependencies]
cosmwasm-vm = { version = "1.0.0", default-features = false }
Expand Down
Loading