Skip to content

Commit

Permalink
fix(txpool, cmd, gtk): broadcast transactions with zero fee (#1589)
Browse files Browse the repository at this point in the history
Co-authored-by: Javad Rajabzadeh <[email protected]>
  • Loading branch information
b00f and Ja7ad authored Nov 10, 2024
1 parent e89feff commit ca9820b
Show file tree
Hide file tree
Showing 33 changed files with 612 additions and 482 deletions.
2 changes: 1 addition & 1 deletion cmd/gtk/assets/ui/dialog_transaction_bond.ui
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Fee (Optional):</property>
<property name="label" translatable="yes">Fee:</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/assets/ui/dialog_transaction_transfer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Fee (Optional):</property>
<property name="label" translatable="yes">Fee:</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/assets/ui/dialog_transaction_withdraw.ui
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Fee (Optional):</property>
<property name="label" translatable="yes">Fee:</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down
8 changes: 6 additions & 2 deletions cmd/gtk/dialog_address_change_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ func changePassword(wlt *wallet.Wallet) {
}

err = wlt.UpdatePassword(oldPassword, newPassword)
errorCheck(err)
if err != nil {
showError(err)

return
}

err = wlt.Save()
errorCheck(err)
fatalErrorCheck(err)

dlg.Close()
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/gtk/dialog_addresss_private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func showAddressPrivateKey(wlt *wallet.Wallet, addr string) {
}

prv, err := wlt.PrivateKey(password, addr)
errorCheck(err)
if err != nil {
showError(err)

return
}

dlg := getDialogObj(builder, "id_dialog_address_private_key")
addressEntry := getEntryObj(builder, "id_entry_address")
Expand Down
23 changes: 8 additions & 15 deletions cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/wallet"
Expand Down Expand Up @@ -35,6 +34,9 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

estimatedFee := estimatedFee(wlt, payload.TypeBond)
feeEntry.SetText(fmt.Sprintf("%g", estimatedFee.ToPAC()))

for _, ai := range wlt.AllAccountAddresses() {
senderEntry.Append(ai.Address, ai.Address)
}
Expand All @@ -48,6 +50,7 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
onSenderChanged := func() {
senderStr := senderEntry.GetActiveID()
updateAccountHint(senderHint, senderStr, wlt)
updateBalanceHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onReceiverChanged := func() {
Expand All @@ -56,10 +59,6 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
updateValidatorHint(receiverHint, receiverStr, wlt)
}

onAmountChanged := func() {
updateAmountHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onFeeChanged := func() {
updateFeeHint(feeHint, wlt, payload.TypeTransfer)
}
Expand All @@ -74,25 +73,20 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {

amt, err := amount.FromString(amountStr)
if err != nil {
errorCheck(err)
showError(err)

return
}

feeStr, _ := feeEntry.GetText()
opts := []wallet.TxOption{
wallet.OptionMemo(memo),
}

fee, _ := feeEntry.GetText()
if fee != "" {
feeAmount, err := amount.FromString(fee)
cmd.FatalErrorCheck(err)
opts = append(opts, wallet.OptionFee(feeAmount))
wallet.OptionFeeFromString(feeStr),
}

trx, err := wlt.MakeBondTx(sender, receiver, publicKey, amt, opts...)
if err != nil {
errorCheck(err)
showError(err)

return
}
Expand Down Expand Up @@ -120,7 +114,6 @@ Memo: %s
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
"on_fee_changed": onFeeChanged,
"on_send": onSend,
"on_cancel": onClose,
Expand Down
24 changes: 8 additions & 16 deletions cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/wallet"
Expand All @@ -34,6 +33,9 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

estimatedFee := estimatedFee(wlt, payload.TypeTransfer)
feeEntry.SetText(fmt.Sprintf("%g", estimatedFee.ToPAC()))

for _, i := range wlt.AllAccountAddresses() {
senderEntry.Append(i.Address, i.Address)
}
Expand All @@ -42,17 +44,13 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
onSenderChanged := func() {
senderStr := senderEntry.GetActiveID()
updateAccountHint(senderHint, senderStr, wlt)
updateBalanceHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onReceiverChanged := func() {
receiverStr, _ := receiverEntry.GetText()
updateAccountHint(receiverHint, receiverStr, wlt)
}

onAmountChanged := func() {
updateAmountHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onFeeChanged := func() {
updateFeeHint(feeHint, wlt, payload.TypeTransfer)
}
Expand All @@ -65,25 +63,20 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {

amt, err := amount.FromString(amountStr)
if err != nil {
errorCheck(err)
showError(err)

return
}

feeStr, _ := feeEntry.GetText()
opts := []wallet.TxOption{
wallet.OptionMemo(memo),
}

fee, _ := feeEntry.GetText()
if fee != "" {
feeAmount, err := amount.FromString(fee)
cmd.FatalErrorCheck(err)
opts = append(opts, wallet.OptionFee(feeAmount))
wallet.OptionFeeFromString(feeStr),
}

trx, err := wlt.MakeTransferTx(sender, receiver, amt, opts...)
if err != nil {
errorCheck(err)
showError(err)

return
}
Expand Down Expand Up @@ -111,7 +104,6 @@ Memo: %s
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
"on_fee_changed": onFeeChanged,
"on_send": onSend,
"on_cancel": onClose,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func broadcastTransactionUnbond(wlt *wallet.Wallet) {

trx, err := wlt.MakeUnbondTx(validator, opts...)
if err != nil {
errorCheck(err)
showError(err)

return
}
Expand Down
23 changes: 8 additions & 15 deletions cmd/gtk/dialog_transaction_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/wallet"
Expand All @@ -34,6 +33,9 @@ func broadcastTransactionWithdraw(wlt *wallet.Wallet) {
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())

estimatedFee := estimatedFee(wlt, payload.TypeWithdraw)
feeEntry.SetText(fmt.Sprintf("%g", estimatedFee.ToPAC()))

for _, ai := range wlt.AllValidatorAddresses() {
validatorEntry.Append(ai.Address, ai.Address)
}
Expand All @@ -46,6 +48,7 @@ func broadcastTransactionWithdraw(wlt *wallet.Wallet) {
onSenderChanged := func() {
senderStr := validatorEntry.GetActiveID()
updateValidatorHint(validatorHint, senderStr, wlt)
updateStakeHint(stakeHint, validatorEntry.GetActiveID(), wlt)
}

onReceiverChanged := func() {
Expand All @@ -54,10 +57,6 @@ func broadcastTransactionWithdraw(wlt *wallet.Wallet) {
updateAccountHint(receiverHint, receiverStr, wlt)
}

onAmountChanged := func() {
updateAmountHint(stakeHint, validatorEntry.GetActiveID(), wlt)
}

onFeeChanged := func() {
updateFeeHint(feeHint, wlt, payload.TypeTransfer)
}
Expand All @@ -71,25 +70,20 @@ func broadcastTransactionWithdraw(wlt *wallet.Wallet) {

amt, err := amount.FromString(amountStr)
if err != nil {
errorCheck(err)
showError(err)

return
}

feeStr, _ := feeEntry.GetText()
opts := []wallet.TxOption{
wallet.OptionMemo(memo),
}

fee, _ := feeEntry.GetText()
if fee != "" {
feeAmount, err := amount.FromString(fee)
cmd.FatalErrorCheck(err)
opts = append(opts, wallet.OptionFee(feeAmount))
wallet.OptionFeeFromString(feeStr),
}

trx, err := wlt.MakeWithdrawTx(sender, receiver, amt, opts...)
if err != nil {
errorCheck(err)
showError(err)

return
}
Expand Down Expand Up @@ -117,7 +111,6 @@ Memo: %s
signals := map[string]any{
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_stake_changed": onAmountChanged,
"on_fee_changed": onFeeChanged,
"on_send": onSend,
"on_cancel": onClose,
Expand Down
8 changes: 6 additions & 2 deletions cmd/gtk/dialog_wallet_create_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ func createAddress(wdgWallet *widgetWallet) {
_, err = wdgWallet.model.wallet.NewValidatorAddress(walletAddressLabel)
}

errorCheck(err)
if err != nil {
showError(err)

return
}

err = wdgWallet.model.wallet.Save()
errorCheck(err)
fatalErrorCheck(err)

wdgWallet.model.rebuildModel()

Expand Down
4 changes: 1 addition & 3 deletions cmd/gtk/model_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (model *walletModel) rebuildModel() {
model.listStore.Clear()
for _, item := range data {
iter := model.listStore.Append()
err := model.listStore.Set(iter,
_ = model.listStore.Set(iter,
[]int{
IDAddressesColumnNo,
IDAddressesColumnAddress,
Expand All @@ -94,8 +94,6 @@ func (model *walletModel) rebuildModel() {
item[4],
item[5],
})

errorCheck(err)
}

return false
Expand Down
6 changes: 5 additions & 1 deletion cmd/gtk/startup_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ func startupAssistant(workingDir string, chainType genesis.ChainType) bool {
snapshotURL,
storeDir,
)
fatalErrorCheck(err)
if err != nil {
showError(err)

return
}

ctx := context.Background()
mdCh := getMetadata(ctx, importer, listBox)
Expand Down
Loading

0 comments on commit ca9820b

Please sign in to comment.