Skip to content

Commit a39a206

Browse files
committed
Address Go and Rust comments.
1 parent 78eee2b commit a39a206

File tree

11 files changed

+69
-31
lines changed

11 files changed

+69
-31
lines changed

go/feed/feed.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
FeedVersion8
2222
FeedVersion9
2323
FeedVersion10
24+
FeedVersion13
2425
_
2526
)
2627

go/report/v13/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package v10
1+
package v13
22

33
import (
44
"fmt"

go/report/v13/data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package v10
1+
package v13
22

33
import (
44
"math/big"

rust/Cargo.lock

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

rust/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Add the following to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
chainlink-data-streams-report = "1.0.3"
24-
chainlink-data-streams-sdk = { version = "1.0.3", features = ["full"] }
23+
chainlink-data-streams-report = "1.0.4"
24+
chainlink-data-streams-sdk = { version = "1.0.4", features = ["full"] }
2525
```
2626

2727
#### Features

rust/crates/report/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chainlink-data-streams-report"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
edition = "2021"
55
description = "Chainlink Data Streams Report"
66
license = "MIT"

rust/crates/report/src/report.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod v7;
1010
pub mod v8;
1111
pub mod v9;
1212
pub mod v10;
13+
pub mod v13;
1314

1415
use base::{ReportBase, ReportError};
1516

@@ -123,7 +124,7 @@ pub fn decode_full_report(payload: &[u8]) -> Result<(Vec<[u8; 32]>, Vec<u8>), Re
123124
#[cfg(test)]
124125
mod tests {
125126
use super::*;
126-
use crate::report::{v1::ReportDataV1, v2::ReportDataV2, v3::ReportDataV3, v4::ReportDataV4, v5::ReportDataV5, v6::ReportDataV6, v7::ReportDataV7, v8::ReportDataV8, v9::ReportDataV9, v10::ReportDataV10};
127+
use crate::report::{v1::ReportDataV1, v2::ReportDataV2, v3::ReportDataV3, v4::ReportDataV4, v5::ReportDataV5, v6::ReportDataV6, v7::ReportDataV7, v8::ReportDataV8, v9::ReportDataV9, v10::ReportDataV10, v13::ReportDataV13};
127128
use num_bigint::BigInt;
128129

129130
const V1_FEED_ID: ID = ID([
@@ -166,11 +167,20 @@ mod tests {
166167
00, 10, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58,
167168
163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114,
168169
]);
170+
const V13_FEED_ID: ID = ID([
171+
00, 13, 19, 169, 185, 197, 227, 122, 9, 159, 55, 78, 146, 195, 121, 20, 175, 92, 38, 143,
172+
58, 138, 151, 33, 241, 114, 81, 53, 191, 180, 203, 184,
173+
]);
169174

170175
pub const MOCK_TIMESTAMP: u32 = 1718885772;
171176
pub const MOCK_FEE: usize = 10;
172177
pub const MOCK_PRICE: isize = 100;
173178
pub const MARKET_STATUS_OPEN: u32 = 2;
179+
pub const MOCK_BEST_ASK: isize = 227;
180+
pub const MOCK_BEST_BID: isize = 229;
181+
pub const MOCK_ASK_VOLUME: u64 = 1500;
182+
pub const MOCK_BID_VOLUME: u64 = 1200;
183+
pub const MOCK_LAST_TRADED_PRICE: isize = 228;
174184

175185
pub fn generate_mock_report_data_v1() -> ReportDataV1 {
176186
let report_data = ReportDataV1 {
@@ -347,20 +357,18 @@ mod tests {
347357
report_data
348358
}
349359

350-
pub fn generate_mock_report_data_v13() -> ReportDataV10 {
351-
const MOCK_MULTIPLIER: isize = 1000000000000000000; // 1.0 with 18 decimals
352-
353-
let report_data = ReportDataV10 {
354-
feed_id: V10_FEED_ID,
360+
pub fn generate_mock_report_data_v13() -> ReportDataV13 {
361+
let report_data = ReportDataV13 {
362+
feed_id: V13_FEED_ID,
355363
valid_from_timestamp: MOCK_TIMESTAMP,
356364
observations_timestamp: MOCK_TIMESTAMP,
357365
native_fee: BigInt::from(MOCK_FEE),
358366
link_fee: BigInt::from(MOCK_FEE),
359367
expires_at: MOCK_TIMESTAMP + 100,
360368
best_ask: BigInt::from(MOCK_BEST_ASK),
361369
best_bid: BigInt::from(MOCK_BEST_BID),
362-
ask_volume: MARKET_ASK_VOLUME,
363-
bid_volume: MARKET_BID_VOLUME,
370+
ask_volume: MOCK_ASK_VOLUME,
371+
bid_volume: MOCK_BID_VOLUME,
364372
last_traded_price: BigInt::from(MOCK_LAST_TRADED_PRICE),
365373
};
366374

@@ -716,4 +724,37 @@ mod tests {
716724

717725
assert_eq!(decoded_report.feed_id, V10_FEED_ID);
718726
}
727+
728+
#[test]
729+
fn test_decode_report_v13() {
730+
let report_data = generate_mock_report_data_v13();
731+
let encoded_report_data = report_data.abi_encode().unwrap();
732+
733+
let report = generate_mock_report(&encoded_report_data);
734+
735+
let (_report_context, report_blob) = decode_full_report(&report).unwrap();
736+
737+
let expected_report_blob = vec![
738+
"000d13a9b9c5e37a099f374e92c37914af5c268f3a8a9721f1725135bfb4cbb8",
739+
"0000000000000000000000000000000000000000000000000000000066741d8c",
740+
"0000000000000000000000000000000000000000000000000000000066741d8c",
741+
"000000000000000000000000000000000000000000000000000000000000000a",
742+
"000000000000000000000000000000000000000000000000000000000000000a",
743+
"0000000000000000000000000000000000000000000000000000000066741df0",
744+
"00000000000000000000000000000000000000000000000000000000000000e3",
745+
"00000000000000000000000000000000000000000000000000000000000000e5",
746+
"00000000000000000000000000000000000000000000000000000000000005dc",
747+
"00000000000000000000000000000000000000000000000000000000000004b0",
748+
"00000000000000000000000000000000000000000000000000000000000000e4",
749+
];
750+
751+
let expected = bytes(&format!("0x{}", expected_report_blob.join("")));
752+
println!("Actual : {}", hex::encode(&report_blob));
753+
println!("Expected: {}", hex::encode(&expected));
754+
assert_eq!(report_blob, expected);
755+
756+
let decoded_report = ReportDataV13::decode(&report_blob).unwrap();
757+
758+
assert_eq!(decoded_report.feed_id, V13_FEED_ID);
759+
}
719760
}

rust/crates/report/src/report/v13.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub struct ReportDataV13 {
4444
pub native_fee: BigInt,
4545
pub link_fee: BigInt,
4646
pub expires_at: u32,
47-
pub last_update_timestamp: u64,
4847
pub best_ask: BigInt,
4948
pub best_bid: BigInt,
5049
pub ask_volume: u64,
@@ -67,7 +66,7 @@ impl ReportDataV13 {
6766
///
6867
/// Returns a `ReportError` if the data is too short or if the data is invalid.
6968
pub fn decode(data: &[u8]) -> Result<Self, ReportError> {
70-
if data.len() < 12 * ReportBase::WORD_SIZE {
69+
if data.len() < 10 * ReportBase::WORD_SIZE {
7170
return Err(ReportError::DataTooShort("ReportDataV13"));
7271
}
7372

@@ -80,11 +79,11 @@ impl ReportDataV13 {
8079
let native_fee = ReportBase::read_uint192(data, 3 * ReportBase::WORD_SIZE)?;
8180
let link_fee = ReportBase::read_uint192(data, 4 * ReportBase::WORD_SIZE)?;
8281
let expires_at = ReportBase::read_uint32(data, 5 * ReportBase::WORD_SIZE)?;
83-
let best_ask = ReportBase::read_int192(data, 7 * ReportBase::WORD_SIZE)?;
84-
let best_bid = ReportBase::read_int192(data, 8 * ReportBase::WORD_SIZE)?;
85-
let ask_volume = ReportBase::read_uint64(data, 9 * ReportBase::WORD_SIZE)?;
86-
let bid_volume = ReportBase::read_uint64(data, 10 * ReportBase::WORD_SIZE)?;
87-
let last_traded_price = ReportBase::read_int192(data, 11 * ReportBase::WORD_SIZE)?;
82+
let best_ask = ReportBase::read_int192(data, 6 * ReportBase::WORD_SIZE)?;
83+
let best_bid = ReportBase::read_int192(data, 7 * ReportBase::WORD_SIZE)?;
84+
let ask_volume = ReportBase::read_uint64(data, 8 * ReportBase::WORD_SIZE)?;
85+
let bid_volume = ReportBase::read_uint64(data, 9 * ReportBase::WORD_SIZE)?;
86+
let last_traded_price = ReportBase::read_int192(data, 10 * ReportBase::WORD_SIZE)?;
8887

8988
Ok(Self {
9089
feed_id,
@@ -119,7 +118,6 @@ impl ReportDataV13 {
119118
buffer.extend_from_slice(&ReportBase::encode_uint192(&self.native_fee)?);
120119
buffer.extend_from_slice(&ReportBase::encode_uint192(&self.link_fee)?);
121120
buffer.extend_from_slice(&ReportBase::encode_uint32(self.expires_at)?);
122-
buffer.extend_from_slice(&ReportBase::encode_uint64(self.last_update_timestamp)?);
123121
buffer.extend_from_slice(&ReportBase::encode_int192(&self.best_ask)?);
124122
buffer.extend_from_slice(&ReportBase::encode_int192(&self.best_bid)?);
125123
buffer.extend_from_slice(&ReportBase::encode_uint64(self.ask_volume)?);
@@ -147,8 +145,6 @@ mod tests {
147145
let encoded = report_data.abi_encode().unwrap();
148146
let decoded = ReportDataV13::decode(&encoded).unwrap();
149147

150-
const MOCK_MULTIPLIER: isize = 1000000000000000000;
151-
152148
let expected_feed_id = ID::from_hex_str(V13_FEED_ID_STR).unwrap();
153149
let expected_timestamp: u32 = MOCK_TIMESTAMP;
154150
let expected_fee = BigInt::from(MOCK_FEE);

rust/crates/sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chainlink-data-streams-sdk"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
edition = "2021"
55
rust-version = "1.70"
66
description = "Chainlink Data Streams client SDK"
@@ -11,7 +11,7 @@ exclude = ["/target/*", "examples/*", "tests/*", "docs/*", "book/*"]
1111
keywords = ["chainlink"]
1212

1313
[dependencies]
14-
chainlink-data-streams-report = { path = "../report", version = "1.0.3" }
14+
chainlink-data-streams-report = { path = "../report", version = "1.0.4" }
1515
reqwest = { version = "0.11.20", features = ["json", "rustls-tls"] }
1616
tokio = { version = "1.29.1", features = ["full"] }
1717
tokio-tungstenite = { version = "0.20.1", features = [

rust/docs/guides/foundry.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ version = "0.0.1"
217217
edition = "2021"
218218

219219
[dependencies]
220-
chainlink-data-streams-report = "1.0.0"
221-
chainlink-data-streams-sdk = { version = "1.0.0", features = ["rest"] }
220+
chainlink-data-streams-report = "1.0.4"
221+
chainlink-data-streams-sdk = { version = "1.0.4", features = ["rest"] }
222222
dotenv = "0.15"
223223
tokio = { version = "1", features = ["full"] }
224224

0 commit comments

Comments
 (0)