Closed Zerim closed 6 years ago
Using ethcore::blockchain::BlockChain
let chain = Arc::new(BlockChain::new(blockchain_settings, &gb, client_db.clone()));
let block = chain.block(&block_hash);
let block_body_data = chain.block_body(&block_hash).unwrap();
let block_header_data = chain.block_header_data(&block_hash).unwrap();
println!("Body");
println!("{:?}", block_body_data.decode());
println!("Header");
println!("{:?}", block_header_data.decode());
let transactions = block_body_data.transactions();
println!("Transactions"); for tx in &transactions { let unsigned = tx.as_unsigned(); let tx_addr = chain.transaction_address(&tx.hash()).unwrap(); let receipt = chain.transaction_receipt(&tx_addr).unwrap(); println!("Receipt"); println!("{:?}", receipt); println!("Logs"); for log in &receipt.logs { println!("{:?}", log); } }
- [ ] How can we interact with contracts based on a block and a contract ABI (without
needing JSON-RPC)?
1. Encode data for contract call by passing the contract ABI into parity's [ethabi](https://github.com/paritytech/ethabi) library
[`pub fn encode_input(&self, tokens: &[Token]) -> Result<Bytes>`](https://docs.rs/ethabi/5.1.1/ethabi/struct.Function.html#method.encode_input)
2. Execute call using the encoded data and parity's ethcore Client
[`fn call_contract(&self, block_id: BlockId, address: Address, data: Bytes) -> Result<Bytes, String>`](https://github.com/adklempner/parity/blob/pub-bc/ethcore/src/client/client.rs#L1378)
3. Decode data using ethabi
[`pub fn decode_output(&self, data: &[u8]) -> Result<Vec<Token>>`](https://docs.rs/ethabi/5.1.1/ethabi/struct.Function.html#method.decode_output)
It seems to me like BlockChainClient
(or rather its implementation Client is the canonical entry point for all kinds of access.
So instead of
let chain = Arc::new(BlockChain::new(blockchain_settings, &gb, client_db.clone()));
let block = chain.block(&block_hash);
I'd always do
let client = Client::new(...);
let block = client.block(block_hash);
To get the transaction data given a transaction hash, instead of crawling the entire block, we can do
let tx = client.transaction(tx_hash);
which gives us a LocalizedTransaction (if the hash exists)tx.signed.unsigned
to get to the Transaction and then do whatever we need to do with that.
[] Given a block number or hash, how do we get the block data? [] Given a transaction hash, how do we get the transaction data? [] How can we interact with contracts based on a block and a contract ABI (without needing JSON-RPC)? [] What should be a common trait be for an Ethereum adapter that works with both Parity as a library and IPC/JSON-RPC for remote access?