multiversx_chain_vm/tx_mock/
blockchain_update.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::collections::HashMap;

use crate::{
    types::VMAddress,
    world_mock::{AccountData, BlockchainState},
};

#[derive(Default)]
pub struct BlockchainUpdate {
    pub accounts: HashMap<VMAddress, AccountData>,
    pub new_token_identifiers: Option<Vec<String>>,
}

impl BlockchainUpdate {
    pub fn empty() -> Self {
        BlockchainUpdate::default()
    }

    pub fn apply(self, blockchain: &mut BlockchainState) {
        blockchain.update_accounts(self.accounts);

        if let Some(token_identifiers) = self.new_token_identifiers {
            blockchain.update_new_token_identifiers(token_identifiers);
        }
    }
}