Skip to content

Commit

Permalink
decode token command
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Jul 15, 2024
1 parent 68fbd5f commit d961a2d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion cmd/nutw/nutw.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -106,6 +107,7 @@ func main() {
p2pkLockCmd,
mnemonicCmd,
restoreCmd,
decodeCmd,
},
}

Expand Down Expand Up @@ -147,7 +149,7 @@ var receiveCmd = &cli.Command{
func receive(ctx *cli.Context) error {
args := ctx.Args()
if args.Len() < 1 {
printErr(errors.New("cashu token not provided"))
printErr(errors.New("token not provided"))
}
serializedToken := args.First()

Expand Down Expand Up @@ -399,6 +401,33 @@ func restore(ctx *cli.Context) error {
return nil
}

var decodeCmd = &cli.Command{
Name: "decode",
Action: decode,
}

func decode(ctx *cli.Context) error {
args := ctx.Args()
if args.Len() < 1 {
printErr(errors.New("token not provided"))
}
serializedToken := args.First()

token, err := cashu.DecodeToken(serializedToken)
if err != nil {
printErr(err)
}

jsonToken, err := json.MarshalIndent(token, "", " ")
if err != nil {
printErr(err)
}

fmt.Println(string(jsonToken))

return nil
}

func promptMintSelection(action string) string {
balanceByMints := nutw.GetBalanceByMints()
mintsLen := len(balanceByMints)
Expand Down

0 comments on commit d961a2d

Please sign in to comment.