-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now ChainwebVersion only holds a list of the names of enabled plugins, to keep it pure data
- Loading branch information
1 parent
ba90fd6
commit 351ce11
Showing
9 changed files
with
74 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-# language BangPatterns #-} | ||
{-# language ScopedTypeVariables #-} | ||
{-# language OverloadedStrings #-} | ||
module Chainweb.VerifierPlugin.Trivial(plugin) where | ||
|
||
import Control.Lens | ||
import Control.Monad | ||
import Data.Aeson | ||
import qualified Data.Set as Set | ||
import qualified Data.Text as Text | ||
import qualified Data.Text.Encoding as Text | ||
|
||
import Pact.Types.Capability | ||
import Pact.Types.Exp | ||
import Pact.Types.PactValue | ||
|
||
import Chainweb.VerifierPlugin | ||
|
||
-- This trivial verifier plugin takes as arguments a list of JSON-encoded | ||
-- capabilities, and grants any subset of them. | ||
plugin :: VerifierPlugin | ||
plugin = VerifierPlugin $ \args caps -> over _Left VerifierError $ do | ||
decodedArgs :: [UserCapability] <- traverse decodeArgToCap args | ||
unless (noDuplicates decodedArgs) $ | ||
Left "duplicate capabilities exist in the arguments" | ||
unless (caps `Set.isSubsetOf` Set.fromList decodedArgs) $ | ||
Left "granted capabilities are not a subset of those in the arguments" | ||
where | ||
noDuplicates :: Ord a => [a] -> Bool | ||
noDuplicates = go Set.empty | ||
where | ||
go _ [] = True | ||
go seen (x:xs) = | ||
not (Set.member x seen) && | ||
(let !seen' = Set.insert x seen in go seen' xs) | ||
decodeArgToCap (PLiteral (LString arg)) = | ||
over _Left Text.pack $ eitherDecodeStrict' (Text.encodeUtf8 arg) | ||
decodeArgToCap _ = | ||
Left "expected string literal in verifier arguments" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters