Add comments for the diff module
@@ -8,6 +8,15 @@ use models::node::{AccountUpdate, TokenId};
// Local imports
use crate::chain::account::records::*;
+/// `StorageAccoundDiff` is a enum that combines all the possible
+/// changes that can be applied to account, which includes:
+///
+/// - Creation of the new account.
+/// - Removing of the existing account.
+/// - Changing balance of the account.
+/// - Changing the public key of the account.
+///
+/// This enum allows one to process account updates in a generic way.
#[derive(Debug)]
pub enum StorageAccountDiff {
BalanceUpdate(StorageAccountUpdate),
@@ -69,9 +78,9 @@ impl Into<(u32, AccountUpdate)> for StorageAccountDiff {
old_nonce: upd.old_nonce as u32,
new_nonce: upd.new_nonce as u32,
old_pub_key_hash: PubKeyHash::from_bytes(&upd.old_pubkey_hash)
- .expect("PubkeyHash update from db deserialzie"),
+ .expect("PubkeyHash update from db deserialize"),
new_pub_key_hash: PubKeyHash::from_bytes(&upd.new_pubkey_hash)
- .expect("PubkeyHash update from db deserialzie"),
+ .expect("PubkeyHash update from db deserialize"),
},
),
}
@@ -79,6 +88,7 @@ impl Into<(u32, AccountUpdate)> for StorageAccountDiff {
}
impl StorageAccountDiff {
+ /// Returns the index of the operation within block.
pub fn update_order_id(&self) -> i32 {
*match self {
StorageAccountDiff::BalanceUpdate(StorageAccountUpdate {
@@ -97,13 +107,14 @@ impl StorageAccountDiff {
}
}
- /// Compares updates by `block number` then by `update_order_id(number within block)`.
+ /// Compares updates by `block number` then by `update_order_id` (which is number within block).
pub fn cmp_order(&self, other: &Self) -> Ordering {
self.block_number()
.cmp(&other.block_number())
.then(self.update_order_id().cmp(&other.update_order_id()))
}
+ /// Returns the block index to which the operation belongs.
pub fn block_number(&self) -> i64 {
*match self {
StorageAccountDiff::BalanceUpdate(StorageAccountUpdate { block_number, .. }) => {
