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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::prelude::{
ExecutableTransaction,
Interpreter,
InterpreterStorage,
RuntimeError,
};
use crate::interpreter::{
InitialBalances,
RuntimeBalances,
};
use fuel_tx::ConsensusParameters;
use fuel_types::Word;
use std::io;
impl<S, T> Interpreter<S, T>
where
S: InterpreterStorage,
{
/// Finalize outputs post-execution.
///
/// For more information, check [`ExecutableTransaction::update_outputs`].
///
/// # Panics
///
/// This will panic if the transaction is malformed (e.g. it contains an output change
/// with asset id that doesn't exist as balance).
///
/// The transaction validation is expected to halt in such case. Since the VM only
/// accepts checked transactions - hence, validated - this case should be
/// unreachable.
pub(crate) fn finalize_outputs<Tx>(
tx: &mut Tx,
revert: bool,
remaining_gas: Word,
initial_balances: &InitialBalances,
balances: &RuntimeBalances,
params: &ConsensusParameters,
) -> Result<(), RuntimeError>
where
Tx: ExecutableTransaction,
{
tx.update_outputs(params, revert, remaining_gas, initial_balances, balances)
.map_err(|e| io::Error::new(
io::ErrorKind::Other,
format!("a valid VM execution shouldn't result in a state where it can't compute its refund. This is a bug! {e}")
))?;
Ok(())
}
}