Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 3.81 KB

File metadata and controls

64 lines (49 loc) · 3.81 KB

Decode Report Data

This example demonstrates how to decode a signed report payload from a Data Streams DON to a report data. This example then decodes the report data into a Version 3 Data Streams Report.

Running the example

Make sure you git cloned the https://github.com/smartcontractkit/data-streams-sdk repository and navigated to the rust/crates/sdk directory.

cargo run --example decode_report_data

Example output

ReportDataV3 {
    feedId: 0x00030ab7d02fbba9c6304f98824524407b1f494741174320cfd17a2c22eec1de,
    validFromTimestamp: 1722348998,
    observationsTimestamp: 1722348998,
    nativeFee: 96211668557200,
    linkFee: 23664882624157200,
    expiresAt: 1722435398,
    benchmarkPrice: 695410242043786500,
    bid: 695331621895065600,
    ask: 695662122213138400,
}

Examine the code

The code for this example can be found in the decode_report_data.rs file in the crates/report/examples directory of the data-streams-sdk repository.

use chainlink_data_streams_report::report::{decode_full_report, v3::ReportDataV3};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let payload = "0006bd87830d5f336e205cf5c63329a1dab8f5d56812eaeb7c69300e66ab8e22000000000000000000000000000000000000000000000000000000000cf7ed13000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000003000101000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000030ab7d02fbba9c6304f98824524407b1f494741174320cfd17a2c22eec1de0000000000000000000000000000000000000000000000000000000066a8f5c60000000000000000000000000000000000000000000000000000000066a8f5c6000000000000000000000000000000000000000000000000000057810653dd9000000000000000000000000000000000000000000000000000541315da76d6100000000000000000000000000000000000000000000000000000000066aa474600000000000000000000000000000000000000000000000009a697ee4230350400000000000000000000000000000000000000000000000009a6506d1426d00000000000000000000000000000000000000000000000000009a77d03ae355fe0000000000000000000000000000000000000000000000000000000000000000672bac991f5233df89f581dc02a89dd8d48419e3558b247d3e65f4069fa45c36658a5a4820dc94fc47a88a21d83474c29ee38382c46b6f9a575b9ce8be4e689c03c76fac19fbec4a29dba704c72cc003a6be1f96af115e322321f0688e24720a5d9bd7136a1d96842ec89133058b888b2e6572b5d4114de2426195e038f1c9a5ce50016b6f5a5de07e08529b845e1c622dcbefa0cfa2ffd128e9932ecee8efd869bc56d09a50ceb360a8d366cfa8eefe3f64279c88bdbc887560efa9944238eb000000000000000000000000000000000000000000000000000000000000000060e2a800f169f26164533c7faff6c9073cd6db240d89444d3487113232f9c31422a0993bb47d56807d0dc26728e4c8424bb9db77511001904353f1022168723010c46627c890be6e701e766679600696866c888ec80e7dbd428f5162a24f2d8262f846bdb06d9e46d295dd8e896fb232be80534b0041660fe4450a7ede9bc3b230722381773a4ae81241568867a759f53c2bdd05d32b209e78845fc58203949e50a608942b270c456001e578227ad00861cf5f47b27b09137a0c4b7f8b4746cef";
    let payload = hex::decode(payload)?;

    let (_report_context, report_blob) = decode_full_report(&payload)?;

    let report = ReportDataV3::decode(&report_blob)?;

    println!("{:#?}", report);

    // Prints:
    //
    // ReportDataV3 {
    //     feedId: 0x00030ab7d02fbba9c6304f98824524407b1f494741174320cfd17a2c22eec1de,
    //     validFromTimestamp: 1722348998,
    //     observationsTimestamp: 1722348998,
    //     nativeFee: 96211668557200,
    //     linkFee: 23664882624157200,
    //     expiresAt: 1722435398,
    //     benchmarkPrice: 695410242043786500,
    //     bid: 695331621895065600,
    //     ask: 695662122213138400,
    // }
    //

    Ok(())
}