Skip to content

Commit

Permalink
dependant computeTxSize on witness size
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jul 6, 2020
1 parent cdba711 commit 6c90fca
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Cardano.Wallet.Shelley.Transaction
import Prelude

import Cardano.Address.Derivation
( XPrv, XPub, toXPub, xprvToBytes, xpubPublicKey )
( XPrv, XPub, toXPub, xprvFromBytes, xprvToBytes, xpubPublicKey )
import Cardano.Binary
( serialize' )
import Cardano.Crypto.DSIGN
Expand Down Expand Up @@ -74,6 +74,7 @@ import Cardano.Wallet.Primitive.Types
, Tx (..)
, TxIn (..)
, TxOut (..)
, mainnetMagic
)
import Cardano.Wallet.Shelley.Compatibility
( Shelley
Expand Down Expand Up @@ -491,7 +492,31 @@ computeTxSize proxy witTag action cs =
where
chaff = L8.pack (show ix) <> BL.fromStrict txid

wits = SL.WitnessSet (Set.union addrWits certWits) mempty mempty
byronWits = Set.map dummyWitnessUniq $ Set.fromList (fst <$> CS.inputs cs)
where
dummyWitness :: BL.ByteString -> SL.BootstrapWitness TPraosStandardCrypto
dummyWitness chaff = error "waiting for proper cardano-ledger-spec"
--SL.makeBootstrapWitness chaff signingKey addrAttr
where
addrAttr = Byron.AddrAttributes
(Just $ Byron.HDAddressPayload (bloatChaff keyLen))
(toByronNetworkMagic mainnetMagic)
(Just xprv) = xprvFromBytes (bloatChaff sigLen)
signingKey = Crypto.SigningKey xprv
sigLen = sizeSigDSIGN $ Proxy @(DSIGN TPraosStandardCrypto)
keyLen = sizeVerKeyDSIGN $ Proxy @(DSIGN TPraosStandardCrypto)
bloatChaff n = BL.toStrict $ BL.take (fromIntegral n) $ BL.cycle chaff

dummyWitnessUniq :: TxIn -> SL.BootstrapWitness TPraosStandardCrypto
dummyWitnessUniq (TxIn (Hash txid) ix) = dummyWitness chaff
where
chaff = L8.pack (show ix) <> BL.fromStrict txid

wits = case witTag of
TxWitnessShelleyUTxO ->
SL.WitnessSet (Set.union addrWits certWits) mempty mempty
TxWitnessByronUTxO ->
SL.WitnessSet mempty mempty byronWits

lookupPrivateKey
:: (Address -> Maybe (k 'AddressK XPrv, Passphrase "encryption"))
Expand Down

0 comments on commit 6c90fca

Please sign in to comment.