-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
juvix dev anoma add-transaction
command (#3193)
- Loading branch information
1 parent
923a019
commit 640d049
Showing
15 changed files
with
258 additions
and
68 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,15 @@ | ||
module Commands.Dev.Anoma.AddTransaction.Options where | ||
|
||
import CommonOptions | ||
|
||
newtype AddTransactionOptions = AddTransactionOptions | ||
{ _addTransactionFile :: AppPath File | ||
} | ||
deriving stock (Data) | ||
|
||
makeLenses ''AddTransactionOptions | ||
|
||
parseAddTransactionOptions :: Parser AddTransactionOptions | ||
parseAddTransactionOptions = do | ||
_addTransactionFile <- parseInputFile FileExtNockma | ||
pure AddTransactionOptions {..} |
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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
module Commands.Dev.Anoma.Base where | ||
|
||
import Anoma.Effect | ||
import Anoma.Effect (Anoma) | ||
import Anoma.Effect qualified as Anoma | ||
import Commands.Base hiding (Atom) | ||
import Juvix.Compiler.Nockma.Pretty | ||
import Juvix.Compiler.Nockma.Translation.FromSource qualified as Nockma | ||
|
||
cellOrFail :: | ||
forall x r a. | ||
(Member App r, Subset x r) => | ||
Term Natural -> | ||
(Term Natural -> Sem x a) -> | ||
Sem r a | ||
cellOrFail term f = case term of | ||
TermAtom {} -> exitFailMsg "Expected nockma input to be a cell" | ||
t@(TermCell {}) -> inject (f t) | ||
|
||
-- | Calls Anoma.Protobuf.NockService.Prove | ||
runNock :: forall r. (Members '[Error SimpleError, Anoma] r, Members AppEffects r) => AppPath File -> Maybe (AppPath File) -> Sem r RunNockmaResult | ||
runNock :: | ||
forall r. | ||
(Members '[Error SimpleError, Anoma] r, Members AppEffects r) => | ||
AppPath File -> | ||
Maybe (AppPath File) -> | ||
Sem r Anoma.RunNockmaResult | ||
runNock programFile margsFile = do | ||
afile <- fromAppPathFile programFile | ||
argsFile <- mapM fromAppPathFile margsFile | ||
parsedArgs <- runAppError @JuvixError (mapM Nockma.cueJammedFileOrPretty argsFile) | ||
parsedTerm <- runAppError @JuvixError (Nockma.cueJammedFileOrPretty afile) | ||
case parsedTerm of | ||
TermAtom {} -> exitFailMsg "Expected nockma input to be a cell" | ||
t@(TermCell {}) -> go t (maybe [] unfoldList parsedArgs) | ||
cellOrFail parsedTerm (go (maybe [] unfoldList parsedArgs)) | ||
where | ||
go :: Term Natural -> [Term Natural] -> Sem r RunNockmaResult | ||
go t args = | ||
runNockma | ||
RunNockmaInput | ||
go :: [Term Natural] -> Term Natural -> Sem r Anoma.RunNockmaResult | ||
go args t = | ||
Anoma.runNockma | ||
Anoma.RunNockmaInput | ||
{ _runNockmaProgram = t, | ||
_runNockmaArgs = args | ||
} | ||
|
||
-- | Calls Anoma.Protobuf.Mempool.AddTransaction | ||
addTransaction :: | ||
forall r. | ||
(Members '[Error SimpleError, Anoma] r, Members AppEffects r) => | ||
AppPath File -> | ||
Sem r () | ||
addTransaction programFile = do | ||
afile <- fromAppPathFile programFile | ||
parsedTerm <- runAppError @JuvixError (Nockma.cueJammedFileOrPretty afile) | ||
cellOrFail parsedTerm $ \t -> | ||
Anoma.addTransaction | ||
Anoma.AddTransactionInput | ||
{ _addTransactionInputCandidate = t | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
( | ||
Logger.configure(level: :none) | ||
eclient = Anoma.Client.Examples.EClient.create_example_client | ||
IO.puts("#{eclient.client.grpc_port} #{eclient.node.node_id}") | ||
) |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
module Anoma.Effect | ||
( module Anoma.Effect.Base, | ||
module Anoma.Effect.RunNockma, | ||
module Anoma.Effect.AddTransaction, | ||
) | ||
where | ||
|
||
import Anoma.Effect.AddTransaction | ||
import Anoma.Effect.Base | ||
import Anoma.Effect.RunNockma |
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,34 @@ | ||
module Anoma.Effect.AddTransaction | ||
( module Anoma.Effect.AddTransaction, | ||
module Anoma.Rpc.AddTransaction, | ||
) | ||
where | ||
|
||
import Anoma.Effect.Base | ||
import Anoma.Rpc.AddTransaction | ||
import Juvix.Compiler.Nockma.Encoding | ||
import Juvix.Compiler.Nockma.Language qualified as Nockma | ||
import Juvix.Prelude | ||
import Juvix.Prelude.Aeson qualified as Aeson | ||
|
||
newtype AddTransactionInput = AddTransactionInput | ||
{ _addTransactionInputCandidate :: Nockma.Term Natural | ||
} | ||
|
||
makeLenses ''AddTransactionInput | ||
|
||
addTransaction :: | ||
forall r. | ||
(Members '[Anoma, Error SimpleError, Logger] r) => | ||
AddTransactionInput -> | ||
Sem r () | ||
addTransaction i = do | ||
nodeInfo <- getNodeInfo | ||
let msg = | ||
AddTransaction | ||
{ _addTransactionNodeInfo = nodeInfo, | ||
_addTransactionTransaction = encodeJam64 (i ^. addTransactionInputCandidate) | ||
} | ||
logMessageValue "Request payload" msg | ||
-- addTransaction always returns an empty response | ||
void (anomaRpc addTransactionGrpcUrl (Aeson.toJSON msg)) |
Oops, something went wrong.