openethereum/ethcore/src/receipt.rs

73 lines
2.7 KiB
Rust
Raw Normal View History

2016-02-05 13:40:41 +01:00
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
2016-02-04 23:58:58 +01:00
//! Receipt
use util::*;
use basic_types::LogBloom;
2016-01-11 13:29:15 +01:00
use log_entry::LogEntry;
/// Information describing execution of a transaction.
#[derive(Default, Debug, Clone)]
pub struct Receipt {
2016-02-03 13:20:32 +01:00
/// The state root after executing the transaction.
pub state_root: H256,
2016-02-03 13:20:32 +01:00
/// The total gas used in the block following execution of the transaction.
2016-01-08 22:04:21 +01:00
pub gas_used: U256,
2016-02-03 13:20:32 +01:00
/// The OR-wide combination of all logs' blooms for this transaction.
pub log_bloom: LogBloom,
2016-02-03 13:20:32 +01:00
/// The logs stemming from this transaction.
pub logs: Vec<LogEntry>,
}
2016-01-11 17:37:22 +01:00
impl Receipt {
2016-02-03 13:20:32 +01:00
/// Create a new receipt.
2016-01-11 17:37:22 +01:00
pub fn new(state_root: H256, gas_used: U256, logs: Vec<LogEntry>) -> Receipt {
Receipt {
state_root: state_root,
gas_used: gas_used,
log_bloom: logs.iter().fold(LogBloom::new(), |mut b, l| { b |= &l.bloom(); b }),
logs: logs,
}
}
}
2016-01-27 17:22:01 +01:00
impl Encodable for Receipt {
fn rlp_append(&self, s: &mut RlpStream) {
2016-01-27 17:22:01 +01:00
s.begin_list(4);
s.append(&self.state_root);
s.append(&self.gas_used);
s.append(&self.log_bloom);
2016-01-28 20:13:05 +01:00
s.append(&self.logs);
}
}
2016-01-30 14:00:36 +01:00
2016-02-01 01:03:57 +01:00
#[test]
fn test_basic() {
2016-02-01 11:00:18 +01:00
let expected = FromHex::from_hex("f90162a02f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee83040caeb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000f838f794dcf421d093428b096ca501a7cd1a740855a7976fc0a00000000000000000000000000000000000000000000000000000000000000000").unwrap();
2016-02-01 01:03:57 +01:00
let r = Receipt::new(
x!("2f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee"),
x!(0x40cae),
vec![LogEntry::new(
x!("dcf421d093428b096ca501a7cd1a740855a7976f"),
vec![],
2016-02-01 11:00:18 +01:00
vec![0u8; 32]
2016-02-01 01:03:57 +01:00
)]
);
assert_eq!(&encode(&r)[..], &expected[..]);
2016-01-30 14:00:36 +01:00
}