⚡ Java framework for C-Lightning to work with the RPC interface, and also the library simplifies the work to develop custom plugins with Java, Kotlin, and all the languages that supports the Java dependencies ⚡
- Introduction
- How to Use
- Example
- Support
- License
This is a wrapper for c-lightning rpc, this project is inspired by this pull request by @renepickhardt.
The wrapper aims to be versatile, the final version should allow the user to execute commands even of custom plugins, allowing them to write the code for the command.
<dependency>
<groupId>io.github.clightning4j</groupId>
<artifactId>jrpclightning</artifactId>
<version>0.2.1</version>
</dependency>
implementation("io.github.clightning4j:jrpclightning:0.2.1")
implementation 'io.github.clightning4j:jrpclightning:0.2.1'
libraryDependencies += "io.github.clightning4j" % "jrpclightning" % "0.2.1"
Each master version has a SNAPSHOT version that is the official version x.x.x + 1
, so for example for the version v0.1.9
the version on if exist a new version of the master branch is v0.1.10-SNAPSHOT
, or some release candidate version, like v0.1.10-rc1
, will be
v0.1.10-rc1-SNAPSHOT
.
Describe a static rule at the moment it is difficult for the snapshot release, for this reason, feel free to open a question on the Github discussion if you have any doubt
An example of gradle configuration is reported below
Gradle (Kotlin DSL)
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor(0, "seconds")
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}
repositories {
... other suff
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
... other stuff
implementation("io.github.clightning4j:jrpclightning:0.1.9-SNAPSHOT")
}
At the moment the library doesn't support all command available on c-lightning, a list of commands is described inside the javadoc
-
You can use the RPC wrapper to call the method getinfo, that returns the json wrapper, called CLightningGetInfo.
CLightningGetInfo infoNode = CLightningRPC.getInstance().getInfo(); String id = infoNode.getId(); String color = infoNode.getColor(); System.out.println("id=" + id); System.out.println("color=" + color);
-
You can create a personal wrapper to support new commands (i.e: personal plugins or command not supported yet by the library)
Create the command wrapper
public class PersonalDelPayRPCCommand extends AbstractRPCCommand<CLightningListPays> { private static final String COMMAND_NAME = "delpay"; public PersonalDelPayRPCCommand() { super(COMMAND_NAME); } @Override protected Type toTypeFromClass() { return new TypeToken<RPCResponseWrapper<CLightningListPays>>(){}.getType(); } }
Create the personal Json wrapper
- In these cases it is used a library wrapper, you can see all wrappers available in the library here
Register the command and run it
PersonalRPCCommand paysCommand = new PersonalRPCCommand(); CLightningRPC.registerCommand(CustomCommand.DELPAY, paysCommand); CLightningListPay result = CLightningRPC.runRegisterCommand(CustomCommand.DELPAY, payload);
Complete javadoc here.
For the configuration of unix socket you can create a file called clightning-rpc.properties inside the classpath in your application.
The example file config is here.
## The CLightning rpc wrapper configurator
RPC_DIR=/media/vincenzo/Maxtor/C-lightning/node/testnet/lightning-rpc
The library supports plugins from version 0.1.8, and the library contains a collections of Annotation to make the developing phase easy.
@RPCMethod(
name = "annotation_hello",
description = "Annotation plugin"
)
public void hello(CLightningPlugin plugin, CLightningJsonObject request, CLightningJsonObject response) {
log(PluginLog.WARNING, request.toString());
response.add("type", "random");
}
@Subscription(notification = "invoice_creation")
public void doInvoiceCreation(CLightningJsonObject data){
log(PluginLog.WARNING, "Notification invoice_creation received inside the plugin lightning rest");
CLightningLogger.getInstance().debug( this.getClass(), "Data received by notification are \n" + data.toString());
}
@Hook(hook = "rpc_command")
public void logAllRPCCommand(CLightningPlugin plugin, CLightningJsonObject request, CLightningJsonObject response) {
log(PluginLog.WARNING, request.toString());
response.add("result", "continue");
}
class Plugin : CLightningPlugin() {
@PluginOption(
name = "hello-kotlin",
description = "This propriety is a fake propriety, there is any problem if it is not exist in the command line",
defValue = "true",
typeValue = "flag"
)
private var sayHello = false
}
A complete example of a plugin wrote with kotlin is available at the following link or a java version it is available at the following link.
Start to write a plugin with the following templates
If you like the library and want to support it, please considerer to donate with the following systems
- 3BQ8qbn8hLdmBKEjt1Hj1Z6SiDsnjJurfU
- liberapay.com/vincenzopalazzo
- Github support
- buymeacoffee
P.S: Lightning donation is coming ;-)
C-lightning RPC wrapper, with the complete support to Plugins and custom settings.
Copyright (C) 2020-2021 Vincenzo Palazzo [email protected]
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.