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