Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More types: block, transactions, receipt, and log. #20

Merged
merged 6 commits into from
Jan 24, 2017
Merged

Conversation

rphmeier
Copy link
Collaborator

No description provided.

@@ -366,14 +422,16 @@ mod tests {
Eth:block:block_by_hash, BlockId::Hash(0x123.into()), true
=>
"eth_getBlockByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#, r#"true"#];
Value::Null => ()
::serde_json::from_str(EXAMPLE_BLOCK).unwrap()
=> ::serde_json::from_str::<Block>(EXAMPLE_BLOCK).unwrap()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note -- testing deserialization isn't really valuable for these tests. we're more interested in whether the right call gets dispatched.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, for simple structures it indeed might not make much sense, but still choosing right params to deserialize from is important and it's part of the logic, and some methods will do different things depending on the output.

Maybe instead of deserializing structs from strings we should just put Default::default()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then we'd also have to serialize the default struct to value -- not a huge win, but you might be right

@rphmeier rphmeier mentioned this pull request Jan 22, 2017
Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Minor typos noted.

pub gas_price: U256,
/// Gas amount
pub gas: U256,
/// Inpur data
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

/// Block number. Null when pending.
#[serde(rename="blockNumber")]
pub block_number: Option<U256>,
/// Transaction Index. Null when pending.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None when pending?

pub total_difficulty: U256,
/// Seal fields
#[serde(rename="sealFields")]
pub seal_fields: Vec<Bytes>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be Option<Vec<Bytes>> or will it default to empty Vec if the field is not there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as things are right now it will fail to deserialize on the field missing. I suppose it could be optional, but then we'd also have to support non-generic nonce and mixHash fields.

@@ -424,7 +482,8 @@ mod tests {
Eth:transaction:tx_by_hash, TransactionId::Hash(0x123.into())
=>
"eth_getTransactionByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#];
Value::Array(vec![]) => Some(())
::serde_json::from_str(EXAMPLE_TX).unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use serde_json to avoid those ::?

@@ -366,14 +422,16 @@ mod tests {
Eth:block:block_by_hash, BlockId::Hash(0x123.into()), true
=>
"eth_getBlockByHash", vec![r#""0x0000000000000000000000000000000000000000000000000000000000000123""#, r#"true"#];
Value::Null => ()
::serde_json::from_str(EXAMPLE_BLOCK).unwrap()
=> ::serde_json::from_str::<Block>(EXAMPLE_BLOCK).unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, for simple structures it indeed might not make much sense, but still choosing right params to deserialize from is important and it's part of the logic, and some methods will do different things depending on the output.

Maybe instead of deserializing structs from strings we should just put Default::default()?

@rphmeier
Copy link
Collaborator Author

For some reason I can't respond directly to your comment which said this, but the issue with passing Default::default() is that we must also provide a corresponding Value which is equivalent. So either we deserialize twice or serialize once -- one isn't much better than the other. We could also just take None in each case...

where D: Deserializer
{
let res = Vec::<Transaction>::deserialize(deserializer).map(BlockTransactions::Full)
.or_else(|_| Vec::<H256>::deserialize(deserializer).map(BlockTransactions::Hashes));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this line seems not to work as expected -- it only works if the type of transaction you're trying to get comes first. My guess is that the calls of the first attempt's visit_* leave the deserializer in an invalid state to deserialize the other type. We might just want to make Block generic over a transaction type and change the eth API to have two calls:

block(&self, BlockId) -> Block<H256> and

block_with_txs(&self, BlockId) -> Block<Transaction>

(uncle functions will return Block<H256>)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like splitting the API better.

@rphmeier rphmeier merged commit 13ca950 into master Jan 24, 2017
@rphmeier rphmeier deleted the more-types branch January 24, 2017 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants