Skip to content

Commit

Permalink
fix: set wallet fee
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Jan 9, 2025
1 parent fc166f9 commit c5313e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions config/config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 4 additions & 10 deletions pkg/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -16,6 +15,7 @@ type Wallet struct {

address string
password string
fee amount.Amount
}

func Open(cfg *config.Wallet) (*Wallet, error) {
Expand All @@ -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...)
Expand Down Expand Up @@ -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),
}

Expand Down

0 comments on commit c5313e0

Please sign in to comment.