eznode
eznode copied to clipboard
Using existing node automatically
Idea mentioned in https://github.com/janoside/btc-rpc-explorer/pull/279#issuecomment-808699687
TL;DR: scroll down to "The simplest client-side implementation..."
Currently I solve this in my repository by simply placing proper configuration files in standard location and then reading them from other apps. This is still sub-optimal, so I intend to use interface files. I hope to refactor it in the following months.
The general idea is that we would standardize these locations:
-
/etc/interfaces/$INTERFACE/*
-
$XDG_CONFIG_HOME/interfaces/$INTERFACE/*
($XDG_CONFIG_HOME
defaults to~/.config
)
Where $INTERFACE
refers to interface name. In case of Bitcoin, we would have these interfaces:
-
bitcoin-rpc-public-$NETWORK
- can only execute harmless calls -
bitcoin-rpc-full-$NETWORK
- full access to bitcoind wallet and chain.
$NETWORK
refers to mainnet
|testnet
|regtest
|signet
. We can have more permission granularity in the future.
There's obligatory _default
file in the interfaces directory. This can be used in case the consumer doesn't want to mess with handling multiple services.
The simplest client-side implementation is to just try to read and parse the files in this order:
-
$XDG_CONFIG_HOME/interfaces/bitcoin-rpc-public-$NETWORK/_default
-
~/.config/interfaces/bitcoin-rpc-public-$NETWORK/_default
(ifXDG_CONFIG_HOME
is not set) -
/etc/interfaces/bitcoin-rpc-public-$NETWORK/_default
When one of them succeeds, break the loop and use it.
The contents of the file should be:
_spec_vesion = "1.0"
_iface_name = "bitcoin-rpc-public-mainnet"
# This is not bitcoind version but RPC and spec version
_iface_version = "1.0"
_impl_name = "bitcoind"
port = 8332
# user:pasword,
auth_token = "public:public"
# Alternatively:
# cookie_file = "/var/run/bitcoin-mainnet/cookie"