├── .github └── workflows │ ├── test_jdk11.yml │ ├── test_jdk17.yml │ └── test_jdk8.yml ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE.txt ├── README.md ├── build.gradle ├── buildSrc ├── build.gradle └── src │ ├── main │ ├── groovy │ │ ├── ApiGenerator.groovy │ │ ├── ApiSettings.groovy │ │ ├── BaseProtocolSettings.groovy │ │ ├── ClassGenerator.groovy │ │ ├── ClassNameUtils.groovy │ │ ├── ProtocolManager.groovy │ │ ├── ProtocolSettings.groovy │ │ ├── WrapperClassGenerator.groovy │ │ └── XSDGenerator.groovy │ └── resources │ │ ├── API.java.template │ │ ├── AsynchronousMethod.java.template │ │ ├── BasicGetterAndSetterSection.java.template │ │ ├── ByteStringGetterAndSetterSection.java.template │ │ ├── ByteStringListGetterAndSetterSection.java.template │ │ ├── EnumGetterAndSetterSection.java.template │ │ ├── InnerClass.java.template │ │ ├── InnerEnum.java.template │ │ ├── InnerMapClass.java.template │ │ ├── IntegerListGetterAndSetterSection.java.template │ │ ├── LongListGetterAndSetterSection.java.template │ │ ├── MapGetterAndSetterSection.java.template │ │ ├── MessageGetterAndSetterSection.java.template │ │ ├── MessageListGetterAndSetterSection.java.template │ │ ├── RepeatableEnumGetterAndSetterSection.java.template │ │ ├── StringListGetterAndSetterSection.java.template │ │ ├── SynchronousMethod.java.template │ │ ├── SynchronousRepeatableResponseMethod.java.template │ │ ├── WrappedEnum.java.template │ │ ├── WrappedMessageClass.java.template │ │ └── package-info.java.template │ └── test │ └── groovy │ └── ClassNameUtilsSpec.groovy ├── docs ├── CNAME ├── index.adoc ├── lightningj-release-pubkey.asc └── stylesheets │ ├── colony.css │ └── rocket-panda.css ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── integrationTest.gradle ├── settings.gradle └── src ├── examples └── lnd │ ├── AsynchronousLndAPIExample.java │ ├── ExampleUtils.java │ ├── ExceptionHandlingExample.java │ ├── JSONConvertExample.java │ ├── LoggingExample.java │ ├── LowLevelAPIExample.java │ ├── SynchronousLndAPIExample.java │ ├── ValidationExample.java │ └── XMLConvertExample.java ├── integration-test └── groovy │ └── org │ └── lightningj │ └── lnd │ └── wrapper │ ├── LNDIntegrationSpec.groovy │ ├── StateServiceIntegrationSpec.groovy │ ├── autopilot │ └── AutopilotIntegrationSpec.groovy │ ├── chainkit │ └── ChainKitIntegrationSpec.groovy │ ├── dev │ └── DevIntegrationSpec.groovy │ ├── neutrino │ └── NeutrinoIntegrationSpec.groovy │ ├── peers │ └── PeersIntegrationSpec.groovy │ ├── verrpc │ └── VersioningIntegrationSpec.groovy │ ├── watchtower │ └── WatchtowerIntegrationSpec.groovy │ └── wtclient │ └── WtclientIntegrationSpec.groovy ├── main ├── java │ └── org │ │ └── lightningj │ │ ├── lnd │ │ ├── util │ │ │ ├── JsonGenUtils.java │ │ │ └── ValidationUtils.java │ │ └── wrapper │ │ │ ├── API.java │ │ │ ├── AsynchronousAPI.java │ │ │ ├── ClientSideException.java │ │ │ ├── CommunicationException.java │ │ │ ├── MacaroonClientInterceptor.java │ │ │ ├── MacaroonContext.java │ │ │ ├── Message.java │ │ │ ├── ServerSideException.java │ │ │ ├── StaticFileMacaroonContext.java │ │ │ ├── StatusException.java │ │ │ ├── StatusExceptionWrapper.java │ │ │ ├── StreamObserverWrapper.java │ │ │ ├── SynchronousAPI.java │ │ │ ├── V1XMLParser.java │ │ │ ├── ValidationException.java │ │ │ ├── ValidationProblems.java │ │ │ ├── ValidationResult.java │ │ │ ├── WrapperFactory.java │ │ │ ├── XMLParser.java │ │ │ └── XMLParserFactory.java │ │ └── util │ │ └── ZBase32.java ├── proto │ ├── autopilot.proto │ ├── chain.notifier.proto │ ├── chainkit.proto │ ├── dev.proto │ ├── invoices.proto │ ├── lightning.api.proto │ ├── neutrino.proto │ ├── peers.proto │ ├── router.proto │ ├── signer.proto │ ├── stateservice.proto │ ├── verrpc.proto │ ├── wallet.kit.proto │ ├── walletunlocker.proto │ ├── watchtower.proto │ └── wtclient.proto └── resources │ ├── lightningj_messages.properties │ └── lightningj_messages_sv.properties └── test ├── groovy └── org │ └── lightningj │ ├── TestUtils.groovy │ ├── lnd │ ├── util │ │ ├── JsonGenUtilsSpec.groovy │ │ └── ValidationUtilsSpec.groovy │ └── wrapper │ │ ├── APISpec.groovy │ │ ├── AsynchronousAPISpec.groovy │ │ ├── ClientSideExceptionSpec.groovy │ │ ├── CommunicationExceptionSpec.groovy │ │ ├── MessageSpec.groovy │ │ ├── ServerSideExceptionSpec.groovy │ │ ├── StaticFileMacaroonContextSpec.groovy │ │ ├── StatusExceptionWrapperSpec.groovy │ │ ├── StreamObserverWrapperSpec.groovy │ │ ├── SynchronousAPISpec.groovy │ │ ├── V1XMLParserSpec.groovy │ │ ├── ValidationExceptionSpec.groovy │ │ ├── ValidationProblemsSpec.groovy │ │ ├── ValidationResultSpec.groovy │ │ ├── WrapperFactorySpec.groovy │ │ ├── XMLParserFactorySpec.groovy │ │ ├── XMLParserSpec.groovy │ │ ├── autopilot │ │ └── AutopilotAPISpec.groovy │ │ ├── chainnotifier │ │ └── ChainNotifierAPISpec.groovy │ │ ├── dev │ │ └── DevAPISpec.groovy │ │ ├── invoices │ │ └── InvoicesAPISpec.groovy │ │ ├── neutrino │ │ └── NeutrinoAPISpec.groovy │ │ ├── peers │ │ └── PeersAPISpec.groovy │ │ ├── router │ │ └── RouterAPISpec.groovy │ │ ├── signer │ │ └── SignerAPISpec.groovy │ │ ├── walletkit │ │ └── WalletKitAPISpec.groovy │ │ └── wtclient │ │ └── WtclientSpec.groovy │ └── util │ └── ZBase32Spec.groovy └── resources ├── admin.macaroon ├── cert.pem └── invalid.macaroon /.github/workflows/test_jdk11.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Java CI JDK 11 7 | 8 | on: [push] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '11' 20 | distribution: 'adopt' 21 | - name: Validate Gradle wrapper 22 | uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b 23 | - name: Build with Gradle 24 | uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee 25 | with: 26 | arguments: build -------------------------------------------------------------------------------- /.github/workflows/test_jdk17.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Java CI JDK 17 7 | 8 | on: [push] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '17' 20 | distribution: 'adopt' 21 | - name: Validate Gradle wrapper 22 | uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b 23 | - name: Build with Gradle 24 | uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee 25 | with: 26 | arguments: build -------------------------------------------------------------------------------- /.github/workflows/test_jdk8.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Java CI JDK 8 7 | 8 | on: [push] 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 8 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '8' 20 | distribution: 'adopt' 21 | - name: Validate Gradle wrapper 22 | uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b 23 | - name: Build with Gradle 24 | uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee 25 | with: 26 | arguments: build -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build 3 | .idea 4 | bin 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | before_install: 4 | - chmod +x gradlew 5 | 6 | jdk: 7 | - openjdk8 8 | - oraclejdk11 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@lightningj.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure that Travis-CI build successfully on your branch. 11 | 2. Update the docs/index.adoc for major additions. 12 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Subject of the issue 2 | Describe your issue here. 3 | 4 | ### Your environment 5 | * version of lightningj 6 | * version and vendor of JDK 7 | * your operationg systems. 8 | 9 | ### Steps to reproduce 10 | Tell us how to reproduce this issue. 11 | 12 | ### Expected behaviour 13 | Tell us what should happen 14 | 15 | ### Actual behaviour 16 | Tell us what happens instead 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Readme for LightningJ 2 | 3 | LightningJ is a project with the intention to simplify the integration of 4 | existing Lightning node implementations for Java developers. It contains 5 | simple to use API implementations and converters between JSON, XML. 6 | 7 | For documentation see docs/index.adoc or the project web-site at 8 | http://www.lightningj.org 9 | 10 | 11 | Build status Master JDK 8: ![JDK 8 Build Status](https://github.com/lightningj-org/lightningj/actions/workflows/test_jdk8.yml/badge.svg?branch=master) 12 | 13 | Build status Master JDK 11: ![JDK 11 Build Status](https://github.com/lightningj-org/lightningj/actions/workflows/test_jdk11.yml/badge.svg?branch=master) 14 | 15 | Build status Master JDK 17: ![JDK 17 Build Status](https://github.com/lightningj-org/lightningj/actions/workflows/test_jdk17.yml/badge.svg?branch=master) -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | group 'test-buildsrc' 2 | version '1.0-SNAPSHOT' 3 | 4 | sourceCompatibility = 1.8 5 | 6 | repositories { 7 | // Spock releases are available from Maven Central 8 | mavenCentral() 9 | // Spock snapshots are available from the Sonatype OSS snapshot repository 10 | // maven { url "http://oss.sonatype.org/content/repositories/snapshots/" } 11 | } 12 | 13 | ext { 14 | grpcVersion = "1.49.2" 15 | } 16 | 17 | dependencies { 18 | //gRPC 19 | implementation 'io.netty:netty-tcnative-boringssl-static:2.0.54.Final' 20 | implementation "io.grpc:grpc-netty:$grpcVersion" 21 | implementation "io.grpc:grpc-protobuf:$grpcVersion" 22 | implementation "io.grpc:grpc-stub:$grpcVersion" 23 | 24 | // CamelCase 25 | implementation 'org.apache.commons:commons-text:1.10.0' 26 | 27 | // JAX-B dependencies for JDK 9+ 28 | implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.0' 29 | implementation 'com.sun.xml.bind:jaxb-impl:3.0.0' 30 | implementation 'javax.annotation:javax.annotation-api:1.3.2' 31 | 32 | // mandatory dependencies for using Spock 33 | testImplementation platform("org.spockframework:spock-bom:2.1-groovy-3.0") 34 | testImplementation "org.spockframework:spock-core" 35 | 36 | testImplementation ("junit:junit:4.12") 37 | // optional dependencies for using Spock 38 | testImplementation "org.hamcrest:hamcrest-core:1.3" // only necessary if Hamcrest matchers are used 39 | testRuntimeOnly "net.bytebuddy:byte-buddy:1.9.7" // allows mocking of classes (in addition to interfaces) 40 | testRuntimeOnly "org.objenesis:objenesis:2.5.1" // allows mocking of classes without default constructor (together with CGLIB) 41 | 42 | // dependencies used by examples in this project 43 | testRuntimeOnly "com.h2database:h2:1.4.182" 44 | } 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/ApiSettings.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | 15 | import static ApiGenerator.* 16 | /** 17 | * Class containing settings for an api point to be generated defined in protocol settings. 18 | * 19 | * 20 | * Created by Philip Vendil on 2019-03-30. 21 | */ 22 | class ApiSettings { 23 | 24 | String baseGrpcClassPath 25 | String grpcClassName 26 | String baseApiClassName 27 | String baseStubClass 28 | String baseProtoClassPath 29 | String baseFileName 30 | 31 | String getGrpcClassPath(String type){ 32 | if(type == TYPE_SYNCHRONOUS){ 33 | return baseGrpcClassPath + "BlockingStub" 34 | } 35 | return baseGrpcClassPath + "Stub" 36 | } 37 | 38 | String getApiClassName(String type){ 39 | if(type == TYPE_SYNCHRONOUS){ 40 | return "Synchronous" + baseApiClassName 41 | } 42 | return "Asynchronous" + baseApiClassName 43 | } 44 | 45 | String getStubClass(String type){ 46 | if(type == TYPE_SYNCHRONOUS){ 47 | return baseStubClass + "BlockingStub" 48 | } 49 | return baseStubClass + "Stub" 50 | } 51 | 52 | String getFileName(String type){ 53 | if(type == TYPE_SYNCHRONOUS){ 54 | return "Synchronous" + baseFileName 55 | } 56 | return "Asynchronous" + baseFileName 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/WrapperClassGenerator.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | import com.google.protobuf.Descriptors 15 | import org.gradle.api.DefaultTask 16 | import org.gradle.api.tasks.Input 17 | import org.gradle.api.tasks.TaskAction 18 | 19 | 20 | /** 21 | * Class for generating Wrapper classes for LND API. 22 | * 23 | * Created by philip on 2017-12-04. 24 | */ 25 | class WrapperClassGenerator extends DefaultTask{ 26 | 27 | @Input 28 | List protocols 29 | 30 | 31 | 32 | @TaskAction 33 | def generate() { 34 | 35 | ProtocolManager.init(project, protocols) 36 | 37 | for(String protocol : protocols) { 38 | ProtocolSettings protocolSettings = new ProtocolSettings(project: project, protocol: protocol) 39 | 40 | Descriptors.FileDescriptor descriptor = protocolSettings.getAPIFileDescriptor() 41 | 42 | createOutputDir(protocolSettings) 43 | 44 | descriptor.enumTypes.each { 45 | ClassGenerator.genEnum(it, protocolSettings) 46 | } 47 | descriptor.messageTypes.each { 48 | ClassGenerator.genClass(it, protocolSettings) 49 | } 50 | 51 | ClassGenerator.genJaxbIndex(protocolSettings, descriptor) 52 | 53 | ClassGenerator.genPackageInfo(protocolSettings) 54 | 55 | ApiGenerator.generateBlockingAPIs(protocolSettings, ProtocolManager.compileClasses, descriptor) 56 | 57 | } 58 | 59 | } 60 | 61 | private File createOutputDir(ProtocolSettings protocolSettings){ 62 | File dir = project.file(protocolSettings.messageOutputDir) 63 | dir.mkdirs() 64 | return dir 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/API.java.template: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package ${wrapperBasePackageName}; 15 | 16 | import io.grpc.ManagedChannel; 17 | import io.grpc.stub.StreamObserver; 18 | import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext; 19 | import ${aPIPackage}.*; 20 | import ${wrapperBasePackageName}.message.*; 21 | import org.lightningj.lnd.wrapper.*; 22 | ${specialAPIImports} 23 | 24 | import javax.net.ssl.SSLException; 25 | import java.io.File; 26 | import java.util.Map; 27 | import java.util.List; 28 | 29 | /** 30 | * API Class for generating ${type} API calls to LDN server using wrapped objects. 31 | * 32 | * Created by Philip Vendil. 33 | */ 34 | public class ${apiClassName} extends ${apiType}{ 35 | 36 | private ${grpcClass}.${stubClass} stub=null; 37 | 38 | /** 39 | * Minimal constructor for setting up a connection with LND Application. 40 | * 41 | * @param host the hostname of ldn application 42 | * @param port the port of the application. 43 | * @param trustedServerCertificate a link of the SSL certificate used by the LND Application. 44 | * @param macaroonFile the file pointing to the macaroon to use, or null if no macaroons are used. 45 | * @throws SSLException if problems occurred setting up the SSL Connection. 46 | * @throws ClientSideException if problems occurred reading the macaroon file. 47 | */ 48 | public ${apiClassName}(String host, int port, File trustedServerCertificate, File macaroonFile) throws SSLException, ClientSideException { 49 | super(host,port,trustedServerCertificate, macaroonFile); 50 | } 51 | 52 | /** 53 | * Constructor for setting up a connection with LND Application with more flexible 54 | * SSL context parameters. 55 | * 56 | * @param host the hostname of ldn application 57 | * @param port the port of the application. 58 | * @param sslContext the SSL Context used when connecting the LND Application. 59 | * @param macaroonContext the macaroon context to use. 60 | */ 61 | public ${apiClassName}(String host, int port, SslContext sslContext, MacaroonContext macaroonContext){ 62 | super(host,port,sslContext, macaroonContext); 63 | } 64 | 65 | /** 66 | * Constructor used for setting up a connection using a GRPC managed channel that 67 | * can be customized. 68 | * 69 | * @param channel the managed channel to use. 70 | */ 71 | public ${apiClassName}(ManagedChannel channel){ 72 | super(channel); 73 | } 74 | 75 | ${callMethods} 76 | 77 | protected ${grpcClass}.${stubClass} getStub(){ 78 | if(stub == null){ 79 | stub = ${grpcClass}.${newStubMethodName}(channel); 80 | } 81 | return stub; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/AsynchronousMethod.java.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Method to generate a ${methodName} request. 3 | * 4 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType}, ${observerTypeName}) 5 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 6 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 7 | *
  • ServerSideException: if server side problems was detected when processing the request. 8 | *
  • CommunicationException: if communication related problems occurred during the call. 9 | * @throws ValidationException if validation problems found in request or response data. 10 | */ 11 | public void ${methodName}(${parameters} ${responseObserverType} responseObserver) throws StatusException,ValidationException{ 12 | ${requestType} request = new ${requestType}(); 13 | ${setMethods} 14 | ${methodName}(request, responseObserver); 15 | } 16 | 17 | /** 18 | * Method to send a ${methodName} request. 19 | * 20 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType},${observerTypeName}) 21 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 22 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 23 | *
  • ServerSideException: if server side problems was detected when processing the request. 24 | *
  • CommunicationException: if communication related problems occurred during the call. 25 | * @throws ValidationException if validation problems found in request or response data. 26 | */ 27 | public void ${methodName}(${requestType} request, ${responseObserverType} responseObserver) throws StatusException,ValidationException{ 28 | StreamObserverWrapper<${apiResponseClassName}.${observerTypeParameterName}> observerWrapper = new StreamObserverWrapper<>(responseObserver, performValidation, "${observerTypeParameterName}"); 29 | getStub().${methodName}((${apiClassName}.${requestType}) processRequest(request), observerWrapper); 30 | } -------------------------------------------------------------------------------- /buildSrc/src/main/resources/BasicGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Getter for ${fieldJsonName}. 4 | */ 5 | ${xmlElement} 6 | public ${fieldJavaType} get${fieldJavaName}() { 7 | return ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(); 8 | } 9 | 10 | /** 11 | * Setter for ${fieldJsonName}. 12 | */ 13 | public void set${fieldJavaName}(${fieldJavaType} value) { 14 | ((${apiClassName}.${className}.Builder) builder).set${fieldJavaName}(value); 15 | } 16 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/ByteStringGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Getter for ${fieldJsonName}. 4 | */ 5 | ${xmlElement} 6 | public byte[] get${fieldJavaName}() { 7 | ByteString value = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(); 8 | if(value != null){ 9 | return value.toByteArray(); 10 | } 11 | return null; 12 | } 13 | 14 | /** 15 | * Setter for ${fieldJsonName}. 16 | */ 17 | public void set${fieldJavaName}(byte[] value) { 18 | if(value != null){ 19 | ((${apiClassName}.${className}.Builder) builder).set${fieldJavaName}(ByteString.copyFrom(value)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/ByteStringListGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | private List ${fieldName} = null; 3 | 4 | /** 5 | * Getter for a list of ${fieldJsonName}. 6 | * @throws ClientSideException if problems occurred constructing the wrapped object. 7 | */ 8 | ${xmlElement} 9 | ${xmlElementWrapper} 10 | public List get${fieldJavaName}() throws ClientSideException{ 11 | if(${fieldName} == null){ 12 | int size = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Count(); 13 | ${fieldName} = new ArrayList<>(size); 14 | for(int i=0; i< size; i++){ 15 | ByteString bs = (ByteString) ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(i); 16 | ${fieldName}.add(bs.toByteArray()); 17 | } 18 | } 19 | return ${fieldName}; 20 | } 21 | 22 | /** 23 | * Setter for list of ${fieldJsonName}. 24 | */ 25 | public void set${fieldJavaName}(List valueList) { 26 | ${fieldName} = valueList; 27 | } 28 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/EnumGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Getter for ${fieldJsonName}. 4 | */ 5 | ${xmlElement} 6 | public ${fieldJavaType} get${fieldJavaName}() { 7 | return ${fieldJavaType}.wrap(((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}()); 8 | } 9 | 10 | /** 11 | * Setter for ${fieldJsonName}. 12 | */ 13 | public void set${fieldJavaName}(${fieldJavaType} value) { 14 | ((${apiClassName}.${className}.Builder) builder).set${fieldJavaName}(value.getApiObject()); 15 | } 16 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/InnerClass.java.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /** 5 | * Inner class ${innerClassName} for class ${className}. 6 | * 7 | * Generated Automatically. 8 | * 9 | * @see org.lightningj.lnd.wrapper.Message 10 | * @see ${apiClassPath}.${className}.${innerClassName} 11 | */ 12 | ${xmlType} 13 | public static class ${innerClassName} extends ${messageType}<${apiClassName}.${className}.${innerClassName}> { 14 | ${innerEnums} 15 | 16 | ${fields} 17 | 18 | /** 19 | * Empty Constructor 20 | */ 21 | public ${innerClassName}(){ 22 | super(${apiClassName}.${className}.${innerClassName}.newBuilder()); 23 | } 24 | 25 | /** 26 | * Json Parsing Constructor 27 | * @throws JsonException if problems was found with the supplied JSON data. 28 | */ 29 | public ${innerClassName}(JsonReader jsonReader) throws JsonException{ 30 | super(jsonReader, ${apiClassName}.${className}.${innerClassName}.newBuilder()); 31 | } 32 | 33 | /** 34 | * Constructor using underlying Lightning API Object 35 | */ 36 | public ${innerClassName}(${apiClassName}.${className}.${innerClassName} apiObject){ 37 | super(apiObject.toBuilder()); 38 | } 39 | 40 | /** 41 | * @return the underlying Lightning API Object Builder. 42 | */ 43 | ${apiClassName}.${className}.${innerClassName}.Builder getBuilder(){ 44 | return (${apiClassName}.${className}.${innerClassName}.Builder) builder; 45 | } 46 | 47 | ${getterAndSetters} 48 | 49 | ${innerClasses} 50 | 51 | ${populateRepeatableFields} 52 | 53 | } 54 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/InnerEnum.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Inner enum ${enumName} for class ${className} 4 | * 5 | * Generated Automatically. 6 | * 7 | * @see ${apiClassPath}.${className}.${enumName} 8 | */ 9 | ${xmlType} 10 | public enum ${enumName} { 11 | ${enumValues} 12 | 13 | private ${apiClassName}.${className}.${enumName} apiObject; 14 | ${enumName}(${apiClassName}.${className}.${enumName} apiObject){ 15 | this.apiObject = apiObject; 16 | } 17 | public ${apiClassName}.${className}.${enumName} getApiObject(){ 18 | return apiObject; 19 | } 20 | 21 | public static ${enumName} wrap(${apiClassName}.${className}.${enumName} apiObject){ 22 | return valueOf(apiObject.name()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/InnerMapClass.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Wrapping class used for conversion between Map and XML notation. 4 | */ 5 | ${entriesXmlType} 6 | public static class ${wrappingClassName}{ 7 | 8 | protected List<${innerClassName}> entry; 9 | 10 | ${xmlElement} 11 | public List<${innerClassName}> getEntry() { 12 | if (entry == null) { 13 | entry = new ArrayList<>(); 14 | } 15 | return this.entry; 16 | } 17 | 18 | } 19 | 20 | /** 21 | * Inner class ${innerClassName} for class ${className}. 22 | * 23 | * 24 | * @see org.lightningj.lnd.wrapper.Message 25 | * Generated Automatically. 26 | */ 27 | ${xmlType} 28 | public static class ${innerClassName} { 29 | 30 | ${fieldKeyType} key; 31 | ${fieldValueType} value; 32 | 33 | /** 34 | * Empty Constructor 35 | */ 36 | public ${innerClassName}(){ 37 | } 38 | 39 | /** 40 | * Json Parsing Constructor 41 | */ 42 | public ${innerClassName}(${fieldKeyType} key, ${fieldValueType} value){ 43 | this.key = key; 44 | this.value = value; 45 | } 46 | 47 | /** 48 | * Getter for key. 49 | */ 50 | ${xmlKeyElement} 51 | public ${fieldKeyType} getKey() { 52 | return key; 53 | } 54 | 55 | /** 56 | * Setter for key. 57 | */ 58 | public void setKey(${fieldKeyType} key) { 59 | this.key = key; 60 | } 61 | 62 | /** 63 | * Getter for value. 64 | */ 65 | ${xmlValueElement} 66 | public ${fieldValueType} getValue() { 67 | return value; 68 | } 69 | 70 | /** 71 | * Setter for value. 72 | */ 73 | public void setValue(${fieldValueType} value) { 74 | this.value = value; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/IntegerListGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | private List ${fieldName} = null; 4 | /** 5 | * Getter for a list of ${fieldJsonName}. 6 | * @throws ClientSideException if problems occurred constructing the wrapped object. 7 | */ 8 | ${xmlElement} 9 | ${xmlElementWrapper} 10 | public List get${fieldJavaName}() throws ClientSideException{ 11 | if(${fieldName} == null){ 12 | int size = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Count(); 13 | ${fieldName} = new ArrayList<>(size); 14 | for(int i=0; i< size; i++){ 15 | ${fieldName}.add(((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(i)); 16 | } 17 | } 18 | return ${fieldName}; 19 | } 20 | 21 | /** 22 | * Setter for list of ${fieldJsonName}. 23 | */ 24 | public void set${fieldJavaName}(List valueList) { 25 | ${fieldName} = valueList; 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/LongListGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | private List ${fieldName} = null; 4 | /** 5 | * Getter for a list of ${fieldJsonName}. 6 | * @throws ClientSideException if problems occurred constructing the wrapped object. 7 | */ 8 | ${xmlElement} 9 | ${xmlElementWrapper} 10 | public List get${fieldJavaName}() throws ClientSideException{ 11 | if(${fieldName} == null){ 12 | int size = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Count(); 13 | ${fieldName} = new ArrayList<>(size); 14 | for(int i=0; i< size; i++){ 15 | ${fieldName}.add(((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(i)); 16 | } 17 | } 18 | return ${fieldName}; 19 | } 20 | 21 | /** 22 | * Setter for list of ${fieldJsonName}. 23 | */ 24 | public void set${fieldJavaName}(List valueList) { 25 | ${fieldName} = valueList; 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/MapGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Returns ${fieldJsonName} as a detached map. I.e. modifications in returned map 4 | * does not affect data in object. A new map is created for each call. 5 | */ 6 | @XmlTransient 7 | public Map<${fieldKeyType},${fieldValueType}> get${fieldJavaName}AsDetachedMap() { 8 | Map<${fieldKeyType},${fieldValueType}> retval = new HashMap<>(); 9 | 10 | for(${fieldJavaName}Entry entry : get${fieldJavaName}Entries().getEntry()){ 11 | retval.put(entry.key,entry.value); 12 | } 13 | 14 | return retval; 15 | } 16 | 17 | /** 18 | * Populates ${fieldJsonName} with all the values in the map. 19 | */ 20 | @XmlTransient 21 | public void set${fieldJavaName}(Map<${fieldKeyType},${fieldValueType}> valueMap) { 22 | if(${fieldName}Entries == null){ 23 | ${fieldName}Entries = new ${fieldJavaName}Entries(); 24 | }else{ 25 | ${fieldName}Entries.getEntry().clear(); 26 | } 27 | for(${fieldKeyType} key : valueMap.keySet()){ 28 | ${fieldName}Entries.getEntry().add(new ${fieldJavaName}Entry(key, valueMap.get(key))); 29 | } 30 | } 31 | 32 | /** 33 | * Gets the map entries as a wrapped list, used for XML conversion. 34 | * 35 | * 36 | */ 37 | ${xmlElement} 38 | public ${className}.${fieldJavaName}Entries get${fieldJavaName}Entries() { 39 | if(${fieldName}Entries == null){ 40 | ${fieldName}Entries = new ${className}.${fieldJavaName}Entries(); 41 | Map<${fieldKeyApiType}, ${fieldValueApiType}> builderMap = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Map(); 42 | for(Map.Entry<${fieldKeyApiType}, ${fieldValueApiType}> entry : builderMap.entrySet()){ 43 | ${fieldName}Entries.getEntry().add(new ${fieldJavaName}Entry(${fieldKeyGetEntry},${fieldValueGetEntry})); 44 | } 45 | } 46 | return ${fieldName}Entries; 47 | } 48 | 49 | /** 50 | * Sets a wrapped list of entries, used for XML conversion. 51 | * 52 | */ 53 | public void set${fieldJavaName}Entries(${className}.${fieldJavaName}Entries entries) { 54 | this.${fieldName}Entries = entries; 55 | } -------------------------------------------------------------------------------- /buildSrc/src/main/resources/MessageGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Getter for a list of ${fieldJsonName}. 4 | * @throws ClientSideException if problems occurred constructing the wrapped object. 5 | */ 6 | ${xmlElement} 7 | public ${fieldJavaType} get${fieldJavaName}() throws ClientSideException{ 8 | return (${fieldJavaType}) wrapperFactory.wrap(((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}()); 9 | } 10 | 11 | /** 12 | * Setter for list of ${fieldJsonName}. 13 | */ 14 | public void set${fieldJavaName}(${fieldJavaType} value) { 15 | ((${apiClassName}.${className}.Builder) builder).set${fieldJavaName}(value.getApiObject()); 16 | } 17 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/MessageListGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | 3 | private List<${fieldJavaType}> ${fieldName} = null; 4 | /** 5 | * Getter for a list of ${fieldJsonName}. 6 | * @throws ClientSideException if problems occurred constructing the wrapped object. 7 | */ 8 | ${xmlElement} 9 | ${xmlElementWrapper} 10 | public List<${fieldJavaType}> get${fieldJavaName}() throws ClientSideException{ 11 | if(${fieldName} == null){ 12 | int size = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Count(); 13 | ${fieldName} = new ArrayList<>(size); 14 | for(int i=0; i< size; i++){ 15 | ${fieldName}.add((${fieldJavaType}) wrapperFactory.wrap(((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(i))); 16 | } 17 | } 18 | return ${fieldName}; 19 | } 20 | 21 | /** 22 | * Setter for list of ${fieldJsonName}. 23 | */ 24 | public void set${fieldJavaName}(List<${fieldJavaType}> valueList) { 25 | ${fieldName} = valueList; 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/RepeatableEnumGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Getter for ${fieldJsonName}. 4 | */ 5 | ${xmlElement} 6 | public List<${fieldJavaType}> get${fieldJavaName}() { 7 | List<${fieldJavaType}> retval = new ArrayList<>(); 8 | for(${fieldApiJavaType} apifeatureBit : ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}List()){ 9 | retval.add(${fieldJavaType}.wrap(apifeatureBit)); 10 | } 11 | return retval; 12 | } 13 | 14 | /** 15 | * Setter for ${fieldJsonName}. 16 | */ 17 | public void set${fieldJavaName}(List<${fieldJavaType}> values) { 18 | ((${apiClassName}.${className}.Builder) builder).clear${fieldJavaName}(); 19 | for(${fieldJavaType} value : values){ 20 | ((${apiClassName}.${className}.Builder) builder).add${fieldJavaName}(value.getApiObject()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/StringListGetterAndSetterSection.java.template: -------------------------------------------------------------------------------- 1 | 2 | private List<${fieldJavaType}> ${fieldName} = null; 3 | 4 | /** 5 | * Getter for a list of ${fieldJsonName}. 6 | * @throws ClientSideException if problems occurred constructing the wrapped object. 7 | */ 8 | ${xmlElement} 9 | ${xmlElementWrapper} 10 | public List<${fieldJavaType}> get${fieldJavaName}() throws ClientSideException{ 11 | if(${fieldName} == null){ 12 | int size = ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}Count(); 13 | ${fieldName} = new ArrayList<>(size); 14 | for(int i=0; i< size; i++){ 15 | ${fieldName}.add((${fieldJavaType}) ((${apiClassName}.${className}.Builder) builder).get${fieldJavaName}(i)); 16 | } 17 | } 18 | return ${fieldName}; 19 | } 20 | 21 | /** 22 | * Setter for list of ${fieldJsonName}. 23 | */ 24 | public void set${fieldJavaName}(List<${fieldJavaType}> valueList) { 25 | ${fieldName} = valueList; 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/SynchronousMethod.java.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Method to generate a ${methodName} request. 3 | * 4 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType}) 5 | * @return a wrapped ${responseType} 6 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 7 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 8 | *
  • ServerSideException: if server side problems was detected when processing the request. 9 | *
  • CommunicationException: if communication related problems occurred during the call. 10 | * @throws ValidationException if validation problems found in request or response data. 11 | */ 12 | public ${responseType} ${methodName}(${parameters}) throws StatusException,ValidationException{ 13 | ${requestType} request = new ${requestType}(); 14 | ${setMethods} 15 | return ${methodName}(request); 16 | } 17 | 18 | /** 19 | * Method to send a ${methodName} request. 20 | * 21 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType}) 22 | * @return a wrapped ${responseType} 23 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 24 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 25 | *
  • ServerSideException: if server side problems was detected when processing the request. 26 | *
  • CommunicationException: if communication related problems occurred during the call. 27 | * @throws ValidationException if validation problems found in request or response data. 28 | */ 29 | public ${responseType} ${methodName}(${requestType} request) throws StatusException,ValidationException{ 30 | try{ 31 | return (${responseType}) processResponse( 32 | new ${responseType}( 33 | getStub().${methodName}( 34 | (${apiClassName}.${requestType}) 35 | processRequest(request)))); 36 | }catch(io.grpc.StatusRuntimeException e){ 37 | throw statusExceptionWrapper.wrap(e); 38 | } 39 | } -------------------------------------------------------------------------------- /buildSrc/src/main/resources/SynchronousRepeatableResponseMethod.java.template: -------------------------------------------------------------------------------- 1 | /** 2 | * Method to generate a ${methodName} request. 3 | * 4 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType}) 5 | * @return a wrapped ${responseType} 6 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 7 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 8 | *
  • ServerSideException: if server side problems was detected when processing the request. 9 | *
  • CommunicationException: if communication related problems occurred during the call. 10 | * @throws ValidationException if validation problems found in request or response data. 11 | */ 12 | public ${responseType} ${methodName}(${parameters}) throws StatusException,ValidationException{ 13 | ${requestType} request = new ${requestType}(); 14 | ${setMethods} 15 | return ${methodName}(request); 16 | } 17 | 18 | /** 19 | * Method to send a ${methodName} request. 20 | * 21 | * @see ${apiPackage}.${grpcClass}.${stubClass}#${methodName}(${apiClassName}.${requestType}) 22 | * @return a wrapped ${responseType} 23 | * @throws StatusException if problems occurred in underlying GRPC call. Can be of one of three sub exceptions 24 | *
  • ClientSideException: if problems was found in the request data, such as invalid or unexpected data. 25 | *
  • ServerSideException: if server side problems was detected when processing the request. 26 | *
  • CommunicationException: if communication related problems occurred during the call. 27 | * @throws ValidationException if validation problems found in request or response data. 28 | */ 29 | public ${responseType} ${methodName}(${requestType} request) throws StatusException,ValidationException{ 30 | try{ 31 | return (${responseType}) processRepeatableResponse( 32 | getStub().${methodName}( 33 | (${apiClassName}.${requestType}) 34 | processRequest(request))); 35 | }catch(io.grpc.StatusRuntimeException e){ 36 | throw statusExceptionWrapper.wrap(e); 37 | } 38 | } -------------------------------------------------------------------------------- /buildSrc/src/main/resources/WrappedEnum.java.template: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package ${wrapperBasePackageName}.message; 15 | 16 | import ${apiClassPath}; 17 | 18 | import ${wrapperBasePackageName}.*; 19 | import jakarta.xml.bind.annotation.*; 20 | ${specialAPIImports} 21 | 22 | /** 23 | * Wrapper enum ${enumName}. 24 | * 25 | * Generated Automatically. 26 | * @see ${apiClassPath}.${enumName} 27 | */ 28 | ${xmlType} 29 | public enum ${enumName} { 30 | ${enumValues} 31 | 32 | private ${apiClassName}.${enumName} apiObject; 33 | ${enumName}(${apiClassName}.${enumName} apiObject){ 34 | this.apiObject = apiObject; 35 | } 36 | 37 | public ${apiClassName}.${enumName} getApiObject(){ 38 | return apiObject; 39 | } 40 | 41 | public static ${enumName} wrap(${apiClassName}.${enumName} apiObject){ 42 | return valueOf(apiObject.name()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/WrappedMessageClass.java.template: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package ${wrapperBasePackageName}.message; 15 | 16 | import ${apiClassPath}; 17 | import org.lightningj.lnd.wrapper.*; 18 | import javax.json.JsonReader; 19 | import javax.json.JsonException; 20 | import com.google.protobuf.ByteString; 21 | import java.util.List; 22 | import java.util.ArrayList; 23 | import java.util.Map; 24 | import java.util.HashMap; 25 | import jakarta.xml.bind.annotation.*; 26 | ${specialAPIImports} 27 | 28 | /** 29 | * Wrapper class for ${className}. 30 | * 31 | * Written by Philip Vendil 32 | * 33 | * @see org.lightningj.lnd.wrapper.Message 34 | * @see ${apiClassPath}.${className} 35 | */ 36 | @XmlRootElement(name = "${className}") 37 | ${xmlType} 38 | public class ${className} extends ${messageType}<${apiClassName}.${className}> { 39 | 40 | ${innerEnums} 41 | ${fields} 42 | 43 | /** 44 | * Empty Constructor 45 | */ 46 | public ${className}(){ 47 | super(${apiClassName}.${className}.newBuilder()); 48 | } 49 | 50 | /** 51 | * Json Parsing Constructor 52 | * 53 | * @throws JsonException if problems was found with the supplied JSON data. 54 | */ 55 | public ${className}(JsonReader jsonReader) throws JsonException{ 56 | super(jsonReader, ${apiClassName}.${className}.newBuilder()); 57 | } 58 | 59 | /** 60 | * Constructor using underlying Lightning API Object 61 | */ 62 | public ${className}(${apiClassName}.${className} apiObject){ 63 | super(apiObject.toBuilder()); 64 | } 65 | 66 | /** 67 | * @return the underlying Lightning API Object Builder. 68 | */ 69 | @XmlTransient 70 | ${apiClassName}.${className}.Builder getBuilder(){ 71 | return (${apiClassName}.${className}.Builder) builder; 72 | } 73 | 74 | ${getterAndSetters} 75 | 76 | ${innerClasses} 77 | 78 | ${populateRepeatableFields} 79 | 80 | } 81 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/package-info.java.template: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | /** 15 | * Autogenerated package-info for Lightning API data structures. 16 | */ 17 | @jakarta.xml.bind.annotation.XmlSchema(namespace = "${namespace}", 18 | xmlns = { 19 | ${externalNameSpaces} 20 | }, 21 | elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED) 22 | @jakarta.xml.bind.annotation.XmlAccessorType(jakarta.xml.bind.annotation.XmlAccessType.PROPERTY) 23 | package ${wrapperBasePackageName}.message; 24 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | www.lightningj.org 2 | -------------------------------------------------------------------------------- /docs/lightningj-release-pubkey.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | 3 | mQENBFp/3DkBCACZ68XwTuSi4CBUT7mPuvvAvCuzG+l9HmHHofS7xIXEbGonjN0B 4 | fPC3qlpsE768aN8Dmd5p8QAoapiUcqOHtKoChrmJ8t0aHXQOdwFNRjYK/7XlT1DX 5 | CItcA3Tkqy6obc8NEl2PNHX5fSJ4cJsICR8FyUiIMmNNc/HVUw4pv3Ub1JRvitX7 6 | nucBdGoYeVaMm5RiJen4UimE3Bg6zxrHE9hCZvtSt7+xXeqyxhTkSLcjbT+6eIMb 7 | c4l4Php0KjqD0dMH//QRdTS7WOgqxCqfBbf77fjnXUsXBGn6u1k8bQUkXFRc/Tdj 8 | xd8DS2H/uOmNanL/DoXXiTu/Zt/yen4qojuNABEBAAG0NmhlcnJ2ZW5kaWwgKFJl 9 | bGVhc2UgU2lnbmluZyBLZXkpIDxpbmZvQGxpZ2h0bmluZ2oub3JnPokBTgQTAQoA 10 | OBYhBHwPgLi9n+O4E4hLoZUVsx3dm7zNBQJaf9w5AhsDBQsJCAcDBRUKCQgLBRYC 11 | AwEAAh4BAheAAAoJEJUVsx3dm7zNtFIH/ihO1BpfHZ9XajX8Wdl2owjdGiHpsblw 12 | b4XFnepKCACojHf5om9aYbL2blUFid86q6VodLHD8uYNFHLcZEEzws2Xf6QWHd3C 13 | WBbk9w6QUQC3W5jRU+t8+uYT/ULyQuGdAITwp0SVeXSAwJWXDe34GPdIh+7Yebdm 14 | ItI5YLzoJsbCnJBH+oVew3RHXKwZK1bJUeRF6bvVNkho8A4aqO0a519F3VElUPcy 15 | ZsKhrFdIeEGU66xO9f0OqNYzsMWKdzdbdfqcSW9B2dHE141j0VOxPzo2UlAOz6+9 16 | N4khTjbF1gQTXLoV4aS5aGsiZPiY5SBvKNi17ZCl0+TZ4QOCtMUUrEG5AQ0EWn/c 17 | OQEIAKde0Mw4ZTnsyy07Y17TmZO0sXibDhbnPjCS0PQhoEsn55fwv7Ds+zfkMg0G 18 | SJahIxOI+jiCTwZ+JpSQIGTINAx7S6bcAEcuwroHAm1QAa+yRtWdlkcnfGTBP+kQ 19 | LezTWwBbqJihDhUCZiY6Vxj9esTUWM9IbQL8SxsxEJlJpVEANpUAXBz4RB2jhnof 20 | P1gzuAqOD9sta043nr89gZQ9Q/fZMhifbzAm4j7Enz0Hrvq7PNTWwlkP9DHnqcjG 21 | 6rhh/xQ0dMJWN6f45fLQrhNuPSaSUSbfv2Y9KDWNf+RFl1E139SnC9ehP1VN3gK1 22 | ZK32tIjnsxBMyLXuk0dqTuVLiV0AEQEAAYkBNgQYAQoAIBYhBHwPgLi9n+O4E4hL 23 | oZUVsx3dm7zNBQJaf9w5AhsgAAoJEJUVsx3dm7zNqVgH/jynr8ktrauMbBgLmVt5 24 | gULaw47jRV0lfU12UVPKR9Xwk5PptyDVk/UYxlcDMUy+spBFhWk+YwOEr6oJBenL 25 | w6Y6bNTrOqtalbG6GTKDyNPBAgzHLNvkuYI1EJjeg1vPjnlLrruNcrqLqYEzTLQj 26 | /oPLfWdbcXuw9xj3Mc3/FzXWzo2hWxiD3GbVj0sC2pW4u8b65BhvLWxLBFmW/YRu 27 | c+QMVEk72bae+ca2OhKQ21Ry6GYyCc9ztgJfIzX5up5HLUOmtix1tYS3bfAdJwlt 28 | eYS6ra6hKGSfo8N63+Xm6Z37sxwDmEl9oYggNU+4BE2EVykP1B7SrlPEE0yzisPg 29 | hpu5AQ0EWn/cOQEIALFG2TaqVWz1ykx8OfqFhuppwq2Mqyz5Zuw/YJGkKPHUxLaH 30 | 5zpKYcjQZgE9swwpYt03x5y+WQBpQvU4dCRTyJDPg/7qVzNuHiFZ7CGA3vV48hqF 31 | eIPwqe5evfPGyTt+YAnXWbLkQnx4A8eRIFr5unH95lAiH6QEJo4XgXmwl9Y9TXcr 32 | bUrDoe3cTb85lLeuHa8cHgRBKaw5P88bAnjZhOWv5wfwEv4YHPjnT8fk2ze50rD8 33 | sHeA1+WIiHqn0pKoOC+3BgycLXjBei9PvLW8zP10tN7qNA9fwzqM+WT2CrpjZ+Tf 34 | y4srVO83vPlgChlL1sHx6Phj5Jse/1iXPoAvQtMAEQEAAYkBNgQYAQoAIBYhBHwP 35 | gLi9n+O4E4hLoZUVsx3dm7zNBQJaf9w5AhsMAAoJEJUVsx3dm7zNQ+cH/1FBEt8A 36 | OHGJ98yqHUA4881QzSUGM/MOKuSg90p8gAUsZG8CB02o9L9z73z0PyCNjSEXKJcu 37 | c8kADUgxwKDWk5DcU0AfiRrBQZDOhUKJqYPCmOMWM+igH6ZdlqO05stwGPHmLxP6 38 | R+sscBR0TNyan0lBcr6YMVy2jY52DsSM+SMbtSuYL1JW8E9AdsckfIttDCDqoI+P 39 | n+RgTOklLr1NsGFLwXn8t71kX7TANBIeiJLsy1LdAvlslx98kR3v4p9cTefXs+o2 40 | JXoTpbVs/kx/p7iD0m2Qplk3H7JSq6DvBO/c36Njz9EiOrY9j5wkUvNdDqEsNd4M 41 | c6JbUIl/DayK2wM= 42 | =NZVd 43 | -----END PGP PUBLIC KEY BLOCK----- -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Maven Central Repository publishing, set correct data in user dir .gradle/gradle.properties 2 | ossrhUsername = 'set in gradle.properties' 3 | ossrhPassword = 'set in gradle.properties' 4 | 5 | grpcVersion=1.61.0 6 | protobufVersion=3.22.5 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningj-org/lightningj/71f9d2dc21a76a889cdaaed24d639af9a105bc79/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /integrationTest.gradle: -------------------------------------------------------------------------------- 1 | 2 | sourceSets{ 3 | integrationTest { 4 | 5 | java{ 6 | srcDirs = ['src/integration-test/java'] 7 | } 8 | 9 | resources{ 10 | srcDirs = ['src/integration-test/resources'] 11 | } 12 | 13 | groovy{ 14 | srcDirs = ['src/integration-test/groovy'] 15 | } 16 | 17 | 18 | compileClasspath += project.sourceSets.main.output 19 | runtimeClasspath += project.sourceSets.main.output 20 | } 21 | } 22 | 23 | configurations { 24 | integrationTestImplementation.extendsFrom testImplementation 25 | integrationTestRuntimeOnly.extendsFrom runtimeOnly 26 | } 27 | 28 | task integrationTest(type: Test, group: "verification", description: "Runs integration tests using live LND node."){ 29 | doFirst{ 30 | def host = project.hasProperty("lightningj.integration.test.lnd.host") ? project.property("lightningj.integration.test.lnd.host") : null 31 | def port = project.hasProperty("lightningj.integration.test.lnd.port") ? project.property("lightningj.integration.test.lnd.port") : null 32 | def tlsCert = project.hasProperty("lightningj.integration.test.lnd.tlscertpath") ? project.property("lightningj.integration.test.lnd.tlscertpath") : null 33 | def macaroon = project.hasProperty("lightningj.integration.test.lnd.macaroonpath") ? project.property("lightningj.integration.test.lnd.macaroonpath") : null 34 | if(!host || !port || !tlsCert || !macaroon){ 35 | println """LND Settings missing in gradle properies. Please update with following properties: 36 | 37 | lightningj.integration.test.lnd.host= 38 | lightningj.integration.test.lnd.port= 39 | lightningj.integration.test.lnd.tlscertpath= 40 | lightningj.integration.test.lnd.macaroonpath= 41 | """ 42 | System.exit(-1) 43 | }else{ 44 | println """Using LND Settings: 45 | host : ${host} 46 | port : ${port} 47 | Path to TLS Cert : ${tlsCert} 48 | Path to Macaroon : ${macaroon} 49 | """ 50 | systemProperty "lightningj.integration.test.lnd.host",host 51 | systemProperty "lightningj.integration.test.lnd.port",port 52 | systemProperty "lightningj.integration.test.lnd.tlscertpath",tlsCert 53 | systemProperty "lightningj.integration.test.lnd.macaroonpath",macaroon 54 | } 55 | } 56 | testClassesDirs = project.sourceSets.integrationTest.output.classesDirs 57 | classpath = project.sourceSets.integrationTest.runtimeClasspath 58 | useJUnitPlatform() 59 | dependsOn(compileWrapperMessages) 60 | } 61 | 62 | integrationTest.shouldRunAfter test 63 | 64 | 65 | /* 66 | Task for specifying for Intellij which source directories to use. 67 | */ 68 | idea { 69 | module { 70 | testSourceDirs += file('src/integration-test/java') 71 | testSourceDirs += file('src/integration-test/groovy') 72 | //testResourceDirs += file('src/integration-test/resources') 73 | 74 | contentRoot = project.projectDir 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'lightningj' 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/examples/lnd/ExampleUtils.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import org.lightningj.lnd.wrapper.AsynchronousLndAPI; 17 | import org.lightningj.lnd.wrapper.ClientSideException; 18 | import org.lightningj.lnd.wrapper.SynchronousLndAPI; 19 | import org.lightningj.lnd.wrapper.message.OpenChannelRequest; 20 | 21 | import javax.net.ssl.SSLException; 22 | import java.io.File; 23 | 24 | /** 25 | * Class that contains utility methods to simplify the example code. 26 | * 27 | * Created by Philip Vendil 28 | */ 29 | public class ExampleUtils { 30 | 31 | static SynchronousLndAPI getSynchronousLndAPI() throws SSLException, ClientSideException { 32 | return new SynchronousLndAPI("localhost",10001,new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"),null); 33 | } 34 | 35 | static AsynchronousLndAPI getAsynchronousLndAPI() throws SSLException, ClientSideException { 36 | return new AsynchronousLndAPI("localhost",10001,new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"),null); 37 | } 38 | 39 | static OpenChannelRequest genOpenChannelRequest() { 40 | OpenChannelRequest openChannelRequest = new OpenChannelRequest(); 41 | openChannelRequest.setNodePubkeyString("02ad1fddad0c572ec3e886cbea31bbafa30b5f7e745da7e936ed9d1471116cdc02"); 42 | openChannelRequest.setLocalFundingAmount(40000); 43 | openChannelRequest.setPushSat(25000); 44 | openChannelRequest.setSatPerByte(0); 45 | return openChannelRequest; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/examples/lnd/ExceptionHandlingExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import io.grpc.stub.StreamObserver; 17 | import org.lightningj.lnd.wrapper.*; 18 | import org.lightningj.lnd.wrapper.message.ChannelBalanceResponse; 19 | 20 | import java.rmi.ServerException; 21 | 22 | import static lnd.ExampleUtils.*; 23 | 24 | /** 25 | * Example of Exception Handling 26 | */ 27 | public class ExceptionHandlingExample { 28 | 29 | public static void main(String[] args) throws Exception{ 30 | 31 | // Get API 32 | SynchronousLndAPI synchronousLndAPI = getSynchronousLndAPI(); 33 | 34 | try{ 35 | // Perform a call 36 | synchronousLndAPI.channelBalance(); 37 | }catch(ValidationException ve){ 38 | // Thrown if request or response contained invalid data 39 | }catch(StatusException se){ 40 | // Thrown if GRPC related exception happened. 41 | } 42 | 43 | // Example of more fine grained exception handling. 44 | try{ 45 | synchronousLndAPI.channelBalance(); 46 | }catch(ValidationException ve){ 47 | // Thrown if request or response contained invalid data 48 | }catch(ClientSideException cse){ 49 | // Thrown if there is some problem on the client side such as invalid request data. 50 | }catch(ServerSideException sse){ 51 | // Thrown if there is some problem on the server side that might persist for some time. 52 | }catch(CommunicationException ce){ 53 | // Thrown if communication problems occurred such as timeout or dropped package and request can be retried. 54 | } 55 | 56 | AsynchronousLndAPI asynchronousLndAPI = getAsynchronousLndAPI(); 57 | 58 | asynchronousLndAPI.channelBalance(new StreamObserver() { 59 | @Override 60 | public void onNext(ChannelBalanceResponse value) { 61 | // Handle ok resonses 62 | } 63 | 64 | @Override 65 | public void onError(Throwable t) { 66 | // Here is exceptions sent of same type as thrown by synchronous API. 67 | } 68 | 69 | @Override 70 | public void onCompleted() { 71 | // Call completed 72 | } 73 | }); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/examples/lnd/JSONConvertExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | 17 | import org.lightningj.lnd.wrapper.SynchronousLndAPI; 18 | import org.lightningj.lnd.wrapper.message.OpenChannelRequest; 19 | import org.lightningj.lnd.wrapper.message.OpenStatusUpdate; 20 | 21 | import javax.json.Json; 22 | import javax.json.JsonObjectBuilder; 23 | import javax.json.JsonReader; 24 | import java.io.StringReader; 25 | import java.util.Iterator; 26 | 27 | import static lnd.ExampleUtils.getSynchronousLndAPI; 28 | /** 29 | * This example shows how to parse and generate JSON data from high level wrapper objects. 30 | * 31 | * Created by Philip Vendil. 32 | */ 33 | public class JSONConvertExample { 34 | 35 | public static void main(String[] args) throws Exception{ 36 | 37 | // Get API 38 | SynchronousLndAPI synchronousLndAPI = getSynchronousLndAPI(); 39 | 40 | // To convert JSON request data to a wrapped request object (High level) 41 | // Do the following 42 | String jsonData = "{\"node_pubkey\":\"\",\"node_pubkey_string\":\"02ad1fddad0c572ec3e886cbea31bbafa30b5f7e745da7e936ed9d1471116cdc02\",\"local_funding_amount\":40000,\"push_sat\":25000,\"targetConf\":0,\"satPerByte\":0,\"private\":false,\"min_htlc_msat\":0}"; 43 | 44 | // The library uses the javax.json-api 1.0 (JSR 374) API to parse and generate JSON. 45 | // To parse a JSON String, start by creating a JsonReader 46 | JsonReader jsonReader = Json.createReader(new StringReader(jsonData)); 47 | 48 | // Then parse by creating a Wrapped Message object. 49 | OpenChannelRequest openChannelRequest = new OpenChannelRequest(jsonReader); 50 | 51 | // Perform the call. 52 | Iterator result = synchronousLndAPI.openChannel(openChannelRequest); 53 | 54 | // This call will wait for a the channel has opened, which means confirmation block must 55 | // generated in btc. If simnet is used you can manually generate blocks with 56 | // 'btcctl --simnet --rpcuser=kek --rpcpass=kek generate 3' 57 | 58 | while(result.hasNext()){ 59 | // To generate JSON from a response there are three possiblities, either 60 | OpenStatusUpdate next = result.next(); 61 | // To get JSON as String 62 | System.out.println("Received Update: " + next.toJsonAsString(false)); 63 | // To have the result more human readable set pretty print to true 64 | System.out.println("Received Update: " + next.toJsonAsString(true)); 65 | // It is also possible to get the JSON as a populated JsonObjectBuilder 66 | JsonObjectBuilder jsonObjectBuilder = next.toJson(); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/examples/lnd/LoggingExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import org.lightningj.lnd.wrapper.SynchronousLndAPI; 17 | import org.lightningj.lnd.wrapper.message.ChannelBalanceResponse; 18 | 19 | import java.util.logging.Handler; 20 | import java.util.logging.Level; 21 | import java.util.logging.Logger; 22 | 23 | /** 24 | * Created by philip on 2018-01-19. 25 | */ 26 | public class LoggingExample extends ExampleUtils{ 27 | 28 | public static void main(String[] args) throws Exception{ 29 | 30 | // This code sets log level programmatically, this should in a real world application 31 | // Be done in an external log configuration. This is only to show request and response debug logging 32 | // when turned on. 33 | Handler[] handlers = Logger.getLogger(LoggingExample.class.getName()).getParent().getHandlers(); 34 | for (Handler handler : handlers) { 35 | handler.setLevel(Level.FINE); 36 | } 37 | Logger logger = Logger.getLogger("org.lightningj.lnd.wrapper.API");//API.class.getName()); 38 | logger.setLevel(Level.FINE); 39 | 40 | 41 | SynchronousLndAPI synchronousLndAPI = getSynchronousLndAPI(); 42 | 43 | // Generate a request and output is written to stderr. 44 | ChannelBalanceResponse channelBalanceResponse = synchronousLndAPI.channelBalance(); 45 | System.out.println("Exiting"); 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/examples/lnd/LowLevelAPIExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import io.grpc.ManagedChannel; 17 | import io.grpc.StatusRuntimeException; 18 | import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts; 19 | import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder; 20 | import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext; 21 | import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder; 22 | import io.grpc.netty.shaded.io.netty.handler.ssl.SslProvider; 23 | import org.lightningj.lnd.proto.LightningApi; 24 | import org.lightningj.lnd.proto.LightningGrpc; 25 | 26 | 27 | import java.io.File; 28 | 29 | 30 | /** 31 | * Example on how to use the low level GRPC-Java API 32 | */ 33 | public class LowLevelAPIExample { 34 | 35 | public static void main(String[] args) throws Exception{ 36 | 37 | File trustedServerCertificate = new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"); 38 | // Method to create SSL Context, trusting a specified LND node TLS certificate. 39 | // It is possible to customize the SSL setting by supplying a javax.net.ssl.SSLContext as well 40 | SslContext sslContext = GrpcSslContexts.configure(SslContextBuilder.forClient().forClient(), SslProvider.OPENSSL) 41 | .trustManager(trustedServerCertificate) 42 | .build(); 43 | 44 | // Then create a managed communication channed 45 | ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 10001) 46 | .sslContext(sslContext) 47 | .build(); 48 | 49 | // Then create the low level API by calling. 50 | LightningGrpc.LightningBlockingStub stub = LightningGrpc.newBlockingStub(channel); 51 | // To create asynchronous API us LightningGrpc.newStub(channel) 52 | 53 | // Create a request object using messages in "org.lightningj.lnd.proto.LightningApi" 54 | LightningApi.WalletBalanceRequest.Builder walletBalanceRequest = LightningApi.WalletBalanceRequest.newBuilder(); 55 | try{ 56 | LightningApi.WalletBalanceResponse response = stub.walletBalance(walletBalanceRequest.build()); 57 | System.out.println("Wallet Balance: " + response.getTotalBalance()); 58 | }catch(StatusRuntimeException sre){ 59 | // Handle exceptions a with status code in sre.getStatus() 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/examples/lnd/ValidationExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import org.lightningj.lnd.wrapper.*; 17 | import org.lightningj.lnd.wrapper.message.OpenChannelRequest; 18 | 19 | import java.util.List; 20 | 21 | import static lnd.ExampleUtils.*; 22 | 23 | /** 24 | * Example of validation API. 25 | */ 26 | public class ValidationExample { 27 | 28 | public static void main(String[] args) throws Exception{ 29 | 30 | // Validation is features to validate that in and outgoing messages fulfills 31 | // requirements in defined Proto Specification. 32 | 33 | // Get API 34 | SynchronousLndAPI synchronousLndAPI = getSynchronousLndAPI(); 35 | 36 | // To manually validate a wrapped Message it is possible to call the validate() method. 37 | OpenChannelRequest openChannelRequest = genOpenChannelRequest(); 38 | // To validate call validate() and it will return ValidationResult 39 | ValidationResult validationResult = openChannelRequest.validate(); 40 | // The ValidationResult.isValid() returns true if the message was valud. 41 | validationResult.isValid(); 42 | // If there is problems it is possible to retrieve the problems found either 43 | // in a single aggregated list for all sub-messages. 44 | List allProblems= validationResult.getAggregatedValidationErrors(); 45 | // Or as a tree structure with all problems in this message in: 46 | validationResult.getMessageErrors(); 47 | // and all sub messages as their own report. 48 | validationResult.getSubMessageResults(); 49 | 50 | 51 | try{ 52 | // Each call might throw a ValidationException 53 | synchronousLndAPI.channelBalance(); 54 | }catch(ValidationException ve){ 55 | // A ValidationException has the faulty messages ValidationReport as a field. 56 | ValidationResult vr = ve.getValidationResult(); 57 | }catch(StatusException se){ 58 | //... 59 | } 60 | 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/examples/lnd/XMLConvertExample.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package lnd; 15 | 16 | import org.lightningj.lnd.wrapper.SynchronousLndAPI; 17 | import org.lightningj.lnd.wrapper.XMLParser; 18 | import org.lightningj.lnd.wrapper.XMLParserFactory; 19 | import org.lightningj.lnd.wrapper.message.OpenChannelRequest; 20 | import org.lightningj.lnd.wrapper.message.OpenStatusUpdate; 21 | 22 | import java.util.Iterator; 23 | 24 | import static lnd.ExampleUtils.getSynchronousLndAPI; 25 | 26 | /** 27 | * Example on how to convert a wrapped object to XML. 28 | * 29 | * Created by Philip Vendil 30 | */ 31 | public class XMLConvertExample { 32 | 33 | public static void main(String[] args) throws Exception{ 34 | 35 | // Get API 36 | SynchronousLndAPI synchronousLndAPI = getSynchronousLndAPI(); 37 | 38 | // Create a XMLParserFactory 39 | XMLParserFactory xmlParserFactory = new XMLParserFactory(); 40 | 41 | // Retrieve XML Parser for a given XML version schema. (Currently "1.0") 42 | XMLParser xmlParser = xmlParserFactory.getXMLParser("1.0"); 43 | 44 | byte[] xmlRequestData = "02ad1fddad0c572ec3e886cbea31bbafa30b5f7e745da7e936ed9d1471116cdc02400002500000false0".getBytes("UTF-8"); 45 | 46 | // Convert to a wrapped high level message object. 47 | OpenChannelRequest openChannelRequest = (OpenChannelRequest) xmlParser.unmarshall(xmlRequestData); 48 | 49 | // Perform the call. 50 | Iterator result = synchronousLndAPI.openChannel(openChannelRequest); 51 | 52 | // This call will wait for a the channel has opened, which means confirmation block must 53 | // generated in btc. If simnet is used you can manually generate blocks with 54 | // 'btcctl --simnet --rpcuser=kek --rpcpass=kek generate 3' 55 | 56 | while(result.hasNext()){ 57 | // To generate XML from a response do the following: 58 | OpenStatusUpdate next = result.next(); 59 | // To get XML as byte[] 60 | byte[] responseData = xmlParser.marshall(next); 61 | System.out.println("XML Response data: " + new String(responseData,"UTF-8")); 62 | // To get XML pretty printed 63 | byte[] responseDataPrettyPrinted = xmlParser.marshall(next,true); 64 | System.out.println("Pretty Printed XML Response data: " + new String(responseDataPrettyPrinted,"UTF-8")); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/StateServiceIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import org.lightningj.lnd.wrapper.stateservice.SynchronousStateServiceAPI 17 | import org.lightningj.lnd.wrapper.stateservice.AsynchronousStateServiceAPI 18 | 19 | import spock.lang.Shared 20 | import spock.lang.Specification 21 | 22 | /** 23 | * Integration tests running the autopilot APIs against a live test-net LND node. 24 | */ 25 | class StateServiceIntegrationSpec extends Specification{ 26 | 27 | @Shared String lndHost 28 | @Shared int lndPort 29 | @Shared File tlsCertPath 30 | @Shared File macaroonPath 31 | 32 | SynchronousStateServiceAPI synchronousAPI 33 | AsynchronousStateServiceAPI asynchronousAPI 34 | 35 | def setupSpec(){ 36 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 37 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 38 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 39 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 40 | } 41 | 42 | def setup(){ 43 | asynchronousAPI = new AsynchronousStateServiceAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 44 | synchronousAPI = new SynchronousStateServiceAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 45 | } 46 | 47 | //@Ignore // Wait until proper instructions on how to enable to API. 48 | def "Test to verify state service api is available"(){ 49 | expect: 50 | synchronousAPI.getState() != null 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/autopilot/AutopilotIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.autopilot 15 | 16 | import io.grpc.stub.StreamObserver 17 | import org.lightningj.lnd.wrapper.AsynchronousLndAPI 18 | import org.lightningj.lnd.wrapper.SynchronousLndAPI 19 | import org.lightningj.lnd.wrapper.autopilot.message.StatusRequest 20 | import org.lightningj.lnd.wrapper.autopilot.message.StatusResponse 21 | import org.lightningj.lnd.wrapper.message.AddInvoiceResponse 22 | import org.lightningj.lnd.wrapper.message.ChannelGraph 23 | import org.lightningj.lnd.wrapper.message.Invoice 24 | import spock.lang.Ignore 25 | import spock.lang.Shared 26 | import spock.lang.Specification 27 | 28 | /** 29 | * Integration tests running the autopilot APIs against a live test-net LND node. 30 | */ 31 | class AutopilotIntegrationSpec extends Specification{ 32 | 33 | @Shared String lndHost 34 | @Shared int lndPort 35 | @Shared File tlsCertPath 36 | @Shared File macaroonPath 37 | 38 | SynchronousAutopilotAPI synchronousAPI 39 | AsynchronousAutopilotAPI asynchronousAPI 40 | 41 | def setupSpec(){ 42 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 43 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 44 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 45 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 46 | } 47 | 48 | def setup(){ 49 | asynchronousAPI = new AsynchronousAutopilotAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 50 | synchronousAPI = new SynchronousAutopilotAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 51 | } 52 | 53 | //@Ignore // Wait until proper instructions on how to enable to API. 54 | def "Test to verify autopilot api is available"(){ 55 | expect: 56 | synchronousAPI.status() != null 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/chainkit/ChainKitIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.chainkit 15 | 16 | 17 | import spock.lang.Shared 18 | import spock.lang.Specification 19 | 20 | /** 21 | * Integration tests running the chainkit client APIs against a live test-net LND node. 22 | */ 23 | class ChainKitIntegrationSpec extends Specification{ 24 | 25 | 26 | @Shared String lndHost 27 | @Shared int lndPort 28 | @Shared File tlsCertPath 29 | @Shared File macaroonPath 30 | 31 | SynchronousChainKitAPI synchronousAPI 32 | AsynchronousChainKitAPI asynchronousAPI 33 | 34 | def setupSpec(){ 35 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 36 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 37 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 38 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 39 | } 40 | 41 | def setup(){ 42 | asynchronousAPI = new AsynchronousChainKitAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 43 | synchronousAPI = new SynchronousChainKitAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 44 | } 45 | 46 | def "Test to verify chainkit api is available"(){ 47 | expect: 48 | synchronousAPI.getBlockHash(123L) != null 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/dev/DevIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.dev 15 | 16 | 17 | import org.lightningj.lnd.wrapper.peers.AsynchronousPeersAPI 18 | import org.lightningj.lnd.wrapper.peers.SynchronousPeersAPI 19 | import spock.lang.Shared 20 | import spock.lang.Specification 21 | 22 | /** 23 | * Integration tests running the nautrino APIs against a live test-net LND node. 24 | */ 25 | class DevIntegrationSpec extends Specification{ 26 | 27 | @Shared String lndHost 28 | @Shared int lndPort 29 | @Shared File tlsCertPath 30 | @Shared File macaroonPath 31 | 32 | SynchronousDevAPI synchronousAPI 33 | AsynchronousDevAPI asynchronousAPI 34 | 35 | def setupSpec(){ 36 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 37 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 38 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 39 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 40 | } 41 | 42 | def setup(){ 43 | asynchronousAPI = new AsynchronousDevAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 44 | synchronousAPI = new SynchronousDevAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 45 | } 46 | 47 | def "Test to verify dev api is available"(){ 48 | expect: 49 | synchronousAPI.importGraph([],[]) 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/neutrino/NeutrinoIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.neutrino 15 | 16 | 17 | import org.lightningj.lnd.wrapper.autopilot.AsynchronousAutopilotAPI 18 | import org.lightningj.lnd.wrapper.autopilot.SynchronousAutopilotAPI 19 | import spock.lang.Shared 20 | import spock.lang.Specification 21 | 22 | /** 23 | * Integration tests running the nautrino APIs against a live test-net LND node. 24 | */ 25 | class NeutrinoIntegrationSpec extends Specification{ 26 | 27 | @Shared String lndHost 28 | @Shared int lndPort 29 | @Shared File tlsCertPath 30 | @Shared File macaroonPath 31 | 32 | SynchronousNeutrinoAPI synchronousAPI 33 | AsynchronousNeutrinoAPI asynchronousAPI 34 | 35 | def setupSpec(){ 36 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 37 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 38 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 39 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 40 | } 41 | 42 | def setup(){ 43 | asynchronousAPI = new AsynchronousNeutrinoAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 44 | synchronousAPI = new SynchronousNeutrinoAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 45 | } 46 | 47 | //@Ignore // Wait until proper instructions on how to enable to API. 48 | def "Test to verify neutrino api is available"(){ 49 | expect: 50 | synchronousAPI.status() != null 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/peers/PeersIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.peers 15 | 16 | 17 | import org.lightningj.lnd.wrapper.neutrino.AsynchronousNeutrinoAPI 18 | import org.lightningj.lnd.wrapper.neutrino.SynchronousNeutrinoAPI 19 | import org.lightningj.lnd.wrapper.peers.message.UpdateAddressAction 20 | import org.lightningj.lnd.wrapper.peers.message.UpdateFeatureAction 21 | import spock.lang.Shared 22 | import spock.lang.Specification 23 | 24 | import java.security.SecureRandom 25 | 26 | /** 27 | * Integration tests running the nautrino APIs against a live test-net LND node. 28 | */ 29 | class PeersIntegrationSpec extends Specification{ 30 | 31 | @Shared String lndHost 32 | @Shared int lndPort 33 | @Shared File tlsCertPath 34 | @Shared File macaroonPath 35 | 36 | SynchronousPeersAPI synchronousAPI 37 | AsynchronousPeersAPI asynchronousAPI 38 | 39 | def setupSpec(){ 40 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 41 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 42 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 43 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 44 | } 45 | 46 | def setup(){ 47 | asynchronousAPI = new AsynchronousPeersAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 48 | synchronousAPI = new SynchronousPeersAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 49 | } 50 | 51 | //@Ignore // Wait until proper instructions on how to enable to API. 52 | def "Test to verify peers api is available"(){ 53 | expect: 54 | synchronousAPI.updateNodeAnnouncement([],null,randomString(),[]) 55 | } 56 | 57 | static final char[] AliasCharset = "abcdefghijklmnopqrstqvst".toCharArray() 58 | 59 | String randomString(){ 60 | char[] retval = new char[10] 61 | for(int i=0;i<10;i++){ 62 | retval[i] = AliasCharset[SecureRandom.getInstanceStrong().nextInt(AliasCharset.length-1)] 63 | } 64 | return new String(retval) 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/verrpc/VersioningIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.verrpc 15 | 16 | 17 | import spock.lang.Shared 18 | import spock.lang.Specification 19 | 20 | /** 21 | * Integration tests running the versioning APIs against a live test-net LND node. 22 | */ 23 | class VersioningIntegrationSpec extends Specification{ 24 | 25 | @Shared String lndHost 26 | @Shared int lndPort 27 | @Shared File tlsCertPath 28 | @Shared File macaroonPath 29 | 30 | SynchronousVersionerAPI synchronousAPI 31 | AsynchronousVersionerAPI asynchronousAPI 32 | 33 | def setupSpec(){ 34 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 35 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 36 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 37 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 38 | } 39 | 40 | def setup(){ 41 | asynchronousAPI = new AsynchronousVersionerAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 42 | synchronousAPI = new SynchronousVersionerAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 43 | } 44 | 45 | def "Test to verify version api is available"(){ 46 | expect: 47 | synchronousAPI.getVersion() != null 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/watchtower/WatchtowerIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.watchtower 15 | 16 | 17 | import spock.lang.Shared 18 | import spock.lang.Specification 19 | 20 | /** 21 | * Integration tests running the watchtower APIs against a live test-net LND node. 22 | */ 23 | class WatchtowerIntegrationSpec extends Specification{ 24 | 25 | @Shared String lndHost 26 | @Shared int lndPort 27 | @Shared File tlsCertPath 28 | @Shared File macaroonPath 29 | 30 | SynchronousWatchtowerAPI synchronousAPI 31 | AsynchronousWatchtowerAPI asynchronousAPI 32 | 33 | def setupSpec(){ 34 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 35 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 36 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 37 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 38 | } 39 | 40 | def setup(){ 41 | asynchronousAPI = new AsynchronousWatchtowerAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 42 | synchronousAPI = new SynchronousWatchtowerAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 43 | } 44 | 45 | def "Test to verify watchtower api is available"(){ 46 | expect: 47 | synchronousAPI.getInfo() != null 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/integration-test/groovy/org/lightningj/lnd/wrapper/wtclient/WtclientIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.wtclient 15 | 16 | import org.lightningj.lnd.wrapper.watchtower.AsynchronousWatchtowerAPI 17 | import org.lightningj.lnd.wrapper.watchtower.SynchronousWatchtowerAPI 18 | import spock.lang.Shared 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Integration tests running the watchtower client APIs against a live test-net LND node. 23 | */ 24 | class WtclientIntegrationSpec extends Specification{ 25 | 26 | @Shared String lndHost 27 | @Shared int lndPort 28 | @Shared File tlsCertPath 29 | @Shared File macaroonPath 30 | 31 | SynchronousWatchtowerClientAPI synchronousAPI 32 | AsynchronousWatchtowerClientAPI asynchronousAPI 33 | 34 | def setupSpec(){ 35 | lndHost = System.getProperty("lightningj.integration.test.lnd.host") 36 | lndPort = Integer.parseInt(System.getProperty("lightningj.integration.test.lnd.port")) 37 | tlsCertPath = new File(System.getProperty("lightningj.integration.test.lnd.tlscertpath")) 38 | macaroonPath = new File(System.getProperty("lightningj.integration.test.lnd.macaroonpath")) 39 | } 40 | 41 | def setup(){ 42 | asynchronousAPI = new AsynchronousWatchtowerClientAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 43 | synchronousAPI = new SynchronousWatchtowerClientAPI(lndHost,lndPort,tlsCertPath, macaroonPath) 44 | } 45 | 46 | def "Test to verify watchtower client api is available"(){ 47 | expect: 48 | synchronousAPI.listTowers(true,false) 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/util/ValidationUtils.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.util; 15 | 16 | import com.google.protobuf.Descriptors; 17 | import com.google.protobuf.Message; 18 | import com.google.protobuf.MessageLiteOrBuilder; 19 | import org.lightningj.lnd.wrapper.ValidationProblems; 20 | import org.lightningj.lnd.wrapper.ValidationResult; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Helper class with methods to perform validation of Message objects. 26 | * 27 | * Created by Philip Vendil. 28 | */ 29 | public class ValidationUtils { 30 | 31 | 32 | /** 33 | * Method to validate a message and generate a validation result. 34 | *

    35 | * This method hasn't been tested properly since there currently are no validation requirements 36 | * in the proto specification. 37 | *

    38 | * @param messageOrBuilder the message or builder to validate. 39 | * @param messageDescriptor the related message descriptor. 40 | * @return a ValidationResult containing all found validation errors. 41 | */ 42 | public static ValidationResult validateMessage(MessageLiteOrBuilder messageOrBuilder, Descriptors.Descriptor messageDescriptor){ 43 | ValidationResult retval = new ValidationResult(messageDescriptor.getName()); 44 | for(Descriptors.FieldDescriptor fieldDescriptor : messageDescriptor.getFields()){ 45 | if(fieldDescriptor.isRequired()){ 46 | Object field=null; 47 | if(messageOrBuilder instanceof Message.Builder){ 48 | field = ((Message.Builder) messageOrBuilder).getField(fieldDescriptor); 49 | } 50 | if(messageOrBuilder instanceof Message){ 51 | field = ((Message) messageOrBuilder).getField(fieldDescriptor); 52 | } 53 | if(field == null){ 54 | ValidationProblems ve = new ValidationProblems(messageDescriptor.getName(),fieldDescriptor.getName(),"lightningj.validation.fieldisrequired", new Object[]{fieldDescriptor.getName()},"Field " + fieldDescriptor.getName() + " is required."); 55 | retval.getMessageErrors().add(ve); 56 | }else { 57 | if (fieldDescriptor.isRepeated() && ((List) field).size() == 0){ 58 | ValidationProblems ve = new ValidationProblems(messageDescriptor.getName(),fieldDescriptor.getName(),"lightningj.validation.fieldisrequired", new Object[]{fieldDescriptor.getName()},"Field " + fieldDescriptor.getName() + " is required."); 59 | retval.getMessageErrors().add(ve); 60 | } 61 | } 62 | 63 | if(fieldDescriptor.getJavaType() == Descriptors.FieldDescriptor.JavaType.MESSAGE){ 64 | ValidationResult subMessageResult = validateMessage((Message) field, fieldDescriptor.getMessageType()); 65 | if(!subMessageResult.isValid()){ 66 | retval.getSubMessageResults().add(subMessageResult); 67 | } 68 | } 69 | } 70 | } 71 | return retval; 72 | } 73 | 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/AsynchronousAPI.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.ManagedChannel; 17 | import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext; 18 | 19 | import javax.net.ssl.SSLException; 20 | import java.io.File; 21 | 22 | /** 23 | * Base call for all Asynchronous API implementations. 24 | * 25 | * Created by Philip Vendil. 26 | */ 27 | abstract public class AsynchronousAPI extends API{ 28 | 29 | /** 30 | * Minimal constructor for setting up a connection with LND Application. 31 | * 32 | * @param host the hostname of ldn application 33 | * @param port the port of the application. 34 | * @param trustedServerCertificate a link of the SSL certificate used by the LND Application. 35 | * @param macaroonFile the file pointing to the macaroon to use, or null if no macaroons are used. 36 | * @throws SSLException if problems occurred setting up the SSL Connection. 37 | * @throws ClientSideException if problems occurred reading the macaroon file. 38 | */ 39 | protected AsynchronousAPI(String host, int port, File trustedServerCertificate, File macaroonFile) throws SSLException, ClientSideException { 40 | super(host, port, trustedServerCertificate, macaroonFile); 41 | } 42 | 43 | /** 44 | * Constructor for setting up a connection with LND Application with more flexible 45 | * SSL context parameters. 46 | * 47 | * @param host the hostname of ldn application 48 | * @param port the port of the application. 49 | * @param sslContext the SSL Context used when connecting the LND Application. 50 | * @param macaroonContext the macaroon context to use. 51 | */ 52 | protected AsynchronousAPI(String host, int port, SslContext sslContext, MacaroonContext macaroonContext) { 53 | super(host, port, sslContext, macaroonContext); 54 | } 55 | 56 | /** 57 | * Constructor used for setting up a connection using a GRPC managed channel that 58 | * can be customized. 59 | * 60 | * @param channel the managed channel to use. 61 | */ 62 | protected AsynchronousAPI(ManagedChannel channel) { 63 | super(channel); 64 | } 65 | 66 | 67 | /** 68 | * Method to convert and validate (if validation is enabled) a response from LDN Server to a wrapped object. 69 | * 70 | * @param responseMessage the response message to convert 71 | * @return a wrapped response message 72 | * @throws ValidationException exception containing a validation report with all validation 73 | * problems found, if validation is used. 74 | */ 75 | protected Message processResponse(Message responseMessage) throws ValidationException{ 76 | log.fine("Received response message: " + responseMessage.toString()); 77 | // TODO add tracetimes 78 | validate(responseMessage); 79 | return responseMessage; 80 | } 81 | 82 | 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/ClientSideException.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.Status; 17 | 18 | /** 19 | * Exception indicating an error occurred on client side which 20 | * indicate there is some problem on the client side such 21 | * as invalid request data. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | public class ClientSideException extends StatusException { 26 | 27 | /** 28 | * Exception indicating an error occurred on client side which 29 | * indicate there is some problem on the client side such 30 | * as invalid request data. 31 | * 32 | * @param message detail message of the exception. 33 | * @param status The underlying GRPC status code, might be null. 34 | */ 35 | public ClientSideException(String message, Status status) { 36 | super(message, status); 37 | } 38 | 39 | /** 40 | * Exception indicating an error occurred on client side which 41 | * indicate there is some problem on the client side such 42 | * as invalid request data. 43 | * 44 | * @param message detail message of the exception. 45 | * @param status The underlying GRPC status code, might be null. 46 | * @param cause the underlying exception. 47 | */ 48 | public ClientSideException(String message, Status status, Throwable cause) { 49 | super(message, status, cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/CommunicationException.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.Status; 17 | 18 | /** 19 | * Exception indicating an error occurred when communicating 20 | * with server. This could indicate timeout or dropped package 21 | * and request can be retried. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | public class CommunicationException extends StatusException { 26 | 27 | /** 28 | * Exception indicating an error occurred when communicating 29 | * with server. This could indicate timeout or dropped package 30 | * and request can be retried. 31 | * 32 | * @param message detail message of the exception. 33 | * @param status The underlying GRPC status code, might be null. 34 | */ 35 | public CommunicationException(String message, Status status) { 36 | super(message, status); 37 | } 38 | 39 | /** 40 | * Exception indicating an error occurred when communicating 41 | * with server. This could indicate timeout or dropped package 42 | * and request can be retried. 43 | * 44 | * @param message detail message of the exception. 45 | * @param status The underlying GRPC status code, might be null. 46 | * @param cause the underlying exception. 47 | */ 48 | public CommunicationException(String message, Status status, Throwable cause) { 49 | super(message, status, cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/MacaroonClientInterceptor.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | 17 | import io.grpc.*; 18 | 19 | import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; 20 | 21 | /** 22 | * Macaroon Client Call Interceptor used to inject current macaroon into each GRPC call. 23 | * 24 | * @see MacaroonContext 25 | * Created by Philip Vendil on 2018-02-03. 26 | */ 27 | public class MacaroonClientInterceptor implements io.grpc.ClientInterceptor { 28 | 29 | private static final Metadata.Key MACAROON_METADATA_KEY = Metadata.Key.of("macaroon", ASCII_STRING_MARSHALLER); 30 | 31 | private MacaroonContext macaroonContext; 32 | 33 | 34 | public MacaroonClientInterceptor(MacaroonContext macaroonContext) { 35 | this.macaroonContext = macaroonContext; 36 | 37 | } 38 | 39 | /** 40 | * Intercept {@link ClientCall} creation by the {@code next} {@link Channel}. 41 | *

    42 | *

    Many variations of interception are possible. Complex implementations may return a wrapper 43 | * around the result of {@code next.newCall()}, whereas a simpler implementation may just modify 44 | * the header metadata prior to returning the result of {@code next.newCall()}. 45 | *

    46 | *

    {@code next.newCall()} must not be called under a different {@link Context} 47 | * other than the current {@code Context}. The outcome of such usage is undefined and may cause 48 | * memory leak due to unbounded chain of {@code Context}s. 49 | * 50 | * @param method the remote method to be called. 51 | * @param callOptions the runtime options to be applied to this call. 52 | * @param next the channel which is being intercepted. 53 | * @return the call object for the remote operation, never {@code null}. 54 | */ 55 | @Override 56 | public ClientCall interceptCall(MethodDescriptor method, CallOptions callOptions, Channel next) { 57 | return new ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOptions)) { 58 | @Override 59 | public void start(Listener responseListener, Metadata headers) { 60 | String macaroonData = null; 61 | if(macaroonContext != null){ 62 | macaroonData = macaroonContext.getCurrentMacaroonAsHex(); 63 | } 64 | if(macaroonData != null) { 65 | headers.put(MACAROON_METADATA_KEY, macaroonData); 66 | } 67 | super.start(responseListener, headers); 68 | } 69 | }; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/MacaroonContext.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | 17 | 18 | /** 19 | * Interface for MacaroonContext used to manage which Macaroon that should be used 20 | * for API calls. 21 | * 22 | * @see org.lightningj.lnd.wrapper.StaticFileMacaroonContext 23 | * 24 | * Created by Philip Vendil on 2018-02-04. 25 | */ 26 | public interface MacaroonContext { 27 | 28 | /** 29 | * Method that should return the macaroon in serialized (hex encoded form) that should be used in header 30 | * for calls towards server node. 31 | * 32 | * @return the current macaroon or null of no valid macaroon is available. 33 | */ 34 | String getCurrentMacaroonAsHex(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/ServerSideException.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.Status; 17 | 18 | /** 19 | * Exception indicating an error occurred on server side which 20 | * indicate there is some problem on the server side that might 21 | * persist for some time. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | public class ServerSideException extends StatusException { 26 | 27 | /** 28 | * Exception indicating an error occurred on server side which 29 | * indicate there is some problem on the server side that might 30 | * persist for some time. 31 | * 32 | * @param message detail message of the exception. 33 | * @param status The underlying GRPC status code, might be null. 34 | */ 35 | public ServerSideException(String message, Status status) { 36 | super(message, status); 37 | } 38 | 39 | /** 40 | * Exception indicating an error occurred on server side which 41 | * indicate there is some problem on the server side that might 42 | * persist for some time. 43 | * 44 | * @param message detail message of the exception. 45 | * @param status The underlying GRPC status code, might be null. 46 | * @param cause the underlying exception. 47 | */ 48 | public ServerSideException(String message, Status status, Throwable cause) { 49 | super(message, status, cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/StaticFileMacaroonContext.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | 17 | import jakarta.xml.bind.DatatypeConverter; 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | 21 | /** 22 | * MacaroonContext that reads a static file during construction 23 | * and returns the macaroon content for each calls. 24 | * 25 | * @see org.lightningj.lnd.wrapper.MacaroonContext 26 | * 27 | * Created by Philip Vendil on 2018-02-04. 28 | */ 29 | public class StaticFileMacaroonContext implements MacaroonContext{ 30 | 31 | String currentMacaroonData; 32 | /** 33 | * Constructor to read a specified macaroon path. 34 | * 35 | * @param macaroonPath the path to the macaroon to be used. 36 | * @throws ClientSideException if problem occurs during reading or parsing of macaroon data. status is null. 37 | */ 38 | public StaticFileMacaroonContext(File macaroonPath) throws ClientSideException{ 39 | try { 40 | FileInputStream fis = new FileInputStream(macaroonPath); 41 | byte[] data = new byte[fis.available()]; 42 | fis.read(data); 43 | fis.close(); 44 | 45 | currentMacaroonData = DatatypeConverter.printHexBinary(data); 46 | }catch(Exception e){ 47 | throw new ClientSideException("Error reading macaroon from path '" + macaroonPath + "', message: " + e.getMessage(),null,e); 48 | } 49 | } 50 | 51 | /** 52 | * Method that should return the macaroon that should be used in header for calls towards server node. 53 | * 54 | * @return the current macaroon or null of no valid macaroon is available. 55 | */ 56 | @Override 57 | public String getCurrentMacaroonAsHex() { 58 | return currentMacaroonData; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/StatusException.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.Status; 17 | 18 | /** 19 | * Base exception that is wrapped around GRPC status. 20 | * 21 | * Created by Philip Vendil. 22 | */ 23 | public abstract class StatusException extends Exception{ 24 | 25 | private Status status; 26 | 27 | public StatusException(String message, Status status){ 28 | super(message); 29 | this.status = status; 30 | } 31 | 32 | public StatusException(String message, Status status, Throwable cause){ 33 | super(message, cause); 34 | this.status=status; 35 | } 36 | 37 | /** 38 | * @return the underlying GRPC status code, might be null 39 | * if no related status code could be found. 40 | */ 41 | public Status getStatus(){ 42 | return status; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/StatusExceptionWrapper.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import io.grpc.Status; 17 | import io.grpc.StatusException; 18 | import io.grpc.StatusRuntimeException; 19 | 20 | 21 | /** 22 | * Class wrapping a GRPC status exception. 23 | * 24 | * Created by Philip Vendil. 25 | */ 26 | public class StatusExceptionWrapper { 27 | 28 | private static final StatusExceptionWrapper instance = new StatusExceptionWrapper(); 29 | 30 | /** 31 | * 32 | * @return returns a singleton instance of the StatusExceptionWrapper. 33 | */ 34 | public static StatusExceptionWrapper getInstance(){ 35 | return instance; 36 | } 37 | 38 | /** 39 | * Method that will wrap a StatusRuntimeException or StatusException to either 40 | * a ClientSideException/CommunicationException/ServerSideException (which all are a StatusException). 41 | * 42 | * 43 | * @param e the exception to wrap, should be either StatusRuntimeException or StatusException. 44 | * @throws org.lightningj.lnd.wrapper.StatusException the converted exception. Either a ClientSideException, 45 | * CommunicationException or ServerSideException. 46 | * @see org.lightningj.lnd.wrapper.ClientSideException 47 | * @see org.lightningj.lnd.wrapper.CommunicationException 48 | * @see org.lightningj.lnd.wrapper.ServerSideException 49 | */ 50 | public org.lightningj.lnd.wrapper.StatusException wrap(Exception e) { 51 | if(e instanceof StatusRuntimeException || e instanceof StatusException){ 52 | Status status = null; 53 | if(e instanceof StatusRuntimeException){ 54 | status = ((StatusRuntimeException) e).getStatus(); 55 | } 56 | if(e instanceof StatusException){ 57 | status = ((StatusException) e).getStatus(); 58 | } 59 | if(status != null) { 60 | assert status != Status.OK; 61 | 62 | switch (status.getCode()) { 63 | case CANCELLED: 64 | case INVALID_ARGUMENT: 65 | case NOT_FOUND: 66 | case ALREADY_EXISTS: 67 | case PERMISSION_DENIED: 68 | case OUT_OF_RANGE: 69 | case UNAUTHENTICATED: 70 | return new ClientSideException(e.getMessage(),status,e); 71 | case DEADLINE_EXCEEDED: 72 | case UNAVAILABLE: 73 | return new CommunicationException(e.getMessage(),status,e); 74 | default: 75 | return new ServerSideException(e.getMessage(),status,e); 76 | } 77 | } 78 | return new ServerSideException("Internal Error, couldn't determine status in GRPC call.",null,e); 79 | } 80 | return new ServerSideException("Internal Error, cannot convert exception of type: " +e.getClass().getSimpleName(), null,e); 81 | } 82 | 83 | 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/V1XMLParser.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import java.net.URL; 17 | 18 | /** 19 | * LND Version 1 implementation of XML Api 20 | * Created by Philip Vendil. 21 | */ 22 | public class V1XMLParser extends XMLParser { 23 | 24 | /** 25 | * @return return the version of the related Lnd API. 26 | */ 27 | @Override 28 | protected String getVersion() { 29 | return "1.0"; 30 | } 31 | 32 | /** 33 | * @return the resource location of the related schemas. 34 | */ 35 | @Override 36 | protected String[] getSchemaLocations() { 37 | return new String[]{ 38 | "/lnd_v1.xsd", 39 | "/autopilot_v1.xsd", 40 | "/chainnotifier_v1.xsd", 41 | "/chainkit_v1.xsd", 42 | "/invoices_v1.xsd", 43 | "/router_v1.xsd", 44 | "/signer_v1.xsd", 45 | "/walletkit_v1.xsd", 46 | "/watchtower_v1.xsd", 47 | "/wtclient_v1.xsd", 48 | "/verrpc_v1.xsd", 49 | "/walletunlocker_v1.xsd", 50 | "/stateservice_v1.xsd", 51 | "/dev_v1.xsd", 52 | "/neutrino_v1.xsd", 53 | "/peers_v1.xsd" 54 | }; 55 | } 56 | 57 | /** 58 | * @return the JAXB class path used for JAXBContext separated with ':' 59 | */ 60 | @Override 61 | protected String getJAXBClassPath() { 62 | return "org.lightningj.lnd.wrapper.message:" + 63 | "org.lightningj.lnd.wrapper.autopilot.message:"+ 64 | "org.lightningj.lnd.wrapper.chainnotifier.message:"+ 65 | "org.lightningj.lnd.wrapper.chainkit.message:"+ 66 | "org.lightningj.lnd.wrapper.invoices.message:"+ 67 | "org.lightningj.lnd.wrapper.router.message:"+ 68 | "org.lightningj.lnd.wrapper.signer.message:"+ 69 | "org.lightningj.lnd.wrapper.walletkit.message:" + 70 | "org.lightningj.lnd.wrapper.watchtower.message:" + 71 | "org.lightningj.lnd.wrapper.wtclient.message:" + 72 | "org.lightningj.lnd.wrapper.verrpc.message:" + 73 | "org.lightningj.lnd.wrapper.walletunlocker.message:" + 74 | "org.lightningj.lnd.wrapper.stateservice.message:" + 75 | "org.lightningj.lnd.wrapper.dev.message:" + 76 | "org.lightningj.lnd.wrapper.neutrino.message:" + 77 | "org.lightningj.lnd.wrapper.peers.message"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/ValidationException.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | /** 17 | * Exception indicating an error occurred validating a message. 18 | * Contains an attached validation result with details of message and 19 | * field that failed validation. 20 | * 21 | * 22 | * Created by Philip Vendil. 23 | */ 24 | public class ValidationException extends Exception { 25 | 26 | private ValidationResult validationResult; 27 | 28 | /** 29 | * Exception indicating an error occurred validating a message. 30 | * Contains an attached validation result with details of message and 31 | * field that failed validation. 32 | * 33 | * @param message detail message of the exception. 34 | * @param validationResult the validation result containing all validation problems found. 35 | */ 36 | public ValidationException(String message, ValidationResult validationResult) { 37 | super(message); 38 | this.validationResult = validationResult; 39 | } 40 | 41 | /** 42 | * Exception indicating an error occurred validating a message. 43 | * Contains an attached validation result with details of message and 44 | * field that failed validation. 45 | * 46 | * @param message detail message of the exception. 47 | * @param validationResult the validation result containing all validation problems found. 48 | * @param cause the underlying exception. 49 | */ 50 | public ValidationException(String message, ValidationResult validationResult, Throwable cause) { 51 | super(message, cause); 52 | this.validationResult = validationResult; 53 | } 54 | 55 | /** 56 | * @return attached validation result containing details of message and 57 | * field that failed validation. 58 | */ 59 | public ValidationResult getValidationResult(){ 60 | return validationResult; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/ValidationProblems.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | /** 17 | * Class containing validation problem information about which field and description 18 | * of the problem. 19 | * 20 | * Created by Philip Vendil. 21 | */ 22 | public class ValidationProblems { 23 | 24 | private String messageType; 25 | private String field; 26 | private String descriptionResourceKey; 27 | private Object[] resourceParameters=null; 28 | private String description; 29 | 30 | /** 31 | * Main constructor of a new Validation Problem. 32 | * 33 | * @param messageType the type of message that contained the validation problem. 34 | * @param field the field in the message that contained the validation problem. 35 | * @param descriptionResourceKey the message resource key to get a translatable description. 36 | * @param description a description of the validation problem found. 37 | */ 38 | public ValidationProblems(String messageType, String field, String descriptionResourceKey, String description) { 39 | this.messageType = messageType; 40 | this.field = field; 41 | this.descriptionResourceKey = descriptionResourceKey; 42 | this.description = description; 43 | } 44 | 45 | /** 46 | * Main constructor of a new Validation Problem. 47 | * 48 | * @param messageType the type of message that contained the validation problem. 49 | * @param field the field in the message that contained the validation problem. 50 | * @param descriptionResourceKey the message resource key to get a translatable description. 51 | * @param resourceParameters an array of resource parameters used for locale substitutions 52 | * in message bundles. 53 | * @param description a description of the validation problem found. 54 | */ 55 | public ValidationProblems(String messageType, String field, String descriptionResourceKey, Object[] resourceParameters, String description) { 56 | this.messageType = messageType; 57 | this.field = field; 58 | this.descriptionResourceKey = descriptionResourceKey; 59 | this.resourceParameters = resourceParameters; 60 | this.description = description; 61 | } 62 | 63 | /** 64 | * 65 | * @return the type of message that contained the validation problem. 66 | */ 67 | public String getMessageType() { 68 | return messageType; 69 | } 70 | 71 | /** 72 | * 73 | * @return the field in the message that contained the validation problem. 74 | */ 75 | public String getField() { 76 | return field; 77 | } 78 | 79 | /** 80 | * 81 | * @return the message resource key to get a translatable description. 82 | */ 83 | public String getDescriptionResourceKey() { 84 | return descriptionResourceKey; 85 | } 86 | 87 | /** 88 | * 89 | * @return a description of the validation problem found. 90 | */ 91 | public String getDescription() { 92 | return description; 93 | } 94 | 95 | /** 96 | * 97 | * @return returns an array of resource parameters used for locale substitutions 98 | * in message bundles. 99 | */ 100 | public Object[] getResourceParameters() { 101 | return resourceParameters; 102 | } 103 | 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/WrapperFactory.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import com.google.protobuf.GeneratedMessageV3; 17 | import io.grpc.Status; 18 | 19 | import java.lang.reflect.Constructor; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * Wrapper factory converting a GRPC Message into it's wrapper object. 25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | public class WrapperFactory { 29 | 30 | private static final Map wrapperPackages = new HashMap<>(); 31 | static { 32 | wrapperPackages.put("org.lightningj.lnd.proto.LightningApi$","org.lightningj.lnd.wrapper.message."); 33 | wrapperPackages.put("org.lightningj.lnd.autopilot.proto.AutopilotOuterClass$","org.lightningj.lnd.wrapper.autopilot.message."); 34 | wrapperPackages.put("org.lightningj.lnd.chainnotifier.proto.ChainNotifierOuterClass$","org.lightningj.lnd.wrapper.chainnotifier.message."); 35 | wrapperPackages.put("org.lightningj.lnd.invoices.proto.InvoicesOuterClass$"," org.lightningj.lnd.wrapper.invoices.message."); 36 | wrapperPackages.put("org.lightningj.lnd.router.proto.RouterOuterClass$","org.lightningj.lnd.wrapper.router.message."); 37 | wrapperPackages.put("org.lightningj.lnd.signer.proto.SignerOuterClass$","org.lightningj.lnd.wrapper.signer.message."); 38 | wrapperPackages.put("org.lightningj.lnd.walletkit.proto.WalletKitOuterClass$","org.lightningj.lnd.wrapper.walletkit.message."); 39 | } 40 | 41 | 42 | private static final WrapperFactory instance = new WrapperFactory(); 43 | 44 | /** 45 | * 46 | * @return returns a singleton instance of the WrapperFactory. 47 | */ 48 | public static WrapperFactory getInstance(){ 49 | return instance; 50 | } 51 | 52 | 53 | /** 54 | * Method to wrap an GRPC object to it's wrapped object. 55 | * 56 | * @param apiObject the GRPC object to wrap 57 | * @return the wrapped variant of the GRPC object. 58 | * @throws ClientSideException if problems occurred constructing the wrapped object. 59 | */ 60 | public Message wrap(GeneratedMessageV3 apiObject) throws ClientSideException{ 61 | Class c; 62 | try { 63 | String sourceName = apiObject.getClass().getName(); 64 | String className = null; 65 | for(String sourcePackage : wrapperPackages.keySet()) 66 | if(sourceName.startsWith(sourcePackage)){ 67 | sourceName = sourceName.substring(sourcePackage.length()); 68 | String targetBasePackage = wrapperPackages.get(sourcePackage); 69 | className = targetBasePackage + sourceName; 70 | } 71 | if(className == null){ 72 | throw new ClientSideException("Error looking up wrapper class, verify that wrapper class for API class: " + apiObject.getClass().getName() + " exists.", Status.INTERNAL); 73 | } 74 | c = WrapperFactory.class.getClassLoader().loadClass(className); 75 | }catch(Exception e){ 76 | throw new ClientSideException("Error converting GRPC object " + apiObject.getClass().getSimpleName() + " to wrapped object, message: " + e.getMessage(),null,e); 77 | } 78 | try { 79 | Constructor constructor = c.getConstructor(apiObject.getClass()); 80 | return (Message) constructor.newInstance(apiObject); 81 | }catch(Exception e){ 82 | throw new ClientSideException("Error constructing wrapper for GRPC object " + apiObject.getClass().getSimpleName() + ", message: " + e.getMessage(),null,e); 83 | } 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/lightningj/lnd/wrapper/XMLParserFactory.java: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | import java.util.Set; 19 | 20 | /** 21 | * Factory class to retrieve Singleton XML Parser within the factory instance. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | public class XMLParserFactory { 26 | 27 | 28 | private Map xmlParsers = new HashMap<>(); 29 | 30 | /** 31 | * Constructor for new XMLParser that initiates all supported versions of XML Parsers. 32 | * 33 | */ 34 | public XMLParserFactory(){ 35 | XMLParser v1Parser = new V1XMLParser(); 36 | xmlParsers.put(v1Parser.getVersion(),v1Parser); 37 | } 38 | 39 | /** 40 | * Method to retrieve the XMLParser for a given version. 41 | * 42 | * @param version the version to retrieve. 43 | * @return the corresponding XMLParser. 44 | * @throws IllegalArgumentException if unsupported version found. 45 | */ 46 | public XMLParser getXMLParser(String version) throws IllegalArgumentException{ 47 | XMLParser retval = xmlParsers.get(version); 48 | if(retval == null){ 49 | throw new IllegalArgumentException("Error no XML Parser with version " + version + " supported."); 50 | } 51 | return retval; 52 | } 53 | 54 | /** 55 | * Returns a set of supported XML Parser versions. 56 | * 57 | * @return a set of supported XML Parser versions. 58 | */ 59 | public Set getSupportedVersions(){ 60 | return xmlParsers.keySet(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/proto/autopilot.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (71c58c2) tag : Downloaded 2020-08-12 5 | */ 6 | syntax = "proto3"; 7 | 8 | package autopilotrpc; 9 | 10 | option java_package = "org.lightningj.lnd.autopilot.proto"; 11 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"; 12 | 13 | // Autopilot is a service that can be used to get information about the current 14 | // state of the daemon's autopilot agent, and also supply it with information 15 | // that can be used when deciding where to open channels. 16 | service Autopilot { 17 | /* 18 | Status returns whether the daemon's autopilot agent is active. 19 | */ 20 | rpc Status (StatusRequest) returns (StatusResponse); 21 | 22 | /* 23 | ModifyStatus is used to modify the status of the autopilot agent, like 24 | enabling or disabling it. 25 | */ 26 | rpc ModifyStatus (ModifyStatusRequest) returns (ModifyStatusResponse); 27 | 28 | /* 29 | QueryScores queries all available autopilot heuristics, in addition to any 30 | active combination of these heruristics, for the scores they would give to 31 | the given nodes. 32 | */ 33 | rpc QueryScores (QueryScoresRequest) returns (QueryScoresResponse); 34 | 35 | /* 36 | SetScores attempts to set the scores used by the running autopilot agent, 37 | if the external scoring heuristic is enabled. 38 | */ 39 | rpc SetScores (SetScoresRequest) returns (SetScoresResponse); 40 | } 41 | 42 | message StatusRequest { 43 | } 44 | 45 | message StatusResponse { 46 | // Indicates whether the autopilot is active or not. 47 | bool active = 1; 48 | } 49 | 50 | message ModifyStatusRequest { 51 | // Whether the autopilot agent should be enabled or not. 52 | bool enable = 1; 53 | } 54 | 55 | message ModifyStatusResponse { 56 | } 57 | 58 | message QueryScoresRequest { 59 | repeated string pubkeys = 1; 60 | 61 | // If set, we will ignore the local channel state when calculating scores. 62 | bool ignore_local_state = 2; 63 | } 64 | 65 | message QueryScoresResponse { 66 | message HeuristicResult { 67 | string heuristic = 1; 68 | map scores = 2; 69 | } 70 | 71 | repeated HeuristicResult results = 1; 72 | } 73 | 74 | message SetScoresRequest { 75 | // The name of the heuristic to provide scores to. 76 | string heuristic = 1; 77 | 78 | /* 79 | A map from hex-encoded public keys to scores. Scores must be in the range 80 | [0.0, 1.0]. 81 | */ 82 | map scores = 2; 83 | } 84 | 85 | message SetScoresResponse { 86 | } -------------------------------------------------------------------------------- /src/main/proto/chainkit.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (35bfd27) tag : Downloaded 2023-11-21 5 | */ 6 | syntax = "proto3"; 7 | 8 | package chainrpc; 9 | 10 | option java_package = "org.lightningj.lnd.chainkit.proto"; 11 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/chainrpc"; 12 | 13 | // ChainKit is a service that can be used to get information from the 14 | // chain backend. 15 | service ChainKit { 16 | /* lncli: `chain getblock` 17 | GetBlock returns a block given the corresponding block hash. 18 | */ 19 | rpc GetBlock (GetBlockRequest) returns (GetBlockResponse); 20 | 21 | /* lncli: `chain getblockheader` 22 | GetBlockHeader returns a block header with a particular block hash. 23 | */ 24 | rpc GetBlockHeader (GetBlockHeaderRequest) returns (GetBlockHeaderResponse); 25 | 26 | /* lncli: `chain getbestblock` 27 | GetBestBlock returns the block hash and current height from the valid 28 | most-work chain. 29 | */ 30 | rpc GetBestBlock (GetBestBlockRequest) returns (GetBestBlockResponse); 31 | 32 | /* lncli: `chain getblockhash` 33 | GetBlockHash returns the hash of the block in the best blockchain 34 | at the given height. 35 | */ 36 | rpc GetBlockHash (GetBlockHashRequest) returns (GetBlockHashResponse); 37 | } 38 | 39 | message GetBlockRequest { 40 | // The hash of the requested block. 41 | bytes block_hash = 1; 42 | } 43 | 44 | // TODO(ffranr): The neutrino GetBlock response includes many 45 | // additional helpful fields. Consider adding them here also. 46 | message GetBlockResponse { 47 | // The raw bytes of the requested block. 48 | bytes raw_block = 1; 49 | } 50 | 51 | message GetBlockHeaderRequest { 52 | // The hash of the block with the requested header. 53 | bytes block_hash = 1; 54 | } 55 | 56 | message GetBlockHeaderResponse { 57 | // The header of the block with the requested hash. 58 | bytes raw_block_header = 1; 59 | } 60 | 61 | message GetBestBlockRequest { 62 | } 63 | 64 | message GetBestBlockResponse { 65 | // The hash of the best block. 66 | bytes block_hash = 1; 67 | 68 | // The height of the best block. 69 | int32 block_height = 2; 70 | } 71 | 72 | message GetBlockHashRequest { 73 | // Block height of the target best chain block. 74 | int64 block_height = 1; 75 | } 76 | 77 | message GetBlockHashResponse { 78 | // The hash of the best block at the specified height. 79 | bytes block_hash = 1; 80 | } -------------------------------------------------------------------------------- /src/main/proto/dev.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (a5849bb) tag : Downloaded 2022-05-29 5 | */ 6 | syntax = "proto3"; 7 | 8 | import "lightning.api.proto"; 9 | 10 | package devrpc; 11 | 12 | option java_package = "org.lightningj.lnd.dev.proto"; 13 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/devrpc"; 14 | 15 | service Dev { 16 | /* 17 | ImportGraph imports a ChannelGraph into the graph database. Should only be 18 | used for development. 19 | */ 20 | rpc ImportGraph (lnrpc.ChannelGraph) returns (ImportGraphResponse); 21 | } 22 | 23 | message ImportGraphResponse { 24 | } -------------------------------------------------------------------------------- /src/main/proto/peers.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (9a368f0) tag : Downloaded 2023-02-25 5 | */ 6 | syntax = "proto3"; 7 | 8 | import "lightning.api.proto"; 9 | 10 | package peersrpc; 11 | 12 | option java_package = "org.lightningj.lnd.peers.proto"; 13 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/peersrpc"; 14 | 15 | // Peers is a service that can be used to get information and interact 16 | // with the other nodes of the network. 17 | service Peers { 18 | /* lncli: peers updatenodeannouncement 19 | UpdateNodeAnnouncement allows the caller to update the node parameters 20 | and broadcasts a new version of the node announcement to its peers. 21 | */ 22 | rpc UpdateNodeAnnouncement (NodeAnnouncementUpdateRequest) 23 | returns (NodeAnnouncementUpdateResponse); 24 | } 25 | 26 | // UpdateAction is used to determine the kind of action we are referring to. 27 | enum UpdateAction { 28 | // ADD indicates this is an "insertion" kind of action. 29 | ADD = 0; 30 | 31 | // REMOVE indicates this is a "deletion" kind of action. 32 | REMOVE = 1; 33 | } 34 | 35 | enum FeatureSet { 36 | /* 37 | SET_INIT identifies features that should be sent in an Init message to 38 | a remote peer. 39 | */ 40 | SET_INIT = 0; 41 | 42 | /* 43 | SET_LEGACY_GLOBAL identifies features that should be set in the legacy 44 | GlobalFeatures field of an Init message, which maintains backwards 45 | compatibility with nodes that haven't implemented flat features. 46 | */ 47 | SET_LEGACY_GLOBAL = 1; 48 | 49 | /* 50 | SET_NODE_ANN identifies features that should be advertised on node 51 | announcements. 52 | */ 53 | SET_NODE_ANN = 2; 54 | 55 | /* 56 | SET_INVOICE identifies features that should be advertised on invoices 57 | generated by the daemon. 58 | */ 59 | SET_INVOICE = 3; 60 | 61 | /* 62 | SET_INVOICE_AMP identifies the features that should be advertised on 63 | AMP invoices generated by the daemon. 64 | */ 65 | SET_INVOICE_AMP = 4; 66 | } 67 | 68 | message UpdateAddressAction { 69 | // Determines the kind of action. 70 | UpdateAction action = 1; 71 | 72 | // The address used to apply the update action. 73 | string address = 2; 74 | } 75 | 76 | message UpdateFeatureAction { 77 | // Determines the kind of action. 78 | UpdateAction action = 1; 79 | 80 | // The feature bit used to apply the update action. 81 | lnrpc.FeatureBit feature_bit = 2; 82 | } 83 | 84 | message NodeAnnouncementUpdateRequest { 85 | // Set of changes for the features that the node supports. 86 | repeated UpdateFeatureAction feature_updates = 1; 87 | 88 | // Color is the node's color in hex code format. 89 | string color = 2; 90 | 91 | // Alias or nick name of the node. 92 | string alias = 3; 93 | 94 | // Set of changes for the node's known addresses. 95 | repeated UpdateAddressAction address_updates = 4; 96 | } 97 | 98 | message NodeAnnouncementUpdateResponse { 99 | repeated lnrpc.Op ops = 1; 100 | } -------------------------------------------------------------------------------- /src/main/proto/stateservice.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (96326e0) tag : Downloaded 2023-02-25 5 | */ 6 | syntax = "proto3"; 7 | 8 | package lnrpc; 9 | 10 | option java_package = "org.lightningj.lnd.stateservice.proto"; 11 | option go_package = "github.com/lightningnetwork/lnd/lnrpc"; 12 | 13 | /* 14 | * Comments in this file will be directly parsed into the API 15 | * Documentation as descriptions of the associated method, message, or field. 16 | * These descriptions should go right above the definition of the object, and 17 | * can be in either block or // comment format. 18 | * 19 | * An RPC method can be matched to an lncli command by placing a line in the 20 | * beginning of the description in exactly the following format: 21 | * lncli: `methodname` 22 | * 23 | * Failure to specify the exact name of the command will cause documentation 24 | * generation to fail. 25 | * 26 | * More information on how exactly the gRPC documentation is generated from 27 | * this proto file can be found here: 28 | * https://github.com/lightninglabs/lightning-api 29 | */ 30 | 31 | // State service is a always running service that exposes the current state of 32 | // the wallet and RPC server. 33 | service State { 34 | // SubscribeState subscribes to the state of the wallet. The current wallet 35 | // state will always be delivered immediately. 36 | rpc SubscribeState (SubscribeStateRequest) 37 | returns (stream SubscribeStateResponse); 38 | 39 | // GetState returns the current wallet state without streaming further 40 | // changes. 41 | rpc GetState (GetStateRequest) returns (GetStateResponse); 42 | } 43 | 44 | enum WalletState { 45 | // NON_EXISTING means that the wallet has not yet been initialized. 46 | NON_EXISTING = 0; 47 | 48 | // LOCKED means that the wallet is locked and requires a password to unlock. 49 | LOCKED = 1; 50 | 51 | // UNLOCKED means that the wallet was unlocked successfully, but RPC server 52 | // isn't ready. 53 | UNLOCKED = 2; 54 | 55 | // RPC_ACTIVE means that the lnd server is active but not fully ready for 56 | // calls. 57 | RPC_ACTIVE = 3; 58 | 59 | // SERVER_ACTIVE means that the lnd server is ready to accept calls. 60 | SERVER_ACTIVE = 4; 61 | 62 | // WAITING_TO_START means that node is waiting to become the leader in a 63 | // cluster and is not started yet. 64 | WAITING_TO_START = 255; 65 | } 66 | 67 | message SubscribeStateRequest { 68 | } 69 | 70 | message SubscribeStateResponse { 71 | WalletState state = 1; 72 | } 73 | 74 | message GetStateRequest { 75 | } 76 | 77 | message GetStateResponse { 78 | WalletState state = 1; 79 | } -------------------------------------------------------------------------------- /src/main/proto/verrpc.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (71c58c2) tag : Downloaded 2020-08-12 5 | */ 6 | syntax = "proto3"; 7 | 8 | package verrpc; 9 | 10 | option java_package = "org.lightningj.lnd.verrpc.proto"; 11 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/verrpc"; 12 | 13 | // Versioner is a service that can be used to get information about the version 14 | // and build information of the running daemon. 15 | service Versioner { 16 | /* lncli: `version` 17 | GetVersion returns the current version and build information of the running 18 | daemon. 19 | */ 20 | rpc GetVersion (VersionRequest) returns (Version); 21 | } 22 | 23 | message VersionRequest { 24 | } 25 | 26 | message Version { 27 | // A verbose description of the daemon's commit. 28 | string commit = 1; 29 | 30 | // The SHA1 commit hash that the daemon is compiled with. 31 | string commit_hash = 2; 32 | 33 | // The semantic version. 34 | string version = 3; 35 | 36 | // The major application version. 37 | uint32 app_major = 4; 38 | 39 | // The minor application version. 40 | uint32 app_minor = 5; 41 | 42 | // The application patch number. 43 | uint32 app_patch = 6; 44 | 45 | // The application pre-release modifier, possibly empty. 46 | string app_pre_release = 7; 47 | 48 | // The list of build tags that were supplied during compilation. 49 | repeated string build_tags = 8; 50 | 51 | // The version of go that compiled the executable. 52 | string go_version = 9; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/proto/watchtower.proto: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is fetched from https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto 3 | * And is distributed under LNDs MIT License. 4 | * LND (71c58c2) tag : Downloaded 2020-08-12 5 | */ 6 | syntax = "proto3"; 7 | 8 | package watchtowerrpc; 9 | 10 | option java_package = "org.lightningj.lnd.watchtower.proto"; 11 | option go_package = "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"; 12 | 13 | // Watchtower is a service that grants access to the watchtower server 14 | // functionality of the daemon. 15 | service Watchtower { 16 | /* lncli: tower info 17 | GetInfo returns general information concerning the companion watchtower 18 | including its public key and URIs where the server is currently 19 | listening for clients. 20 | */ 21 | rpc GetInfo (GetInfoRequest) returns (GetInfoResponse); 22 | } 23 | 24 | message GetInfoRequest { 25 | } 26 | 27 | message GetInfoResponse { 28 | // The public key of the watchtower. 29 | bytes pubkey = 1; 30 | 31 | // The listening addresses of the watchtower. 32 | repeated string listeners = 2; 33 | 34 | // The URIs of the watchtower. 35 | repeated string uris = 3; 36 | } -------------------------------------------------------------------------------- /src/main/resources/lightningj_messages.properties: -------------------------------------------------------------------------------- 1 | lightningj.validation.fieldisrequired = Field {0} is required. -------------------------------------------------------------------------------- /src/main/resources/lightningj_messages_sv.properties: -------------------------------------------------------------------------------- 1 | lightningj.validation.fieldisrequired = F\u00E4lt {0} \u00E4r obligatoriskt. -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/TestUtils.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj 15 | 16 | import javax.json.Json 17 | import javax.json.JsonReader 18 | 19 | /** 20 | * Class containing static test util methods. 21 | * 22 | * Created by Philip Vendil. 23 | */ 24 | class TestUtils { 25 | 26 | /** 27 | * Help method that creates a Json Reader with given input. 28 | * @param jsonData string representation of JSON data 29 | * @return a newly created JsonReader 30 | */ 31 | static JsonReader jsonRead(String jsonData){ 32 | return Json.createReader(new StringReader(jsonData)) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/util/ValidationUtilsSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.util 15 | 16 | import com.google.protobuf.Descriptors 17 | import org.lightningj.lnd.proto.LightningApi 18 | import spock.lang.Specification 19 | 20 | /** 21 | * Unit tests for ValidationUtils. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | class ValidationUtilsSpec extends Specification { 26 | 27 | def "Verify that no fields in LightningApi is required, and propert testing cannot be performed"(){ 28 | 29 | when: 30 | boolean foundRequired = false 31 | LightningApi.getDescriptor().messageTypes.each{ 32 | it.fields.each{ Descriptors.FieldDescriptor fieldDescriptor -> 33 | if(fieldDescriptor.required){ 34 | foundRequired = true 35 | } 36 | 37 | } 38 | } 39 | then: 40 | !foundRequired 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/AsynchronousAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | import java.util.logging.Logger 20 | 21 | /** 22 | * Unit tests for AsynchronousAPI methods. 23 | * 24 | * Created by Philip Vendil. 25 | */ 26 | class AsynchronousAPISpec extends Specification { 27 | 28 | AsynchronousLndAPI api = new AsynchronousLndAPI(Mock(ManagedChannel)) 29 | 30 | def setup(){ 31 | api.log = Mock(Logger) 32 | } 33 | 34 | def "AsynchronousLndAPI initializes constructors properly."(){ 35 | setup: 36 | File macaroonPath = new File(this.getClass().getResource("/admin.macaroon").path) 37 | when: // This constructor 38 | AsynchronousLndAPI api1 = new AsynchronousLndAPI("localhost",8080,new File("src/test/resources/cert.pem"), macaroonPath) 39 | then: 40 | api1.channel != null 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/ClientSideExceptionSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | 15 | package org.lightningj.lnd.wrapper 16 | 17 | import io.grpc.Status 18 | import spock.lang.Specification 19 | 20 | /** 21 | * Unit tests of ClientSideException. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | class ClientSideExceptionSpec extends Specification { 26 | 27 | def "Verify that constructor populated fields properly"(){ 28 | when: 29 | ClientSideException e = new ClientSideException("SomeMessage", Status.ABORTED) 30 | then: 31 | e.message == "SomeMessage" 32 | e.status == Status.ABORTED 33 | when: 34 | e = new ClientSideException("SomeMessage", Status.ABORTED, new IOException()) 35 | then: 36 | e.message == "SomeMessage" 37 | e.status == Status.ABORTED 38 | e.cause instanceof IOException 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/CommunicationExceptionSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import io.grpc.Status 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests CommunicationException. 21 | * 22 | * Created by Philip Vendil. 23 | */ 24 | class CommunicationExceptionSpec extends Specification { 25 | 26 | def "Verify that constructor populated fields properly"(){ 27 | when: 28 | CommunicationException e = new CommunicationException("SomeMessage", Status.ABORTED) 29 | then: 30 | e.message == "SomeMessage" 31 | e.status == Status.ABORTED 32 | when: 33 | e = new CommunicationException("SomeMessage", Status.ABORTED, new IOException()) 34 | then: 35 | e.message == "SomeMessage" 36 | e.status == Status.ABORTED 37 | e.cause instanceof IOException 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/ServerSideExceptionSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import io.grpc.Status 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for ServerSideException. 21 | * 22 | * Created by Philip Vendil. 23 | */ 24 | class ServerSideExceptionSpec extends Specification { 25 | 26 | def "Verify that constructor populated fields properly"(){ 27 | when: 28 | ServerSideException e = new ServerSideException("SomeMessage", Status.ABORTED) 29 | then: 30 | e.message == "SomeMessage" 31 | e.status == Status.ABORTED 32 | when: 33 | e = new ServerSideException("SomeMessage", Status.ABORTED, new IOException()) 34 | then: 35 | e.message == "SomeMessage" 36 | e.status == Status.ABORTED 37 | e.cause instanceof IOException 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/StaticFileMacaroonContextSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import spock.lang.Specification 17 | 18 | /** 19 | * Unit tests for StaticFileMacaroonContext. 20 | * 21 | * Created by Philip Vendil on 2018-02-04. 22 | */ 23 | class StaticFileMacaroonContextSpec extends Specification { 24 | 25 | def "Verify that the constructor is reads and parses the macaroon correctly and getCurrentMacaroon() returns the parsed macaroon"(){ 26 | setup: 27 | File macaroonPath = new File(this.getClass().getResource("/admin.macaroon").path) 28 | when: 29 | StaticFileMacaroonContext macaroonContext = new StaticFileMacaroonContext(macaroonPath) 30 | then: 31 | macaroonContext.currentMacaroonAsHex == """303031316C6F636174696F6E206C6E640A303033326964656E74696669657220302D35666331623134616465343334346438383961333836393665346163363638300A303032667369676E617475726520C706ADA85CEA02671ED5B862E51AC79D34029FD9A9A4A02EB8CE86A9328ED84E0A""" 32 | } 33 | 34 | def "Verify that ClientSideException is thrown if macaroon file is not found"(){ 35 | when: 36 | new StaticFileMacaroonContext(new File("notexists.macaroon")) 37 | then: 38 | def e = thrown ClientSideException 39 | e.message == "Error reading macaroon from path 'notexists.macaroon', message: notexists.macaroon (No such file or directory)" 40 | e.status == null 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/StatusExceptionWrapperSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import spock.lang.Specification 17 | import spock.lang.Unroll 18 | 19 | import static io.grpc.Status.* 20 | /** 21 | * Unit tests for StatusExceptionWrapper. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | class StatusExceptionWrapperSpec extends Specification { 26 | StatusExceptionWrapper exceptionWrapper = new StatusExceptionWrapper() 27 | 28 | @Unroll 29 | def "Verify that wrap converts to grpc StatusException with Code #code into exception with type #type"(){ 30 | 31 | when: 32 | StatusException e = exceptionWrapper.wrap(new io.grpc.StatusException(code)) 33 | then: 34 | e.getClass().getSimpleName() == type 35 | e.getStatus() == code 36 | 37 | where: 38 | code | type 39 | CANCELLED | "ClientSideException" 40 | UNKNOWN | "ServerSideException" 41 | INVALID_ARGUMENT | "ClientSideException" 42 | DEADLINE_EXCEEDED | "CommunicationException" 43 | NOT_FOUND | "ClientSideException" 44 | ALREADY_EXISTS | "ClientSideException" 45 | PERMISSION_DENIED | "ClientSideException" 46 | RESOURCE_EXHAUSTED | "ServerSideException" 47 | FAILED_PRECONDITION | "ServerSideException" 48 | ABORTED | "ServerSideException" 49 | OUT_OF_RANGE | "ClientSideException" 50 | UNIMPLEMENTED | "ServerSideException" 51 | INTERNAL | "ServerSideException" 52 | UNAVAILABLE | "CommunicationException" 53 | DATA_LOSS | "ServerSideException" 54 | UNAUTHENTICATED | "ClientSideException" 55 | 56 | } 57 | 58 | def "Verify that both io.grpc.StatusException and io.grpc.StatusRuntimeException is wrapped"(){ 59 | when: 60 | StatusException e = exceptionWrapper.wrap(new io.grpc.StatusRuntimeException(ABORTED)) 61 | then: 62 | e.getClass().getSimpleName() == "ServerSideException" 63 | e.getStatus() == ABORTED 64 | } 65 | 66 | def "Verify that exceptions that isn't io.grpc.StatusException nor io.grpc.StatusRuntimeException generates ServerSideException"(){ 67 | when: 68 | StatusException e = exceptionWrapper.wrap(new IOException()) 69 | then: 70 | e.getClass().getSimpleName() == "ServerSideException" 71 | e.getStatus() == null 72 | e.message == "Internal Error, cannot convert exception of type: IOException" 73 | } 74 | 75 | def "Verify that io.grpc.StatusException with status OK generates assertion error"(){ 76 | when: 77 | exceptionWrapper.wrap(new io.grpc.StatusRuntimeException(OK)) 78 | then: 79 | thrown(java.lang.AssertionError) 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/SynchronousAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.proto.LightningApi 18 | import org.lightningj.lnd.wrapper.message.WalletBalanceResponse 19 | import spock.lang.Specification 20 | 21 | import java.util.logging.Logger 22 | 23 | /** 24 | * Unit tests for SynchronousAPI methods. 25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class SynchronousAPISpec extends Specification { 29 | 30 | SynchronousLndAPI api = new SynchronousLndAPI(Mock(ManagedChannel)) 31 | 32 | def setup(){ 33 | api.log = Mock(Logger) 34 | } 35 | 36 | def "SynchronousAPI initializes constructors properly."(){ 37 | setup: 38 | File macaroonPath = new File(this.getClass().getResource("/admin.macaroon").path) 39 | when: // This constructor 40 | SynchronousLndAPI api1 = new SynchronousLndAPI("localhost",8080,new File("src/test/resources/cert.pem"),macaroonPath) 41 | then: 42 | api1.channel != null 43 | } 44 | 45 | def "Verify that processResponse performs validation and debug logging"(){ 46 | setup: 47 | Message m = Mock(Message) 48 | when: 49 | api.processResponse(m) 50 | then: 51 | 1 * m.validate() >> { APISpec.getValidValidationResult()} 52 | 53 | when: 54 | WalletBalanceResponse resp = new WalletBalanceResponse() 55 | WalletBalanceResponse resp2 = api.processResponse(resp) 56 | then: 57 | resp == resp2 58 | 1 * api.log.fine({ it =~'Received response message: WalletBalanceResponse: '}) 59 | } 60 | 61 | 62 | def "Verify that processRepeatableResponse performs validation and debug logging on each message in iterator."(){ 63 | when: 64 | Iterator result = api.processRepeatableResponse([genWalletBalanceResponseApi(3213L),genWalletBalanceResponseApi(4213L)].iterator()) 65 | WalletBalanceResponse r1 = result.next() 66 | WalletBalanceResponse r2 = result.next() 67 | then: 68 | !result.hasNext() 69 | r1.totalBalance == 3213L 70 | r2.totalBalance == 4213L 71 | 1 * api.log.fine( {it =~'Received response message: WalletBalanceResponse: '}) 72 | 1 * api.log.fine( { it =~ 'Received response message: WalletBalanceResponse: '}) 73 | } 74 | 75 | private LightningApi.WalletBalanceResponse genWalletBalanceResponseApi(long totalValue){ 76 | LightningApi.WalletBalanceResponseOrBuilder b = LightningApi.WalletBalanceResponse.newBuilder() 77 | b.setTotalBalance(totalValue) 78 | b.build() 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/V1XMLParserSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import spock.lang.Specification 17 | 18 | /** 19 | * Unit tests for V1XMLParser. 20 | * 21 | * Created by Philip Vendil. 22 | */ 23 | class V1XMLParserSpec extends Specification { 24 | 25 | def "Verify that abstract method returns correct values"(){ 26 | setup: 27 | V1XMLParser p = new V1XMLParser() 28 | expect: 29 | p.getVersion() == "1.0" 30 | p.getSchemaLocations() == [ "/lnd_v1.xsd", 31 | "/autopilot_v1.xsd", 32 | "/chainnotifier_v1.xsd", 33 | "/chainkit_v1.xsd", 34 | "/invoices_v1.xsd", 35 | "/router_v1.xsd", 36 | "/signer_v1.xsd", 37 | "/walletkit_v1.xsd", 38 | "/watchtower_v1.xsd", 39 | "/wtclient_v1.xsd", 40 | "/verrpc_v1.xsd", 41 | "/walletunlocker_v1.xsd", 42 | "/stateservice_v1.xsd", 43 | "/dev_v1.xsd", 44 | "/neutrino_v1.xsd", 45 | "/peers_v1.xsd"] as String[] 46 | p.getJAXBClassPath() == "org.lightningj.lnd.wrapper.message:" + 47 | "org.lightningj.lnd.wrapper.autopilot.message:"+ 48 | "org.lightningj.lnd.wrapper.chainnotifier.message:"+ 49 | "org.lightningj.lnd.wrapper.chainkit.message:"+ 50 | "org.lightningj.lnd.wrapper.invoices.message:"+ 51 | "org.lightningj.lnd.wrapper.router.message:"+ 52 | "org.lightningj.lnd.wrapper.signer.message:"+ 53 | "org.lightningj.lnd.wrapper.walletkit.message:"+ 54 | "org.lightningj.lnd.wrapper.watchtower.message:" + 55 | "org.lightningj.lnd.wrapper.wtclient.message:" + 56 | "org.lightningj.lnd.wrapper.verrpc.message:" + 57 | "org.lightningj.lnd.wrapper.walletunlocker.message:" + 58 | "org.lightningj.lnd.wrapper.stateservice.message:" + 59 | "org.lightningj.lnd.wrapper.dev.message:" + 60 | "org.lightningj.lnd.wrapper.neutrino.message:" + 61 | "org.lightningj.lnd.wrapper.peers.message" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/ValidationExceptionSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests of ValidationException. 21 | * 22 | * Created by Philip Vendil. 23 | */ 24 | class ValidationExceptionSpec extends Specification { 25 | 26 | def "Verify that constructor populated fields properly"(){ 27 | setup: 28 | ValidationResult validationResult = new ValidationResult() 29 | when: 30 | ValidationException e = new ValidationException("SomeMessage", validationResult) 31 | then: 32 | e.message == "SomeMessage" 33 | e.getValidationResult() == validationResult 34 | when: 35 | e = new ValidationException("SomeMessage", validationResult, new IOException()) 36 | then: 37 | e.message == "SomeMessage" 38 | e.getValidationResult() == validationResult 39 | e.cause instanceof IOException 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/ValidationProblemsSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import spock.lang.Specification 17 | 18 | import java.text.MessageFormat 19 | 20 | /** 21 | * Unit tests for ValidationProblems. 22 | * 23 | * Created by Philip Vendil. 24 | */ 25 | class ValidationProblemsSpec extends Specification { 26 | 27 | def "Verify that constructor and getters retrives correct valuds"(){ 28 | when: 29 | ValidationProblems ve = new ValidationProblems("Invoice", "receipt","some.recource.key", "Some description") 30 | then: 31 | ve.getMessageType() == "Invoice" 32 | ve.getField() == "receipt" 33 | ve.getDescription() == "Some description" 34 | ve.getDescriptionResourceKey() == "some.recource.key" 35 | } 36 | 37 | def "Verify that resource bundle loading works properly"(){ 38 | setup: 39 | ValidationProblems ve = new ValidationProblems("Invoice", "receipt","some.recource.key", ["someField"] as Object[], "Some description") 40 | ResourceBundle br = ResourceBundle.getBundle("lightningj_messages") 41 | ResourceBundle br_sv = ResourceBundle.getBundle("lightningj_messages", new Locale("sv", "SE")) 42 | 43 | when: "Verify that one with parameters is working for default locale" 44 | String text = MessageFormat.format(br.getString("lightningj.validation.fieldisrequired"),ve.getResourceParameters()) 45 | then: 46 | text == "Field someField is required." 47 | 48 | when: "Verify that one with parameters is working for swedish locale" 49 | text = MessageFormat.format(br_sv.getString("lightningj.validation.fieldisrequired"),ve.getResourceParameters()) 50 | then: 51 | text == "Fält someField är obligatoriskt." 52 | 53 | when: "Verify that null resourceParameters doesn't throw exception" 54 | ve = new ValidationProblems("Invoice", "receipt","some.recource.key", "Some description") 55 | text = MessageFormat.format(br.getString("lightningj.validation.fieldisrequired"),ve.getResourceParameters()) 56 | then: 57 | text == "Field {0} is required." 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/WrapperFactorySpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import com.google.protobuf.GeneratedMessageV3 17 | import org.lightningj.lnd.proto.LightningApi 18 | import org.lightningj.lnd.wrapper.message.WalletBalanceRequest 19 | import org.lightningj.lnd.wrapper.message.WalletBalanceResponse 20 | import spock.lang.Specification 21 | 22 | /** 23 | * Unit tests for WrapperFactory. 24 | * 25 | * Created by Philip Vendil. 26 | */ 27 | class WrapperFactorySpec extends Specification { 28 | 29 | WrapperFactory factory = new WrapperFactory() 30 | 31 | def "Verify that convertToWrapper converts API message to wrapper message correctly"(){ 32 | when: 33 | WalletBalanceRequest o = factory.wrap(LightningApi.WalletBalanceRequest.getDefaultInstance()) 34 | then: 35 | o.getApiObject() == LightningApi.WalletBalanceRequest.getDefaultInstance() 36 | 37 | when: 38 | WalletBalanceResponse o2 = factory.wrap(LightningApi.WalletBalanceResponse.newBuilder().setTotalBalance(123L).build()) 39 | then: 40 | o2.totalBalance == 123L 41 | } 42 | 43 | def "Verify that ClientSideException it throws for invalid objects"(){ 44 | when: 45 | factory.wrap(Mock(GeneratedMessageV3)) 46 | then: 47 | def e = thrown ClientSideException 48 | e.message =~ 'Error converting GRPC object GeneratedMessageV3' 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/XMLParserFactorySpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper 15 | 16 | import spock.lang.Specification 17 | import spock.lang.Unroll 18 | 19 | /** 20 | * Unit test for XMLParserFactory. 21 | * 22 | * Created by Philip Vendil 23 | */ 24 | class XMLParserFactorySpec extends Specification { 25 | 26 | XMLParserFactory factory = new XMLParserFactory() 27 | 28 | def "Verify that getSupportedVersions returns all supported versions"(){ 29 | expect: 30 | factory.supportedVersions.contains("1.0") 31 | } 32 | 33 | @Unroll 34 | def "Verify that getXMLParser returns correct XMLParser for version #version"(){ 35 | expect: 36 | factory.getXMLParser(version).class == expectedClass 37 | where: 38 | version | expectedClass 39 | "1.0" | V1XMLParser.class 40 | 41 | } 42 | 43 | def "Verify that getXMLParser throws IllegalArgumentException for unsupported version"(){ 44 | when: 45 | factory.getXMLParser("0.0") 46 | then: 47 | def e = thrown(IllegalArgumentException) 48 | e.message == "Error no XML Parser with version 0.0 supported." 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/autopilot/AutopilotAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.autopilot 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for Autopilot API classes. 21 | *

    22 | * This class just verifies that the API classes have been generated. 23 | * Functional tests is in the integration tests. 24 | *

    25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class AutopilotAPISpec extends Specification { 29 | 30 | // Initialization is tested in SynchronousAPISpec 31 | 32 | def asyncApi = new AsynchronousAutopilotAPI(Mock(ManagedChannel)) 33 | def syncApi = new SynchronousAutopilotAPI(Mock(ManagedChannel)) 34 | 35 | def "Verify that apis have been created."(){ 36 | expect: 37 | asyncApi != null 38 | syncApi != null 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/chainnotifier/ChainNotifierAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.chainnotifier 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.wrapper.autopilot.AsynchronousAutopilotAPI 18 | import org.lightningj.lnd.wrapper.autopilot.SynchronousAutopilotAPI 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Unit tests for ChainNotifier API classes. 23 | *

    24 | * This class just verifies that the API classes have been generated. 25 | * Functional tests is in the integration tests. 26 | *

    27 | * 28 | * Created by Philip Vendil. 29 | */ 30 | class ChainNotifierAPISpec extends Specification { 31 | 32 | // Initialization is tested in SynchronousAPISpec 33 | 34 | def asyncApi = new AsynchronousChainNotifierAPI(Mock(ManagedChannel)) 35 | def syncApi = new SynchronousChainNotifierAPI(Mock(ManagedChannel)) 36 | 37 | def "Verify that apis have been created."(){ 38 | expect: 39 | asyncApi != null 40 | syncApi != null 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/dev/DevAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.dev 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for Invoices API classes. 21 | *

    22 | * This class just verifies that the API classes have been generated. 23 | * Functional tests is in the integration tests. 24 | *

    25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class DevAPISpec extends Specification { 29 | 30 | // Initialization is tested in SynchronousAPISpec 31 | 32 | def asyncApi = new AsynchronousDevAPI(Mock(ManagedChannel)) 33 | def syncApi = new SynchronousDevAPI(Mock(ManagedChannel)) 34 | 35 | def "Verify that apis have been created."(){ 36 | expect: 37 | asyncApi != null 38 | syncApi != null 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/invoices/InvoicesAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.invoices 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for Invoices API classes. 21 | *

    22 | * This class just verifies that the API classes have been generated. 23 | * Functional tests is in the integration tests. 24 | *

    25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class InvoicesAPISpec extends Specification { 29 | 30 | // Initialization is tested in SynchronousAPISpec 31 | 32 | def asyncApi = new AsynchronousInvoicesAPI(Mock(ManagedChannel)) 33 | def syncApi = new SynchronousInvoicesAPI(Mock(ManagedChannel)) 34 | 35 | def "Verify that apis have been created."(){ 36 | expect: 37 | asyncApi != null 38 | syncApi != null 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/neutrino/NeutrinoAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.neutrino 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for Invoices API classes. 21 | *

    22 | * This class just verifies that the API classes have been generated. 23 | * Functional tests is in the integration tests. 24 | *

    25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class NeutrinoAPISpec extends Specification { 29 | 30 | // Initialization is tested in SynchronousAPISpec 31 | 32 | def asyncApi = new AsynchronousNeutrinoAPI(Mock(ManagedChannel)) 33 | def syncApi = new SynchronousNeutrinoAPI(Mock(ManagedChannel)) 34 | 35 | def "Verify that apis have been created."(){ 36 | expect: 37 | asyncApi != null 38 | syncApi != null 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/peers/PeersAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.peers 15 | 16 | import io.grpc.ManagedChannel 17 | import spock.lang.Specification 18 | 19 | /** 20 | * Unit tests for Invoices API classes. 21 | *

    22 | * This class just verifies that the API classes have been generated. 23 | * Functional tests is in the integration tests. 24 | *

    25 | * 26 | * Created by Philip Vendil. 27 | */ 28 | class PeersAPISpec extends Specification { 29 | 30 | // Initialization is tested in SynchronousAPISpec 31 | 32 | def asyncApi = new AsynchronousPeersAPI(Mock(ManagedChannel)) 33 | def syncApi = new SynchronousPeersAPI(Mock(ManagedChannel)) 34 | 35 | def "Verify that apis have been created."(){ 36 | expect: 37 | asyncApi != null 38 | syncApi != null 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/router/RouterAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.router 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.wrapper.invoices.AsynchronousInvoicesAPI 18 | import org.lightningj.lnd.wrapper.invoices.SynchronousInvoicesAPI 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Unit tests for Router API classes. 23 | *

    24 | * This class just verifies that the API classes have been generated. 25 | * Functional tests is in the integration tests. 26 | *

    27 | * 28 | * Created by Philip Vendil. 29 | */ 30 | class RouterAPISpec extends Specification { 31 | 32 | // Initialization is tested in SynchronousAPISpec 33 | 34 | def asyncApi = new AsynchronousRouterAPI(Mock(ManagedChannel)) 35 | def syncApi = new SynchronousRouterAPI(Mock(ManagedChannel)) 36 | 37 | def "Verify that apis have been created."(){ 38 | expect: 39 | asyncApi != null 40 | syncApi != null 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/signer/SignerAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.signer 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.wrapper.router.AsynchronousRouterAPI 18 | import org.lightningj.lnd.wrapper.router.SynchronousRouterAPI 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Unit tests for Signer API classes. 23 | *

    24 | * This class just verifies that the API classes have been generated. 25 | * Functional tests is in the integration tests. 26 | *

    27 | * 28 | * Created by Philip Vendil. 29 | */ 30 | class SignerAPISpec extends Specification { 31 | 32 | // Initialization is tested in SynchronousAPISpec 33 | 34 | def asyncApi = new AsynchronousSignerAPI(Mock(ManagedChannel)) 35 | def syncApi = new SynchronousSignerAPI(Mock(ManagedChannel)) 36 | 37 | def "Verify that apis have been created."(){ 38 | expect: 39 | asyncApi != null 40 | syncApi != null 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/walletkit/WalletKitAPISpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.walletkit 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.wrapper.signer.AsynchronousSignerAPI 18 | import org.lightningj.lnd.wrapper.signer.SynchronousSignerAPI 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Unit tests for WalletKit API classes. 23 | *

    24 | * This class just verifies that the API classes have been generated. 25 | * Functional tests is in the integration tests. 26 | *

    27 | * 28 | * Created by Philip Vendil. 29 | */ 30 | class WalletKitAPISpec extends Specification { 31 | 32 | // Initialization is tested in SynchronousAPISpec 33 | 34 | def asyncApi = new AsynchronousWalletKitAPI(Mock(ManagedChannel)) 35 | def syncApi = new SynchronousWalletKitAPI(Mock(ManagedChannel)) 36 | 37 | def "Verify that apis have been created."(){ 38 | expect: 39 | asyncApi != null 40 | syncApi != null 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/groovy/org/lightningj/lnd/wrapper/wtclient/WtclientSpec.groovy: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * * 3 | * LightningJ * 4 | * * 5 | * This software is free software; you can redistribute it and/or * 6 | * modify it under the terms of the GNU Lesser General Public License * 7 | * (LGPL-3.0-or-later) * 8 | * License as published by the Free Software Foundation; either * 9 | * version 3 of the License, or any later version. * 10 | * * 11 | * See terms of license at gnu.org. * 12 | * * 13 | *************************************************************************/ 14 | package org.lightningj.lnd.wrapper.wtclient 15 | 16 | import io.grpc.ManagedChannel 17 | import org.lightningj.lnd.wrapper.walletkit.AsynchronousWalletKitAPI 18 | import org.lightningj.lnd.wrapper.walletkit.SynchronousWalletKitAPI 19 | import spock.lang.Specification 20 | 21 | /** 22 | * Unit tests for WTClient API classes. 23 | *

    24 | * This class just verifies that the API classes have been generated. 25 | * Functional tests is in the integration tests. 26 | *

    27 | * 28 | * Created by Philip Vendil. 29 | */ 30 | class WtclientSpec extends Specification { 31 | 32 | // Initialization is tested in SynchronousAPISpec 33 | 34 | def asyncApi = new AsynchronousWatchtowerClientAPI(Mock(ManagedChannel)) 35 | def syncApi = new SynchronousWatchtowerClientAPI(Mock(ManagedChannel)) 36 | 37 | def "Verify that apis have been created."(){ 38 | expect: 39 | asyncApi != null 40 | syncApi != null 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/resources/admin.macaroon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightningj-org/lightningj/71f9d2dc21a76a889cdaaed24d639af9a105bc79/src/test/resources/admin.macaroon -------------------------------------------------------------------------------- /src/test/resources/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEtDCCApwCCQDO3UPGCYSVETANBgkqhkiG9w0BAQsFADAcMQswCQYDVQQGEwJO 3 | TzENMAsGA1UEAwwEVGVzdDAeFw0xODAxMTUxNjE2MDRaFw0xOTAxMTUxNjE2MDRa 4 | MBwxCzAJBgNVBAYTAk5PMQ0wCwYDVQQDDARUZXN0MIICIjANBgkqhkiG9w0BAQEF 5 | AAOCAg8AMIICCgKCAgEAuxgLdnAz9oK8bJayW5knXnNhlm+7YAD8+DCtWr8tfv+q 6 | kh9NUXkeKpxzgMAq4/elpUOMal2tTrrJwH90oIqyw1WFpW+4VnNZPQz5h52p7bnV 7 | DZvvzrXqpzl6TXb9bw45OVeQlSXqRLYLsr4UPnPS3gN8GEa3qUaFXETsCjsrIbSX 8 | CgV/8wlhRE0VDjxAi/n1W5J1VrZzwLvXEO960tBNNfV5lIqkcCz3h2SNAA9QX65p 9 | +1voJq+Vbl96TIE026De2LGaamnLT8mJm3T+ITRKoyVvCc28KosFYpkqFlj2wq2z 10 | FBQW2MC7Z7AEdi+Sc/eYivJTAXzYiMwauD7/QP1AOXsIIo8wM4gU0nEx0theiiCQ 11 | K9W3KpFuJCurdbdLkjaruf/innhA+UES3CzAjUhD+XF8MH+xSai93JiXpT8V0As0 12 | Y2wmvQI+QIOtp43dWr/da3r/x9aficE0enkR7Baf+2m7RLCBS/abzdNJZsnUGmci 13 | xCa+TS8TNYRbAg9nfFGn2UdfZgvlu0dxo6qB7mBCzkAbP2fzyeYJPR7Rze0Rkk4h 14 | /Iv6ex+ocK34059c1PltWOiPeMeMtqonruBmZOVlK5FkDqb3N808rPCo8EmIy2qp 15 | bxOjvS52pr3gMB4+DYO7Td0Yulozys2OJ/qnyGGXim83m1w6d+rN58KFLvxxaSEC 16 | AwEAATANBgkqhkiG9w0BAQsFAAOCAgEAqFtaJuZsLGK0fcnuMH1WPcaQsqcnodVX 17 | m5v/gIZd2XSKWyjElpZHYLvvvQ7uTQxi/hS0qsXuJlXtKNyrl6Qu3p6+1AvkGqJz 18 | vZXK0iOv0P/ag0F7onYbjSXS+yQ/M3lqwYIbhzjVRf2We8D89jJVz3iZZxVmoZXW 19 | /xUjZGR15lRy2gszh253Ow0mCNrgsO7dRNhL8Wrab0vuRPzuirPPXvysjERRaF6z 20 | G37pvcoEftDLuEe8HTWC6J5YArE0F0mdwP8unA+OX4ixHrc/YxwmWIup+RZe84fH 21 | /hxSAaudCK8yH4evq6z5ZW1CZMBbljlx1VEiBlxntJURvqeBAXZyBgqMCCdcnmuY 22 | TQHvsfA1ko1Y64nHFS0sb6IedApg5EPfj0wDocuUW+mzkhN3ugMEWSMnfOsQUBzd 23 | s0eb049dQPNrxulRaC0YzUdWxQrMUpvxqwYyu8caAuMtPt1ipqJvM/pu68gF/cJ6 24 | 1BgdzDZi47ncdE7mq8ejTOBKHeTjwZL74pZ7eHjwBWhNPiD6JLNkI2chjiltS6Ny 25 | x/c67y+KVDEgW8DyimwqIiQIrFdN1sLEkptSP/tugjuueoBLf+1QbG3eA/O57SH/ 26 | XZ0WlHzZbSUJ3Ui/lo9ioGfqYp/vxiz71y/wrQBV+Vqr5awG4NFLf0om7T63q5qw 27 | 1mSvKGSNSKc= 28 | -----END CERTIFICATE----- 29 | -------------------------------------------------------------------------------- /src/test/resources/invalid.macaroon: -------------------------------------------------------------------------------- 1 | 5511location lnd 2 | 0032identifier 0-5fc1b14ade4344d889a38696e4ac6680 3 | 002fsignature ���\�gոb�ǝ4�٩��.�Ά�2��N 4 | --------------------------------------------------------------------------------