Skip to content

Commit

Permalink
Make verifiers take only one argument
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Feb 13, 2024
1 parent d37f549 commit 6a6c7e2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
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
24 changes: 12 additions & 12 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
, "proof" J..= _verifierProof va
, "caps" J..= J.Array (_verifierCaps va)
]
instance FromJSON a => FromJSON (Verifier a) where
parseJSON = withObject "Verifier" $ \o -> do
name <- o .: "name"
args <- o .: "args"
proof <- o .: "proof"
caps <- o .: "caps"
return $ Verifier name args caps
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])

Check failure on line 1318 in tests/PactContinuationSpec.hs

View workflow job for this annotation

GitHub Actions / build (9.6, 3.10, ubuntu-20.04, true, +build-tool)

• Couldn't match expected type ‘PactValue’

Check failure on line 1318 in tests/PactContinuationSpec.hs

View workflow job for this annotation

GitHub Actions / build (9.6, 3.10, ubuntu-22.04, true, +build-tool)

• Couldn't match expected type ‘PactValue’

Check failure on line 1318 in tests/PactContinuationSpec.hs

View workflow job for this annotation

GitHub Actions / build (9.6, 3.10, macOS-latest, true, +build-tool)

• Couldn't match expected type ‘PactValue’
[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

0 comments on commit 6a6c7e2

Please sign in to comment.