Skip to content

Commit

Permalink
Get rid of lie that we do properly support >1 signer in API
Browse files Browse the repository at this point in the history
  • Loading branch information
uhbif19 committed May 28, 2024
1 parent ec9b338 commit 1881d35
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/Cardano/CEM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class

data TransitionSpec script = MkTransitionSpec
{ constraints :: [TxFanConstraint script]
-- List of additional signers (not enforced by TxIns)
, signers :: [PubKeyHash]
, -- List of additional signers (in addition to one required by TxIns)
signers :: [PubKeyHash]
}
deriving stock (Show)

Expand Down
4 changes: 2 additions & 2 deletions src/Cardano/CEM/Monads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ data ResolvedTx = MkResolvedTx
, toMint :: TxMintValue BuildTx Era
, interval :: Interval POSIXTime
, additionalSigners :: [PubKeyHash]
, -- FIXME: rename
signer :: [SigningKey PaymentKey]
, -- FIXME
signer :: ~(SigningKey PaymentKey)
}
deriving stock (Show, Eq)

Expand Down
14 changes: 5 additions & 9 deletions src/Cardano/CEM/Monads/L1Commons.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ cardanoTxBodyFromResolvedTx ::
m (Either (TxBodyErrorAutoBalance Era) (TxBody Era, TxInMode))
cardanoTxBodyFromResolvedTx (MkResolvedTx {..}) = do
-- (lowerBound, upperBound) <- convertValidityBound validityBound
-- TODO
-- FIXME
let keyWitnessedTxIns = [fst $ last txIns]
MkBlockchainParams {protocolParameters} <- queryBlockchainParams

let additionalSignersKeys =
filter (\x -> signingKeyToPKH x `elem` additionalSigners) signer
filter (\x -> signingKeyToPKH x `elem` additionalSigners) [signer]

let preBody =
TxBodyContent
Expand Down Expand Up @@ -72,11 +72,7 @@ cardanoTxBodyFromResolvedTx (MkResolvedTx {..}) = do
, txVotingProcedures = Nothing
}

let
mainSignor = signer !! 0
mainAddress' = signingKeyToAddress mainSignor

mainAddress <- fromPlutusAddressInMonad mainAddress'
signerAddress <- fromPlutusAddressInMonad $ signingKeyToAddress signer
txInsUtxo <- queryUtxo $ ByTxIns $ map fst txIns

runExceptT $ do
Expand All @@ -85,9 +81,9 @@ cardanoTxBodyFromResolvedTx (MkResolvedTx {..}) = do
callBodyAutoBalance
preBody
txInsUtxo
mainAddress
signerAddress
let
tx = makeSignedTransactionWithKeys signer body
tx = makeSignedTransactionWithKeys [signer] body
txInMode = TxInMode ShelleyBasedEraBabbage tx
return (body, txInMode)

Expand Down
26 changes: 6 additions & 20 deletions src/Cardano/CEM/OffChain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@ awaitTx txId = do
then return ()
else go $ n - 1

data TxSigner = MkTxSigner
{ signerKey :: SigningKey PaymentKey
, allowTxInSpending :: Bool
, allowFeeCovering :: Bool
}
deriving stock (Show, Eq)

mkMainSigner :: SigningKey PaymentKey -> TxSigner
mkMainSigner signerKey =
MkTxSigner
{ signerKey
, allowTxInSpending = True
, allowFeeCovering = True
}

data CEMAction script
= MkCEMAction (CEMParams script) (Transition script)

Expand Down Expand Up @@ -106,7 +91,7 @@ instance Show SomeCEMAction where

data TxSpec = MkTxSpec
{ actions :: [SomeCEMAction]
, specSigners :: [TxSigner]
, specSigner :: SigningKey PaymentKey
}
deriving stock (Show)

Expand Down Expand Up @@ -227,7 +212,7 @@ resolveAction
, txOuts
, toMint = TxMintNone
, additionalSigners = signers scriptTransition
, signer = []
, signer = error "TODO"
, interval = always
}
where
Expand Down Expand Up @@ -280,10 +265,11 @@ resolveTxAndSubmit spec = runExceptT $ do
-- Merge specs
let
mergedSpec' = head actionsSpecs
mergedSpec = mergedSpec' {signer = map signerKey $ specSigners spec}
mergedSpec = mergedSpec' {signer = specSigner spec}

