Merge pull request #1 from vincenzopalazzo/macros/cln-offer
plugin: init the structure of the plugins
This commit is contained in:
commit
3a95f266d7
1
Makefile
1
Makefile
|
@ -32,7 +32,6 @@ force:
|
|||
|
||||
integration:
|
||||
@make default
|
||||
cd cln-integration; make fmt
|
||||
cd cln-integration; make check
|
||||
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.11"
|
||||
version = "0.6.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
|
||||
checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
|
@ -76,9 +76,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.79"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
|
||||
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
|
@ -177,9 +177,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.85"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b918671670962b48bc23753aef0c51d072dca6f52f01f800854ada6ddb7f7d3"
|
||||
checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
@ -190,7 +190,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
[[package]]
|
||||
name = "clightning-testing"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/laanwj/cln4rust.git#d4cb15cb48299f0048ed226020baf670e3f82156"
|
||||
source = "git+https://github.com/laanwj/cln4rust.git#46ff0e4dc7426926041410cc7486dc80a764a939"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitcoincore-rpc",
|
||||
|
@ -204,7 +204,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "clightningrpc"
|
||||
version = "0.3.0-beta.8"
|
||||
source = "git+https://github.com/laanwj/cln4rust.git#d4cb15cb48299f0048ed226020baf670e3f82156"
|
||||
source = "git+https://github.com/laanwj/cln4rust.git#46ff0e4dc7426926041410cc7486dc80a764a939"
|
||||
dependencies = [
|
||||
"clightningrpc-common",
|
||||
"serde",
|
||||
|
@ -251,9 +251,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.1"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05e7cf40684ae96ade6232ed84582f40ce0a66efcd43a5117aef610534f8e0b8"
|
||||
checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -297,9 +297,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
|||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3"
|
||||
checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd"
|
||||
|
||||
[[package]]
|
||||
name = "hex_lit"
|
||||
|
@ -512,9 +512,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.16"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||
|
||||
[[package]]
|
||||
name = "secp256k1"
|
||||
|
@ -539,18 +539,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.196"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
|
||||
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.196"
|
||||
version = "1.0.197"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
|
||||
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -559,9 +559,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.113"
|
||||
version = "1.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
|
||||
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -579,9 +579,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.48"
|
||||
version = "2.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
||||
checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -661,7 +661,7 @@ version = "0.52.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
"windows-targets 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -681,17 +681,17 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.0",
|
||||
"windows_aarch64_msvc 0.52.0",
|
||||
"windows_i686_gnu 0.52.0",
|
||||
"windows_i686_msvc 0.52.0",
|
||||
"windows_x86_64_gnu 0.52.0",
|
||||
"windows_x86_64_gnullvm 0.52.0",
|
||||
"windows_x86_64_msvc 0.52.0",
|
||||
"windows_aarch64_gnullvm 0.52.3",
|
||||
"windows_aarch64_msvc 0.52.3",
|
||||
"windows_i686_gnu 0.52.3",
|
||||
"windows_i686_msvc 0.52.3",
|
||||
"windows_x86_64_gnu 0.52.3",
|
||||
"windows_x86_64_gnullvm 0.52.3",
|
||||
"windows_x86_64_msvc 0.52.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -702,9 +702,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
|||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
|
@ -714,9 +714,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
|||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
|
@ -726,9 +726,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
|||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
|
@ -738,9 +738,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
|||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
|
@ -750,9 +750,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
|||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
|
@ -762,9 +762,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
|||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
|
@ -774,6 +774,6 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
|||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
version = "0.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6"
|
||||
|
|
|
@ -11,7 +11,7 @@ fmt:
|
|||
$(CC) fmt --all
|
||||
|
||||
check:
|
||||
$(CC) test --all
|
||||
$(CC) test --all -- --nocapture
|
||||
|
||||
example:
|
||||
@echo "No example for the moment"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::sync::Once;
|
||||
|
||||
use clightning_testing::cln;
|
||||
use serde_json::json;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
mod utils;
|
||||
|
||||
|
@ -25,12 +25,17 @@ async fn test_init_plugin() -> anyhow::Result<()> {
|
|||
init();
|
||||
let pwd = std::env!("PWD");
|
||||
let plugin_name = std::env!("PLUGIN_NAME");
|
||||
log::debug!("plugin path: {pwd}/../{plugin_name}");
|
||||
let cln1 = cln::Node::with_params(
|
||||
&format!("--developer --experimental-splicing --plugin={pwd}/../{plugin_name}"),
|
||||
&format!("--developer --experimental-offers --plugin={pwd}/../{plugin_name}"),
|
||||
"regtest",
|
||||
)
|
||||
.await?;
|
||||
let splice: Result<serde_json::Value, _> = cln1.rpc().call("getinfo", json!({}));
|
||||
assert!(splice.is_ok(), "{:?}", splice);
|
||||
let info = cln1.rpc().call::<Value, Value>("ocean-info", json!({}));
|
||||
log::info!("{:?}", info);
|
||||
if info.is_err() {
|
||||
let _ = cln1.print_logs();
|
||||
}
|
||||
assert!(info.is_ok(), "{:?}", info);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
state := core.PluginState{}
|
||||
plugin := plugin.New(&state, true, plugin.DummyOnInit[*core.PluginState])
|
||||
plugin.RegisterOption("foo", "string", "Hello Go", "An example of option", false)
|
||||
plugin.RegisterRPCMethod("hello", "", "an example of rpc method", core.Hello)
|
||||
state := core.State{}
|
||||
plugin := plugin.New(&state, true, core.OnInit)
|
||||
plugin.RegisterNotification("shutdown", core.OnShutdown)
|
||||
|
||||
plugin.RegisterRPCMethod("ocean-pay", "", "Ocean pay an offer for a miner payout", core.OceanPay)
|
||||
plugin.RegisterRPCMethod("ocean-info", "", "Return the information of the plugin", core.GetInfo)
|
||||
|
||||
plugin.Start()
|
||||
}
|
||||
|
|
7
go.mod
7
go.mod
|
@ -3,12 +3,13 @@ module github.com/cln-reckless/cln4go.plugin
|
|||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20230413130716-35626bd3b34b
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20230413130716-35626bd3b34b
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20240225150542-fa830ceeae65
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20240225150542-fa830ceeae65
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/vincenzopalazzo/cln4go v0.0.1-beta.8 // indirect
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20230413130716-35626bd3b34b // indirect
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20240225150542-fa830ceeae65 // indirect
|
||||
github.com/vincenzopalazzo/cpstl/go v0.0.0-20221204131531-d0659db4dd2a // indirect
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,20 +1,28 @@
|
|||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/vincenzopalazzo/cln4go v0.0.1-beta.8 h1:j5KAUwSehDa9HrFd5M6/kRD8NEiTc0CiClixl5e9gTk=
|
||||
github.com/vincenzopalazzo/cln4go v0.0.1-beta.8/go.mod h1:2NnveaBEhWeXc6SAyTLGIYRJsVq+5RjTRKh105b8Y2M=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20220802085837-fb816fecb890 h1:ylUf6ddD7TGHC+CXrAq0EQr5EsPVRYuiHDlPs1AIXf4=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20220802085837-fb816fecb890/go.mod h1:7X4Hn+hwG3Ts/S3tgEqsowfUHZqyjx7/1z/8oDw7Muw=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20230413130716-35626bd3b34b h1:WIFJ0/HDdiiwqLwWN2uunudA6HPFIlsl2/CsPJRdM7w=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20230413130716-35626bd3b34b/go.mod h1:7C64iH2eVEE7WkIMQa8fmtQmFNzprDt6rIZOxG57Thg=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20240225150542-fa830ceeae65 h1:fW3un3bcVFgWc1+n9U/rU49JwKol6LPnvaG/s9Drlto=
|
||||
github.com/vincenzopalazzo/cln4go/client v0.0.0-20240225150542-fa830ceeae65/go.mod h1:7C64iH2eVEE7WkIMQa8fmtQmFNzprDt6rIZOxG57Thg=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20220802085837-fb816fecb890 h1:NvP9FlygyCWYaZizyxTdGBe3yRuzPzdnoxz3g28PAps=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20220802085837-fb816fecb890/go.mod h1:zyOWcz5aSHCsLuZLaVBTjbRnxlf5Ac+Rfhu5Ciuyy2c=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20220818123810-7039d15d24ca h1:BkPn3LskgTCmMsgW9pZ9ZZc5nObZF0lo+hIl5mz0Wak=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20220818123810-7039d15d24ca/go.mod h1:zyOWcz5aSHCsLuZLaVBTjbRnxlf5Ac+Rfhu5Ciuyy2c=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20230413130716-35626bd3b34b h1:tg6sPkYyV5mnMVkCqbM7ow4u6hmyl9l5uCWiu5mKHUY=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20230413130716-35626bd3b34b/go.mod h1:zyOWcz5aSHCsLuZLaVBTjbRnxlf5Ac+Rfhu5Ciuyy2c=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20240225150542-fa830ceeae65 h1:tcjluTHscWMynrF3Jlufi5ue8WdPKXCh7Nr9rPpMJuY=
|
||||
github.com/vincenzopalazzo/cln4go/comm v0.0.0-20240225150542-fa830ceeae65/go.mod h1:zyOWcz5aSHCsLuZLaVBTjbRnxlf5Ac+Rfhu5Ciuyy2c=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20220802085837-fb816fecb890 h1:L32YhQYlO2CeIp7AvjfN8ozuEba1R5/vi2bpH91B5mM=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20220802085837-fb816fecb890/go.mod h1:vb+knVG7/MR+oTnDRRwDH7WqO6U0FbcRNWjQeu0xdds=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20220818123810-7039d15d24ca h1:wgoFUhwXvQxbsxsrJE6+jMr1sagIHRD/f7F5irHxkaA=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20220818123810-7039d15d24ca/go.mod h1:vb+knVG7/MR+oTnDRRwDH7WqO6U0FbcRNWjQeu0xdds=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20230413130716-35626bd3b34b h1:hh8bn9l/wX3FiH0G8uIP46YNP7QXpa1sSQnt+JpoBTQ=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20230413130716-35626bd3b34b/go.mod h1:vb+knVG7/MR+oTnDRRwDH7WqO6U0FbcRNWjQeu0xdds=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20240225150542-fa830ceeae65 h1:lsmN/x6H3h3Np0Wxyio0p0o76NfcLJFo+ECO/EDDSqM=
|
||||
github.com/vincenzopalazzo/cln4go/plugin v0.0.0-20240225150542-fa830ceeae65/go.mod h1:vb+knVG7/MR+oTnDRRwDH7WqO6U0FbcRNWjQeu0xdds=
|
||||
github.com/vincenzopalazzo/cpstl/go v0.0.0-20221204131531-d0659db4dd2a h1:eh427yzx/JbkOuLjSS2bPop/14HMq7eYGWC1bp29mzU=
|
||||
github.com/vincenzopalazzo/cpstl/go v0.0.0-20221204131531-d0659db4dd2a/go.mod h1:VNETfpfs0pZQKEg9qwSm7M1gfVrliFFzxKVVppNaxbM=
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
json "github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/vincenzopalazzo/cln4go/plugin"
|
||||
)
|
||||
|
||||
// / FetchOffer - Fetch the offer invoice
|
||||
func FetchOffer(cln *plugin.Plugin[*State], fetchInfo map[string]any) (map[string]any, error) {
|
||||
fetchInvoice, err := cln.State.Rpc("fetchinvoice", fetchInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clnFetchInvoice := struct{}{}
|
||||
if err := json.Decode(fetchInvoice, &clnFetchInvoice); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/vincenzopalazzo/cln4go/plugin"
|
||||
)
|
||||
|
||||
// / GetInfo - Return the info of the ocean plugin
|
||||
func GetInfo(cln *plugin.Plugin[*State], _ map[string]any) (map[string]any, error) {
|
||||
cln.Log("debug", "calling getinfo for plugin")
|
||||
return map[string]any{
|
||||
"v": "0.0.1",
|
||||
}, nil
|
||||
}
|
|
@ -1,17 +1,89 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
json "github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/vincenzopalazzo/cln4go/client"
|
||||
"github.com/vincenzopalazzo/cln4go/plugin"
|
||||
)
|
||||
|
||||
type PluginState struct{}
|
||||
|
||||
func Hello(plugin *plugin.Plugin[*PluginState], request map[string]any) (map[string]any, error) {
|
||||
return map[string]any{"message": "hello from cln4go.template"}, nil
|
||||
type State struct {
|
||||
rpc *client.UnixRPC
|
||||
}
|
||||
|
||||
func OnShutdown(plugin *plugin.Plugin[*PluginState], request map[string]any) {
|
||||
func (self *State) Rpc(method string, args map[string]any) (map[string]any, error) {
|
||||
return client.Call[map[string]any, map[string]any](self.rpc, method, args)
|
||||
}
|
||||
|
||||
func OceanPay(cln *plugin.Plugin[*State], request map[string]any) (map[string]any, error) {
|
||||
clnRequest := struct {
|
||||
invstr string
|
||||
}{}
|
||||
if err := json.Decode(request, &clnRequest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
invstrDecode, err := cln.State.Rpc("decode", map[string]any{
|
||||
"string": clnRequest.invstr,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clnDecode := struct {
|
||||
invType string `mapstructure:"type"`
|
||||
valid bool
|
||||
}{}
|
||||
|
||||
if err := json.Decode(invstrDecode, &clnDecode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var payInvoice map[string]any
|
||||
switch clnDecode.invType {
|
||||
case "bolt12 offer":
|
||||
case "bolt12 invoice_request", "bolt12 invoice":
|
||||
payInvoice, err = FetchOffer(cln, map[string]any{
|
||||
// TODO: adding the correct request for cln
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("Invoice String %s not supported: %s", clnDecode.invType, clnRequest.invstr)
|
||||
}
|
||||
|
||||
payResponse, err := cln.State.Rpc("pay", payInvoice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return payResponse, nil
|
||||
}
|
||||
|
||||
func OnShutdown(plugin *plugin.Plugin[*State], request map[string]any) {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func OnInit(plugin *plugin.Plugin[*State], conf map[string]any) map[string]any {
|
||||
clnConf := struct {
|
||||
LightningDir string `mapstructure:"lightning-dir"`
|
||||
RpcFile string `mapstructure:"rpc-file"`
|
||||
}{}
|
||||
if err := json.Decode(conf, &clnConf); err != nil {
|
||||
return map[string]any{
|
||||
"disable": err,
|
||||
}
|
||||
}
|
||||
rpc, err := client.NewUnix(fmt.Sprintf("%s/%s", clnConf.LightningDir, clnConf.RpcFile))
|
||||
if err != nil {
|
||||
return map[string]any{
|
||||
"disable": err,
|
||||
}
|
||||
}
|
||||
plugin.State.rpc = rpc
|
||||
return map[string]any{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue