Skip to content

Commit

Permalink
upgrade Byron & Jormungandr compatibility code with empty withdrawals
Browse files Browse the repository at this point in the history
Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists
  • Loading branch information
KtorZ committed Jul 10, 2020
1 parent 74abe1c commit 0211c5c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
18 changes: 17 additions & 1 deletion lib/byron/src/Cardano/Wallet/Byron/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
Expand Down Expand Up @@ -86,7 +87,11 @@ import Cardano.Crypto
import Cardano.Crypto.ProtocolMagic
( ProtocolMagicId, unProtocolMagicId )
import Cardano.Wallet.Api.Types
( DecodeAddress (..), EncodeAddress (..) )
( DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, EncodeStakeAddress (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( NetworkDiscriminant (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand Down Expand Up @@ -355,6 +360,9 @@ fromTxAux txAux = case taTx txAux of

, outputs =
fromTxOut <$> NE.toList outputs

, withdrawals =
mempty
}

fromTxIn :: TxIn -> W.TxIn
Expand Down Expand Up @@ -496,6 +504,14 @@ fromProtocolMagicId = W.ProtocolMagic . fromIntegral . unProtocolMagicId
Address Encoding / Decoding
-------------------------------------------------------------------------------}

instance EncodeStakeAddress n where
encodeStakeAddress = error
"encodeStakeAddress: there's no such thing as stake address in Byron"

instance DecodeStakeAddress n where
decodeStakeAddress = error
"decodeStakeAddress: there's no such thing as stake address in Byron"

instance EncodeAddress 'Mainnet where
encodeAddress =
gEncodeAddress
Expand Down
5 changes: 3 additions & 2 deletions lib/byron/src/Cardano/Wallet/Byron/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
witnesses <- forM (CS.inputs cs) $ \(_, TxOut addr _) ->
mkWitness protocolMagic sigData <$> lookupPrivateKey addr
pure
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs)
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs) mempty
, SealedTx $ CBOR.toStrictByteString $ CBOR.encodeSignedTx tx witnesses
)
where
Expand Down Expand Up @@ -190,6 +190,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
-- FIXME Do not require Tx to have resolvedInputs
, resolvedInputs = (,Coin 0) <$> inps
, outputs = outs
, withdrawals = mempty
}
, SealedTx bytes
)
Expand Down Expand Up @@ -243,7 +244,7 @@ genesisBlockFromTxOuts gp outs = Block
}
where
mkTx out@(TxOut (Address bytes) _) =
Tx (Hash $ blake2b256 bytes) [] [out]
Tx (Hash $ blake2b256 bytes) [] [out] mempty

dummyAddress
:: forall (n :: NetworkDiscriminant). (MaxSizeOf Address n ByronKey)
Expand Down
4 changes: 2 additions & 2 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ getGenericTransaction tid = label "getGenericTransaction" $ do
(ins, outs) <- getTokenTransfer
let witnessCount = length ins
_wits <- replicateM witnessCount getWitness
return $ Tx tid ins outs
return $ Tx tid ins outs mempty
where
getWitness :: Get ByteString
getWitness = do
Expand Down Expand Up @@ -509,7 +509,7 @@ getLegacyTransaction tid = do
-- Legacy transactions only show up in the genesis block and are treated as
-- coinbase transactions with no inputs.
let inps = mempty
pure $ Tx tid inps outs
pure $ Tx tid inps outs mempty

data MkFragment
= MkFragmentSimpleTransaction
Expand Down
15 changes: 14 additions & 1 deletion lib/jormungandr/src/Cardano/Wallet/Jormungandr/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ module Cardano.Wallet.Jormungandr.Compatibility
import Prelude

import Cardano.Wallet.Api.Types
( DecodeAddress (..), EncodeAddress (..) )
( DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, EncodeStakeAddress (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( NetworkDiscriminant (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand Down Expand Up @@ -110,6 +114,15 @@ baseUrlToText = T.pack . showBaseUrl
Address Encoding / Decoding
-------------------------------------------------------------------------------}

instance EncodeStakeAddress n where
encodeStakeAddress = error
"encodeStakeAddress: there's no such thing as stake address in Jörmungandr"

instance DecodeStakeAddress n where
decodeStakeAddress = error
"decodeStakeAddress: there's no such thing as stake address in Jörmungandr"


-- | Encode an 'Address' to a human-readable format. This produces two kinds of
-- encodings:
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ newTransactionLayer block0H = TransactionLayer
{ txId = fragmentId fragment
, resolvedInputs = inps
, outputs = outs
, withdrawals = mempty
}
, finalizeFragment fragment
)
Expand Down

0 comments on commit 0211c5c

Please sign in to comment.