Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qrcode support for safe transfer #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/safe/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/fox-one/mixin-cli/v2/cmdutil"
"github.com/fox-one/mixin-cli/v2/session"
"github.com/fox-one/mixin-sdk-go/v2"
"github.com/fox-one/pkg/qrcode"
"github.com/shopspring/decimal"
"github.com/spf13/cobra"
)
Expand All @@ -17,6 +18,7 @@ func NewCmdTransfer() *cobra.Command {
input mixin.TransferInput
amount string
yes bool
qrcode bool
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -51,6 +53,14 @@ func NewCmdTransfer() *cobra.Command {
if err != nil {
return fmt.Errorf("list unspent outputs failed: %w", err)
}

if opt.qrcode {
url := mixin.URL.SafePay(&input)
cmd.Println(url)
qrcode.Print(url)
return nil
}

balance := decimal.Zero
for i, utxo := range outputs {
if balance = balance.Add(utxo.Amount); balance.GreaterThan(input.Amount) {
Expand Down Expand Up @@ -165,6 +175,7 @@ func NewCmdTransfer() *cobra.Command {
cmd.Flags().StringSliceVar(&opt.input.OpponentMultisig.Receivers, "receivers", nil, "multisig receivers")
cmd.Flags().Uint8Var(&opt.input.OpponentMultisig.Threshold, "threshold", 0, "multisig threshold")
cmd.Flags().BoolVar(&opt.yes, "yes", false, "approve payment automatically")
cmd.Flags().BoolVar(&opt.qrcode, "qrcode", false, "show qrcode")

return cmd
}