IntersectMBO / cardano-launcher

Shelley cardano-node and cardano-wallet launcher for NodeJS applications
https://input-output-hk.github.io/cardano-launcher/
Apache License 2.0
33 stars 9 forks source link

Windows Socket Path toggle for development pls #119

Open kardall opened 3 years ago

kardall commented 3 years ago

Is it possible to set the CARDANO_NODE_SOCKET_PATH environment variable when the wallet launches?

That way I don't have to run a completely separate node JUST to do some tests or something? Just have a toggle in the settings like "Development Socket" or something to turn it on/off.

You have to relaunch your command prompt just for it but.

Currently, the only way I found out how to get it, is a powershell command:

[System.IO.Directory]::GetFiles("\\\\.\\\\pipe\\\\") | findstr "cardano-node"

That outputs something like: \\.\\pipe\\cardano-node-mainnet.16184.0

If I manually set the environment variable in Windows, it works perfectly, but I have to update it with the current pid in order to work every time I restart the wallet and it's getting to be a bit annoying.

rvl commented 3 years ago

Hi @kardall, you should be able to set the pipe name through the LaunchConfig.nodeConfig -> CardanoNodeConfig.socketFile parameter of new Launcher().

Please let me know if that works for you.

kardall commented 3 years ago

That means you have to recompile the whole thing.

If you could do something like make it load from the config.yaml file, and you could manually enter it there after the "Protocol" maybe? That way it's kind of grouped, but at least then the loader could read that file and load in the name there. That would make it so that other people could do this without having to bother with compiling the wallet.

{
   "ApplicationName":"cardano-sl",
   "ApplicationVersion":1,
   "ByronGenesisFile":"genesis-byron.json",
   "ByronGenesisHash":"5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
   "LastKnownBlockVersion-Alt":0,
   "LastKnownBlockVersion-Major":3,
   "LastKnownBlockVersion-Minor":0,
   "MaxKnownMajorProtocolVersion":2,
   "Protocol":"Cardano",
   "SocketFile":"\\.\\pipe\\cardano-node-socket.0",
   "RequiresNetworkMagic":"RequiresNoMagic",
   "ShelleyGenesisFile":"genesis-shelley.json",
   "ShelleyGenesisHash":"1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
   "TraceBlockFetchClient":false,
...
}
rvl commented 3 years ago

OK, how are you actually using cardano-launcher? Are you calling the NPM module from your own application, or some other way?

kardall commented 3 years ago

I am using the Daedalus Wallet.

But during 0.97 I couldn't get the node to work properly, so I gave up on Windows and switched to the Linux builds.

So I recently decided that... you know... if the Daedalus wallet app is a node, why can't I use its socket to query the blockchain to do development. But to do that I needed access to the pipe.

See... my VMs that run cnode have 17 and 19gb on VMWare each. But since the wallet is native, it is only using around 8gb when running. So I was thinking about an angle where, if someone wants to try to query the blockchain, they could just use the Daedalus Wallet which they probably already run, and use it to do some work.

In order to do that I needed the Pipe, and I figured out how to get it, modified the cardanocli-js module to work on Win32 and got at least the cardano-cli query tip --mainnet to work properly. I just thought that it would be super awesome if people didn't have to do what I did (run a node-powershell command to pull the pipe and insert the environment variable) and it could just be a 'feature' you toggle in the wallet perhaps, or even manually assign in the config in this case.

rvl commented 3 years ago

I see now, thanks.

It is probably not a good idea from a support perspective for Daedalus to follow the CARDANO_NODE_SOCKET_PATH environment variable. Same issue with user-modified config files.

But I was thinking pretty much the same thing as you - why not use the node and wallet which Daedalus already runs? There is a feature branch in PR #105 where cardano-launcher (i.e. Daedalus) will save JSON files which have the pipe name / socket path, as well as other information. Would that help in your case?

kardall commented 3 years ago

I'm not asking that the launcher follows that path, I'm just saying that by default if you try to execute cardano-cli query tip --mainnet manually in a command prompt with the Daedalus Wallet folder added in as a path, it errors because it can't find the CARDANO_NODE_SOCKET_PATH environment variable.

Which in the case of the windows Daedalus Wallet application, does not use specifically but sets the pipe value internally and must communicate to the cli where that socket is somehow during command executions on the blockchain.

So all this entire thing is revolving around, is allowing that named pipe be written somewhere publicly outside of compiled code as a setting or a toggle within the wallet, so that you could even read the JSON file yourself and pull that named value out of it for your own application.

I did not know that feature branch existed, I will go take a look at it and see :)

kardall commented 3 years ago

I checked out that submission. It would do what I wanted yes.

In the mean-time, I did the following in nodejs:

const cardano = require('./src/cardano.js')
const ps = require('node-powershell')
// see if we can find the socket name
// '[System.IO.Directory]::GetFiles("\\\\.\\\\pipe\\\\") | findstr "cardano-node"'

function getSocketPath(callback) {
    console.log('Getting Daedalus Wallet IPC Socket Pipe')
    ps = new shell({verbose: false})
    ps.addCommand('[System.IO.Directory]::GetFiles("\\\\.\\\\pipe\\\\") | findstr "cardano-node"')
    ps.invoke().then(output => {
        callback(null, output)
        ps.dispose()
      })
      .catch(err => {
        console.log(err)
      })

}

getSocketPath(function onGetSocketPath(err, data) {
    // console.log(data)
    console.log('Setting CARDANO_NODE_SOCKET_PATH Environment Variable...')
    process.env['CARDANO_NODE_SOCKET_PATH'] = data.trim()
    console.log('Environment Variable Set!')
    doQueries()
})

function doQueries() {
  console.log('Current Tip:')
  console.log(cardano.queryTip())
}

This automatically sets whatever the pipe turns out to be, for that individual NodeJS Process. So I mean... it works, but it's hacky and the cardanocli-js module has to be converted/upgraded to allow for the difference in win32 commands like linux mkdir -p ... to the win32 mkdir ...