diff --git a/.vscode/launch.json b/.vscode/launch.json index 12955e8..fccadb1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", @@ -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 @@ -27,6 +27,6 @@ "mode": "local", "processId": "${command:pickProcess}", "cwd": "${workspaceFolder}", - } */ + } ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f0906a6..9424718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/psweb/handlers.go b/cmd/psweb/handlers.go index 2235b7e..4d8d75a 100644 --- a/cmd/psweb/handlers.go +++ b/cmd/psweb/handlers.go @@ -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 @@ -1793,6 +1799,7 @@ func liquidHandler(w http.ResponseWriter, r *http.Request) { AutoSwapCandidate *SwapParams AutoSwapTargetPct uint64 AdvertiseEnabled bool + DescriptorsWallet bool } data := Page{ @@ -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" @@ -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": diff --git a/cmd/psweb/liquid/elements.go b/cmd/psweb/liquid/elements.go index b0ead0f..91e97fa 100644 --- a/cmd/psweb/liquid/elements.go +++ b/cmd/psweb/liquid/elements.go @@ -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 +} diff --git a/cmd/psweb/main.go b/cmd/psweb/main.go index 1b80801..c67241b 100644 --- a/cmd/psweb/main.go +++ b/cmd/psweb/main.go @@ -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 @@ -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 diff --git a/cmd/psweb/templates/liquid.gohtml b/cmd/psweb/templates/liquid.gohtml index bc649be..076cec0 100644 --- a/cmd/psweb/templates/liquid.gohtml +++ b/cmd/psweb/templates/liquid.gohtml @@ -200,7 +200,32 @@ Amount is capped at remote channel balance to mimic brute force discovery" for="

Receive Liquid

{{if eq .LiquidAddress ""}} -
+ + +
+
+ +
+
+ +
+
+ {{if .DescriptorsWallet}} +
+
+
+
+
+ +
+
+
+ {{else}} + + {{end}}