packageDocumentation import path from 'path' ; import getPort from 'get-port' ; import { StartService , ShutdownMethod , cleanShutdownFD } from './service' ; import { FilePath , DirPath , makeRtsArgs } from './common' ; /**
 * Definition of a `cardano-node` network.
 */ export interface CardanoNetwork { /**
     * The YAML configuration file for cardano-node.
     */ configFile : FilePath ; /**
     * Network topology data to pass to cardano-node.
     */ topologyFile : FilePath ; /**
     * Path to the Byron genesis file in JSON format.
     * This is required for testnet and staging but not mainnet.
     * It is used to configure the parameters of cardano-wallet.
     * It should match the ByronGenesisFile configured in the cardano-node YAML file.
     * Note that the Byron-era genesis file is always required,
     * even if currently in Shelley era.
     */ genesisFile ? : FilePath ; } /** Predefined networks. */ export const networks = { mainnet : { configFile : 'configuration.json' , topologyFile : 'topology.json' , } , testnet : { configFile : 'configuration.json' , topologyFile : 'topology.json' , genesisFile : 'genesis-byron.json' , } , staging : { configFile : 'configuration.json' , topologyFile : 'topology.json' , genesisFile : 'genesis-byron.json' , } , } ; internal export interface CardanoNodeArgs { /**
     * Filename for the socket file to use for communicating with the
     * node.
     */ socketFile : FilePath ; /**
     * The path to a file describing the topology.
     * Topology is ...
     */ topologyFile : FilePath ; /** Directory where the state is stored. */ databaseDir : DirPath ; /** Path to the delegation certificate. */ delegationCertificate ? : string ; /** Path to the signing key. */ signingKey ? : string ; /** Path to the KES signing key. */ kesKey ? : string ; /** Path to the VRF signing key. */ vrfKey ? : string ; /** Path to the delegation certificate */ operationalCertificate ? : string ; /** Configures the address to bind for P2P communication. */ listen : { /** The TCP port for node P2P. */ port : number ; /** Optionally limit node P2P to one ipv4 address. */ address ? : string ; /** Optionally limit node P2P to one ipv6 address. */ address6 ? : string ; } ; /** Configuration file for cardano-node. */ configFile : FilePath ; /** Validate all on-disk database files. */ validateDb ? : boolean ; /** GHC runtime system options. */ rtsOpts ? : string [ ] ; /**
     * Extra arguments to add to the `cardano-node` command line.
     */ extra ? : string [ ] ; } /**
 * Configuration parameters for starting cardano-node.
 *
 * These parameters can be set in [[LaunchConfig.nodeConfig]].
 */ export interface CardanoNodeConfig { kind : 'shelley' ; /** Directory containing configurations for all networks.
     * Defaults to the using the `$CARDANO_NODE_CONFIGS`
     * environment variable if not supplied.
     */ configurationDir : DirPath ; /** Path to the delegation certificate. The delegation certificate allows the delegator
     * (the issuer of said certificate) to give his/her own block signing rights to somebody
     * else (the delegatee). The delegatee can then sign blocks on behalf of the delegator.
     * */ delegationCertificate ? : string ; /** Network parameters. */ network : CardanoNetwork ; /** Path to the KES signing key. */ kesKey ? : string ; /** Path to the VRF signing key. */ vrfKey ? : string ; /** Path to the delegation certificate */ operationalCertificate ? : string ; /** Path to the signing key. */ signingKey ? : string ; /**
     * Filename for the socket to use for communicating with the
     * node. Optional -- will be set automatically if not provided.
     */ socketFile ? : FilePath ; /**
     * GHC runtime system options for cardano-node.
     * Can be used for debugging, tuning performance, etc.
     * See: https://downloads.haskell.org/ghc/8.10.7/docs/html/users_guide/runtime_control.html#setting-rts-options-on-the-command-line
     */ rtsOpts ? : string [ ] ; } let pipeCounter = 0 ; param networkName return function windowsPipeName ( networkName ) { return `\\\\.\\pipe\\cardano-node-${ networkName }.${ process . pid }.${ pipeCounter ++ }` ; } /**
 * Convert a [[CardanoNodeConfig]] into command-line arguments
 * ([[CardanoNodeArgs]]) for `cardano-node`.
 */ function makeArgs ( stateDir , config , networkName , listenPort ) { let socketFile = config . socketFile ; if ( ! socketFile ) { if ( process . platform === 'win32' ) { config . socketFile = socketFile = windowsPipeName ( networkName ) ; } else { socketFile = 'cardano-node.socket' ; config . socketFile = path . join ( stateDir , socketFile ) ; } } if ( ! config . network ) { if ( networks [ networkName ] ) { config . network = networks [ networkName ] ; } else { throw new Error ( `CardanoNodeConfig does not have a network defined, and ${ networkName } is not a recognised network name.` ) ; } } if ( ! config . configurationDir ) { const def = process . env . CARDANO_NODE_CONFIGS ; if ( def ) { config . configurationDir = path . join ( def as string , networkName ) ; } } return { socketFile , topologyFile : path . join ( config . configurationDir , config . network . topologyFile ) , databaseDir : 'chain' , delegationCertificate : config . delegationCertificate , listen : { port : listenPort , address : '127.0.0.1' , address6 : '::1' , } , configFile : path . join ( config . configurationDir , config . network . configFile ) , signingKey : config . signingKey , kesKey : config . kesKey , vrfKey : config . vrfKey , rtsOpts : config . rtsOpts , } ; } export interface NodeStartService extends StartService { /** This will contain the cardano-node socket file path. */ socketPath : string ; /** This will contain the TCP port which the cardano-node is listening on. */ listenPort : number ; } param stateDir param config return export async function startCardanoNode ( stateDir , config , networkName ) { const listenPort = await getPort ( ) ; const args = makeArgs ( stateDir , config , networkName , listenPort ) ; return { command : 'cardano-node' , args : [ 'run' , '--socket-path' , args . socketFile , '--shutdown-ipc' , '' + cleanShutdownFD , '--topology' , args . topologyFile , '--database-path' , args . databaseDir , '--port' , '' + args . listen . port , '--config' , args . configFile , ] . concat ( args . listen . address ? [ '--host-addr' , args . listen . address ] : [ ] ) . concat ( args . listen . address6 ? [ '--host-ipv6-addr' , args . listen . address6 ] : [ ] ) . concat ( args . validateDb || false ? [ '--validate-db' ] : [ ] ) . concat ( args . signingKey ? [ '--signing-key' , args . signingKey ] : [ ] ) . concat ( args . delegationCertificate ? [ '--delegation-certificate' , args . delegationCertificate ] : [ ] ) . concat ( args . kesKey ? [ '--shelley-kes-key' , args . kesKey ] : [ ] ) . concat ( args . vrfKey ? [ '--shelley-vrf-key' , args . vrfKey ] : [ ] ) . concat ( args . operationalCertificate ? [ '--shelley-operational-certificate' , args . operationalCertificate ] : [ ] ) . concat ( makeRtsArgs ( args . rtsOpts ) ) . concat ( args . extra || [ ] ) , shutdownMethod : ShutdownMethod . CloseFD , cwd : stateDir , socketPath : args . socketFile , listenPort : args . listen . port , } ; }