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

fix: set wallet fee #255

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
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
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
Loading