Fixed receipt serialization and RPC (#6555)
This commit is contained in:
committed by
Gav Wood
parent
2b39c43e81
commit
4dc7d3dc45
@@ -261,7 +261,7 @@ impl MinerService for TestMinerService {
|
||||
contract_address: None,
|
||||
logs: r.logs.clone(),
|
||||
log_bloom: r.log_bloom,
|
||||
state_root: r.state_root,
|
||||
outcome: r.outcome.clone(),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use ethkey::Secret;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};
|
||||
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
|
||||
use ethcore::receipt::LocalizedReceipt;
|
||||
use ethcore::receipt::{LocalizedReceipt, TransactionOutcome};
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
use ethcore::miner::{ExternalMiner, MinerService};
|
||||
use ethsync::SyncState;
|
||||
@@ -1007,7 +1007,7 @@ fn rpc_eth_transaction_receipt() {
|
||||
log_index: 1,
|
||||
}],
|
||||
log_bloom: 0.into(),
|
||||
state_root: Some(0.into()),
|
||||
outcome: TransactionOutcome::StateRoot(0.into()),
|
||||
};
|
||||
|
||||
let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap();
|
||||
@@ -1020,7 +1020,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","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","statusCode":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#;
|
||||
|
||||
assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use v1::types::{Log, H160, H256, H2048, U256};
|
||||
use ethcore::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt};
|
||||
use ethcore::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt, TransactionOutcome};
|
||||
|
||||
/// Receipt
|
||||
#[derive(Debug, Serialize)]
|
||||
@@ -49,6 +49,25 @@ pub struct Receipt {
|
||||
/// Logs bloom
|
||||
#[serde(rename="logsBloom")]
|
||||
pub logs_bloom: H2048,
|
||||
/// Status code
|
||||
#[serde(rename="statusCode")]
|
||||
pub status_code: Option<u8>,
|
||||
}
|
||||
|
||||
impl Receipt {
|
||||
fn outcome_to_state_root(outcome: TransactionOutcome) -> Option<H256> {
|
||||
match outcome {
|
||||
TransactionOutcome::Unknown | TransactionOutcome::StatusCode(_) => None,
|
||||
TransactionOutcome::StateRoot(root) => Some(root.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn outcome_to_status_code(outcome: &TransactionOutcome) -> Option<u8> {
|
||||
match *outcome {
|
||||
TransactionOutcome::Unknown | TransactionOutcome::StateRoot(_) => None,
|
||||
TransactionOutcome::StatusCode(ref code) => Some(*code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LocalizedReceipt> for Receipt {
|
||||
@@ -62,7 +81,8 @@ impl From<LocalizedReceipt> for Receipt {
|
||||
gas_used: Some(r.gas_used.into()),
|
||||
contract_address: r.contract_address.map(Into::into),
|
||||
logs: r.logs.into_iter().map(Into::into).collect(),
|
||||
state_root: r.state_root.map(Into::into),
|
||||
status_code: Self::outcome_to_status_code(&r.outcome),
|
||||
state_root: Self::outcome_to_state_root(r.outcome),
|
||||
logs_bloom: r.log_bloom.into(),
|
||||
}
|
||||
}
|
||||
@@ -79,7 +99,8 @@ impl From<RichReceipt> for Receipt {
|
||||
gas_used: Some(r.gas_used.into()),
|
||||
contract_address: r.contract_address.map(Into::into),
|
||||
logs: r.logs.into_iter().map(Into::into).collect(),
|
||||
state_root: r.state_root.map(Into::into),
|
||||
status_code: Self::outcome_to_status_code(&r.outcome),
|
||||
state_root: Self::outcome_to_state_root(r.outcome),
|
||||
logs_bloom: r.log_bloom.into(),
|
||||
}
|
||||
}
|
||||
@@ -96,7 +117,8 @@ impl From<EthReceipt> for Receipt {
|
||||
gas_used: None,
|
||||
contract_address: None,
|
||||
logs: r.logs.into_iter().map(Into::into).collect(),
|
||||
state_root: r.state_root.map(Into::into),
|
||||
status_code: Self::outcome_to_status_code(&r.outcome),
|
||||
state_root: Self::outcome_to_state_root(r.outcome),
|
||||
logs_bloom: r.log_bloom.into(),
|
||||
}
|
||||
}
|
||||
@@ -109,7 +131,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn receipt_serialization() {
|
||||
let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","transactionLogIndex":null,"type":"mined"}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f"}"#;
|
||||
let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","transactionLogIndex":null,"type":"mined"}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","statusCode":null}"#;
|
||||
|
||||
let receipt = Receipt {
|
||||
transaction_hash: Some(0.into()),
|
||||
@@ -136,6 +158,7 @@ mod tests {
|
||||
}],
|
||||
logs_bloom: 15.into(),
|
||||
state_root: Some(10.into()),
|
||||
status_code: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&receipt).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user