Skip to content

Commit

Permalink
Address some feedback. Add test for new Addr CBOR roundtripping
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Apr 25, 2022
1 parent cd5c7d0 commit 07edc09
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 182 deletions.
14 changes: 10 additions & 4 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ pattern TxOut addr vl datum refScript <-

{-# COMPLETE TxOut #-}

-- | Helper function for constructing a TxOut. Both compacted and uncompacted
-- address should be the exact same addrress in different forms.
mkTxOut ::
forall era.
(Era era, HasCallStack) =>
Expand All @@ -323,13 +325,13 @@ mkTxOut ::
Datum era ->
StrictMaybe (Core.Script era) ->
TxOut era
mkTxOut addr _ vl NoDatum SNothing
mkTxOut addr _cAddr vl NoDatum SNothing
| Just adaCompact <- getAdaOnly (Proxy @era) vl,
Addr network paymentCred stakeRef <- addr,
StakeRefBase stakeCred <- stakeRef,
Just (Refl, addr28Extra) <- encodeAddress28 network paymentCred =
TxOut_AddrHash28_AdaOnly stakeCred addr28Extra adaCompact
mkTxOut addr _ vl (DatumHash dh) SNothing
mkTxOut addr _cAddr vl (DatumHash dh) SNothing
| Just adaCompact <- getAdaOnly (Proxy @era) vl,
Addr network paymentCred stakeRef <- addr,
StakeRefBase stakeCred <- stakeRef,
Expand Down Expand Up @@ -731,8 +733,12 @@ instance
where
toCBOR (TxOut addr v d s) = encodeTxOut (compactAddr addr) v d s

-- FIXME: Starting with Babbage we need to reserialize all Addresses. After
-- Vasil Hardfork we can switch to a more efficient version below:
-- FIXME: ^ Starting with Babbage we need to reserialize all Addresses. It is
-- safe to reserialize an address, because we do not rely on this instance for
-- computing a hash of a transaction and it is only used in storing TxOuts in
-- the ledger state.
--
-- After Vasil Hardfork we can switch it back to a more efficient version below:
--
-- toCBOR (TxOutCompact addr cv) = encodeTxOut @era addr cv NoDatum SNothing
-- toCBOR (TxOutCompactDH addr cv dh) = encodeTxOut @era addr cv (DatumHash dh) SNothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Cardano.Binary
toCBOR,
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.CompactAddress (fromCborRewardAcnt)
import Cardano.Ledger.CompactAddress (fromCborAddr, fromCborRewardAcnt)
import Cardano.Ledger.Compactible (Compactible (..))
import qualified Cardano.Ledger.Shelley.API as Ledger
import Cardano.Ledger.Shelley.Genesis (ShelleyGenesis)
Expand Down Expand Up @@ -137,7 +137,9 @@ roundtrip2' enc dec a = case deserialiseFromBytes dec bs of
-------------------------------------------------------------------------------}

prop_roundtrip_Addr :: Ledger.Addr Mock.C_Crypto -> Property
prop_roundtrip_Addr = roundtrip toCBOR fromCBOR
prop_roundtrip_Addr =
roundtrip toCBOR fromCBOR
.&&. roundtrip toCBOR fromCborAddr acnt

prop_roundtrip_RewardAcnt :: Ledger.RewardAcnt Mock.C_Crypto -> Property
prop_roundtrip_RewardAcnt acnt =
Expand Down
Loading

0 comments on commit 07edc09

Please sign in to comment.