-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify how the arguments are passed to the anoma node (#3258)
- Loading branch information
1 parent
b954100
commit a4faa31
Showing
19 changed files
with
259 additions
and
97 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
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,83 @@ | ||
module Commands.Dev.Anoma.Prove.Options.ProveArg | ||
( ProveArg (..), | ||
parseProveArg, | ||
) | ||
where | ||
|
||
import Commands.Dev.Anoma.Prove.Options.ProveArgTag | ||
import CommonOptions | ||
import Juvix.Data.IntegerWithBase | ||
import Juvix.Parser.Lexer | ||
import Juvix.Prelude.Parsing hiding (many, option) | ||
|
||
type Parse = Parsec Void Text | ||
|
||
newtype ProveArg' = ProveArg' | ||
{ _proveArg :: Sigma ProveArgTag ProveArgTypeSym0 | ||
} | ||
|
||
data ProveArg | ||
= ProveArgNat Natural | ||
| ProveArgBase64 (AppPath File) | ||
| ProveArgBytes (AppPath File) | ||
deriving stock (Data) | ||
|
||
parseProveArg :: Parser ProveArg | ||
parseProveArg = fromProveArg' <$> parseProveArg' | ||
where | ||
fromProveArg' :: ProveArg' -> ProveArg | ||
fromProveArg' (ProveArg' (ty :&: a)) = case ty of | ||
SProveArgTagNat -> ProveArgNat a | ||
SProveArgTagBase64 -> ProveArgBase64 a | ||
SProveArgTagBytes -> ProveArgBytes a | ||
|
||
parseProveArg' :: Parser ProveArg' | ||
parseProveArg' = | ||
option | ||
pp | ||
( long "arg" | ||
<> completer (listCompleter [show a <> ":" | a <- allElements @ProveArgTag]) | ||
<> metavar "ARG_TYPE:ARG" | ||
<> helpDoc ("An argument to the program:" <> line <> proveArgTagHelp) | ||
) | ||
where | ||
pProveArgTag :: Parse ProveArgTag | ||
pProveArgTag = | ||
choice | ||
[ chunk (show a) $> a | ||
| a :: ProveArgTag <- allElements | ||
] | ||
|
||
pAppPath :: Parse (AppPath File) | ||
pAppPath = do | ||
i <- mkPrepath . unpack <$> takeRest | ||
return | ||
AppPath | ||
{ _pathIsInput = True, | ||
_pathPath = i | ||
} | ||
|
||
pProveArg' :: Parse ProveArg' | ||
pProveArg' = do | ||
dty <- pProveArgTag | ||
withSomeSing dty $ \ty -> do | ||
chunk ":" | ||
a <- pProveArgType ty | ||
return (ProveArg' (ty :&: a)) | ||
|
||
pProveArgType :: SProveArgTag t -> Parse (ProveArgType t) | ||
pProveArgType p = do | ||
ret <- case p of | ||
SProveArgTagBytes -> pAppPath | ||
SProveArgTagBase64 -> pAppPath | ||
SProveArgTagNat -> do | ||
off <- getOffset | ||
i <- (^. withLocParam . integerWithBaseValue) <$> integerWithBase' | ||
if | ||
| i < 0 -> parseFailure off "Expected a non-negative integer" | ||
| otherwise -> return (fromIntegral i) | ||
eof | ||
return ret | ||
|
||
pp :: ReadM ProveArg' | ||
pp = eitherReader $ \strInput -> parseHelper pProveArg' (pack strInput) |
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,42 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module Commands.Dev.Anoma.Prove.Options.ProveArgTag where | ||
|
||
import CommonOptions | ||
import Prelude qualified | ||
|
||
data ProveArgTag | ||
= ProveArgTagNat | ||
| ProveArgTagBase64 | ||
| ProveArgTagBytes | ||
deriving stock (Eq, Bounded, Enum, Data) | ||
|
||
instance Show ProveArgTag where | ||
show = \case | ||
ProveArgTagNat -> "nat" | ||
ProveArgTagBase64 -> "base64" | ||
ProveArgTagBytes -> "bytes" | ||
|
||
type ProveArgType :: ProveArgTag -> GHCType | ||
type family ProveArgType s = res where | ||
ProveArgType 'ProveArgTagNat = Natural | ||
ProveArgType 'ProveArgTagBase64 = AppPath File | ||
ProveArgType 'ProveArgTagBytes = AppPath File | ||
|
||
$(genDefunSymbols [''ProveArgType]) | ||
$(genSingletons [''ProveArgTag]) | ||
|
||
proveArgTagHelp :: AnsiDoc | ||
proveArgTagHelp = itemize (tagHelp <$> allElements) | ||
where | ||
tagHelp :: ProveArgTag -> AnsiDoc | ||
tagHelp t = | ||
let mvar, explain :: AnsiDoc | ||
(mvar, explain) = first sty $ case t of | ||
ProveArgTagNat -> ("NATURAL", "is passed verbatim as a nockma atom") | ||
ProveArgTagBase64 -> ("FILE", "is a file with a base64 encoded nockma atom") | ||
ProveArgTagBytes -> ("FILE", "is a file with a byte encoded nockma atom") | ||
sty = annotate (bold <> colorDull Blue) | ||
tagvar :: AnsiDoc | ||
tagvar = sty (show t <> ":" <> mvar) | ||
in tagvar <+> "where" <+> mvar <+> explain |
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
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
Oops, something went wrong.