Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export DEBIAN_FRONTEND=noninteractive
export BITCOIN_VERSION=0.20.1
export ELEMENTS_VERSION=0.18.1.8
export RUST_VERSION=nightly

sudo useradd -ms /bin/bash tester
sudo apt-get update -qq

Expand Down Expand Up @@ -66,3 +68,8 @@ sudo chmod 0440 /etc/sudoers.d/tester
elements-$ELEMENTS_VERSION-x86_64-linux-gnu.tar.bz2 \
elements-$ELEMENTS_VERSION
)

if [ "$RUST" == "1" ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
-y --default-toolchain ${RUST_VERSION}
fi
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,37 @@ jobs:
with:
name: Junit Report ${{ github.run_number }}.${{ matrix.cfg }}
path: report.*

rust-test:
name: Rust Test Config
runs-on: ubuntu-20.04
needs: [smoke-test]
env:
DEVELOPER: 1
RUST: 1
VALGRIND: 0
# Run only the rust tests, others are not impacted.
TEST_CMD: "make -j 8 && pytest -vvv tests/test_cln_rs.py"
steps:
- name: Checkout
uses: actions/checkout@v2.0.0

- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6

- name: Install dependencies
run: |
bash -x .github/scripts/setup.sh

- name: Build
run: |
bash -x .github/scripts/build.sh

- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Junit Report ${{ github.run_number }}.${{ matrix.cfg }}
path: report.*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ doc/lightning*.[1578]
# Ignore unrelated stuff
.DS_Store
.gdb_history

# Rust targets
target
Cargo.lock
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[workspace]
members = [
"cln-rpc",
]
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ ALL_TEST_PROGRAMS :=
ALL_FUZZ_TARGETS :=
ALL_C_SOURCES :=
ALL_C_HEADERS := header_versions_gen.h version_gen.h
# Extra (non C) targets that should be built by default.
DEFAULT_TARGETS :=

CPPFLAGS += -DBINTOPKGLIBEXECDIR="\"$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))\""
CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I/usr/local/include $(SQLITE3_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) -DBUILD_ELEMENTS=1
Expand Down Expand Up @@ -260,7 +262,7 @@ ifeq ($(HAVE_POSTGRES),1)
LDLIBS += $(POSTGRES_LDLIBS)
endif

default: show-flags all-programs all-test-programs doc-all
default: show-flags all-programs all-test-programs doc-all default-targets

ifneq ($(SUPPRESS_GENERATION),1)
FORCE = FORCE
Expand Down Expand Up @@ -323,6 +325,13 @@ endif
$(call VERBOSE,"printgen $@",tools/generate-wire.py -s -P --page impl $($@_args) ${@:.c=.h} `basename $< .csv | sed 's/_exp_/_/'` < $< > $@ && $(call SHA256STAMP,//,)); \
fi

RUST_PROFILE ?= debug
ifneq ($(RUST_PROFILE),debug)
CARGO_OPTS := --profile=$(RUST_PROFILE) --quiet
else
CARGO_OPTS := --quiet
endif

include external/Makefile
include bitcoin/Makefile
include common/Makefile
Expand All @@ -345,6 +354,9 @@ include contrib/libhsmd_python/Makefile
ifneq ($(FUZZING),0)
include tests/fuzz/Makefile
endif
ifneq ($(RUST),0)
include cln-rpc/Makefile
endif

# We make pretty much everything depend on these.
ALL_GEN_HEADERS := $(filter %gen.h,$(ALL_C_HEADERS))
Expand Down Expand Up @@ -410,7 +422,7 @@ else
endif
endif

pytest: $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS)
pytest: $(ALL_PROGRAMS) $(DEFAULT_TARGETS) $(ALL_TEST_PROGRAMS)
ifeq ($(PYTEST),)
@echo "py.test is required to run the integration tests, please install using 'pip3 install -r requirements.txt', and rerun 'configure'."
exit 1
Expand Down Expand Up @@ -607,6 +619,7 @@ update-ccan:
# Now ALL_PROGRAMS is fully populated, we can expand it.
all-programs: $(ALL_PROGRAMS)
all-test-programs: $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS)
default-targets: $(DEFAULT_TARGETS)

distclean: clean
$(RM) ccan/config.h config.vars
Expand All @@ -630,6 +643,7 @@ clean: obsclean
find . -name '*gcda' -delete
find . -name '*gcno' -delete
find . -name '*.nccout' -delete
if [ "${RUST}" -eq "1" ]; then cargo clean; fi

# These must both be enabled for update-mocks
ifeq ($(DEVELOPER)$(EXPERIMENTAL_FEATURES),11)
Expand Down
23 changes: 23 additions & 0 deletions cln-rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "cln-rpc"
version = "0.1.0"
edition = "2021"

[[example]]
name = "cln-rpc-getinfo"
path = "examples/getinfo.rs"

[dependencies]
anyhow = "1.0.51"
bytes = "1.1.0"
log = "0.4.14"
serde = { version = "1.0.131", features = ["derive"] }
serde_json = "1.0.72"
tokio-util = { version = "0.6.9", features = ["codec"] }
tokio = { version = "1", features = ["net"]}
native-tls = { version = "*", features = ["vendored"] }
futures-util = { version = "*", features = [ "sink" ] }

[dev-dependencies]
tokio = { version = "1", features = ["net", "macros", "rt-multi-thread"]}
env_logger = "*"
16 changes: 16 additions & 0 deletions cln-rpc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cln-rpc-wrongdir:
$(MAKE) -C .. cln-rpc-all

CLN_RPC_EXAMPLES := target/debug/examples/cln-rpc-getinfo
CLN_RPC_GENALL = cln-rpc/src/model.rs
CLN_RPC_SOURCES = $(shell find cln-rpc -name *.rs) ${CLN_RPC_GENALL}
JSON_SCHEMA = doc/schemas/*.schema.json
DEFAULT_TARGETS += $(CLN_RPC_EXAMPLES) $(CLN_RPC_GENALL)

$(CLN_RPC_GENALL): $(JSON_SCHEMA)
PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py

target/debug/examples/cln-rpc-getinfo: $(shell find cln-rpc -name *.rs)
cargo build --example cln-rpc-getinfo

cln-rpc-all: ${CLN_RPC_GEN_ALL} ${CLN_RPC_EXAMPLES}
3 changes: 3 additions & 0 deletions cln-rpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `cln-rpc`: Talk to c-lightning


18 changes: 18 additions & 0 deletions cln-rpc/examples/getinfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Context;
use cln_rpc::{model::GetinfoRequest, ClnRpc, Request};
use log::info;
use std::env::args;
use std::path::Path;
use tokio;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
env_logger::init();
let rpc_path = args().nth(1).context("missing argument: socket path")?;
let p = Path::new(&rpc_path);

let mut rpc = ClnRpc::new(p).await?;
let response = rpc.call(Request::Getinfo(GetinfoRequest {})).await?;
info!("{}", serde_json::to_string_pretty(&response)?);
Ok(())
}
Loading