Skip to content

Commit

Permalink
fix: some missing big int
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Jul 18, 2023
1 parent 1d1fab2 commit 71de35f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions components/fctl/cmd/ledger/send.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ledger

import (
"fmt"
"math/big"
"strconv"

"github.com/formancehq/fctl/cmd/ledger/internal"
fctl "github.com/formancehq/fctl/pkg"
Expand Down Expand Up @@ -90,9 +90,9 @@ func (c *SendController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
asset = args[3]
}

amount, err := strconv.ParseInt(amountStr, 10, 64)
if err != nil {
return nil, err
amount, ok := big.NewInt(0).SetString(amountStr, 10)
if !ok {
return nil, fmt.Errorf("unable to parse '%s' as big int", amountStr)
}

metadata, err := fctl.ParseMetadata(fctl.GetStringSlice(cmd, c.metadataFlag))
Expand All @@ -107,7 +107,7 @@ func (c *SendController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
Metadata: metadata,
Postings: []shared.Posting{
{
Amount: big.NewInt(amount),
Amount: amount,
Asset: asset,
Destination: destination,
Source: source,
Expand Down
8 changes: 4 additions & 4 deletions components/fctl/cmd/ledger/transactions/num.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package transactions

import (
"fmt"
"strconv"
"math/big"
"strings"
"time"

Expand Down Expand Up @@ -123,9 +123,9 @@ func (c *NumController) Run(cmd *cobra.Command, args []string) (fctl.Renderable,
return nil, fmt.Errorf("malformed var: %s", v)
}

amount, err := strconv.ParseInt(amountParts[0], 10, 64)
if err != nil {
return nil, fmt.Errorf("malformed var: %s", v)
amount, ok := big.NewInt(0).SetString(amountParts[0], 10)
if !ok {
return nil, fmt.Errorf("unable to parse '%s' as big int", amountParts[0])
}

vars[parts[0]] = map[string]any{
Expand Down
9 changes: 4 additions & 5 deletions components/fctl/cmd/wallets/credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package wallets
import (
"fmt"
"math/big"
"strconv"

"github.com/formancehq/fctl/cmd/wallets/internal"
fctl "github.com/formancehq/fctl/pkg"
Expand Down Expand Up @@ -96,9 +95,9 @@ func (c *CreditWalletController) Run(cmd *cobra.Command, args []string) (fctl.Re
return nil, errors.New("You need to specify wallet id using --id or --name flags")
}

amount, err := strconv.ParseUint(amountStr, 10, 64)
if err != nil {
return nil, errors.Wrap(err, "parsing amount")
amount, ok := big.NewInt(0).SetString(amountStr, 10)
if !ok {
return nil, fmt.Errorf("unable to parse '%s' as big int", amountStr)
}

metadata, err := fctl.ParseMetadata(fctl.GetStringSlice(cmd, c.metadataFlag))
Expand All @@ -120,7 +119,7 @@ func (c *CreditWalletController) Run(cmd *cobra.Command, args []string) (fctl.Re
CreditWalletRequest: &shared.CreditWalletRequest{
Amount: shared.Monetary{
Asset: asset,
Amount: big.NewInt(int64(amount)),
Amount: amount,
},
Metadata: metadata,
Sources: sources,
Expand Down
9 changes: 4 additions & 5 deletions components/fctl/cmd/wallets/debit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package wallets
import (
"fmt"
"math/big"
"strconv"

"github.com/formancehq/fctl/cmd/wallets/internal"
fctl "github.com/formancehq/fctl/pkg"
Expand Down Expand Up @@ -112,9 +111,9 @@ func (c *DebitWalletController) Run(cmd *cobra.Command, args []string) (fctl.Ren

description := fctl.GetString(cmd, c.descriptionFlag)

amount, err := strconv.ParseInt(amountStr, 10, 32)
if err != nil {
return nil, errors.Wrap(err, "parsing amount")
amount, ok := big.NewInt(0).SetString(amountStr, 10)
if !ok {
return nil, fmt.Errorf("unable to parse '%s' as big int", amountStr)
}

var destination *shared.Subject
Expand All @@ -129,7 +128,7 @@ func (c *DebitWalletController) Run(cmd *cobra.Command, args []string) (fctl.Ren
DebitWalletRequest: &shared.DebitWalletRequest{
Amount: shared.Monetary{
Asset: asset,
Amount: big.NewInt(amount),
Amount: amount,
},
Pending: &pending,
Metadata: metadata,
Expand Down

1 comment on commit 71de35f

@vercel
Copy link

@vercel vercel bot commented on 71de35f Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.