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 |
--------------------------------------------------------------------------------