-
Notifications
You must be signed in to change notification settings - Fork 16
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
Transaction.hs: reduce boilerplate and move towards ShelleyBasedEra #783
Transaction.hs: reduce boilerplate and move towards ShelleyBasedEra #783
Conversation
5a540fb
to
d53b701
Compare
-- TODO: Because we have separated Byron related transaction | ||
-- construction into separate commands, we can parameterize this | ||
-- on ShelleyBasedEra era and remove Either TxCertificatesValidationError | ||
-- construction into separate commands, we can remove | ||
-- Either TxNotSupportedInEraValidationError |
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.
Does this comment mean I should just remove the call to conjureWitness
?
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, sbe == supported
in the function body, so this conjureWitness
will never fail, so i'd say yes. The same for other places in this PR, where we changed CardanoEra
to ShelleyBasedEra
.
528f47e
to
2096e19
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.
Good job!
-- | First argument is the kind of data that is not supported. | ||
-- Second argument in the era that doesn't support the data. | ||
TxNotSupportedInAnyCardanoEraValidationError T.Text AnyCardanoEra | ||
-- | First argument is the kind of data that is not supported. |
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 not sure if this haddock is 100% correct - I think it should be after |
, as it references the second constructor.
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.
@carbolymer> nah it's all good:
-- TODO: Because we have separated Byron related transaction | ||
-- construction into separate commands, we can parameterize this | ||
-- on ShelleyBasedEra era and remove Either TxCertificatesValidationError | ||
-- construction into separate commands, we can remove | ||
-- Either TxNotSupportedInEraValidationError |
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, sbe == supported
in the function body, so this conjureWitness
will never fail, so i'd say yes. The same for other places in this PR, where we changed CardanoEra
to ShelleyBasedEra
.
validateTxCurrentTreasuryValue sbe mCurrentTreasuryValue = | ||
case mCurrentTreasuryValue of | ||
Nothing -> Right Nothing | ||
Just (TxCurrentTreasuryValue { unTxCurrentTreasuryValue }) -> |
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.
suggestion:
validateTxCurrentTreasuryValue sbe mCurrentTreasuryValue = | |
case mCurrentTreasuryValue of | |
Nothing -> Right Nothing | |
Just (TxCurrentTreasuryValue { unTxCurrentTreasuryValue }) -> | |
validateTxCurrentTreasuryValue sbe = | |
mapM $ \(TxCurrentTreasuryValue { unTxCurrentTreasuryValue }) -> |
or you can use forM
, ...or neither 😄
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.
=> ShelleyBasedEra era | ||
-> Maybe TxTreasuryDonation | ||
-> Either (TxNotSupportedInEraValidationError era) (Maybe (Featured ConwayEraOnwards era L.Coin)) | ||
validateTxTreasuryDonation sbe mTreasuryDonation = |
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.
same suggestion as 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.
2096e19
to
b2b9781
Compare
d53b701
to
f42b8c6
Compare
instance Error TxProtocolParametersValidationError where | ||
prettyError (ProtocolParametersNotSupported e) = | ||
"Transaction protocol parameters are not supported in " <> pretty e | ||
|
||
validateProtocolParameters | ||
:: CardanoEra era |
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.
This will only fail if we call validateProtocolParameters
with ByronEra
. However the code won't compile if we call this with ByronEra
:
ghci> validateProtocolParameters ByronEra Nothing
<interactive>:22:1: error: [GHC-39999]
• No instance for ‘IsShelleyBasedEra ByronEra’
arising from a use of ‘print’
• In a stmt of an interactive GHCi command: print it
What we should do is change the parameter from CardanoEra era
to ShelleyBasedEra era
but actually in this case no validation is done!
So we can remove this function and directly use setTxProtocolParams
.
Have a look at the other functions that demand CardanoEra era
but should be parameterized on ShelleyBasedEra era
. If no validation is done, we can just drop them. I'd do that in a separate PR.
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.
OK will do in a follow-up PR right away 👍
@Jimbo4350> so can you approve in the meantime?
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 can't because it would be adding churn. If you do what I explained above it should also result in the removal of the unnecessary error constructors.
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.
@Jimbo4350> done 👍 Please rereview.
f42b8c6
to
bfef03a
Compare
bfef03a
to
4f9fda2
Compare
cf4e491
to
639d6a0
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.
LGTM! However you can remove the TxNotSupportedInAnyCardanoEraValidationError
constructor.
data TxNotSupportedInEraValidationError era = | ||
-- | First argument is the kind of data that is not supported. | ||
-- Second argument is the era that doesn't support the data. | ||
TxNotSupportedInAnyCardanoEraValidationError T.Text AnyCardanoEra |
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.
This constructor can actually be removed.
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.
Good catch, done 👍
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.
It should return AnyShelleyBasedEra
because: https://github.com/IntersectMBO/cardano-cli/pull/783/files#diff-a38343c1825e6e334224d0a8a1ba78a458652970f00c54f5fb0d040be28f822eR606
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.
@Jimbo4350> not really, because this constructor is passed as a function to conjureWitness and there remains one single caller to conjureWitness
that uses a CardanoEra era
value.
Once this last caller is eliminated, we will be able to tighten TxNotSupportedInAnyCardanoEraValidationError
's type.
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.
We could use shelleyBasedToCardanoEra
.
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.
@Jimbo4350> but this is awkward because conjureWitness
expects a function to build the error, to which it applies the CardanoEra
. If I want to keep conjureWitness
existing type (which I think is nice), I need to do something like this:
which is weird, because the value passed by conjureWitness
gets ignored when building the error.
…ustom Text message instead.
639d6a0
to
b843840
Compare
Changelog
How to trust this PR
Checklist