From c5313e0b8dbb36a29f86d9a8b517c429d22c92a0 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Fri, 10 Jan 2025 00:06:01 +0800 Subject: [PATCH] fix: set wallet fee --- config/config.go | 7 ++++--- config/config.sample.yml | 3 +++ pkg/wallet/wallet.go | 14 ++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 33ff40e4..f23234b2 100644 --- a/config/config.go +++ b/config/config.go @@ -33,9 +33,10 @@ type Database struct { } type Wallet struct { - Address string `yaml:"address"` - Path string `yaml:"path"` - Password string `yaml:"password"` + Address string `yaml:"address"` + Path string `yaml:"path"` + Password string `yaml:"password"` + Fee amount.Amount `yaml:"fee"` } type DiscordBot struct { diff --git a/config/config.sample.yml b/config/config.sample.yml index 79739ace..f647431b 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -34,6 +34,9 @@ wallet: # Password for the wallet file. password: + # The fee to be paid for each transaction sent by Pagu. + fee: 0.01 + # Phoenix (TestNet) configuration phoenix: # Number of coins to send when the faucet is used. diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index 40987658..9c1da7d8 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/pactus-project/pactus/genesis" - "github.com/pactus-project/pactus/types/tx/payload" "github.com/pactus-project/pactus/wallet" "github.com/pagu-project/pagu/config" "github.com/pagu-project/pagu/pkg/amount" @@ -16,6 +15,7 @@ type Wallet struct { address string password string + fee amount.Amount } func Open(cfg *config.Wallet) (*Wallet, error) { @@ -28,11 +28,13 @@ func Open(cfg *config.Wallet) (*Wallet, error) { Wallet: wlt, address: cfg.Address, password: cfg.Password, + fee: cfg.Fee, }, nil } func (w *Wallet) BondTransaction(pubKey, toAddress, memo string, amt amount.Amount) (string, error) { opts := []wallet.TxOption{ + wallet.OptionFee(w.fee.ToPactusAmount()), wallet.OptionMemo(memo), } tx, err := w.Wallet.MakeBondTx(w.address, toAddress, pubKey, amt.ToPactusAmount(), opts...) @@ -70,16 +72,8 @@ func (w *Wallet) BondTransaction(pubKey, toAddress, memo string, amt amount.Amou } func (w *Wallet) TransferTransaction(toAddress, memo string, amt amount.Amount) (string, error) { - // calculate fee using amount struct. - fee, err := w.Wallet.CalculateFee(amt.ToPactusAmount(), payload.TypeTransfer) - if err != nil { - log.Error("error calculating fee", "err", err, "client") - - return "", err - } - opts := []wallet.TxOption{ - wallet.OptionFee(fee), + wallet.OptionFee(w.fee.ToPactusAmount()), wallet.OptionMemo(memo), }