Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make verifiers take only one argument #1336

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ hie.yaml
commands.sqlite
cabal.project.local*
/golden/lcov/actual
.DS_Store
.DS_Store
.ghci_history
10 changes: 5 additions & 5 deletions src/Pact/ApiReq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ data ApiReq = ApiReq {
_ylCodeFile :: Maybe FilePath,
_ylKeyPairs :: Maybe [ApiKeyPair],
_ylSigners :: Maybe [ApiSigner],
_ylVerifiers :: Maybe [Verifier ParsedVerifierArgs],
_ylVerifiers :: Maybe [Verifier ParsedVerifierProof],
_ylNonce :: Maybe Text,
_ylPublicMeta :: Maybe ApiPublicMeta,
_ylNetworkId :: Maybe NetworkId
Expand Down Expand Up @@ -548,7 +548,7 @@ mkExec
-- ^ public metadata
-> [(DynKeyPair, [SigCapability])]
-- ^ signing keypairs + caplists
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-- ^ verifiers
-> Maybe NetworkId
-- ^ optional 'NetworkId'
Expand Down Expand Up @@ -577,7 +577,7 @@ mkUnsignedExec
-- ^ public metadata
-> [Signer]
-- ^ payload signers
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-- ^ payload verifiers
-> Maybe NetworkId
-- ^ optional 'NetworkId'
Expand Down Expand Up @@ -641,7 +641,7 @@ mkCont
-- ^ command public metadata
-> [(DynKeyPair, [SigCapability])]
-- ^ signing keypairs
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-- ^ verifiers
-> Maybe Text
-- ^ optional nonce
Expand Down Expand Up @@ -677,7 +677,7 @@ mkUnsignedCont
-- ^ command public metadata
-> [Signer]
-- ^ payload signers
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-- ^ verifiers
-> Maybe Text
-- ^ optional nonce
Expand Down
8 changes: 4 additions & 4 deletions src/Pact/Types/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mkCommand
:: J.Encode c
=> J.Encode m
=> [(Ed25519KeyPair, [SigCapability])]
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-> m
-> Text
-> Maybe NetworkId
Expand All @@ -172,7 +172,7 @@ mkCommandWithDynKeys
:: J.Encode c
=> J.Encode m
=> [(DynKeyPair, [UserCapability])]
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-> m
-> Text
-> Maybe NetworkId
Expand Down Expand Up @@ -245,7 +245,7 @@ mkUnsignedCommand
:: J.Encode m
=> J.Encode c
=> [Signer]
-> [Verifier ParsedVerifierArgs]
-> [Verifier ParsedVerifierProof]
-> m
-> Text
-> Maybe NetworkId
Expand Down Expand Up @@ -369,7 +369,7 @@ data Payload m c = Payload
, _pNonce :: !Text
, _pMeta :: !m
, _pSigners :: ![Signer]
, _pVerifiers :: !(Maybe [Verifier ParsedVerifierArgs])
, _pVerifiers :: !(Maybe [Verifier ParsedVerifierProof])
, _pNetworkId :: !(Maybe NetworkId)
} deriving (Show, Eq, Generic, Functor, Foldable, Traversable)
instance (NFData a,NFData m) => NFData (Payload m a)
Expand Down
28 changes: 14 additions & 14 deletions src/Pact/Types/Verifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module Pact.Types.Verifier
( VerifierName(..)
, Verifier(..)
, verifierName
, verifierArgs
, verifierProof
, verifierCaps
, ParsedVerifierArgs(..)
, ParsedVerifierProof(..)
) where

import Control.DeepSeq
Expand All @@ -34,9 +34,9 @@ newtype VerifierName = VerifierName Text
deriving newtype (J.Encode, Arbitrary, NFData, Eq, Show, Ord, FromJSON)
deriving stock Generic

data Verifier args = Verifier
data Verifier prf = Verifier
{ _verifierName :: VerifierName
, _verifierArgs :: args
, _verifierProof :: prf
, _verifierCaps :: [UserCapability]
}
deriving (Eq, Show, Generic, Ord, Functor, Foldable, Traversable)
Expand All @@ -53,22 +53,22 @@ instance Arbitrary a => Arbitrary (Verifier a) where
instance J.Encode a => J.Encode (Verifier a) where
build va = J.object
[ "name" J..= _verifierName va
, "args" J..= _verifierArgs va
, "caps" J..= J.Array (_verifierCaps va)
, "proof" J..= _verifierProof va
, "clist" J..= J.Array (_verifierCaps va)
]
instance FromJSON a => FromJSON (Verifier a) where
parseJSON = withObject "Verifier" $ \o -> do
name <- o .: "name"
args <- o .: "args"
caps <- o .: "caps"
return $ Verifier name args caps
proof <- o .: "proof"
caps <- o .: "clist"
return $ Verifier name proof caps

newtype ParsedVerifierArgs = ParsedVerifierArgs [PactValue]
newtype ParsedVerifierProof = ParsedVerifierProof PactValue
deriving newtype (NFData, Eq, Show, Ord, FromJSON)
deriving stock Generic

instance J.Encode ParsedVerifierArgs where
build (ParsedVerifierArgs as) = J.build (J.Array as)
instance J.Encode ParsedVerifierProof where
build (ParsedVerifierProof as) = J.build as

instance Arbitrary ParsedVerifierArgs where
arbitrary = ParsedVerifierArgs <$> scale (min 10) arbitrary
instance Arbitrary ParsedVerifierProof where
arbitrary = ParsedVerifierProof <$> arbitrary
2 changes: 1 addition & 1 deletion tests/PactContinuationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ testVerifiers = context "using a verifier" $ it "should parse and run" $ do
[(simpleKeys,[])]
[Verifier
(VerifierName "TESTING-VERIFIER")
(ParsedVerifierArgs [PLiteral $ LDecimal 3])
(ParsedVerifierProof $ PLiteral (LDecimal 3))
[SigCapability (QualifiedName (ModuleName "coin" Nothing) "TRANSFER" def) [PLiteral (LString "jeff"), PLiteral (LDecimal 10)]]]
Nothing (Just "test1")
allResults <- runAll [cmd]
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Pact/Utils/LegacyValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ spec_pact_types_command =
, Case checkAesonCompat
, Case checkLegacyValueCompat
]
spec_case @(Verifier ParsedVerifierArgs)
spec_case @(Verifier ParsedVerifierProof)
[ Case checkRoundtrip
, Case checkRoundtrip2
, Case checkAesonCompat
Expand Down
Loading