diff --git a/examples/local_signer.rs b/examples/local_signer.rs index c7577f59..2a2c06a8 100644 --- a/examples/local_signer.rs +++ b/examples/local_signer.rs @@ -22,7 +22,10 @@ async fn main() -> Result<(), failure::Error> { // get the mined tx let tx = client.get_transaction(tx.hash).await?; + let receipt = client.get_transaction_receipt(tx.hash).await?; + println!("{}", serde_json::to_string(&tx)?); + println!("{}", serde_json::to_string(&receipt)?); Ok(()) } diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 67051be1..4c745d85 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -7,7 +7,10 @@ mod http; use crate::{ signers::{Client, Signer}, - types::{Address, Block, BlockId, BlockNumber, Transaction, TransactionRequest, TxHash, U256}, + types::{ + Address, Block, BlockId, BlockNumber, Transaction, TransactionReceipt, TransactionRequest, + TxHash, U256, + }, utils, }; @@ -111,6 +114,17 @@ impl Provider

{ } } + /// Gets the transaction receipt for tx hash + pub async fn get_transaction_receipt>( + &self, + hash: T, + ) -> Result { + let hash = hash.into(); + self.0 + .request("eth_getTransactionReceipt", Some(hash)) + .await + } + /// Gets the transaction which matches the provided hash via the `eth_getTransactionByHash` API pub async fn get_transaction>( &self, diff --git a/src/types/log.rs b/src/types/log.rs new file mode 100644 index 00000000..3865bba1 --- /dev/null +++ b/src/types/log.rs @@ -0,0 +1,51 @@ +use crate::types::{Address, Bytes, H256, U256, U64}; +use serde::{Deserialize, Serialize}; + +/// A log produced by a transaction. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Log { + /// H160 + pub address: Address, + + /// topics: Array of 0 to 4 32 Bytes of indexed log arguments. + /// (In solidity: The first topic is the hash of the signature of the event + /// (e.g. Deposit(address,bytes32,uint256)), except you declared the event + /// with the anonymous specifier.) + pub topics: Vec, + + /// Data + pub data: Bytes, + + /// Block Hash + #[serde(rename = "blockHash")] + pub block_hash: Option, + + /// Block Number + #[serde(rename = "blockNumber")] + pub block_number: Option, + + /// Transaction Hash + #[serde(rename = "transactionHash")] + pub transaction_hash: Option, + + /// Transaction Index + #[serde(rename = "transactionIndex")] + pub transaction_index: Option, + + /// Integer of the log index position in the block. Noe if it's a pending log. + #[serde(rename = "logIndex")] + pub log_index: Option, + + /// Integer of the transactions index position log was created from. + /// None when it's a pending log. + #[serde(rename = "transactionLogIndex")] + pub transaction_log_index: Option, + + /// Log Type + #[serde(rename = "logType")] + pub log_type: Option, + + /// True when the log was removed, due to a chain reorganization. + /// false if its a valid log. + pub removed: Option, +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 7af71d02..e903cc49 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -5,7 +5,7 @@ pub use ethereum_types::H256 as TxHash; pub use ethereum_types::{Address, Bloom, H256, U256, U64}; mod transaction; -pub use transaction::{Transaction, TransactionRequest}; +pub use transaction::{Transaction, TransactionReceipt, TransactionRequest}; mod keys; pub use keys::{PrivateKey, PublicKey, TxError}; @@ -18,3 +18,6 @@ pub use bytes::Bytes; mod block; pub use block::{Block, BlockId, BlockNumber}; + +mod log; +pub use log::Log; diff --git a/src/types/transaction.rs b/src/types/transaction.rs index 27e78aab..ca920981 100644 --- a/src/types/transaction.rs +++ b/src/types/transaction.rs @@ -1,6 +1,6 @@ //! Transaction types use crate::{ - types::{Address, Bytes, Signature, H256, U256, U64}, + types::{Address, Bloom, Bytes, Log, Signature, H256, U256, U64}, utils::keccak256, }; use rlp::RlpStream; @@ -231,6 +231,43 @@ impl Transaction { } } +/// "Receipt" of an executed transaction: details of its execution. +#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +pub struct TransactionReceipt { + /// Transaction hash. + #[serde(rename = "transactionHash")] + pub transaction_hash: H256, + /// Index within the block. + #[serde(rename = "transactionIndex")] + pub transaction_index: U64, + /// Hash of the block this transaction was included within. + #[serde(rename = "blockHash")] + pub block_hash: Option, + /// Number of the block this transaction was included within. + #[serde(rename = "blockNumber")] + pub block_number: Option, + /// Cumulative gas used within the block after this was executed. + #[serde(rename = "cumulativeGasUsed")] + pub cumulative_gas_used: U256, + /// Gas used by this transaction alone. + /// + /// Gas used is `None` if the the client is running in light client mode. + #[serde(rename = "gasUsed")] + pub gas_used: Option, + /// Contract address created, or `None` if not a deployment. + #[serde(rename = "contractAddress")] + pub contract_address: Option

, + /// Logs generated within this transaction. + pub logs: Vec, + /// Status: either 1 (success) or 0 (failure). + pub status: Option, + /// State root. + pub root: Option, + /// Logs bloom + #[serde(rename = "logsBloom")] + pub logs_bloom: Bloom, +} + #[cfg(test)] mod tests { use super::*;