Skip to content

Commit 38ecd89

Browse files
authored
Update market_status type from u8 to u32 in V8 schema (#20)
1 parent 8dc1608 commit 38ecd89

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

rust/crates/report/src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ mod tests {
228228
expires_at: MOCK_TIMESTAMP + 100,
229229
last_update_timestamp: MOCK_TIMESTAMP as u64,
230230
mid_price: BigInt::from(MOCK_PRICE),
231-
market_status: MARKET_STATUS_OPEN as u8,
231+
market_status: MARKET_STATUS_OPEN,
232232
};
233233

234234
report_data

rust/crates/report/src/report/base.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,4 @@ impl ReportBase {
9797
buffer[24..32].copy_from_slice(&bytes_value); // Place at the end of the 32 bytes word
9898
Ok(buffer)
9999
}
100-
101-
pub(crate) fn read_uint8(data: &[u8], offset: usize) -> Result<u8, ReportError> {
102-
if offset + Self::WORD_SIZE > data.len() {
103-
return Err(ReportError::DataTooShort("uint8"));
104-
}
105-
let value_bytes = &data[offset + 31..offset + 32];
106-
Ok(u8::from_be_bytes(
107-
value_bytes
108-
.try_into()
109-
.map_err(|_| ReportError::InvalidLength("uint8"))?,
110-
))
111-
}
112-
113-
pub(crate) fn encode_uint8(value: u8) -> Result<[u8; 32], ReportError> {
114-
let mut buffer = [0u8; 32];
115-
buffer[31] = value; // Place at the end of the 32 bytes word
116-
Ok(buffer)
117-
}
118100
}

rust/crates/report/src/report/v8.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use num_bigint::BigInt;
2727
/// uint32 expiresAt;
2828
/// uint64 lastUpdateTimestamp;
2929
/// int192 midPrice;
30-
/// uint8 marketStatus;
30+
/// uint32 marketStatus;
3131
/// }
3232
/// ```
3333
#[derive(Debug)]
@@ -40,7 +40,7 @@ pub struct ReportDataV8 {
4040
pub expires_at: u32,
4141
pub last_update_timestamp: u64,
4242
pub mid_price: BigInt,
43-
pub market_status: u8,
43+
pub market_status: u32,
4444
}
4545

4646
impl ReportDataV8 {
@@ -73,7 +73,7 @@ impl ReportDataV8 {
7373
let expires_at = ReportBase::read_uint32(data, 5 * ReportBase::WORD_SIZE)?;
7474
let last_update_timestamp = ReportBase::read_uint64(data, 6 * ReportBase::WORD_SIZE)?;
7575
let mid_price = ReportBase::read_int192(data, 7 * ReportBase::WORD_SIZE)?;
76-
let market_status = ReportBase::read_uint8(data, 8 * ReportBase::WORD_SIZE)?;
76+
let market_status = ReportBase::read_uint32(data, 8 * ReportBase::WORD_SIZE)?;
7777

7878
Ok(Self {
7979
feed_id,
@@ -108,7 +108,7 @@ impl ReportDataV8 {
108108
buffer.extend_from_slice(&ReportBase::encode_uint32(self.expires_at)?);
109109
buffer.extend_from_slice(&ReportBase::encode_uint64(self.last_update_timestamp)?);
110110
buffer.extend_from_slice(&ReportBase::encode_int192(&self.mid_price)?);
111-
buffer.extend_from_slice(&ReportBase::encode_uint8(self.market_status)?);
111+
buffer.extend_from_slice(&ReportBase::encode_uint32(self.market_status)?);
112112

113113
Ok(buffer)
114114
}
@@ -134,7 +134,7 @@ mod tests {
134134
let expected_timestamp: u32 = MOCK_TIMESTAMP;
135135
let expected_fee = BigInt::from(MOCK_FEE);
136136
let expected_price = BigInt::from(MOCK_PRICE);
137-
let expected_market_status: u8 = MARKET_STATUS_OPEN as u8;
137+
let expected_market_status: u32 = MARKET_STATUS_OPEN;
138138

139139
assert_eq!(decoded.feed_id, expected_feed_id);
140140
assert_eq!(decoded.valid_from_timestamp, expected_timestamp);

0 commit comments

Comments
 (0)