@@ -87,6 +87,7 @@ import Control.Monad
87
87
import Data.Bifunctor (bimap , first , second )
88
88
import Data.ByteString.Short (ShortByteString )
89
89
import Data.Function ((&) )
90
+ import Data.Functor
90
91
import qualified Data.List as List
91
92
import Data.Map.Strict (Map )
92
93
import qualified Data.Map.Strict as Map
@@ -1449,6 +1450,13 @@ substituteExecutionUnits
1449
1450
redeemer
1450
1451
exunits
1451
1452
1453
+ adjustWitness
1454
+ :: (ScriptWitness witctx era -> Either (TxBodyErrorAutoBalance era ) (ScriptWitness witctx era ))
1455
+ -> Witness witctx era
1456
+ -> Either (TxBodyErrorAutoBalance era ) (Witness witctx era )
1457
+ adjustWitness _ (KeyWitness ctx) = Right $ KeyWitness ctx
1458
+ adjustWitness g (ScriptWitness ctx witness') = ScriptWitness ctx <$> g witness'
1459
+
1452
1460
mapScriptWitnessesTxIns
1453
1461
:: [(TxIn , BuildTxWith BuildTx (Witness WitCtxTxIn era ))]
1454
1462
-> Either (TxBodyErrorAutoBalance era ) [(TxIn , BuildTxWith BuildTx (Witness WitCtxTxIn era ))]
@@ -1460,27 +1468,18 @@ substituteExecutionUnits
1460
1468
]
1461
1469
mappedScriptWitnesses =
1462
1470
[ (txin, BuildTxWith <$> wit')
1463
- | -- The tx ins are indexed in the map order by txid
1464
- (ix, (txin, BuildTxWith wit)) <- zip [0 .. ] (orderTxIns txins)
1465
- , let wit' = case wit of
1466
- KeyWitness {} -> Right wit
1467
- ScriptWitness ctx witness -> ScriptWitness ctx <$> witness'
1468
- where
1469
- witness' = substituteExecUnits (ScriptWitnessIndexTxIn ix) witness
1471
+ | (ix, txin, wit) <- txInsToIndexed txins
1472
+ , let wit' = adjustWitness (substituteExecUnits ix) wit
1470
1473
]
1471
1474
in traverse
1472
- ( \ (txIn, eWitness) ->
1473
- case eWitness of
1474
- Left e -> Left e
1475
- Right wit -> Right (txIn, wit)
1476
- )
1475
+ (\ (txIn, eWitness) -> (txIn,) <$> eWitness)
1477
1476
mappedScriptWitnesses
1478
1477
1479
1478
mapScriptWitnessesWithdrawals
1480
1479
:: TxWithdrawals BuildTx era
1481
1480
-> Either (TxBodyErrorAutoBalance era ) (TxWithdrawals BuildTx era )
1482
1481
mapScriptWitnessesWithdrawals TxWithdrawalsNone = Right TxWithdrawalsNone
1483
- mapScriptWitnessesWithdrawals (TxWithdrawals supported withdrawals ) =
1482
+ mapScriptWitnessesWithdrawals txWithdrawals' @ (TxWithdrawals supported _ ) =
1484
1483
let mappedWithdrawals
1485
1484
:: [ ( StakeAddress
1486
1485
, L. Coin
@@ -1489,55 +1488,30 @@ substituteExecutionUnits
1489
1488
]
1490
1489
mappedWithdrawals =
1491
1490
[ (addr, withdrawal, BuildTxWith <$> mappedWitness)
1492
- | -- The withdrawals are indexed in the map order by stake credential
1493
- (ix, (addr, withdrawal, BuildTxWith wit)) <- zip [0 .. ] (orderStakeAddrs withdrawals)
1494
- , let mappedWitness = adjustWitness (substituteExecUnits (ScriptWitnessIndexWithdrawal ix)) wit
1491
+ | (ix, addr, withdrawal, wit) <- txWithdrawalsToIndexed txWithdrawals'
1492
+ , let mappedWitness = adjustWitness (substituteExecUnits ix) wit
1495
1493
]
1496
1494
in TxWithdrawals supported
1497
1495
<$> traverse
1498
- ( \ (sAddr, ll, eWitness) ->
1499
- case eWitness of
1500
- Left e -> Left e
1501
- Right wit -> Right (sAddr, ll, wit)
1502
- )
1496
+ (\ (sAddr, ll, eWitness) -> (sAddr,ll,) <$> eWitness)
1503
1497
mappedWithdrawals
1504
- where
1505
- adjustWitness
1506
- :: (ScriptWitness witctx era -> Either (TxBodyErrorAutoBalance era ) (ScriptWitness witctx era ))
1507
- -> Witness witctx era
1508
- -> Either (TxBodyErrorAutoBalance era ) (Witness witctx era )
1509
- adjustWitness _ (KeyWitness ctx) = Right $ KeyWitness ctx
1510
- adjustWitness g (ScriptWitness ctx witness') = ScriptWitness ctx <$> g witness'
1511
1498
1512
1499
mapScriptWitnessesCertificates
1513
1500
:: TxCertificates BuildTx era
1514
1501
-> Either (TxBodyErrorAutoBalance era ) (TxCertificates BuildTx era )
1515
1502
mapScriptWitnessesCertificates TxCertificatesNone = Right TxCertificatesNone
1516
- mapScriptWitnessesCertificates
1517
- ( TxCertificates
1518
- supported
1519
- certs
1520
- (BuildTxWith witnesses)
1521
- ) =
1522
- let mappedScriptWitnesses
1523
- :: [(StakeCredential , Either (TxBodyErrorAutoBalance era ) (Witness WitCtxStake era ))]
1524
- mappedScriptWitnesses =
1525
- [ (stakecred, ScriptWitness ctx <$> witness')
1526
- | -- The certs are indexed in list order
1527
- (ix, cert) <- zip [0 .. ] certs
1528
- , stakecred <- maybeToList (selectStakeCredentialWitness cert)
1529
- , ScriptWitness ctx witness <-
1530
- maybeToList (List. lookup stakecred witnesses)
1531
- , let witness' = substituteExecUnits (ScriptWitnessIndexCertificate ix) witness
1532
- ]
1533
- in TxCertificates supported certs . BuildTxWith
1534
- <$> traverse
1535
- ( \ (sCred, eScriptWitness) ->
1536
- case eScriptWitness of
1537
- Left e -> Left e
1538
- Right wit -> Right (sCred, wit)
1539
- )
1540
- mappedScriptWitnesses
1503
+ mapScriptWitnessesCertificates txCertificates'@ (TxCertificates supported certs _) =
1504
+ let mappedScriptWitnesses
1505
+ :: [(StakeCredential , Either (TxBodyErrorAutoBalance era ) (Witness WitCtxStake era ))]
1506
+ mappedScriptWitnesses =
1507
+ [ (stakeCred, witness')
1508
+ | (ix, _, stakeCred, witness) <- txCertificatesToIndexed txCertificates'
1509
+ , let witness' = adjustWitness (substituteExecUnits ix) witness
1510
+ ]
1511
+ in TxCertificates supported certs . BuildTxWith
1512
+ <$> traverse
1513
+ (\ (sCred, eScriptWitness) -> (sCred,) <$> eScriptWitness)
1514
+ mappedScriptWitnesses
1541
1515
1542
1516
mapScriptWitnessesVotes
1543
1517
:: Maybe (Featured ConwayEraOnwards era (TxVotingProcedures build era ))
@@ -1547,13 +1521,11 @@ substituteExecutionUnits
1547
1521
mapScriptWitnessesVotes Nothing = return Nothing
1548
1522
mapScriptWitnessesVotes (Just (Featured _ TxVotingProceduresNone )) = return Nothing
1549
1523
mapScriptWitnessesVotes (Just (Featured _ (TxVotingProcedures _ ViewTx ))) = return Nothing
1550
- mapScriptWitnessesVotes (Just (Featured era (TxVotingProcedures vProcedures (BuildTxWith sWitMap )))) = do
1524
+ mapScriptWitnessesVotes (Just (Featured era txVotingProcedures' @ (TxVotingProcedures vProcedures (BuildTxWith _ )))) = do
1551
1525
let eSubstitutedExecutionUnits =
1552
1526
[ (vote, updatedWitness)
1553
- | let allVoteMap = L. unVotingProcedures vProcedures
1554
- , (vote, scriptWitness) <- toList sWitMap
1555
- , index <- maybeToList $ Map. lookupIndex vote allVoteMap
1556
- , let updatedWitness = substituteExecUnits (ScriptWitnessIndexVoting $ fromIntegral index) scriptWitness
1527
+ | (ix, vote, witness) <- txVotingProceduresToIndexed txVotingProcedures'
1528
+ , let updatedWitness = substituteExecUnits ix witness
1557
1529
]
1558
1530
1559
1531
substitutedExecutionUnits <- traverseScriptWitnesses eSubstitutedExecutionUnits
@@ -1570,13 +1542,11 @@ substituteExecutionUnits
1570
1542
mapScriptWitnessesProposals Nothing = return Nothing
1571
1543
mapScriptWitnessesProposals (Just (Featured _ TxProposalProceduresNone )) = return Nothing
1572
1544
mapScriptWitnessesProposals (Just (Featured _ (TxProposalProcedures _ ViewTx ))) = return Nothing
1573
- mapScriptWitnessesProposals (Just (Featured era txpp@ (TxProposalProcedures osetProposalProcedures (BuildTxWith sWitMap)))) = do
1574
- let allProposalsList = toList $ convProposalProcedures txpp
1575
- eSubstitutedExecutionUnits =
1545
+ mapScriptWitnessesProposals (Just (Featured era txpp@ (TxProposalProcedures osetProposalProcedures (BuildTxWith _)))) = do
1546
+ let eSubstitutedExecutionUnits =
1576
1547
[ (proposal, updatedWitness)
1577
- | (proposal, scriptWitness) <- toList sWitMap
1578
- , index <- maybeToList $ List. elemIndex proposal allProposalsList
1579
- , let updatedWitness = substituteExecUnits (ScriptWitnessIndexProposing $ fromIntegral index) scriptWitness
1548
+ | (ix, proposal, scriptWitness) <- txProposalProceduresToIndexed txpp
1549
+ , let updatedWitness = substituteExecUnits ix scriptWitness
1580
1550
]
1581
1551
1582
1552
substitutedExecutionUnits <- traverseScriptWitnesses eSubstitutedExecutionUnits
0 commit comments