Skip to content

Commit

Permalink
Merge branch 'feat/onboarding-flow' into argon2
Browse files Browse the repository at this point in the history
* feat/onboarding-flow:
  Test fmar (#242)
  fix: decode breez created at, expires at, description and description hash
  fix: breez payment type check
  • Loading branch information
bumi committed Jan 30, 2024
2 parents d3bf0df + 2e7af2e commit 1b3f235
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/wails.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Wails build
on:
push:
release:
types: [published]
jobs:
build:
strategy:
fail-fast: false
matrix:
build: [
{ name: nostr-wallet-connect, platform: linux/amd64, os: ubuntu-latest },
]
env:
REGISTRY: ghcr.io
IMAGENAME: ${{ github.event.repository.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: Setup GoLang
uses: actions/setup-go@v4
with:
check-latest: true
go-version: 1.21
# Setup and configure NodeJS
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
shell: bash
- name: Install Linux Wails deps
run: sudo apt-get update && sudo apt-get install libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu libgtk-3-dev nsis
shell: bash
- name: Wails Doctor
working-directory: .
run: wails doctor
shell: bash
# Building step
- name: Build App
working-directory: .
run: wails build --platform ${{ matrix.build.platform }} -tags "wails"
#-o ${{ matrix.build.name }}
shell: bash
- uses: actions/upload-artifact@v3
with:
name: Wails Build ${{runner.os}} nostr-wallet-connect
path: |
*/bin/
*\bin\*
# - uses: dAppServer/[email protected]
# with:
# build-name: ${{ matrix.build.name }}
# build-platform: ${{ matrix.build.platform }}
# package: false
# go-version: '1.21'
64 changes: 0 additions & 64 deletions .github/workflows/workflow.yaml

This file was deleted.

34 changes: 22 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
FROM node:18-alpine as frontend
FROM node:19-alpine as frontend
WORKDIR /build
COPY frontend ./frontend
RUN cd frontend && yarn install && yarn build
RUN cd frontend && yarn install && yarn build:http

FROM golang:latest as builder
FROM golang:1.21 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM

RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

RUN apt-get update && \
apt-get install -y gcc
apt-get install -y gcc

ENV CGO_ENABLED=1
ENV GOOS=linux
ENV GOARCH=amd64
#ENV GOARCH=$GOARCH

#RUN echo "AAA $GOARCH"

# Move to working directory /build
WORKDIR /build

# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go mod download

# Copy the code into the container
COPY . .

# Copy frontend dist files into the container
COPY --from=frontend /build/frontend/dist ./frontend/dist

RUN go build -o main .
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build -o main .

# Start a new, final image to reduce size.
FROM alpine as final
RUN wget https://github.com/breez/breez-sdk-go/raw/main/breez_sdk/lib/linux-amd64/libbreez_sdk_bindings.so

# FROM gcr.io/distroless/static-debian11
# Start a new, final image to reduce size.
FROM debian as final

# USER small-user:small-user

# Copy the binaries and entrypoint from the builder image.
ENV LD_LIBRARY_PATH=/usr/lib/libbreez
#
# # Copy the binaries and entrypoint from the builder image.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/libbreez_sdk_bindings.so /usr/lib/libbreez/
COPY --from=builder /build/main /bin/

ENTRYPOINT [ "/bin/main" ]
53 changes: 38 additions & 15 deletions breez.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"log"
"os"
"path/filepath"
"strings"
"time"

"github.com/breez/breez-sdk-go/breez_sdk"
decodepay "github.com/nbd-wtf/ln-decodepay"
)

type BreezService struct {
Expand Down Expand Up @@ -168,7 +170,10 @@ func (bs *BreezService) LookupInvoice(ctx context.Context, senderPubkey string,
}
if payment != nil {
log.Printf("p: %v", payment)
transaction = breezPaymentToTransaction(payment)
transaction, err = breezPaymentToTransaction(payment)
if err != nil {
return nil, err
}
return transaction, nil
} else {
return nil, errors.New("not found")
Expand All @@ -183,9 +188,15 @@ func (bs *BreezService) ListTransactions(ctx context.Context, senderPubkey strin

transactions = []Nip47Transaction{}
for _, payment := range payments {
transaction := breezPaymentToTransaction(&payment)
if payment.PaymentType != breez_sdk.PaymentTypeReceived && payment.PaymentType != breez_sdk.PaymentTypeSent {
// skip other types of payments for now
continue
}

transactions = append(transactions, *transaction)
transaction, err := breezPaymentToTransaction(&payment)
if err == nil {
transactions = append(transactions, *transaction)
}
}
return transactions, nil
}
Expand All @@ -201,28 +212,40 @@ func (bs *BreezService) GetInfo(ctx context.Context, senderPubkey string) (info
}, nil
}

func breezPaymentToTransaction(payment *breez_sdk.Payment) *Nip47Transaction {
func breezPaymentToTransaction(payment *breez_sdk.Payment) (*Nip47Transaction, error) {
var lnDetails breez_sdk.PaymentDetailsLn
if payment.Details != nil {
lnDetails, _ = payment.Details.(breez_sdk.PaymentDetailsLn)
}
var txType string
if payment.PaymentType == breez_sdk.PaymentTypeSent {
txType = "outgoing"
} else if payment.PaymentType == breez_sdk.PaymentTypeSent {
} else {
txType = "incoming"
}

paymentRequest, err := decodepay.Decodepay(strings.ToLower(lnDetails.Data.Bolt11))
if err != nil {
log.Printf("Failed to decode bolt11 invoice: %v", payment)
return nil, err
}

createdAt := int64(paymentRequest.CreatedAt)
expiresAtUnix := time.UnixMilli(int64(paymentRequest.CreatedAt) * 1000).Add(time.Duration(paymentRequest.Expiry) * time.Second).Unix()
expiresAt := &expiresAtUnix

tx := &Nip47Transaction{
Type: txType,
Invoice: lnDetails.Data.Bolt11,
Preimage: lnDetails.Data.PaymentPreimage,
PaymentHash: lnDetails.Data.PaymentHash,
Amount: int64(payment.AmountMsat),
FeesPaid: int64(payment.FeeMsat),
CreatedAt: time.Now().Unix(),
ExpiresAt: nil,
Metadata: nil,
Type: txType,
Invoice: lnDetails.Data.Bolt11,
Preimage: lnDetails.Data.PaymentPreimage,
PaymentHash: lnDetails.Data.PaymentHash,
Amount: int64(payment.AmountMsat),
FeesPaid: int64(payment.FeeMsat),
CreatedAt: createdAt,
ExpiresAt: expiresAt,
Metadata: nil,
Description: paymentRequest.Description,
DescriptionHash: paymentRequest.DescriptionHash,
}
if payment.Status == breez_sdk.PaymentStatusComplete {
settledAt := payment.PaymentTime
Expand All @@ -233,5 +256,5 @@ func breezPaymentToTransaction(payment *breez_sdk.Payment) *Nip47Transaction {
tx.Description = *payment.Description
}

return tx
return tx, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.1

require (
github.com/breez/breez-sdk-go v0.2.10
github.com/breez/breez-sdk-go v0.2.14
github.com/davrux/echo-logrus/v4 v4.0.3
github.com/go-gormigrate/gormigrate/v2 v2.1.1
github.com/gorilla/sessions v1.2.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/breez/breez-sdk-go v0.2.10 h1:D9mEtVTNWhwoV7L6esxpyjoFyFkFoJ2w2l7iZdfE7NA=
github.com/breez/breez-sdk-go v0.2.10/go.mod h1:EalYMEeQVwRzr6UXnF4QpLlpuWNwQQN9xwtDKNIutBo=
github.com/breez/breez-sdk-go v0.2.14 h1:d9AAbSWXQpE/nMZyVBvmg808zSe5jRl9PkyRLiMD298=
github.com/breez/breez-sdk-go v0.2.14/go.mod h1:EalYMEeQVwRzr6UXnF4QpLlpuWNwQQN9xwtDKNIutBo=
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
Expand Down

0 comments on commit 1b3f235

Please sign in to comment.