From 4c6d1dd4bd55e7ee8ad697d008d3292fbf09f99e Mon Sep 17 00:00:00 2001 From: jaspervdm Date: Wed, 7 Oct 2020 14:09:27 +0200 Subject: [PATCH] Define get_data_from_file function on ReadablePMMR trait (#3464) --- core/src/core/pmmr/pmmr.rs | 11 +++++++++++ core/src/core/pmmr/readonly_pmmr.rs | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/core/src/core/pmmr/pmmr.rs b/core/src/core/pmmr/pmmr.rs index 86a37bbdf..1e8cb199a 100644 --- a/core/src/core/pmmr/pmmr.rs +++ b/core/src/core/pmmr/pmmr.rs @@ -40,6 +40,9 @@ pub trait ReadablePMMR { /// Get the hash from the underlying MMR file (ignores the remove log). fn get_from_file(&self, pos: u64) -> Option; + /// Get the data element at provided position in the MMR (ignores the remove log). + fn get_data_from_file(&self, pos: u64) -> Option; + /// Total size of the tree, including intermediary nodes and ignoring any pruning. fn unpruned_size(&self) -> u64; @@ -412,6 +415,14 @@ where } } + fn get_data_from_file(&self, pos: u64) -> Option { + if pos > self.last_pos { + None + } else { + self.backend.get_data_from_file(pos) + } + } + fn unpruned_size(&self) -> u64 { self.last_pos } diff --git a/core/src/core/pmmr/readonly_pmmr.rs b/core/src/core/pmmr/readonly_pmmr.rs index bc2f0752e..536c6736d 100644 --- a/core/src/core/pmmr/readonly_pmmr.rs +++ b/core/src/core/pmmr/readonly_pmmr.rs @@ -148,6 +148,14 @@ where } } + fn get_data_from_file(&self, pos: u64) -> Option { + if pos > self.last_pos { + None + } else { + self.backend.get_data_from_file(pos) + } + } + fn unpruned_size(&self) -> u64 { self.last_pos }