pchain_world_state/
error.rs

1/*
2    Copyright © 2023, ParallelChain Lab 
3    Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
4*/
5
6//! Error handling behaviour of this crate.
7
8/// WorldStateError enumerates the possible error of [WorldState](crate::states::WorldState). 
9#[derive(Debug)]
10pub enum WorldStateError {
11    /// Attempted to create a trie with a state root not in the database.
12	InvalidStateRoot,
13	/// Trie item not found in the database,
14	IncompleteDatabase,
15    /// A value was found in the trie with a nibble key that was not byte-aligned.
16	ValueAtIncompleteKey,
17	/// Corrupt Trie item.
18	DecoderError,
19	/// Encoded node contains invalid hash reference.
20	InvalidHash,
21    /// Attempted to convert protected WSKey to AppKey
22    ProtectedKey
23}
24
25impl<T, E> From<trie_db::TrieError<T, E>> for WorldStateError{
26    fn from(err: trie_db::TrieError<T, E>) -> Self {
27        match err {
28            trie_db::TrieError::InvalidStateRoot(_) => WorldStateError::InvalidStateRoot,
29            trie_db::TrieError::IncompleteDatabase(_) => WorldStateError::IncompleteDatabase,
30            trie_db::TrieError::ValueAtIncompleteKey(_, _) => WorldStateError::ValueAtIncompleteKey,
31            trie_db::TrieError::DecoderError(_, _) => WorldStateError::DecoderError,
32            trie_db::TrieError::InvalidHash(_, _) => WorldStateError::InvalidHash,
33        }
34    }
35}