From a729f26952d57cc3aaa6a1c2b665f33d34d249bd Mon Sep 17 00:00:00 2001 From: James Hiew Date: Thu, 27 Oct 2022 09:25:37 +0100 Subject: [PATCH] Split merkle_tree::Error::InvalidValue --- shared/src/ledger/storage/merkle_tree.rs | 6 ++++-- shared/src/ledger/storage/traits.rs | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shared/src/ledger/storage/merkle_tree.rs b/shared/src/ledger/storage/merkle_tree.rs index 3add9dd7f03..782152206b3 100644 --- a/shared/src/ledger/storage/merkle_tree.rs +++ b/shared/src/ledger/storage/merkle_tree.rs @@ -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.")] diff --git a/shared/src/ledger/storage/traits.rs b/shared/src/ledger/storage/traits.rs index ee9805a8eee..d4fad5179e5 100644 --- a/shared/src/ledger/storage/traits.rs +++ b/shared/src/ledger/storage/traits.rs @@ -62,7 +62,7 @@ impl<'a, H: StorageHasher + Default> SubTreeRead for &'a Smt { 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 @@ -90,7 +90,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Smt { ) -> Result { 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) @@ -149,7 +149,7 @@ impl<'a, H: StorageHasher + Default> SubTreeWrite for &'a mut Amt { 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) @@ -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) } }