-
Notifications
You must be signed in to change notification settings - Fork 5
feat: types.HeaderHooks
JSON round-trip support
#94
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
Conversation
if r := registeredExtras; r.Registered() { | ||
return r.Get().hooks.hooksFromHeader(h) | ||
} |
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.
nit no need to assign to r
:
if r := registeredExtras; r.Registered() { | |
return r.Get().hooks.hooksFromHeader(h) | |
} | |
if registeredExtras.Registered() { | |
return registeredExtras.Get().hooks.hooksFromHeader(h) | |
} |
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 did it to avoid unnecessary verbosity and code stuttering. One of the core guiding principles that I follow (and recommend) is for code to get out of the way of the human seeing the meaning being communicated to the computer. Here there's a trade-off between distraction (a 5-syllable variable being unnecessarily repeated, with 3 of them repeated again in the method name) and a meat-RAM allocation (remembering what r
is). I chose the latter because it only needs to be remembered for one line.
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 was actually saying this for readability more than for memory usage 😄
Assigning to r
made me think initially we were copying the variable because the method calls were perhaps modifying it. I feel it could hide something eventually if you see what I mean?
hdr := new(Header) | ||
stub := &stubHeaderHooks{ | ||
setHeaderToOnUnmarshalOrDecode: Header{ | ||
Extra: []byte("can you solve this puzzle? 0xbda01b6cf56c303bd3f581599c0d5c0b"), |
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.
🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔 🤔
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.
Well?
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.
Any hint on an encoding?
Is this your 256 bits private key? 😄
Why this should be merged
JSON equivalent of #89.
How this works
The check for registered extras, previously used in
{En,De}codeRLP()
methods is abstracted into aHeader.hooks() HeaderHooks
method that either returns (a) an instance of the registered type or (b) aNOOPHeaderHooks
if no registration was performed. This is then used for all hooks, new (JSON) and old (RLP).How this was tested
Extension of existing unit tests.