Skip to content

Commit

Permalink
Give Direct.Wallet.sign a new type signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Dec 3, 2021
1 parent 3d9413b commit 41bc7ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion hydra-node/src/Hydra/Chain/Direct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import Hydra.Ledger.Cardano (
getTxBody,
makeSignedTransaction,
shelleyBasedEra,
toLedgerTx,
utxoPairs,
)
import qualified Hydra.Ledger.Cardano as Api
Expand Down Expand Up @@ -379,7 +380,7 @@ finalizeTx TinyWallet{sign, getUtxo, coverFee} headState partialTx = do
<> show walletUtxo
)
Right validatedTx -> do
pure $ sign validatedTx
pure $ toLedgerTx $ sign $ bodyFromTx validatedTx

fromPostChainTx ::
(MonadSTM m, MonadThrow (STM m)) =>
Expand Down
19 changes: 8 additions & 11 deletions hydra-node/src/Hydra/Chain/Direct/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ import Hydra.Ledger.Cardano (
NetworkId (Testnet),
fromLedgerTxId,
genKeyPair,
getTxId,
makeSignedTransaction,
mkVkAddress,
signWith,
toLedgerAddr,
toLedgerKeyWitness,
)
import qualified Hydra.Ledger.Cardano as Api
import Hydra.Logging (Tracer, traceWith)
import Hydra.Prelude
import Ouroboros.Consensus.Cardano.Block (BlockQuery (..), CardanoEras, pattern BlockAlonzo)
Expand Down Expand Up @@ -146,7 +149,7 @@ type AlonzoPoint = Point (ShelleyBlock Era)
data TinyWallet m = TinyWallet
{ getUtxo :: STM m (Map TxIn TxOut)
, getAddress :: Address
, sign :: ValidatedTx Era -> ValidatedTx Era
, sign :: Api.TxBody Api.Era -> Api.Tx Api.Era
, coverFee :: Map TxIn TxOut -> ValidatedTx Era -> STM m (Either ErrCoverFee (ValidatedTx Era))
, verificationKey :: VerificationKey
}
Expand Down Expand Up @@ -191,19 +194,13 @@ withTinyWallet tracer magic (vk, sk) iocp addr action = do
fst <$> readTMVar utxoVar
, getAddress =
address
, sign = \validatedTx@ValidatedTx{body, wits} ->
let txid = Ledger.TxId (SafeHash.hashAnnotated body)
wit =
fromLedgerTxId txid
, sign = \body ->
let wit =
getTxId body
`signWith` ( Cardano.Api.PaymentVerificationKey (Ledger.VKey vk)
, Cardano.Api.PaymentSigningKey sk
)
in validatedTx
{ wits =
wits
{ txwitsVKey = toLedgerKeyWitness @Cardano.Api.AlonzoEra [wit]
}
}
in makeSignedTransaction [wit] body
, coverFee = \lookupUtxo partialTx -> do
(walletUtxo, pparams) <- readTMVar utxoVar
case coverFee_ pparams lookupUtxo walletUtxo partialTx of
Expand Down

0 comments on commit 41bc7ed

Please sign in to comment.