Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lnd-manageJ #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 22 additions & 11 deletions cmd/testrunner/lnd-managej.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strings"
"time"
)

const lndManageJHost = "lnd-managej"
Expand All @@ -32,7 +35,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,
),
)
Expand Down Expand Up @@ -123,13 +126,15 @@ 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 {
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
}
Expand All @@ -139,12 +144,18 @@ func (l *lndManageJConnection) SendPayment(invoice string, aliasMap map[string]s
return errors.New("payment error")
}

body, err := io.ReadAll(resp.Body)
if err != nil {
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
var timestampAndMessage TimestampAndMessage
line := scanner.Text()
_ = json.Unmarshal([]byte(line), &timestampAndMessage)
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
}

fmt.Println(string(body))

return nil
}
19 changes: 5 additions & 14 deletions lnd-managej/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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