Skip to content

Commit

Permalink
Add humantime dependency and update timestamp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kpob committed Jun 10, 2024
1 parent ab21b72 commit 6bf99f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions odra-casper/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ prettycli = "0.1.1"
thiserror = "1.0.40"
bytes = "1.5.0"
anyhow = "1.0.86"
humantime = "2.1.0"
10 changes: 7 additions & 3 deletions odra-casper/rpc-client/src/casper_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Client for interacting with Casper node.
use std::time::SystemTime;
use std::{fs, path::PathBuf, str::from_utf8_unchecked, time::Duration};

use anyhow::Context;
Expand Down Expand Up @@ -263,16 +264,19 @@ impl CasperClient {
}
);
let result: serde_json::Value = self.post_request(request);
let result = result["result"]["last_added_block_info"]["timestamp"]
let result = result["last_added_block_info"]["timestamp"]
.as_str()
.unwrap_or_else(|| {
panic!(
"Couldn't get block time - malformed JSON response: {:?}",
result
)
});
let timestamp: u64 = result.parse().expect("Couldn't parse block time");
timestamp
let system_time = humantime::parse_rfc3339_weak(result).expect("Couldn't parse block time");
system_time
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_else(|_| panic!("Couldn't parse block time"))
.as_millis() as u64
}

/// Get the event bytes from storage
Expand Down

0 comments on commit 6bf99f4

Please sign in to comment.