-
Notifications
You must be signed in to change notification settings - Fork 245
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
chore(other): use type aliases where possible to improve clarity #859
Conversation
…d to be U64, not u64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very much against using aliases for nonce and timestamp, this is just confusing.
I've removed the number aliases, kept the hash aliases as discussed Any existing references using the number-type aliases I've kept around, just avoided introducing any new ones. |
…oy-rs#859) * improve type aliasing on untyped types * prefer type alias * clean up * fix typo * fix typo * add TxNonce and BlockTimestamp * fix clippy, keep impl From as is * do not use TxNonce for EIP1186AccountProofResponse as type is expected to be U64, not u64 * avoid aliasing for genesis as it is often read from file and rarely interacted with dynamically * fix clippy * revert consensus, engine related type changes * prefer import types as long as they do not clash * fix docs link * do not use TxNonce and BlockTimestamp aliases * rule: alias for hash types, not number types * remove newly added BlockNumber references, leave the old ones as is * remove TxIndex alias use
Motivation
Reduces magic values, reduces chance of error and makes it easier for end-users to see what value they are getting e.g.
TxHash
instead ofFixedBytes<32>
whenwatch()
-ing a transaction. Main goal is to limit showing internal types and help with consistency / standardize fields / encourage native types (u64
vsU64
) and sizes.Related PR in
core
: alloy-rs/core#654 + alloy-rs/core#655Solution
Proposed changes:
TxHash
BlockHash
u64
- UseChainId
Not used:
Transaction index:u64
- UseTxIndex
Block number:u64
- UseBlockNumber
Transaction nonce:u64
- UseTxNonce
Block timestamp:u64
- UseBlockTimestamp
Should have no impact and no logic changes should be present.
From testing it appears that
rust-analyzer
does not yet correctly deal with type aliases (long standing issue), as in it forwards the rust-lang/rust-analyzer#1666Fortunately it does appear to be supported in RustRover:
PR also includes a number of QOL fixes
PR Checklist