-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fix user facing encoding of stake pool ids (from base16 to bech32). #2055
Fix user facing encoding of stake pool ids (from base16 to bech32). #2055
Conversation
ca0f2bb
to
f563f17
Compare
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.
Hi @hasufell.
Looks pretty good so far!
General comments:
-
I'm not sure whether using
MonadThrow
indecodePoolIdBech32
gives us much advantage overEither TextDecodingError
. It's harder for callers to see how the function will fail, as the type signature no longer includesTextDecodingError
. But perhaps you have a good reason for usingMonadThrow
here? -
I couldn't find a roundtrip encoding/decoding test specifically for
{decode,encode}PoolIdBech32
. Did you intend to write one? I think it would be worth adding such a test. For inspiration, have a look at the varioustextRoundtrip
tests. -
There are a few small issues with coding style. It's worth taking a look at our coding standards. These should hopefully be easy to fix. 👍
Sure! I was referring to the comments on the review. 👍 AFAIK, all the issues are mentioned in these comments. |
Wrt the build failure... I cannot reproduce it. |
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.
Hi @hasufell
Thanks for your changes. I see that you've converted decodePoolIdBech32
from using MonadThrow
to returning an ordinary Either
value, which I think makes the failure modes a bit clearer.
There are still a couple of issues I think we should fix:
-
Roundtrip encoding tests: as mentioned in the previous review, I couldn't find a roundtrip property test for
decodePoolIdBech32
andencodePoolIdBech32
. Would it be okay to add one?I'm guessing that the following property should hold:
decodePoolIdBech32 (encodePoolIdBech32 p) == Right p
Note that we do have similar tests from which you can draw inspiration: have a search for
textRoundtrip
, and lots of stuff should pop up. Feel free to ask me if you need any assistance. -
Formatting: There are still a couple of formatting issues to sort out (see review comments).
. bimap ShowFmt ApiT | ||
. decodePoolIdBech32 |
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.
Request: use 4-space indents.
See #2055 (comment)
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.
Please provide a formatter or an editor config that works. Otherwise these issues will pop up over and over again. I'm not counting spaces while I code.
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.
@hasufell wrote:
Please provide a formatter or an editor config that works. Otherwise these issues will pop up over and over again.
Regarding automated formatting: Unfortunately our team doesn't use an automated formatter besides stylish-haskell (for imports), but if you feel strongly that we should do, then you could start a discussion in our team channel, and try to convince the team of the benefits. 👍
Regarding an editor config: We do provide one here.
@hasufell wrote:
I'm not counting spaces while I code.
Our team coding standard is actually rather simple in this respect: we just indent each level by 4 spaces. (We make an exception for where
clauses, which are indented by 2 spaces.)
Are you facing an issue that makes it hard to indent in this way? If so, we can discuss ways to fix the issue.
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.
Regarding automated formatting: Unfortunately our team doesn't use an automated formatter besides stylish-haskell (for imports), but if you feel strongly that we should do, then you could start a discussion in our team channel, and try to convince the team of the benefits. +1
I don't have a strong opinion, except that I avoid formatting discussions as much as possible. I'm just saying these things will pop up again if the tooling (formatter or config) doesn't work consistently. I don't think about indentation while coding and I am not counting spaces while doing so.
I also believe developers time is too valuable to count spaces in pull requests (your time and my time). I'll do whatever formatting you want, as long as I'm provided with the tools to do so.
Regarding an editor config: We do provide one here.
I'm using that one and it seems it doesn't work consistently. Help appreciated. Here is my editor config https://gogs.hasufell.de/hasufell/vim-config/src/branch/workman
Are you facing an issue that makes it hard to indent in this way? If so, we can discuss ways to fix the issue.
See above.
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.
@hasufell wrote:
I'll do whatever formatting you want, as long as I'm provided with the tools to do so.
I'm sorry, I don't have an automated tool to provide you with, otherwise I would. As I mentioned before, if there is a tool that you think we could use, then feel free to discuss it in the team channel. I would happy to help with the discussion!
I don't think about indentation while coding and I am not counting spaces while doing so.
I also believe developers time is too valuable to count spaces in pull requests (your time and my time).
The reason for having a team standard is so that we don't have to waste time during PR reviews debating code style. If we have to discuss this in every PR, it would certainly waste time.
As far as I know, most people in our team just configure their tab key to emit 4 spaces. Then no counting is required. Would that work for you?
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.
@hasufell Just in case there's any doubt, we generally indent code with:
- 4 spaces per level of nesting.
- 2 spaces for a
where
clause.
Example:
launchMissiles trace a b c = do
missiles <- prepareMissiles
forM_ missiles $ \missile -> do
log trace Warning $ MsgMissileLaunch missile
launchMissile missile
pure missiles
where
launchMissile m =
inializeLauncherModule m
lightFuse m
prepareMissiles = do
missiles <- enumerateMissiles
verifyMissilesIntact missiles
pure missiles
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.
Which constructs?
As was in my link to the haskell-vim readme.
So my configuration for haskell-vim now is
let g:haskell_indent_if = 0
let g:haskell_indent_case = 4
let g:haskell_indent_let = 4
let g:haskell_indent_where = 6
let g:haskell_indent_before_where = 2
let g:haskell_indent_after_bare_where = 2
let g:haskell_indent_do = 4
let g:haskell_indent_in = 0
let g:haskell_indent_guard = 2
This doesn't play nicely with do
I believe. See below.
- do
foo :: IO Int
foo = do
x <- pure 1
do
pure (2 + x)
- if
foo :: IO Int
foo =
if True
then pure 3
else pure 2
- case
foo :: IO Int
foo =
case True of
True -> 3
False -> 2
- let
foo :: IO Int
foo =
let x = 3 in
x + 1
foo :: IO Int
foo =
let x = 1
in x + 1
- guard
foo :: IO Int
foo
| otherwise = 2
- where
foo :: IO Int
foo = x + 1
where
x = 3
So please either confirm this configuration or suggest an alternative.
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 don't see any problem with do
above ? Also, guards should be 4-space indented like the rest
let g:haskell_indent_guard = 4
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.
The problem with do is if you write something on the same line as do:
foo :: IO Int
foo = do
x <- pure 1
do y <- pure 2
pure (x + y)
This will cause a compile error.
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.
That is arguably a horrible choice of formatting and It's perhaps much better that the compiler fails to parse this :)
That has been done: b52ee3f |
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.
LGTM 👍
6ce8e9e
to
433ea9b
Compare
bors r+ |
|
2055: Fix user facing encoding wrt #2023 r=hasufell a=hasufell So I kept the legacy parsing for both json and the query params to not break API for existing users. Co-authored-by: Julian Ospald <[email protected]> Co-authored-by: Julian Ospald <[email protected]>
Build failed |
433ea9b
to
e96b26b
Compare
bors r+ |
2055: Fix user facing encoding wrt #2023 r=hasufell a=hasufell So I kept the legacy parsing for both json and the query params to not break API for existing users. Co-authored-by: Julian Ospald <[email protected]>
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.
actually, on second thoughts. I didn't see any tests that shows that:
a) hex-encoded pool ids are still accepted in path parameters
b) bech32 encoded pool ids are accepted in path parameters
These are the tests that fail if hex encoding for path is disabled: Failing tests
I believe we just have to adjust this: instance Wellformed (PathParam ApiPoolId) where
wellformed = PathParam $ T.replicate 64 "0" And add a bech32 param there. |
I don't think you can provide multiple well-formed data in here. But okay, pretty convincing for the hex backward-compability. |
bors r+ |
Build succeeded |
2085: [ADP-416] Allow multiple well-formed values in "/Cardano.Wallet.Api/"… r=KtorZ a=hasufell Related: #2055 (comment) [Test log](https://gist.github.com/hasufell/c07ead1a20824bea6c20b2dc9b315bd4) shows that it tries both variants of pool id encodings when combined with #2055 Co-authored-by: Julian Ospald <[email protected]> Co-authored-by: KtorZ <[email protected]>
So I kept the legacy parsing for both json and the query params to not break API for existing users.