Skip to content

Commit

Permalink
wallet - cli flag to specify mint in mint quote request
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Jan 16, 2025
1 parent 9a6339f commit 546f151
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions cmd/nutw/nutw.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func receive(ctx *cli.Context) error {
return nil
}

const invoiceFlag = "invoice"
const (
invoiceFlag = "invoice"
mintFlag = "mint"
)

var mintCmd = &cli.Command{
Name: "mint",
Expand All @@ -251,6 +254,10 @@ var mintCmd = &cli.Command{
Name: invoiceFlag,
Usage: "Specify paid invoice to mint tokens",
},
&cli.StringFlag{
Name: mintFlag,
Usage: "Specify mint from which to request mint quote",
},
},
Action: mint,
}
Expand All @@ -269,31 +276,36 @@ func mint(ctx *cli.Context) error {
if args.Len() < 1 {
printErr(errors.New("specify an amount to mint"))
}
amountStr := args.First()
err := requestMint(amountStr)
amount, err := strconv.ParseUint(args.First(), 10, 64)
if err != nil {
printErr(err)
return errors.New("invalid amount")
}

return nil
}
mint := nutw.CurrentMint()
if ctx.IsSet(mintFlag) {
mint = ctx.String(mintFlag)
}

func requestMint(amountStr string) error {
amount, err := strconv.ParseUint(amountStr, 10, 64)
err = requestMint(amount, mint)
if err != nil {
return errors.New("invalid amount")
printErr(err)
}

mintResponse, err := nutw.RequestMint(amount, nutw.CurrentMint())
return nil
}

func requestMint(amount uint64, mintURL string) error {
mintResponse, err := nutw.RequestMint(amount, mintURL)
if err != nil {
return err
}

fmt.Printf("invoice: %v\n\n", mintResponse.Request)

subMananger, err := submanager.NewSubscriptionManager(nutw.CurrentMint())
subMananger, err := submanager.NewSubscriptionManager(mintURL)
if err != nil {
return err
fmt.Println("after paying the invoice you can redeem the ecash by doing 'nutw mint --invoice [invoice]'")
return nil
}
defer subMananger.Close()

Expand All @@ -302,7 +314,8 @@ func requestMint(amountStr string) error {

subscription, err := subMananger.Subscribe(nut17.Bolt11MintQuote, []string{mintResponse.Quote})
if err != nil {
return err
fmt.Println("after paying the invoice you can redeem the ecash by doing 'nutw mint --invoice [invoice]'")
return nil
}

fmt.Println("checking if invoice gets paid...")
Expand Down

0 comments on commit 546f151

Please sign in to comment.