Skip to content

Commit 8f822b9

Browse files
authored
add MerklePrefix::apply (#28)
1 parent e386949 commit 8f822b9

File tree

1 file changed

+13
-0
lines changed
  • crates/ibc-types-core-commitment/src

1 file changed

+13
-0
lines changed

crates/ibc-types-core-commitment/src/prefix.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::prelude::*;
2+
use crate::MerklePath;
23

34
use crate::Error;
45

@@ -10,6 +11,18 @@ pub struct MerklePrefix {
1011
pub key_prefix: Vec<u8>,
1112
}
1213

14+
impl MerklePrefix {
15+
/// apply the prefix to the supplied paths
16+
pub fn apply(&self, paths: Vec<String>) -> MerklePath {
17+
let commitment_str =
18+
core::str::from_utf8(&self.key_prefix).expect("commitment prefix is not valid utf-8");
19+
let mut key_path: Vec<String> = vec![format!("{commitment_str:?}")];
20+
key_path.append(paths.clone().as_mut());
21+
22+
MerklePath { key_path }
23+
}
24+
}
25+
1326
impl TypeUrl for MerklePrefix {
1427
const TYPE_URL: &'static str = "/ibc.core.commitment.v1.MerklePrefix";
1528
}

0 commit comments

Comments
 (0)