Skip to content

Commit

Permalink
Merge pull request #93 from Impa10r/v1.7.3
Browse files Browse the repository at this point in the history
v1.7.3
  • Loading branch information
Impa10r authored Nov 20, 2024
2 parents e820444 + 888f8ac commit 9f3fb58
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
/* {
{
"name": "Launch Package",
"type": "go",
"request": "launch",
Expand All @@ -15,7 +15,7 @@
"envFile": "${workspaceFolder}/.env",
//"args": ["-datadir", "/home/vlad/.peerswap_t4"]
//"args": ["-datadir", "/home/vlad/.peerswap3"]
}, */
},
// sudo bash -c 'echo 0 > /proc/sys/kernel/yama/ptrace_scope'
// go install -tags cln -gcflags 'all=-N -l' ./cmd/psweb
// lcli -k plugin subcommand=stop plugin=/home/vlad/go/bin/psweb
Expand All @@ -27,6 +27,6 @@
"mode": "local",
"processId": "${command:pickProcess}",
"cwd": "${workspaceFolder}",
} */
}
]
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Versions

## 1.7.3

- Show L-BTC balance changes when sending backup by telegram
- Add generating bech32m addresses for descriptors wallets

## 1.7.2

- Ignore inline comments in peerswap.conf
Expand Down
19 changes: 16 additions & 3 deletions cmd/psweb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,12 @@ func liquidHandler(w http.ResponseWriter, r *http.Request) {
return
}

walletInfo, err := liquid.GetWalletInfo(config.Config.ElementsWallet)
if err != nil {
redirectWithError(w, r, "/?", err)
return
}

