Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a basic foreign export library for the node. Providing the `void runNode(int argc, char ** argv)` as the c entry point. Arguments are parsed the same as the command line cardano-node.
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Revision history for cardano-node-c | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
|
||
* First version. Released on an unsuspecting world. |
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,19 @@ | ||
cabal-version: 3.0 | ||
|
||
name: cardano-node-capi | ||
version: 0.1.0.0 | ||
description: ffi c library around the full node | ||
author: IOHK | ||
maintainer: operations@iohk.io | ||
|
||
extra-source-files: CHANGELOG.md | ||
|
||
library | ||
exposed-modules: Node | ||
build-depends: base | ||
, aeson | ||
, bytestring | ||
, cardano-node | ||
, optparse-applicative-fork | ||
hs-source-dirs: src | ||
default-language: Haskell2010 |
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,35 @@ | ||
module Node where | ||
|
||
import Data.Aeson (eitherDecodeStrict) | ||
import Cardano.Node.Run (runNode) | ||
|
||
import Foreign.Ptr (Ptr) | ||
import Foreign.C (CString, peekCString) | ||
import Foreign.Marshal.Array (peekArray) | ||
import Data.ByteString.Char8 (pack) | ||
|
||
import System.IO (hSetBuffering, BufferMode (LineBuffering), stdout) | ||
|
||
import Options.Applicative | ||
import Cardano.Node.Parsers (nodeCLIParser, parserHelpHeader, parserHelpOptions, | ||
renderHelpDoc) | ||
|
||
-- allow setting stdout to linebuffering if needed | ||
foreign export ccall setLineBuffering :: IO () | ||
setLineBuffering :: IO () | ||
setLineBuffering = hSetBuffering stdout LineBuffering | ||
|
||
-- | @crunNode@ is an exported C entry point to start a node. | ||
-- We parese the same arguments as the node CLI, but allow to | ||
-- pass the argumnets as @char *argv[]@ from C. | ||
foreign export ccall "runNode" crunNode :: Int -> Ptr CString -> IO () | ||
crunNode :: Int -> Ptr CString -> IO () | ||
crunNode argc argv = peekArray argc argv >>= mapM peekCString >>= \args -> | ||
case execParserPure pref opts args of | ||
Success pnc -> runNode pnc | ||
Failure f -> print f | ||
CompletionInvoked _ -> putStrLn "Completion Invoked?" | ||
where | ||
pref = prefs showHelpOnEmpty | ||
opts = info nodeCLIParser | ||
( fullDesc <> progDesc "Start node of the Cardano blockchain." ) |