mep_vm/
return_data.rs

1// Copyright 2015-2020 Parity Technologies (UK) Ltd.
2// This file is part of Parity Ethereum.
3
4// Parity Ethereum is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Ethereum is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Ethereum.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Return data structures
18
19use ethereum_types::U256;
20
21/// Return data buffer. Holds memory from a previous call and a slice into that memory.
22#[derive(Debug)]
23pub struct ReturnData {
24	mem: Vec<u8>,
25	offset: usize,
26	size: usize,
27}
28
29impl ::std::ops::Deref for ReturnData {
30	type Target = [u8];
31	fn deref(&self) -> &[u8] {
32		&self.mem[self.offset..self.offset + self.size]
33	}
34}
35
36impl ReturnData {
37	/// Create empty `ReturnData`.
38	pub fn empty() -> Self {
39		ReturnData {
40			mem: Vec::new(),
41			offset: 0,
42			size: 0,
43		}
44	}
45	/// Create `ReturnData` from give buffer and slice.
46	pub fn new(mem: Vec<u8>, offset: usize, size: usize) -> Self {
47		ReturnData { mem, offset, size }
48	}
49}
50
51/// Gas Left: either it is a known value, or it needs to be computed by processing
52/// a return instruction.
53#[derive(Debug)]
54pub enum GasLeft {
55	/// Known gas left
56	Known(U256),
57	/// Return or Revert instruction must be processed.
58	NeedsReturn {
59		/// Amount of gas left.
60		gas_left: U256,
61		/// Return data buffer.
62		data: ReturnData,
63		/// Apply or revert state changes on revert.
64		apply_state: bool
65	},
66}