Skip to content

Commit

Permalink
uncomplete work
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeantonio21 committed Nov 14, 2022
1 parent f4fe6d9 commit f439d24
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
27 changes: 27 additions & 0 deletions base_layer/core/src/base_node/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,32 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletService for BaseNodeWalletRpc
async fn get_height_at_time(&self, request: Request<u64>) -> Result<Response<u64>, RpcStatus> {
let requested_epoch_time: u64 = request.into_message();

dbg!("FLAG0: the requested epoch time = {}", requested_epoch_time);

let zero_header = self
.db()
.fetch_header(0u64)
.await
.rpc_status_internal_error(LOG_TARGET)?
.ok_or_else(|| RpcStatus::not_found(&format!("Header not found during search at height {}", 0u64)))?;

dbg!(
"FLAG1: the zero height block timestamp is: {}",
zero_header.timestamp.as_u64()
);

let one_header = self
.db()
.fetch_header(1u64)
.await
.rpc_status_internal_error(LOG_TARGET)?
.ok_or_else(|| RpcStatus::not_found(&format!("Header not found during search at height {}", 1u64)))?;

dbg!(
"FLAG2: the one height block timestamp is: {}",
one_header.timestamp.as_u64()
);

let tip_header = self
.db()
.fetch_tip_header()
Expand All @@ -554,6 +580,7 @@ impl<B: BlockchainBackend + 'static> BaseNodeWalletService for BaseNodeWalletRpc
let mut right_height = tip_header.height();

while left_height <= right_height {
dbg!("FLAG1: the right_height is: {}", right_height);
let mut mid_height = (left_height + right_height) / 2;

if mid_height == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ use crate::{
},
};

pub const BIRTHDAY_GENESIS_FROM_UNIX_EPOCH: u64 = 1640995200; // seconds since 2022-01-01 00:00:00 UTC
pub const LOG_TARGET: &str = "wallet::utxo_scanning";

pub struct UtxoScannerTask<TBackend, TWalletConnectivity> {
Expand Down Expand Up @@ -325,11 +326,7 @@ where
client: &mut BaseNodeWalletRpcClient,
) -> Result<BlockHeader, UtxoScannerError> {
let tip_info = client.get_tip_info().await?;
let wallet_birthday_height = self.get_birthday_header_height_hash(client).await?.height;
let chain_height = tip_info
.metadata
.map(|m| m.height_of_longest_chain())
.unwrap_or(wallet_birthday_height);
let chain_height = tip_info.metadata.map(|m| m.height_of_longest_chain()).unwrap_or(0);
let end_header = client.get_header_by_height(chain_height).await?;
let end_header = BlockHeader::try_from(end_header).map_err(UtxoScannerError::ConversionError)?;

Expand Down Expand Up @@ -706,6 +703,8 @@ where
// Calculate the unix epoch time of two days before the wallet birthday. This is to avoid any weird time zone
// issues
let epoch_time = u64::from(birthday.saturating_sub(2)) * 60 * 60 * 24;
// add the elapsed seconds from Unix epoch, to be consistent with block timestamps
let epoch_time = epoch_time + BIRTHDAY_GENESIS_FROM_UNIX_EPOCH;
let block_height = match client.get_height_at_time(epoch_time).await {
Ok(b) => b,
Err(e) => {
Expand Down

0 comments on commit f439d24

Please sign in to comment.