Skip to content

Commit

Permalink
fix panic in send command (#53)
Browse files Browse the repository at this point in the history
* get mint url for keyset in send command

* fix send regex

* use mint url from filteredKeySets
  • Loading branch information
elnosh authored Sep 20, 2023
1 parent 1494df2 commit 8ff4951
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions cmd/cashu/feni.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package main

import (
"fmt"
"github.com/c-bata/go-prompt"
"github.com/cashubtc/cashu-feni/cmd/cashu/feni"
"os"
"regexp"
"strings"

"github.com/c-bata/go-prompt"
"github.com/cashubtc/cashu-feni/cmd/cashu/feni"
)

var sendRegex = regexp.MustCompile("send [0-9] ")
var sendRegex = regexp.MustCompile("send [0-9]")
var advancedPrompt = &feni.CobraPrompt{
RootCmd: feni.RootCmd,
PersistFlagValues: true,
Expand Down
20 changes: 13 additions & 7 deletions cmd/cashu/feni/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package feni
import (
"bytes"
"fmt"
"strconv"

"github.com/c-bata/go-prompt"
"github.com/cashubtc/cashu-feni/cashu"
"github.com/cashubtc/cashu-feni/crypto"
"github.com/samber/lo"
"github.com/spf13/cobra"
"strconv"
)

func init() {
Expand Down Expand Up @@ -81,6 +82,7 @@ func askMintSelection(cmd *cobra.Command) error {
Wallet.loadDefaultMint()
return nil
}

func askInt(cmd *cobra.Command) int {
reader := cmd.InOrStdin()
in := []byte{}
Expand All @@ -101,7 +103,6 @@ func askInt(cmd *cobra.Command) int {
s, err := strconv.Atoi(string(in))
fmt.Printf("%d, %v", s, err)
return s
return 0
}

func send(cmd *cobra.Command, args []string) {
Expand All @@ -117,24 +118,29 @@ func send(cmd *cobra.Command, args []string) {
if lockFlag != "" && flagIsPay2ScriptHash() {
p2sh = true
}

mint, _ := strconv.Atoi(args[1])
Wallet.Client.Url = filteredKeySets[mint].MintUrl
Wallet.loadDefaultMint()
amount, err := strconv.Atoi(args[0])

amount, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
panic(err)
fmt.Println("invalid amount")
return
}
_, sendProofs, err := Wallet.SplitToSend(uint64(amount), lockFlag, true)
_, sendProofs, err := Wallet.SplitToSend(amount, lockFlag, true)
if err != nil {
panic(err)
fmt.Println(err)
return
}
var hide bool
if lockFlag != "" && !p2sh {
hide = true
}
token, err := Wallet.serializeToken(sendProofs, hide)
if err != nil {
panic(err)
fmt.Println(err)
return
}
fmt.Println(token)
}
Expand Down

0 comments on commit 8ff4951

Please sign in to comment.