denpamusic/laravel-bitcoinrpc

How to define two separate instance of different ports

M-Shahbaz opened this issue · 9 comments

This project is great and easy to work with bitcoin json rpc.
As I was testing, is it possible to define other instance with different config settings, e.g: for a forked alt-coin which usually have same functionalities.

Sorry, this project was initially been designed to be used with single daemon, so as of now it's only possible to create separate instances manualy through use of underlying denpamusic/php-bitcoinrpc package.

use Denpa\Bitcoin\Client as LitecoinClient;

$litecoin = new LitecoinClient(['port' => 9332, 'user' => '...', 'pass' => '...']);
$block = $litecoin->getBlock('a6b4e9d54a30c2aa8a9af64eb68f21b07166d96c69fe61f1c12b3896fd653b7b');

I'll mark this as a Feature Request though for the upcoming 2.0.x.

Turns out it's really easy to implement this, so it'll probably be available in v1.2.0 as early as Thursday evening UTC after I've thoroughly test it.
For now I've created separate branch for this feature https://github.com/denpamusic/laravel-bitcoinrpc/tree/multi-instance

Basically you can now define separate configuration in config/bitcoind.php file, like this one for litecoin.
Then you can select which configuration to use by simply passing it's name.
e. g.

$block = bitcoind()->client('litecoin')->getBlock('a6b4e9d54a30c2aa8a9af64eb68f21b07166d96c69fe61f1c12b3896fd653b7b');

Complete examples are available in updated readme.

Hope you'll find it useful!

Ok, that is great.
Also as 0.17.0 is going to be released soon, it would be great to have "Dynamic wallet load / create etc." feature integrated as well in future release of this project.

There's no need to change anything in project to support new RPC commands.
You can use it, as soon as they are available in Core e. g. bitcoind()->loadwallet('...'), bitcoind()->createwallet('...') etc. or do you mean some other type of integration?

Thank you for your feature request!
Multiple instances are now implemented in v1.2.0.
See release notes and README.

There's no need to change anything in project to support new RPC commands.
You can use it, as soon as they are available in Core e. g. bitcoind()->loadwallet('...'),
bitcoind()->createwallet('...') etc. or do you mean some other type of integration?

Multi-wallet introduced in 0.15 and is done by setting the HTTP endpoint in the JSON-RPC request in the format, for example https://127.0.0.1:8332/wallet/wallet1.dat

All the other functions would be same, haven't checked how createwallet, loadwallet etc. will work in 0.17.0 release.

I see. Sorry, wasn't aware of that.
It should be implemented in php-bitcoinrpc package then, not here.
It'll probably be called with something like bitcoind()->wallet('wallet1.dat')->importaddress('...');

php-bitcoinrpc v2.0.6 now supports multi-wallet RPC.
As laravel-bitcoinrpc is a wrapper for that package you can now use it here too:
$balance = bitcoind()->wallet('wallet1.dat')->getbalance();
You'll need to run composer update though to update dependencies.

That is great!