type Page struct {
Authenticated bool
ErrorMessage string
Expand All @@ -1793,6 +1799,7 @@ func liquidHandler(w http.ResponseWriter, r *http.Request) {
AutoSwapCandidate *SwapParams
AutoSwapTargetPct uint64
AdvertiseEnabled bool
DescriptorsWallet bool
}

data := Page{
Expand All @@ -1813,6 +1820,7 @@ func liquidHandler(w http.ResponseWriter, r *http.Request) {
AutoSwapTargetPct: config.Config.AutoSwapTargetPct,
AutoSwapCandidate: &candidate,
AdvertiseEnabled: ln.AdvertiseLiquidBalance,
DescriptorsWallet: walletInfo.Descriptors,
}

// executing template named "liquid"
Expand Down Expand Up @@ -2410,15 +2418,20 @@ func submitHandler(w http.ResponseWriter, r *http.Request) {
return

case "newAddress":
res, err := ps.LiquidGetAddress(client)
label := r.FormValue("addressLabel")
addressType := "blech32"
if r.FormValue("bech32m") == "on" {
addressType = "bech32m"
}

addr, err := liquid.GetNewAddress(label, addressType, config.Config.ElementsWallet)
if err != nil {
log.Printf("unable to connect to RPC server: %v", err)
redirectWithError(w, r, "/liquid?", err)
return
}

// Redirect to liquid page with new address
http.Redirect(w, r, "/liquid?addr="+res.Address, http.StatusSeeOther)
http.Redirect(w, r, "/liquid?addr="+addr, http.StatusSeeOther)
return

case "sendLiquid":
Expand Down
69 changes: 69 additions & 0 deletions cmd/psweb/liquid/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,72 @@ func GetBlockchainInfo() (*BlockchainInfo, error) {

return &response, nil
}

type WalletInfo struct {
WalletName string `json:"walletname"`
WalletVersion int `json:"walletversion"`
Format string `json:"format"`
Balance BalanceInfo `json:"balance"`
UnconfirmedBalance BalanceInfo `json:"unconfirmed_balance"`
ImmatureBalance BalanceInfo `json:"immature_balance"`
TxCount int `json:"txcount"`
KeypoolSize int `json:"keypoolsize"`
KeypoolSizeHDInternal int `json:"keypoolsize_hd_internal"`
PayTxFee float64 `json:"paytxfee"`
PrivateKeysEnabled bool `json:"private_keys_enabled"`
AvoidReuse bool `json:"avoid_reuse"`
Scanning bool `json:"scanning"`
Descriptors bool `json:"descriptors"`
ExternalSigner bool `json:"external_signer"`
}

type BalanceInfo struct {
Bitcoin float64 `json:"bitcoin"`
}

// returns block hash
func GetWalletInfo(wallet string) (*WalletInfo, error) {
client := ElementsClient()
service := &Elements{client}
params := &[]interface{}{}

r, err := service.client.call("getwalletinfo", params, "/wallet/"+wallet)
if err = handleError(err, &r); err != nil {
log.Printf("GetWalletInfo: %v", err)
return nil, err
}

var response WalletInfo

err = json.Unmarshal([]byte(r.Result), &response)
if err != nil {
log.Printf("GetWalletInfo unmarshall: %v", err)
return nil, err
}

return &response, nil
}

func GetNewAddress(label, addressType, wallet string) (string, error) {

client := ElementsClient()
service := &Elements{client}

params := []interface{}{label, addressType}

r, err := service.client.call("getnewaddress", params, "/wallet/"+wallet)
if err = handleError(err, &r); err != nil {
log.Printf("Failed to get new address: %v", err)
return "", err
}

var response string

err = json.Unmarshal([]byte(r.Result), &response)
if err != nil {
log.Printf("GetNewAddress unmarshall: %v", err)
return "", err
}

return response, nil
}
11 changes: 9 additions & 2 deletions cmd/psweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

const (
// App VERSION tag
VERSION = "v1.7.2"
VERSION = "v1.7.3"
// Swap Out reserves are hardcoded here:
// https://github.com/ElementsProject/peerswap/blob/c77a82913d7898d0d3b7c83e4a990abf54bd97e5/peerswaprpc/server.go#L105
SWAP_OUT_CHANNEL_RESERVE = 5000
Expand Down Expand Up @@ -388,7 +388,14 @@ func liquidBackup(force bool) {
return
}

err = telegramSendFile(config.Config.DataDir, destinationZip, formatWithThousandSeparators(satAmount))
sign := ""
if satAmount > config.Config.ElementsBackupAmount {
sign = "+"
}

msg := formatWithThousandSeparators(satAmount) + " (" + sign + formatSigned(int64(satAmount)-int64(config.Config.ElementsBackupAmount)) + ")"

err = telegramSendFile(config.Config.DataDir, destinationZip, msg)
if err != nil {
log.Println("Error sending zip:", err)
return
Expand Down
27 changes: 26 additions & 1 deletion cmd/psweb/templates/liquid.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,32 @@ Amount is capped at remote channel balance to mimic brute force discovery" for="
<div class="box has-text-left">
<h4 class="title is-4">Receive Liquid</h4>
{{if eq .LiquidAddress ""}}
<form action="/submit" method="post">
<form autocomplete="off" action="/submit" method="post">
<input autocomplete="false" name="hidden" type="text" style="display:none;">
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label">Label</label>
</div>
<div class="field-body">
<input class="input is-medium" type="text" name="addressLabel" placeholder="Address Label">
</div>
</div>
{{if .DescriptorsWallet}}
<div class="field is-horizontal">
<div class="field-label is-normal">
</div>
<div class="field-body">
<div class="control">
<label class="checkbox is-large">
<input type="checkbox" name="bech32m" checked>
<strong>&nbsp&nbspTaproot (bech32m) address</strong>
</label>
</div>
</div>
</div>
{{else}}
<input type="hidden" name="bech32m" value="off">
{{end}}
<center>
<input type="hidden" name="action" value="newAddress">
<input class="button is-large" type="submit" value="Get New Address">
Expand Down

0 comments on commit 9f3fb58

Please sign in to comment.