Skip to content

Commit

Permalink
Split merkle_tree::Error::InvalidValue
Browse files Browse the repository at this point in the history
  • Loading branch information
james-chf committed Oct 27, 2022
1 parent e9be86c commit a729f26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions shared/src/ledger/storage/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ pub enum Error {
StoreType(String),
#[error("Non-existence proofs not supported for store type: {0}")]
NonExistenceProof(String),
#[error("Invalid value given to sub-tree storage")]
InvalidValue,
#[error("Expected a bytes value")]
ExpectedBytesValue,
#[error("Expected a bridge pool transfer value")]
ExpectedBridgePoolTransferValue,
#[error("ICS23 commitment proofs do not support multiple leaves")]
Ics23MultiLeaf,
#[error("A Tendermint proof can only be constructed from an ICS23 proof.")]
Expand Down
8 changes: 4 additions & 4 deletions shared/src/ledger/storage/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, H: StorageHasher + Default> SubTreeRead for &'a Smt<H> {
let key: &Key = &keys[0];
let value = match values.remove(0) {
MerkleValue::Bytes(b) => b,
_ => return Err(Error::InvalidValue),
_ => return Err(Error::ExpectedBytesValue),
};
let cp = self.membership_proof(&H::hash(key.to_string()).into())?;
// Replace the values and the leaf op for the verification
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Smt<H> {
) -> Result<Hash, Error> {
let value = match value {
MerkleValue::Bytes(bytes) => H::hash(bytes.as_slice()),
_ => return Err(Error::InvalidValue),
_ => return Err(Error::ExpectedBytesValue),
};
self.update(H::hash(key.to_string()).into(), value.into())
.map(Hash::from)
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Amt<H> {
let key = StringKey::try_from_bytes(key.to_string().as_bytes())?;
let value = match value {
MerkleValue::Bytes(bytes) => TreeBytes::from(bytes),
_ => return Err(Error::InvalidValue),
_ => return Err(Error::ExpectedBytesValue),
};
self.update(key, value)
.map(Into::into)
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<'a> SubTreeWrite for &'a mut BridgePoolTree {
self.insert_key(key)
.map_err(|err| Error::MerkleTree(err.to_string()))
} else {
Err(Error::InvalidValue)
Err(Error::ExpectedBridgePoolTransferValue)
}
}

Expand Down

0 comments on commit a729f26

Please sign in to comment.