pub fn commit_state_update(
        &self,
        block_number: u32,
        accounts_updated: &[(u32, AccountUpdate)],
    ) -> QueryResult<()> {
        // Simply go through the every account update, and update the corresponding table.
        // This may look scary, but every match arm is very simple by its nature.
        self.0.conn().transaction(|| {
            for (update_order_id, (id, upd)) in accounts_updated.iter().enumerate() {
                log::debug!(
                    "Committing state update for account {} in block {}",
                    id,
                    block_number
                );
                match *upd {
                    AccountUpdate::Create { ref address, nonce } => {
                        let account_create = StorageAccountCreation {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            is_create: true,
                            block_number: i64::from(block_number),
                            address: address.as_bytes().to_vec(),
                            nonce: i64::from(nonce),
                        };

                        diesel::insert_into(account_creates::table)
                            .values(&account_create)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::Delete { ref address, nonce } => {
                        let account_delete = StorageAccountCreation {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            is_create: false,
                            block_number: i64::from(block_number),
                            address: address.as_bytes().to_vec(),
                            nonce: i64::from(nonce),
                        };

                        diesel::insert_into(account_creates::table)
                            .values(&account_delete)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::UpdateBalance {
                        balance_update: (token, ref old_balance, ref new_balance),
                        old_nonce,
                        new_nonce,
                    } => {
                        let account_update = StorageAccountUpdateInsert {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            block_number: i64::from(block_number),
                            coin_id: i32::from(token),
                            old_balance: old_balance.clone().into(),
                            new_balance: new_balance.clone().into(),
                            old_nonce: i64::from(old_nonce),
                            new_nonce: i64::from(new_nonce),
                        };

                        diesel::insert_into(account_balance_updates::table)
                            .values(&account_update)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::ChangePubKeyHash {
                        ref old_pub_key_hash,
                        ref new_pub_key_hash,
                        old_nonce,
                        new_nonce,
                    } => {
                        let change_pubkey_hash = StorageAccountPubkeyUpdateInsert {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            block_number: i64::from(block_number),
                            old_pubkey_hash: old_pub_key_hash.data.to_vec(),
                            new_pubkey_hash: new_pub_key_hash.data.to_vec(),
                            old_nonce: i64::from(old_nonce),
                            new_nonce: i64::from(new_nonce),
                        };

                        diesel::insert_into(account_pubkey_updates::table)
                            .values(&change_pubkey_hash)
                            .execute(self.0.conn())?;
                    }
                }
            }
            Ok(())
        })
    }
/// Stores the list of updates to the account map in the database.
/// At this step, the changes are not verified yet, and thus are not applied.
Stores the list of updates to the account map in the database.
At this step, the changes are not verified yet, and thus are not applied.
Stores the list of updates to the account map in the database . At this step the changes are not verified yet and thus are not applied .
pub fn commit_state_update(
        &self,
        block_number: u32,
        accounts_updated: &[(u32, AccountUpdate)],
    ) -> QueryResult<()> {
        // Simply go through the every account update, and update the corresponding table.
        // This may look scary, but every match arm is very simple by its nature.
        self.0.conn().transaction(|| {
            for (update_order_id, (id, upd)) in accounts_updated.iter().enumerate() {
                log::debug!(
                    "Committing state update for account {} in block {}",
                    id,
                    block_number
                );
                match *upd {
                    AccountUpdate::Create { ref address, nonce } => {
                        let account_create = StorageAccountCreation {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            is_create: true,
                            block_number: i64::from(block_number),
                            address: address.as_bytes().to_vec(),
                            nonce: i64::from(nonce),
                        };
                        diesel::insert_into(account_creates::table)
                            .values(&account_create)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::Delete { ref address, nonce } => {
                        let account_delete = StorageAccountCreation {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            is_create: false,
                            block_number: i64::from(block_number),
                            address: address.as_bytes().to_vec(),
                            nonce: i64::from(nonce),
                        };
                        diesel::insert_into(account_creates::table)
                            .values(&account_delete)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::UpdateBalance {
                        balance_update: (token, ref old_balance, ref new_balance),
                        old_nonce,
                        new_nonce,
                    } => {
                        let account_update = StorageAccountUpdateInsert {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            block_number: i64::from(block_number),
                            coin_id: i32::from(token),
                            old_balance: old_balance.clone().into(),
                            new_balance: new_balance.clone().into(),
                            old_nonce: i64::from(old_nonce),
                            new_nonce: i64::from(new_nonce),
                        };
                        diesel::insert_into(account_balance_updates::table)
                            .values(&account_update)
                            .execute(self.0.conn())?;
                    }
                    AccountUpdate::ChangePubKeyHash {
                        ref old_pub_key_hash,
                        ref new_pub_key_hash,
                        old_nonce,
                        new_nonce,
                    } => {
                        let change_pubkey_hash = StorageAccountPubkeyUpdateInsert {
                            update_order_id: update_order_id as i32,
                            account_id: i64::from(*id),
                            block_number: i64::from(block_number),
                            old_pubkey_hash: old_pub_key_hash.data.to_vec(),
                            new_pubkey_hash: new_pub_key_hash.data.to_vec(),
                            old_nonce: i64::from(old_nonce),
                            new_nonce: i64::from(new_nonce),
                        };
                        diesel::insert_into(account_pubkey_updates::table)
                            .values(&change_pubkey_hash)
                            .execute(self.0.conn())?;
                    }
                }
            }
            Ok(())
        })
    }
pub fn commit_state_update ( & self , block_number : u32 , accounts_updated : & [ ( u32 , AccountUpdate ) ] , ) -> QueryResult < ( ) > { // Simply go through the every account update, and update the corresponding table. // This may look scary, but every match arm is very simple by its nature. self . 0 . conn ( ) . transaction ( | | { for ( update_order_id , ( id , upd ) ) in accounts_updated . iter ( ) . enumerate ( ) { log :: debug ! ( " " id block_number ) ; match * upd { AccountUpdate :: Create { ref address , nonce } => { let account_create = StorageAccountCreation { update_order_id : update_order_id as i32 , account_id : i64 :: from ( * id ) , is_create : true , block_number : i64 :: from ( block_number ) , address : address . as_bytes ( ) . to_vec ( ) , nonce : i64 :: from ( nonce ) , } ; diesel :: insert_into ( account_creates :: table ) . values ( & account_create ) . execute ( self . 0 . conn ( ) ) ? ; } AccountUpdate :: Delete { ref address , nonce } => { let account_delete = StorageAccountCreation { update_order_id : update_order_id as i32 , account_id : i64 :: from ( * id ) , is_create : false , block_number : i64 :: from ( block_number ) , address : address . as_bytes ( ) . to_vec ( ) , nonce : i64 :: from ( nonce ) , } ; diesel :: insert_into ( account_creates :: table ) . values ( & account_delete ) . execute ( self . 0 . conn ( ) ) ? ; } AccountUpdate :: UpdateBalance { balance_update : ( token , ref old_balance , ref new_balance ) , old_nonce , new_nonce , } => { let account_update = StorageAccountUpdateInsert { update_order_id : update_order_id as i32 , account_id : i64 :: from ( * id ) , block_number : i64 :: from ( block_number ) , coin_id : i32 :: from ( token ) , old_balance : old_balance . clone ( ) . into ( ) , new_balance : new_balance . clone ( ) . into ( ) , old_nonce : i64 :: from ( old_nonce ) , new_nonce : i64 :: from ( new_nonce ) , } ; diesel :: insert_into ( account_balance_updates :: table ) . values ( & account_update ) . execute ( self . 0 . conn ( ) ) ? ; } AccountUpdate :: ChangePubKeyHash { ref old_pub_key_hash , ref new_pub_key_hash , old_nonce , new_nonce , } => { let change_pubkey_hash = StorageAccountPubkeyUpdateInsert { update_order_id : update_order_id as i32 , account_id : i64 :: from ( * id ) , block_number : i64 :: from ( block_number ) , old_pubkey_hash : old_pub_key_hash . data . to_vec ( ) , new_pubkey_hash : new_pub_key_hash . data . to_vec ( ) , old_nonce : i64 :: from ( old_nonce ) , new_nonce : i64 :: from ( new_nonce ) , } ; diesel :: insert_into ( account_pubkey_updates :: table ) . values ( & change_pubkey_hash ) . execute ( self . 0 . conn ( ) ) ? ; } } } Ok ( ( ) ) } ) }
Stores the list of updates to the account map in the database.
Stores the list of updates to the account map in the database .
&self
block_number
u32
accounts_updated
&[(u32, AccountUpdate)]