I noted that my mind has a bug, in fact when I have started to design the java RPC wrapper I choose to use the mediator pattern and create a query string with a library rules, such as the example below.
public CLightningPay pay(String bolt11, String satoshi, String label, float riskFactor, String maxFeePercent, int retryFor, String maxDelay) {
if (bolt11 == null || bolt11.trim().isEmpty()) {
throw new CLightningException("The method pay have the parameter bolt11 is null or empty");
}
if (satoshi == null) {
throw new CLightningException("The method pay have the parameter satoshi is null");
}
if (label == null) {
throw new CLightningException("The method pay have the parameter label is null");
}
if (maxFeePercent == null) {
throw new CLightningException("The method pay have the parameter maxFeePercent is null");
}
if (maxDelay == null) {
throw new CLightningException("The method pay have the parameter maxDelay is null");
}
StringBuilder payload = new StringBuilder();
payload.append("bolt11=").append(bolt11);
if (!satoshi.trim().isEmpty()) {
payload.append(JOIN_TOKEN_PROP).append("satoshi=").append(satoshi);
}
if (!label.trim().isEmpty()) {
payload.append(JOIN_TOKEN_PROP).append("label=").append(label);
}
payload.append(JOIN_TOKEN_PROP).append("riskfactor=").append(riskFactor);
if (!maxFeePercent.trim().isEmpty()) {
payload.append(JOIN_TOKEN_PROP).append("maxfeepercent=").append(maxFeePercent);
}
payload.append(JOIN_TOKEN_PROP).append("retry_for=").append(retryFor);
if (!maxDelay.trim().isEmpty()) {
payload.append(JOIN_TOKEN_PROP).append("maxDelay=").append(maxDelay);
}
String payloadString = payload.toString();
CLightningLogger.getInstance().debug(TAG, "Payload for pay connect is: " + payloadString);
CLightningPay pay = (CLightningPay) mediatorCommand.runCommand(Command.PAY, payloadString);
return pay;
}
ublic CLightningGetRoutes getRoute(String id, String mSatoshi, float riskFactor, int cltv,
String fromid, String fuzzpercent, int maxHope, ExcludeChannel... exclude){
doCheckString("getRoute", "id", id, false);
doCheckString("getRoute", "mSatoshi", mSatoshi, false);
doCheckString("getRoute", "fromid", fromid, true);
doCheckString("getRoute", "fuzzpercent", fuzzpercent, true);
doCheckPositiveNumber("getRoute", "riskFactor", riskFactor);
doCheckPositiveNumber("getRoute", "cltv", cltv);
doCheckPositiveNumber("getRoute", "maxHope", maxHope);
HashMap<String, Object> payload = new HashMap<>();
payload.put("id", id);
payload.put("msatoshi", maxHope);
payload.put("riskfactor", riskFactor);
payload.put("cltv", cltv);
payload.put("maxhope", maxHope);
if(!fromid.isEmpty()){
payload.put("fromid", fromid);
}
if(!fuzzpercent.isEmpty()){
payload.put("fuzzpercent", fuzzpercent);
}
if(exclude.length > 0){
payload.put("exclude", exclude);
}
return (CLightningGetRoutes) mediatorCommand.runCommand(Command.GETROUTE, payload);
}