@@ -31,6 +31,7 @@ import Data.Map qualified as Map
31
31
import Data.Maybe (catMaybes )
32
32
import Data.ProtoLens (Message (defMessage ))
33
33
import Data.Text (Text )
34
+ import Data.Text qualified as Text
34
35
import Data.Traversable (for )
35
36
import Data.Void (Void )
36
37
import Ledger (Language (PlutusV2 ), POSIXTime (POSIXTime ), PaymentPubKeyHash (PaymentPubKeyHash , unPaymentPubKeyHash ), TxId , TxOutRef , Versioned (Versioned ), after , applyArguments , ciTxOutValue , interval )
@@ -53,17 +54,16 @@ import Plutus.V2.Ledger.Api (
53
54
MintingPolicy (MintingPolicy ),
54
55
POSIXTimeRange ,
55
56
TokenName (TokenName ),
56
- UpperBound ( UpperBound ) ,
57
+ UpperBound ,
57
58
Validator (Validator ),
58
59
Value ,
59
60
toBuiltin ,
60
61
toData ,
61
62
)
62
63
import PlutusTx (toBuiltinData )
63
64
import PlutusTx.Prelude (Group (inv ), fromBuiltin )
64
- import Proto.TxBuilderService (CreateGcFsTxReq , CreateMintFsTxReq , GcFsInfo , MintFsSuccess'FsIdAndTxOutRef )
65
- import Proto.TxBuilderService_Fields (factStatementId , factStatementUtxo , factStatements , fs , fsId , fsIds , gcAfter , notFoundFsIds , obsoleteFsIds , submitter , validFsIds )
66
- import Safe.Foldable (maximumMay )
65
+ import Proto.TxBuilderService (CreateGcFsTxReq , CreateMintFsTxReq , GcFsInfo , MintFsInfo )
66
+ import Proto.TxBuilderService_Fields (alreadyPublished , factStatements , fs , fsId , fsIds , fsUtxo , gcAfter , notFoundFsIds , obsoleteFsIds , publishedFsIds , submitter , validFsIds )
67
67
import Test.Plutip.Internal.BotPlutusInterface.Setup ()
68
68
import Test.Plutip.Internal.LocalCluster ()
69
69
import Text.Printf (printf )
@@ -451,16 +451,16 @@ findOnchainState coopDeployment authenticators =
451
451
toCardanoC :: ProtoCardano (Either Text ) proto cardano => proto -> Contract w s Text cardano
452
452
toCardanoC proto = let x = toCardano @ (Either Text ) proto in either throwError return x
453
453
454
- mkPublishingSpec :: CoopDeployment -> [PaymentPubKeyHash ] -> CreateMintFsTxReq -> Contract w s Text (Maybe PublishingSpec , [ MintFsSuccess'FsIdAndTxOutRef ] )
454
+ mkPublishingSpec :: CoopDeployment -> [PaymentPubKeyHash ] -> CreateMintFsTxReq -> Contract w s Text (Maybe PublishingSpec , MintFsInfo )
455
455
mkPublishingSpec coopDeployment authenticators req = do
456
456
when (null $ req ^. factStatements) (throwError " Must have at least one Fact Statement to process" )
457
457
458
458
CoopOnchainState authBatches published <- findOnchainState coopDeployment authenticators
459
459
submitterPPkh <- PaymentPubKeyHash <$> toCardanoC (req ^. submitter)
460
460
let alreadyPublished' =
461
461
[ defMessage
462
- & factStatementId .~ fsInfo ^. fsId
463
- & factStatementUtxo .~ fsOref'
462
+ & fsId .~ fsInfo ^. fsId
463
+ & fsUtxo .~ fsOref'
464
464
| fsInfo <- req ^. factStatements
465
465
, fsOref <- maybe [] return $ Map. lookup (LedgerBytes . toBuiltin $ fsInfo ^. fsId) published
466
466
, fsOref' <- fromCardano fsOref
@@ -470,24 +470,26 @@ mkPublishingSpec coopDeployment authenticators req = do
470
470
| fsInfo <- req ^. factStatements
471
471
, not $ Map. member (LedgerBytes . toBuiltin $ fsInfo ^. fsId) published
472
472
]
473
+ fsIdsToPublish = (^. fsId) <$> fsInfosToPublish
474
+ info :: MintFsInfo =
475
+ defMessage
476
+ & alreadyPublished .~ alreadyPublished'
477
+ & publishedFsIds .~ fsIdsToPublish
473
478
474
479
if null fsInfosToPublish
475
480
then
476
481
( do
477
482
logInfo @ String " Nothing new to publish"
478
- return (Nothing , alreadyPublished' )
483
+ return (Nothing , info )
479
484
)
480
485
else do
481
486
let stillValidAuthPairs' = stillValidAuthPairs authBatches
482
487
authInfos = take (length fsInfosToPublish) stillValidAuthPairs'
488
+ howManyValidAuthOuts = length stillValidAuthPairs'
483
489
484
- when (length fsInfosToPublish > length stillValidAuthPairs') $ throwError " Must have enough valid authentication pairs (cert+auth) to authenticate Fact Statements"
485
-
486
- txValidUntil <-
487
- maybe
488
- (throwError " Must have sufficient $AUTH inputs" )
489
- return
490
- (maximumMay $ (\ (_, _, _, UpperBound ext _) -> ext) <$> authInfos)
490
+ when (length fsInfosToPublish > howManyValidAuthOuts) $
491
+ throwError $
492
+ " Must have enough valid Authenticator UTxOs holding valid $AUTH tokens, wanted" <> (Text. pack . show . length $ fsInfosToPublish) <> " , got " <> (Text. pack . show $ howManyValidAuthOuts)
491
493
492
494
fsDatums <-
493
495
for
@@ -507,9 +509,7 @@ mkPublishingSpec coopDeployment authenticators req = do
507
509
)
508
510
authInfos
509
511
fsDatums
510
- if length fsInfosWithAuth /= length fsInfosToPublish
511
- then throwError " Must have enough $AUTH outputs to authenticate each Fact Statement"
512
- else return (Just $ PublishingSpec submitterPPkh fsInfosWithAuth txValidUntil, alreadyPublished')
512
+ return (Just $ PublishingSpec submitterPPkh fsInfosWithAuth, info)
513
513
where
514
514
stillValidAuthPairs :: Map LedgerBytes CoopAuthBatch -> [(CoopAuthBatch , (TxOutRef , ChainIndexTxOut ), PaymentPubKeyHash , UpperBound POSIXTime )]
515
515
stillValidAuthPairs authBatches = do
@@ -519,11 +519,11 @@ mkPublishingSpec coopDeployment authenticators req = do
519
519
authOut <- Map. toList authOuts
520
520
return (batch, authOut, authWallet, ivTo . cert'validity . auth'certDatum $ batch)
521
521
522
- runMintFsTx :: CoopDeployment -> [PaymentPubKeyHash ] -> (Value , PaymentPubKeyHash ) -> (Bool , Integer ) -> CreateMintFsTxReq -> Contract w s Text (Maybe TxId , [ MintFsSuccess'FsIdAndTxOutRef ] )
522
+ runMintFsTx :: CoopDeployment -> [PaymentPubKeyHash ] -> (Value , PaymentPubKeyHash ) -> (Bool , Integer ) -> CreateMintFsTxReq -> Contract w s Text (Maybe TxId , MintFsInfo )
523
523
runMintFsTx coopDeployment authenticators feeSpec (submit, minutes) req = do
524
- (mayPublishingSpec, alreadyPublished' ) <- mkPublishingSpec coopDeployment authenticators req
524
+ (mayPublishingSpec, info ) <- mkPublishingSpec coopDeployment authenticators req
525
525
maybe
526
- (return (Nothing , alreadyPublished' ))
526
+ (return (Nothing , info ))
527
527
( \ publishingSpec -> do
528
528
(now, _) <- currentNodeClientTimeRange
529
529
let mintFsTrx =
@@ -537,14 +537,13 @@ runMintFsTx coopDeployment authenticators feeSpec (submit, minutes) req = do
537
537
if submit
538
538
then submitTrx @ Void mintFsTrx
539
539
else submitTrx' @ Void mintFsTrx
540
- return (Just txId, alreadyPublished' )
540
+ return (Just txId, info )
541
541
)
542
542
mayPublishingSpec
543
543
544
544
data PublishingSpec = PublishingSpec
545
545
{ ps'submitter :: PaymentPubKeyHash
546
546
, ps'factStatementSpecs :: [FactStatementSpec ]
547
- , _ps'validUntil :: Extended POSIXTime
548
547
}
549
548
550
549
data FactStatementSpec = FactStatementSpec
0 commit comments