Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
[receipt]: add sender & receiver to RichReceipts (#11179)
Browse files Browse the repository at this point in the history
* [receipts]: add `to` & `from` to `RichReceipts`

* [rpc]: add test for `pending_receipt`

* docs(common_types/receipt): add note Option field
  • Loading branch information
niklasad1 authored Oct 18, 2019
1 parent 2d2513b commit c8b4373
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,11 @@ impl miner::MinerService for Miner {
let prev_gas = if index == 0 { Default::default() } else { receipts[index - 1].gas_used };
let receipt = &receipts[index];
RichReceipt {
from: tx.sender(),
to: match tx.action {
Action::Create => None,
Action::Call(ref address) => Some(*address),
},
transaction_hash: tx.hash(),
transaction_index: index,
cumulative_gas_used: receipt.gas_used,
Expand Down
8 changes: 8 additions & 0 deletions ethcore/types/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ pub struct RichReceipt {
/// The gas used in the execution of the transaction. Note the difference of meaning to `Receipt::gas_used`.
pub gas_used: U256,
/// Contract address.
/// NOTE: It is an Option because only `Action::Create` transactions has a contract address
pub contract_address: Option<Address>,
/// Logs
pub logs: Vec<LogEntry>,
/// Logs bloom
pub log_bloom: Bloom,
/// Transaction outcome.
pub outcome: TransactionOutcome,
/// Receiver address
/// NOTE: It is an Option because only `Action::Call` transactions has a receiver address
pub to: Option<H160>,
/// Sender
pub from: H160
}

/// Receipt with additional info.
Expand All @@ -147,6 +153,7 @@ pub struct LocalizedReceipt {
/// The gas used in the execution of the transaction. Note the difference of meaning to `Receipt::gas_used`.
pub gas_used: U256,
/// Contract address.
/// NOTE: It is an Option because only `Action::Create` transactions has a contract address
pub contract_address: Option<Address>,
/// Logs
pub logs: Vec<LocalizedLogEntry>,
Expand All @@ -155,6 +162,7 @@ pub struct LocalizedReceipt {
/// Transaction outcome.
pub outcome: TransactionOutcome,
/// Receiver address
/// NOTE: It is an Option because only `Action::Call` transactions has a receiver address
pub to: Option<H160>,
/// Sender
pub from: H160
Expand Down
32 changes: 30 additions & 2 deletions rpc/src/v1/tests/mocked/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use types::{
ids::{BlockId, TransactionId},
transaction::{Transaction, Action},
log_entry::{LocalizedLogEntry, LogEntry},
receipt::{LocalizedReceipt, TransactionOutcome},
receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome},
snapshot::RestorationStatus,
};

Expand Down Expand Up @@ -971,7 +971,7 @@ fn rpc_eth_transaction_receipt() {
"params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
"id": 1
}"#;
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","status":null,"to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#;

assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}
Expand All @@ -991,6 +991,34 @@ fn rpc_eth_transaction_receipt_null() {
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

#[test]
fn rpc_eth_pending_receipt() {
let pending = RichReceipt {
from: H160::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap(),
to: Some(H160::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
transaction_hash: H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap(),
transaction_index: 0,
cumulative_gas_used: U256::from(0x20),
gas_used: U256::from(0x10),
contract_address: None,
logs: Vec::new(),
log_bloom: Bloom::zero(),
outcome: TransactionOutcome::Unknown,
};
let tester = EthTester::default();

tester.miner.pending_receipts.lock().push(pending);

let request = r#"{
"jsonrpc": "2.0",
"method": "eth_getTransactionReceipt",
"params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
"id": 1
}"#;
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238","transactionIndex":"0x0"},"id":1}"#;
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
}

// These tests are incorrect: their output is undefined as long as eth_getCompilers is [].
// Will ignore for now, but should probably be replaced by more substantial tests which check
// the output of eth_getCompilers to determine whether to test. CI systems can then be preinstalled
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/tests/mocked/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ fn rpc_parity_block_receipts() {
"params": [],
"id": 1
}"#;
let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","root":null,"status":null,"to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#;

assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
}
Expand Down
10 changes: 6 additions & 4 deletions rpc/src/v1/types/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ pub struct Receipt {
/// Logs
pub logs: Vec<Log>,
/// State Root
#[serde(rename = "root")]
// NOTE(niklasad1): EIP98 makes this optional field, if it's missing then skip serializing it
#[serde(skip_serializing_if = "Option::is_none", rename = "root")]
pub state_root: Option<H256>,
/// Logs bloom
pub logs_bloom: H2048,
/// Status code
#[serde(rename = "status")]
// NOTE(niklasad1): Unknown after EIP98 rules, if it's missing then skip serializing it
#[serde(skip_serializing_if = "Option::is_none", rename = "status")]
pub status_code: Option<U64>,
}

Expand Down Expand Up @@ -91,8 +93,8 @@ impl From<LocalizedReceipt> for Receipt {
impl From<RichReceipt> for Receipt {
fn from(r: RichReceipt) -> Self {
Receipt {
from: None,
to: None,
from: Some(r.from),
to: r.to.map(Into::into),
transaction_hash: Some(r.transaction_hash),
transaction_index: Some(r.transaction_index.into()),
block_hash: None,
Expand Down

0 comments on commit c8b4373

Please sign in to comment.