diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs index e80e8758bc7..1c8f73364cb 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs @@ -26,10 +26,8 @@ module Cardano.Wallet.Shelley.Transaction -- * Internals , _minimumFee , _decodeSignedTx - , _mkStdByronTx , _estimateMaxNumberOfInputs , mkUnsignedShelleyTx - , mkUnsignedByronTx , mkShelleyWitness , mkByronWitness , realFee @@ -76,6 +74,7 @@ import Cardano.Wallet.Shelley.Compatibility ( Shelley , TPraosStandardCrypto , toCardanoLovelace + , toCardanoNetwork , toCardanoTxIn , toCardanoTxOut , toSealed @@ -118,7 +117,7 @@ import Ouroboros.Network.Block import qualified Cardano.Api as Cardano import qualified Cardano.Byron.Codec.Cbor as CBOR -import qualified Cardano.Crypto as Byron +import qualified Cardano.Crypto as Crypto import qualified Cardano.Crypto.Hash.Class as Hash import qualified Cardano.Crypto.Wallet as CC import qualified Cardano.Wallet.Primitive.Types as W @@ -131,6 +130,7 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as L8 import qualified Data.Set as Set import qualified Data.Text as T +import qualified Shelley.Spec.Ledger.Address.Bootstrap as SL import qualified Shelley.Spec.Ledger.BaseTypes as SL import qualified Shelley.Spec.Ledger.Keys as SL import qualified Shelley.Spec.Ledger.LedgerState as SL @@ -180,19 +180,26 @@ newTransactionLayer _proxy protocolMagic epochLength = TransactionLayer -> [(TxIn, TxOut)] -> [TxOut] -> Either ErrMkTx (Tx, SealedTx) - _mkStdTx keyFrom slot ownedIns outs = case (txWitnessTagFor @k) of - TxWitnessShelleyUTxO -> do + _mkStdTx keyFrom slot ownedIns outs = do let timeToLive = defaultTTL epochLength slot let fee = realFee ownedIns outs let unsigned = mkUnsignedShelleyTx timeToLive ownedIns outs [] fee - addrWits <- fmap Set.fromList $ forM ownedIns $ \(_, TxOut addr _) -> do - (k, pwd) <- lookupPrivateKey keyFrom addr - pure $ mkShelleyWitness unsigned (getRawKey k, pwd) let metadata = SL.SNothing - let wits = SL.WitnessSet addrWits mempty mempty + wits <- case (txWitnessTagFor @k) of + TxWitnessShelleyUTxO -> do + addrWits <- fmap Set.fromList $ forM ownedIns $ \(_, TxOut addr _) -> do + (k, pwd) <- lookupPrivateKey keyFrom addr + pure $ mkShelleyWitness unsigned (getRawKey k, pwd) + pure $ SL.WitnessSet addrWits mempty mempty + TxWitnessByronUTxO -> do + let toSigningKey (k,_) = Crypto.SigningKey $ getRawKey k + bootstrapWits <- fmap Set.fromList $ forM ownedIns $ \(_, TxOut addr _) -> do + pair <- lookupPrivateKey keyFrom addr + let signingKeys = toSigningKey pair + pure $ SL.makeBootstrapWitness _ signingKeys _ + pure $ SL.WitnessSet mempty mempty bootstrapWits + pure $ toSealed $ SL.Tx unsigned wits metadata - TxWitnessByronUTxO -> - _mkStdByronTx protocolMagic keyFrom ownedIns outs _mkDelegationJoinTx :: FeePolicy @@ -384,26 +391,6 @@ _decodeSignedTx bytes = do Left apiErr -> Left $ ErrDecodeSignedTxWrongPayload (Cardano.renderApiError apiErr) -_mkStdByronTx - :: WalletKey k - => ProtocolMagic - -> (Address -> Maybe (k 'AddressK XPrv, Passphrase "encryption")) - -> [(TxIn, TxOut)] - -> [TxOut] - -> Either ErrMkTx (Tx, SealedTx) -_mkStdByronTx pm keyFrom ownedIns outs = do - let (Cardano.TxUnsignedByron _ _ txHash) = - mkUnsignedByronTx ownedIns outs - let tx = (fst <$> ownedIns, outs) - let sigData = Byron.hashToBytes txHash - witnesses <- forM ownedIns $ \(_, TxOut addr _) -> do - ks <- lookupPrivateKey keyFrom addr - pure $ mkByronWitness pm sigData ks - pure - ( Tx (Hash sigData) (second coin <$> ownedIns) outs - , SealedTx $ CBOR.toStrictByteString $ CBOR.encodeSignedTx tx witnesses - ) - _minimumFee :: FeePolicy -> [Certificate] @@ -509,15 +496,6 @@ mkUnsignedShelleyTx ttl ownedIns outs certs fee = in unsigned -mkUnsignedByronTx - :: [(TxIn, TxOut)] - -> [TxOut] - -> Cardano.TxUnsigned -mkUnsignedByronTx ownedIns outs = - Cardano.buildByronTransaction - (toCardanoTxIn . fst <$> ownedIns) - (map toCardanoTxOut outs) - -- TODO: The SlotId-SlotNo conversion based on epoch length would not -- work if the epoch length changed in a hard fork.