From 0d2abe4f80e1e67d60e05bc01a46513ade032bc4 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Mon, 5 Sep 2022 22:12:35 +0200 Subject: [PATCH 1/3] update lnd-manageJ, use file-based H2 DB instead of PostgreSQL --- cmd/testrunner/lnd-managej.go | 16 +++++++--------- lnd-managej/Dockerfile | 19 +++++-------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/cmd/testrunner/lnd-managej.go b/cmd/testrunner/lnd-managej.go index 7e3db56..f91d887 100644 --- a/cmd/testrunner/lnd-managej.go +++ b/cmd/testrunner/lnd-managej.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "strings" ) const lndManageJHost = "lnd-managej" @@ -32,7 +33,7 @@ func getLndManageJConnection(alias string) (nodeInterface, error) { func (l *lndManageJConnection) resetCache() error { resp, err := http.Get( fmt.Sprintf( - "http://%v:8081/beta/pickhardt-payments/reset-graph-cache", + "http://%v:8081/api/payments/reset-graph-cache", lndManageJHost, ), ) @@ -124,12 +125,9 @@ func (l *lndManageJConnection) IsSynced(totalEdges, localChannels int) (bool, er } func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]string) error { - resp, err := http.Get( - fmt.Sprintf( - "http://%v:8081/beta/pickhardt-payments/pay-payment-request/%v/fee-rate-weight/1", - lndManageJHost, invoice, - ), - ) + requestBodyReader := strings.NewReader("{\"feeRateWeight\": 1}") + url := fmt.Sprintf("http://%v:8081/api/payments/pay-payment-request/%v", lndManageJHost, invoice) + resp, err := http.Post(url, "application/json", requestBodyReader) if err != nil { return err } @@ -139,12 +137,12 @@ func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]s return errors.New("payment error") } - body, err := io.ReadAll(resp.Body) + responseBody, err := io.ReadAll(resp.Body) if err != nil { return err } - fmt.Println(string(body)) + fmt.Println(string(responseBody)) return nil } diff --git a/lnd-managej/Dockerfile b/lnd-managej/Dockerfile index da4d7ae..c561041 100644 --- a/lnd-managej/Dockerfile +++ b/lnd-managej/Dockerfile @@ -1,15 +1,8 @@ FROM gradle:latest -RUN apt-get update -RUN apt-get install postgresql sudo -y - -RUN /etc/init.d/postgresql start && \ - sudo -u postgres psql -c "CREATE USER bitcoin WITH PASSWORD 'unset'" && \ - sudo -u postgres createdb lndmanagej -O bitcoin && \ - /etc/init.d/postgresql stop RUN git clone https://github.com/C-Otto/lnd-manageJ.git && \ cd lnd-manageJ && \ - git checkout 777a0e9c2412b3b7bd682b3cd1b4832472135650 + git checkout c57eca472aafe2546768a6f68ffe39499919e36b WORKDIR lnd-manageJ RUN gradle application:bootJar @@ -20,12 +13,10 @@ RUN echo "host=node-start" >> /root/.config/lnd-manageJ.conf RUN echo "macaroon_file=/cfg/start/admin.macaroon" >> /root/.config/lnd-manageJ.conf RUN echo "cert_file=/cfg/start/tls.cert" >> /root/.config/lnd-manageJ.conf +RUN echo "[pickhardt-payments]" >> /root/.config/lnd-manageJ.conf +RUN echo "enabled=true" >> /root/.config/lnd-manageJ.conf + RUN echo "server.address=0.0.0.0" >> /root/override.properties EXPOSE 8081 -CMD /etc/init.d/postgresql start && \ - java -jar application/build/libs/application-boot.jar --spring.config.location=classpath:application.properties,/root/override.properties - - -# docker build -t lnd-managej . -# docker run --network host -v /home/xxx/.lnd/:/root/.lnd lnd-managej +CMD java -Dspring.profiles.active=h2 -jar application/build/libs/application-boot.jar --spring.config.location=classpath:application.properties,/root/override.properties From cc168458784d2aa5c25441102433812d280b9bee Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Mon, 5 Sep 2022 22:23:13 +0200 Subject: [PATCH 2/3] stream response from lnd-manageJ --- cmd/testrunner/lnd-managej.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/testrunner/lnd-managej.go b/cmd/testrunner/lnd-managej.go index f91d887..ac5f48e 100644 --- a/cmd/testrunner/lnd-managej.go +++ b/cmd/testrunner/lnd-managej.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "encoding/json" "errors" "fmt" @@ -137,12 +138,13 @@ func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]s return errors.New("payment error") } - responseBody, err := io.ReadAll(resp.Body) - if err != nil { + scanner := bufio.NewScanner(resp.Body) + for scanner.Scan() { + fmt.Println(scanner.Text()) + } + if err := scanner.Err(); err != nil { return err } - fmt.Println(string(responseBody)) - return nil } From 078fc7723888b71674a81ffc62136383375dba9c Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Mon, 5 Sep 2022 22:40:33 +0200 Subject: [PATCH 3/3] pretty-print responses from lnd-manageJ --- cmd/testrunner/lnd-managej.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/testrunner/lnd-managej.go b/cmd/testrunner/lnd-managej.go index ac5f48e..644d442 100644 --- a/cmd/testrunner/lnd-managej.go +++ b/cmd/testrunner/lnd-managej.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "strings" + "time" ) const lndManageJHost = "lnd-managej" @@ -125,6 +126,11 @@ func (l *lndManageJConnection) IsSynced(totalEdges, localChannels int) (bool, er return true, nil } +type TimestampAndMessage struct { + Timestamp string + Message string +} + func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]string) error { requestBodyReader := strings.NewReader("{\"feeRateWeight\": 1}") url := fmt.Sprintf("http://%v:8081/api/payments/pay-payment-request/%v", lndManageJHost, invoice) @@ -140,7 +146,12 @@ func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]s scanner := bufio.NewScanner(resp.Body) for scanner.Scan() { - fmt.Println(scanner.Text()) + var timestampAndMessage TimestampAndMessage + line := scanner.Text() + _ = json.Unmarshal([]byte(line), ×tampAndMessage) + timestamp, _ := time.Parse(time.RFC3339Nano, timestampAndMessage.Timestamp) + formattedTimestamp := timestamp.Format("2006-01-02T15:04:05.000Z07") + fmt.Printf("%v: %v\n", formattedTimestamp, timestampAndMessage.Message) } if err := scanner.Err(); err != nil { return err