Skip to content

Commit 211bf02

Browse files
authored
Implement accumulator updates for cosmwasm (#880)
* Implement accumulator updates for cosmwasm * Update fee calculation logic for accumulator messages The fee for accumulator messages is base fee times the number of messages but the logic remains the same for the batch method
1 parent 3721dd2 commit 211bf02

File tree

7 files changed

+810
-67
lines changed

7 files changed

+810
-67
lines changed

pythnet/pythnet_sdk/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ pub enum Error {
77

88
#[error("Invalid Version")]
99
InvalidVersion,
10+
11+
#[error("Deserialization error")]
12+
DeserializationError,
1013
}
1114

1215
#[macro_export]

pythnet/pythnet_sdk/src/wire.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub mod v1 {
5757
major_version: u8,
5858
minor_version: u8,
5959
trailing: Vec<u8>,
60-
proof: Proof,
60+
pub proof: Proof,
6161
}
6262

6363
impl AccumulatorUpdateData {
@@ -72,7 +72,8 @@ pub mod v1 {
7272
}
7373

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

111112
impl WormholeMessage {
113+
pub fn new(payload: WormholePayload) -> Self {
114+
Self {
115+
magic: *ACCUMULATOR_UPDATE_WORMHOLE_VERIFICATION_MAGIC,
116+
payload,
117+
}
118+
}
119+
112120
pub fn try_from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error> {
113-
let message = from_slice::<byteorder::BE, Self>(bytes.as_ref()).unwrap();
121+
let message = from_slice::<byteorder::BE, Self>(bytes.as_ref())
122+
.map_err(|_| Error::DeserializationError)?;
114123
require!(
115124
&message.magic[..] == ACCUMULATOR_UPDATE_WORMHOLE_VERIFICATION_MAGIC,
116125
Error::InvalidMagic

target_chains/cosmwasm/Cargo.lock

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

target_chains/cosmwasm/contracts/pyth/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ byteorder = "1.4.3"
3939
cosmwasm-schema = "1.1.9"
4040
osmosis-std = "0.15.2"
4141
pyth-sdk-cw = { path = "../../sdk/rust" }
42+
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
4243

4344
[dev-dependencies]
4445
cosmwasm-vm = { version = "1.0.0", default-features = false }

0 commit comments

Comments
 (0)