-- TODO
!utxo <- lift $ queryUtxo $ ByAddresses [signingKeyToAddress $ head $ signer mergedSpec]
-- FIXME: more robust fee covering
!utxo <-
lift $ queryUtxo $ ByAddresses [signingKeyToAddress $ signer mergedSpec]
let ins = map withKeyWitness $ Map.keys $ unUTxO utxo
let result = submitResolvedTx $ mergedSpec {txIns = txIns mergedSpec ++ ins}
ExceptT $ (bimap UnhandledSubmittingError id) <$> result
20 changes: 10 additions & 10 deletions test/Auction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ auctionSpec = describe "Auction" $ do
{ actions =
[ MkSomeCEMAction $ MkCEMAction auctionParams Create
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

let
Expand All @@ -59,7 +59,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams (MakeBid bid1)
]
, specSigners = [mkMainSigner bidder1]
, specSigner = bidder1
}
~( Left
( MkTransitionError
Expand Down Expand Up @@ -95,7 +95,7 @@ auctionSpec = describe "Auction" $ do
{ actions =
[ MkSomeCEMAction $ MkCEMAction auctionParams Create
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

submitAndCheck $
Expand All @@ -104,7 +104,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams Start
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

let
Expand All @@ -121,7 +121,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams (MakeBid bid1)
]
, specSigners = [mkMainSigner bidder1]
, specSigner = bidder1
}
~( Left
( MkTransitionError
Expand Down Expand Up @@ -160,7 +160,7 @@ auctionSpec = describe "Auction" $ do
{ actions =
[ MkSomeCEMAction $ MkCEMAction auctionParams Create
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

Just NotStarted <- queryScriptState auctionParams
Expand All @@ -183,7 +183,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams Start
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

Just (CurrentBid currentBid') <- queryScriptState auctionParams
Expand All @@ -195,7 +195,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams (MakeBid bid1)
]
, specSigners = [mkMainSigner bidder1]
, specSigner = bidder1
}

Just (CurrentBid currentBid) <- queryScriptState auctionParams
Expand All @@ -207,7 +207,7 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams Close
]
, specSigners = [mkMainSigner seller]
, specSigner = seller
}

submitAndCheck $
Expand All @@ -216,5 +216,5 @@ auctionSpec = describe "Auction" $ do
[ MkSomeCEMAction $
MkCEMAction auctionParams Buyout
]
, specSigners = [mkMainSigner bidder1]
, specSigner = bidder1
}
2 changes: 1 addition & 1 deletion test/OffChain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ offChainSpec = describe "Checking monad works" $ do
, toMint = TxMintNone
, interval = always
, additionalSigners = []
, signer = [key1]
, signer = key1
}
awaitEitherTx =<< submitResolvedTx tx

Expand Down
2 changes: 1 addition & 1 deletion test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mintTestTokens userSk numMint = do
[(tokenToAsset testNftTokenName, fromInteger numMint)]
, interval = always
, additionalSigners = []
, signer = [userSk]
, signer = userSk
}
awaitEitherTx =<< submitResolvedTx tx
return ()
Expand Down
10 changes: 5 additions & 5 deletions test/Voting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@ votingSpec = describe "Voting" $ do
submitAndCheck $
MkTxSpec
{ actions = [mkAction Create]
, specSigners = [mkMainSigner creator]
, specSigner = creator
}

submitAndCheck $
MkTxSpec
{ actions = [mkAction Start]
, specSigners = [mkMainSigner creator]
, specSigner = creator
}

-- Vote

submitAndCheck $
MkTxSpec
{ actions = [mkAction $ Vote (signingKeyToPKH jury1) Yes]
, specSigners = [mkMainSigner jury1]
, specSigner = jury1
}

submitAndCheck $
MkTxSpec
{ actions = [mkAction $ Vote (signingKeyToPKH jury2) No]
, specSigners = [mkMainSigner jury2]
, specSigner = jury2
}

-- Count result

submitAndCheck $
MkTxSpec
{ actions = [mkAction Finalize]
, specSigners = [mkMainSigner jury2]
, specSigner = jury2
}

Just state <- queryScriptState params
Expand Down

0 comments on commit 1881d35

Please sign in to comment.