/// Applies an operation to the local state.
Applies an operation to the local state.
Applies an operation to the local state .
fn apply(&mut self, operation: &Operation) {
        match operation {
            Operation::LedgerTransfer {
                id: _,
                source,
                destination,
                amount,
            } => {
                let source_account = self.accounts.get_mut(&source.id).unwrap();
                source_account.balance =
                    ((source_account.balance - *amount).unwrap() - TRANSACTION_FEE).unwrap();
                let destination_account = self.accounts.get_mut(&destination.id).unwrap();
                destination_account.balance = (destination_account.balance + *amount).unwrap();
            }
            Operation::NeuronStake {
                id: _,
                source,
                destination,
                amount,
            } => {
                let source_account = self.accounts.get_mut(&source.id).unwrap();
                source_account.balance =
                    ((source_account.balance - *amount).unwrap() - TRANSACTION_FEE).unwrap();
                let destination_neuron = self.neurons.get_mut(&destination.id).unwrap();
                destination_neuron.balance = (destination_neuron.balance + *amount).unwrap();
            }
            Operation::NeuronDisburse {
                id: _,
                source,
                destination,
                amount,
            } => {
                let source_neuron = self.neurons.get_mut(&source.id).unwrap();
                let amount = if let Some(amount) = amount {
                    source_neuron.balance =
                        ((source_neuron.balance - *amount).unwrap() - TRANSACTION_FEE).unwrap();
                    *amount
                } else {
                    let amount = source_neuron.balance;
                    source_neuron.balance = Tokens::from_tokens(0).unwrap();
                    amount
                };
                let destination_account = self.accounts.get_mut(&destination.id).unwrap();
                destination_account.balance = (destination_account.balance + amount).unwrap();
            }
            _ => unimplemented!(),
        }
    }
fn apply ( & mut self , operation : & Operation ) { match operation { Operation :: LedgerTransfer { id : _ , source , destination , amount , } => { let source_account = self . accounts . get_mut ( & source . id ) . unwrap ( ) ; source_account . balance = ( ( source_account . balance - * amount ) . unwrap ( ) - TRANSACTION_FEE ) . unwrap ( ) ; let destination_account = self . accounts . get_mut ( & destination . id ) . unwrap ( ) ; destination_account . balance = ( destination_account . balance + * amount ) . unwrap ( ) ; } Operation :: NeuronStake { id : _ , source , destination , amount , } => { let source_account = self . accounts . get_mut ( & source . id ) . unwrap ( ) ; source_account . balance = ( ( source_account . balance - * amount ) . unwrap ( ) - TRANSACTION_FEE ) . unwrap ( ) ; let destination_neuron = self . neurons . get_mut ( & destination . id ) . unwrap ( ) ; destination_neuron . balance = ( destination_neuron . balance + * amount ) . unwrap ( ) ; } Operation :: NeuronDisburse { id : _ , source , destination , amount , } => { let source_neuron = self . neurons . get_mut ( & source . id ) . unwrap ( ) ; let amount = if let Some ( amount ) = amount { source_neuron . balance = ( ( source_neuron . balance - * amount ) . unwrap ( ) - TRANSACTION_FEE ) . unwrap ( ) ; * amount } else { let amount = source_neuron . balance ; source_neuron . balance = Tokens :: from_tokens ( 0 ) . unwrap ( ) ; amount } ; let destination_account = self . accounts . get_mut ( & destination . id ) . unwrap ( ) ; destination_account . balance = ( destination_account . balance + amount ) . unwrap ( ) ; } _ => unimplemented ! ( ) , } }
Applies an operation to the local state.
Applies an operation to the local state .
&mut self
operation
&Operation