Skip to content

Commit

Permalink
Merge pull request #32 from Impa10r/v1.3.3
Browse files Browse the repository at this point in the history
v1.3.3
  • Loading branch information
Impa10r authored Apr 29, 2024
2 parents 70b2728 + fbc716f commit d8a4c4f
Show file tree
Hide file tree
Showing 21 changed files with 570 additions and 278 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
push.sh
cmd/psweb/__debug_bin*
.vscode
.vscode
.vscode/launch.json
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"buildFlags": "-tags lnd",
"buildFlags": "-tags cln",
"program": "${workspaceFolder}/cmd/psweb/",
"showLog": false,
"envFile": "${workspaceFolder}/.env",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Versions

## 1.3.3

- Add channel routing statistics on the peer screen
- Visual improvements for mobile browsers

## 1.3.2

- Add Bitcoin UTXOs selection for Liquid Peg-ins
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Clone the repository and build PeerSwap Web UI:
```bash
git clone https://github.com/Impa10r/peerswap-web && \
cd peerswap-web && \
make install-lnd
make -j$(nproc) install-lnd
```

### CLN:

```bash
git clone https://github.com/Impa10r/peerswap-web && \
cd peerswap-web && \
make install-cln
make -j$(nproc) install-cln
```

This will install `psweb` to your GOPATH (/home/USER/go/bin). You can check that it is working by running `psweb --version`. If not, add the path in ~/.profile and reload with `source .profile`.
Expand Down
15 changes: 15 additions & 0 deletions cmd/psweb/config/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ func loadDefaults(home, dataDir string) {

// LND-specific load from Peerswap config
func LoadPS() {

// find lnd path from peerswap.conf
certPath := GetPeerswapLNDSetting("lnd.tlscertpath")

if certPath != "" {
// Split the file path into its components
directoryPath, _ := filepath.Split(certPath)

// clean the final slash
Config.LightningDir = filepath.Clean(directoryPath)
}

// get peerswap rpc host from peerswap.conf
Config.RpcHost = GetPeerswapLNDSetting("host")

wallet := GetPeerswapLNDSetting("elementsd.rpcwallet")
if wallet != "" {
Config.ElementsWallet = wallet
Expand Down
41 changes: 41 additions & 0 deletions cmd/psweb/internet/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package internet

import (
"log"
"net/http"
"net/url"
"time"

"peerswap-web/cmd/psweb/config"

"golang.org/x/net/proxy"
)

// configures an http client with an optional Tor proxy
func GetHttpClient(useProxy bool) *http.Client {
var httpClient *http.Client

if useProxy && config.Config.ProxyURL != "" {
p, err := url.Parse(config.Config.ProxyURL)
if err != nil {
log.Println("Mempool getHttpClient:", err)
return nil
}
dialer, err := proxy.SOCKS5("tcp", p.Host, nil, proxy.Direct)
if err != nil {
log.Println("Mempool getHttpClient:", err)
return nil
}
httpClient = &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
},
Timeout: 5 * time.Second,
}
} else {
httpClient = &http.Client{
Timeout: 5 * time.Second,
}
}
return httpClient
}
49 changes: 49 additions & 0 deletions cmd/psweb/internet/github.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package internet

import (
"encoding/json"
"log"
"net/http"
)

// fetch the latest tag of PeerSwap Web from github.com
func GetLatestTag() string {

url := "http://api.github.com/repos/impa10r/peerswap-web/tags"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Println("Error creating request:", err)
return ""
}

req.Header.Set("Accept", "application/vnd.github.v3+json")

client := GetHttpClient(true)
resp, err := client.Do(req)
if err != nil {
log.Println("Error making request:", err)
return ""
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
log.Println("Failed to fetch tags. Status code:", resp.StatusCode)
return ""
}

var tags []map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&tags)
if err != nil {
log.Println("Error decoding JSON:", err)
return ""
}

if len(tags) > 0 {
latestTag := tags[0]["name"].(string)
return latestTag
} else {
log.Println("No tags found in the repository.")
return ""
}
}
51 changes: 14 additions & 37 deletions cmd/psweb/mempool/mempool.go → cmd/psweb/internet/mempool.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,22 @@
package mempool
package internet

import (
"bytes"
"encoding/json"
"io"
"log"
"net/http"
"net/url"
"time"

"peerswap-web/cmd/psweb/config"

"golang.org/x/net/proxy"
)

func getHttpClient() *http.Client {
var httpClient *http.Client

if config.Config.ProxyURL != "" {
p, err := url.Parse(config.Config.ProxyURL)
if err != nil {
log.Println("Mempool getHttpClient:", err)
return nil
}
dialer, err := proxy.SOCKS5("tcp", p.Host, nil, proxy.Direct)
if err != nil {
log.Println("Mempool getHttpClient:", err)
return nil
}
httpClient = &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
},
Timeout: 5 * time.Second,
}
} else {
httpClient = &http.Client{
Timeout: 5 * time.Second,
}
}
return httpClient
}

// fetch node alias from mempool.space
func GetNodeAlias(id string) string {
if config.Config.BitcoinApi != "" {
api := config.Config.BitcoinApi + "/api/v1/lightning/search?searchText=" + id
req, err := http.NewRequest("GET", api, nil)
if err == nil {
cl := getHttpClient()
cl := GetHttpClient(config.Config.BitcoinApi != config.Config.LocalMempool)
if cl == nil {
return id[:20] // shortened id
}
Expand Down Expand Up @@ -90,12 +59,13 @@ func GetNodeAlias(id string) string {
return ""
}

// fetch high priority fee rate from mempool.space
func GetFee() uint32 {
if config.Config.BitcoinApi != "" {
api := config.Config.BitcoinApi + "/api/v1/fees/recommended"
req, err := http.NewRequest("GET", api, nil)
if err == nil {
cl := getHttpClient()
cl := GetHttpClient(config.Config.BitcoinApi != config.Config.LocalMempool)
if cl == nil {
return 0
}
Expand Down Expand Up @@ -134,12 +104,13 @@ func GetFee() uint32 {
return 0
}

// fetch transaction block height from mempool.space
func GetTxHeight(txid string) int32 {
if config.Config.BitcoinApi != "" {
api := config.Config.BitcoinApi + "/api/tx/" + txid + "/status"
req, err := http.NewRequest("GET", api, nil)
if err == nil {
cl := getHttpClient()
cl := GetHttpClient(config.Config.BitcoinApi != config.Config.LocalMempool)
if cl == nil {
return 0
}
Expand Down Expand Up @@ -173,14 +144,20 @@ func GetTxHeight(txid string) int32 {
return 0
}

// broadcast new transaction to mempool.space
func SendRawTransaction(rawTx string) string {
if config.Config.BitcoinApi != "" {
api := config.Config.BitcoinApi + "/api/tx"
// Define the request body
requestBody := []byte(rawTx)

cl := GetHttpClient(config.Config.BitcoinApi != config.Config.LocalMempool)
if cl == nil {
return ""
}

// Send POST request
resp, err := http.Post(api, "application/octet-stream", bytes.NewBuffer(requestBody))
resp, err := cl.Post(api, "application/octet-stream", bytes.NewBuffer(requestBody))
if err != nil {
log.Println("Mempool SendRawTransaction:", err)
return ""
Expand Down
Loading

0 comments on commit d8a4c4f

Please sign in to comment.