Skip to content

Commit 04cdb60

Browse files
feat(testing-interface): copy signers from original tx
1 parent 17defed commit 04cdb60

File tree

1 file changed

+12
-3
lines changed
  • src/testing-interface/lib/Convex/ThreatModel/Cardano

1 file changed

+12
-3
lines changed

src/testing-interface/lib/Convex/ThreatModel/Cardano/Api.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ import Convex.MockChain (applyTransaction, initialState)
4343
import Convex.NodeParams (NodeParams)
4444
import Convex.Wallet (Wallet)
4545
import Convex.Wallet qualified as Wallet
46+
import Convex.Wallet.MockWallet (mockWallets)
4647
import Data.ByteString.Short qualified as SBS
4748
import Data.Either (isRight)
49+
import Data.Foldable (foldrM)
4850
import Data.Map qualified as Map
4951
import Data.Maybe (listToMaybe)
5052
import Data.Maybe.Strict
@@ -255,6 +257,9 @@ txSigners (Tx _ wits) = [toHash wit | ShelleyKeyWitness _ (WitVKey wit _) <- wit
255257
. hashKey
256258
. coerceKeyRole
257259

260+
mockWalletHashes :: [(Hash PaymentKey, Wallet)]
261+
mockWalletHashes = map (\w -> (Wallet.verificationKeyHash w, w)) mockWallets
262+
258263
-- | Get the required signers from the transaction body (not witnesses).
259264
txRequiredSigners :: Tx Era -> [Hash PaymentKey]
260265
txRequiredSigners (Tx (ShelleyTxBody _ body _ _ _ _) _) =
@@ -494,7 +499,11 @@ rebalanceAndSign wallet tx utxo = do
494499
-- Re-sign (strip old signatures and add new one)
495500
let Tx finalBody _ = finalTx
496501
unsignedTx = makeSignedTransaction [] finalBody
497-
pure $ Right $ Wallet.signTx wallet unsignedTx
502+
signers = txSigners tx
503+
sign hash tx' = case lookup hash mockWalletHashes of
504+
Just w -> Right $ Wallet.signTx w tx'
505+
Nothing -> Left "Transaction was signed by an unknown wallet"
506+
pure $ foldrM sign unsignedTx signers
498507

499508
{- | Update execution units in a transaction by evaluating all scripts.
500509
@@ -635,8 +644,8 @@ setTxOutputsList newOuts (Tx (ShelleyTxBody era body scripts scriptData auxData
635644
let newOutsSeq =
636645
Seq.fromList
637646
[ CBOR.mkSized
638-
(Ledger.eraProtVerLow @LedgerEra)
639-
(toShelleyTxOut shelleyBasedEra (toCtxUTxOTxOut out))
647+
(Ledger.eraProtVerLow @LedgerEra)
648+
(toShelleyTxOut shelleyBasedEra (toCtxUTxOTxOut out))
640649
| out <- newOuts
641650
]
642651
body' = body{Conway.ctbOutputs = newOutsSeq}

0 commit comments

Comments
 (0)