From b21c38e828feca8a4fd5b710e51d0b6223d6a71b Mon Sep 17 00:00:00 2001 From: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:43:48 +0100 Subject: [PATCH] Fix amount conversion from btc to sats unit (#81) * Fix amount conversion from btc to sats unit * Remove dev logs --- cmd/ocean/transaction.go | 5 ++++- go.mod | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/ocean/transaction.go b/cmd/ocean/transaction.go index ea3c1956..38839dce 100644 --- a/cmd/ocean/transaction.go +++ b/cmd/ocean/transaction.go @@ -6,6 +6,7 @@ import ( "fmt" "math" + "github.com/shopspring/decimal" "github.com/spf13/cobra" pb "github.com/vulpemventures/ocean/api-spec/protobuf/gen/go/ocean/v1" ) @@ -153,9 +154,11 @@ type output struct { } func (o output) proto() *pb.Output { + btc := decimal.NewFromFloat(math.Pow10(8)) + amount := decimal.NewFromFloat(o.Amount).Mul(btc).BigInt().Uint64() return &pb.Output{ Address: o.Address, - Amount: uint64(o.Amount * math.Pow10(8)), + Amount: amount, Asset: o.Asset, } } diff --git a/go.mod b/go.mod index c3d6695c..640f6322 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( require ( github.com/jackc/pgconn v1.12.1 github.com/jackc/pgx/v4 v4.16.1 + github.com/shopspring/decimal v1.2.0 github.com/tyler-smith/go-bip39 v1.1.0 github.com/vulpemventures/go-bip32 v0.0.0-20200624192635-867c159da4d7 )