-
Notifications
You must be signed in to change notification settings - Fork 14
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
Remove UnwitnessedCliFormattedTxBody constructor #707
Remove UnwitnessedCliFormattedTxBody constructor #707
Conversation
@@ -1286,7 +1271,7 @@ runTransactionWitnessCmd | |||
firstExceptT TxCmdWriteFileError . newExceptT | |||
$ writeTxWitnessFileTextEnvelopeCddl sbe outFile witness | |||
|
|||
UnwitnessedCliFormattedTxBody anyTxbody -> do | |||
ReadTxBody anyTxbody -> do |
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.
What is the purpose of ReadTxBody
?
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.
So now its only possible to create CDDL formatted transactions. Therefore data IncompleteTx
should be a newtype
instead. We no longer need two 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> changed 👍
Can you check this is what you had in mind?
a689d50
to
51cf335
Compare
51cf335
to
eb15e23
Compare
cardano-cli/src/Cardano/CLI/Read.hs
Outdated
return $ Right $ IncompleteCddlTxBody $ inAnyShelleyBasedEra sbe $ getTxBody tx | ||
Right txBody -> return $ Right $ IncompleteCddlTxBody txBody |
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> this is what you had in mind right? Treating two cases in the same manner?
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.
You're almost there 👍
So we have:
acceptTxCDDLSerialisation
:: FileOrPipe
-> FileError TextEnvelopeError
-> IO (Either CddlError CddlTx)
acceptTxCDDLSerialisation file err =
case err of
e@(FileError _ (TextEnvelopeDecodeError _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@(FileError _ (TextEnvelopeAesonDecodeError _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@(FileError _ (TextEnvelopeTypeError _ _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@FileErrorTempFile{} -> return . Left $ CddlIOError e
e@FileDoesNotExistError{} -> return . Left $ CddlIOError e
e@FileIOError{} -> return . Left $ CddlIOError e
We cased on the TextEnvelope
related errors because previously by default we used the deprecated "intermediate cli" format. Because it's no longer possible to create that format, and we will no longer support it, we can remove acceptTxCDDLSerialisation
entirely and simply rely on the TextEnvelope
encoding because we now default to the ledger's CDDL format.
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.
See below:
instance IsShelleyBasedEra era => SerialiseAsCBOR (Tx era) where
serialiseToCBOR (ShelleyTx sbe tx) =
shelleyBasedEraConstraints sbe $ serialiseShelleyBasedTx tx
deserialiseFromCBOR _ bs =
shelleyBasedEraConstraints (shelleyBasedEra :: ShelleyBasedEra era)
$ deserialiseShelleyBasedTx (ShelleyTx shelleyBasedEra) bs
-- | The serialisation format for the different Shelley-based eras are not the
-- same, but they can be handled generally with one overloaded implementation.
--
serialiseShelleyBasedTx :: forall ledgerera .
L.EraTx ledgerera
=> L.Tx ledgerera
-> ByteString
serialiseShelleyBasedTx = Plain.serialize'
We call ledger's serialize'
indirectly in our SerialiseAsCBOR (Tx era)
instance and TextEnvelope
is serialized as follows:
class SerialiseAsCBOR a => HasTextEnvelope a where
textEnvelopeType :: AsType a -> TextEnvelopeType
textEnvelopeDefaultDescr :: a -> TextEnvelopeDescr
textEnvelopeDefaultDescr _ = ""
serialiseToTextEnvelope :: forall a. HasTextEnvelope a
=> Maybe TextEnvelopeDescr -> a -> TextEnvelope
serialiseToTextEnvelope mbDescr a =
TextEnvelope {
teType = textEnvelopeType ttoken
, teDescription = fromMaybe (textEnvelopeDefaultDescr a) mbDescr
, teRawCBOR = serialiseToCBOR a
}
where
ttoken :: AsType a
ttoken = proxyToAsType Proxy
Note the SerialiseAsCBOR
constraint and the call to serialiseToCBOR
in serialiseToTextEnvelope
. Hope this makes things clearer!
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.
Looking good, see my comment below which hopefully clarifies things.
cardano-cli/src/Cardano/CLI/Read.hs
Outdated
return $ Right $ IncompleteCddlTxBody $ inAnyShelleyBasedEra sbe $ getTxBody tx | ||
Right txBody -> return $ Right $ IncompleteCddlTxBody txBody |
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.
You're almost there 👍
So we have:
acceptTxCDDLSerialisation
:: FileOrPipe
-> FileError TextEnvelopeError
-> IO (Either CddlError CddlTx)
acceptTxCDDLSerialisation file err =
case err of
e@(FileError _ (TextEnvelopeDecodeError _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@(FileError _ (TextEnvelopeAesonDecodeError _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@(FileError _ (TextEnvelopeTypeError _ _)) ->
first (CddlErrorTextEnv e) <$> readCddlTx file
e@FileErrorTempFile{} -> return . Left $ CddlIOError e
e@FileDoesNotExistError{} -> return . Left $ CddlIOError e
e@FileIOError{} -> return . Left $ CddlIOError e
We cased on the TextEnvelope
related errors because previously by default we used the deprecated "intermediate cli" format. Because it's no longer possible to create that format, and we will no longer support it, we can remove acceptTxCDDLSerialisation
entirely and simply rely on the TextEnvelope
encoding because we now default to the ledger's CDDL format.
cardano-cli/src/Cardano/CLI/Read.hs
Outdated
return $ Right $ IncompleteCddlTxBody $ inAnyShelleyBasedEra sbe $ getTxBody tx | ||
Right txBody -> return $ Right $ IncompleteCddlTxBody txBody |
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.
See below:
instance IsShelleyBasedEra era => SerialiseAsCBOR (Tx era) where
serialiseToCBOR (ShelleyTx sbe tx) =
shelleyBasedEraConstraints sbe $ serialiseShelleyBasedTx tx
deserialiseFromCBOR _ bs =
shelleyBasedEraConstraints (shelleyBasedEra :: ShelleyBasedEra era)
$ deserialiseShelleyBasedTx (ShelleyTx shelleyBasedEra) bs
-- | The serialisation format for the different Shelley-based eras are not the
-- same, but they can be handled generally with one overloaded implementation.
--
serialiseShelleyBasedTx :: forall ledgerera .
L.EraTx ledgerera
=> L.Tx ledgerera
-> ByteString
serialiseShelleyBasedTx = Plain.serialize'
We call ledger's serialize'
indirectly in our SerialiseAsCBOR (Tx era)
instance and TextEnvelope
is serialized as follows:
class SerialiseAsCBOR a => HasTextEnvelope a where
textEnvelopeType :: AsType a -> TextEnvelopeType
textEnvelopeDefaultDescr :: a -> TextEnvelopeDescr
textEnvelopeDefaultDescr _ = ""
serialiseToTextEnvelope :: forall a. HasTextEnvelope a
=> Maybe TextEnvelopeDescr -> a -> TextEnvelope
serialiseToTextEnvelope mbDescr a =
TextEnvelope {
teType = textEnvelopeType ttoken
, teDescription = fromMaybe (textEnvelopeDefaultDescr a) mbDescr
, teRawCBOR = serialiseToCBOR a
}
where
ttoken :: AsType a
ttoken = proxyToAsType Proxy
Note the SerialiseAsCBOR
constraint and the call to serialiseToCBOR
in serialiseToTextEnvelope
. Hope this makes things clearer!
eb15e23
to
af3075a
Compare
7190b09
to
4f4c790
Compare
This one conflicts with #758 and I want this one to go first. |
pure $ InAnyShelleyBasedEra era (getTxBody tx) | ||
-- Why are we differentiating between a transaction body and a transaction? | ||
InAnyShelleyBasedEra era txbody <- pure $ unIncompleteCddlTxBody unwitnessed | ||
-- Why are we differentiating between a transaction body and a. newExceptT transaction? |
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.
"newExceptT" creeped into the 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.
Good catch, corrected 👍 and enqueueing for merge
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.
Nice work 💪. We can get this merged but what we eventually want to do is remove all references to "CDDL". We default to the ledger's serialization so we don't need to be explicit about this. Previously we did because the "intermediate cli tx body" format was a thing.
4f4c790
to
1691ef3
Compare
Changelog
Context
Fixes #690
Checklist