Skip to content

Commit

Permalink
Merge branch 'FI-1116-part-1' into 'master'
Browse files Browse the repository at this point in the history
feat(FI-1116) [ICRC Rosetta] Part 1 of FI-1116

This MR is a subset of the [MR](https://gitlab.com/dfinity-lab/public/ic/-/merge_requests/16870) on ticket FI-1116 and introduces the following changes:
1. Remove the `test_utils` as the storage client is the only place where the function `create_tempdir` is used. 
2. Add getters for identifiers for rosetta block 

See merge request dfinity-lab/public/ic!16976
  • Loading branch information
NikolasHaimerl committed Jan 5, 2024
2 parents c89fab6 + 3020248 commit 97416c3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl StorageClient {
#[cfg(test)]
mod tests {
use super::*;
use crate::{common::utils::unit_test_utils::create_tmp_dir, Metadata};
use crate::Metadata;
use ic_icrc1::{Block, Operation, Transaction};
use ic_icrc1_test_utils::{
arb_amount, blocks_strategy, metadata_strategy, valid_blockchain_with_gaps_strategy,
Expand All @@ -182,6 +182,13 @@ mod tests {
use ic_ledger_core::{block::BlockType, tokens::TokensType};
use proptest::prelude::*;

pub fn create_tmp_dir() -> tempfile::TempDir {
tempfile::Builder::new()
.prefix("test_tmp_")
.tempdir_in(".")
.unwrap()
}

fn convert_operation_type<A, B>(value: Operation<A>) -> Operation<B>
where
A: TokensType,
Expand Down
26 changes: 26 additions & 0 deletions rs/rosetta-api/icrc1/rosetta/src/common/storage/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ impl RosettaBlock {
.map_err(anyhow::Error::msg)?
.transaction)
}

pub fn get_parent_block_identifier(&self) -> BlockIdentifier {
self.parent_hash
.as_ref()
.map(|ph| BlockIdentifier {
index: self.index.saturating_sub(1),
hash: hex::encode(ph),
})
.unwrap_or_else(|| BlockIdentifier {
index: self.index,
hash: hex::encode(&self.block_hash),
})
}

pub fn get_transaction_identifier(&self) -> rosetta_core::identifiers::TransactionIdentifier {
rosetta_core::identifiers::TransactionIdentifier {
hash: hex::encode(&self.transaction_hash),
}
}

pub fn get_block_identifier(&self) -> rosetta_core::identifiers::BlockIdentifier {
rosetta_core::identifiers::BlockIdentifier {
index: self.index,
hash: hex::encode(&self.block_hash),
}
}
}

impl From<&RosettaBlock> for BlockIdentifier {
Expand Down
10 changes: 1 addition & 9 deletions rs/rosetta-api/icrc1/rosetta/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,7 @@ impl BlockResponseBuilder {

let block_identifier = BlockIdentifier::from(&block);

let parent_hash = block
.parent_hash
.as_ref()
.map(hex::encode)
.unwrap_or_else(|| block_identifier.hash.clone());
let parent_block_identifier = BlockIdentifier {
index: block.index.saturating_sub(1),
hash: parent_hash,
};
let parent_block_identifier = block.get_parent_block_identifier();

let icrc1_transaction = block.get_transaction()?;

Expand Down
1 change: 0 additions & 1 deletion rs/rosetta-api/icrc1/rosetta/src/common/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod unit_test_utils;
#[allow(clippy::module_inception)]
pub mod utils;

This file was deleted.

0 comments on commit 97416c3

Please sign in to comment.