darosior/lightningcpp

[Question] How set-up personal plugin

vincenzopalazzo opened this issue · 2 comments

Hi @darosior,

I'm playing with the lightningcpp and I have some difficulty to understand how to run your plugin inside the readme.

First all, I noted maybe a refuse inside the readme file. In your first example you used the class called CLightningWrapper but inside the file clightningrpc.h there is only CLightningRpc. With this change, I compiled your example and worked.

In addition, I developed a plugin with your example, my code look like the following code

#include <clightningrpc.h>
#include <clightningplugin.h>
#include <iostream>
#include <string>

class Helloworld: public RpcMethod {
public:
    Helloworld(): RpcMethod() {
        name = "hello";
        description = "launch me so that I can greet the world";
    }

    Json::Value main(Json::Value &params) {
        return Json::Value("Hello world !");
    }
};

void GetInfoFromRpc();
void PersonalPlugin();

int main (int argc, char *argv[])
{
    //GetInfoFromRpc();

    std::cout << "\n---------------- PERSONAL PLUGIN ----------------\n";

    PersonalPlugin();

    return 0;
}

void GetInfoFromRpc(){
    CLightningRpc lightning = CLightningRpc("/lightningcpp/sandbox/sanboxTestWrapperRPC/lightning_dir_one/regtest/lightning-rpc");
    std::cout << lightning.getInfo() << std::endl;
}

void PersonalPlugin(){
    Plugin testPlugin;
    Helloworld helloworld;
    testPlugin.addMethod(helloworld);
    testPlugin.start();
}

I compiled this code and I inserted the executable inside directory ~/.lightningd/plugins, when I ran clightning the execution frozen and it didn't startup (possible loop inside method start?)

I tried also to startup clightining and only after I copied the executable inside the directory, then I called lightning-cli plugin rescan, In conclusion I have the following error

{
   "code": -32602,
   "message": "/lightningcpp/sandbox/sanboxTestWrapperRPC/lightning_dir_one/plugins/CRPCLightning-Demo: Plugin exited before completing handshake."
}

I don't thing is a bug inside the library but it is a my fault, What am I loasing?

Hi,

First of all, please note this is a one-year old and not well tested lib.

    std::cout << "\n---------------- PERSONAL PLUGIN ----------------\n";

You can't do this : you are writing to lightningd !

I don't thing is a bug inside the library but it is a my fault, What am I loasing?

You can first remove the line above, if it's something else i'd have to try myself. Just a few hints :

  • Use regtest
  • Set log-level=io in lightningd to debug the json sent by the plugin to lightning and vice-versa.
  • Use lightning-cli plugin start </absolute/path/to/pljugin> to avoid having to restart it each time.

Hi, @darosior sorry for the delay.

The line below is the problem.

std::cout << "\n---------------- PERSONAL PLUGIN ----------------\n";

The plugin run now. Thank you and sorry for my stupid error.