Skip to content

Commit

Permalink
refactor: remove payload prefix from payload transaction type
Browse files Browse the repository at this point in the history
  • Loading branch information
a.h.babazadeh committed Aug 31, 2023
1 parent 5c86e03 commit 4054d5f
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 93 deletions.
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func broadcastTransactionBond(wallet *wallet.Wallet, valAddrs []crypto.Address)

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wallet, payload.PayloadTypeBond)
updateFeeHint(amountHint, amtStr, wallet, payload.TypeBond)
}

onSend := func() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func broadcastTransactionSend(wallet *wallet.Wallet) {

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wallet, payload.PayloadTypeTransfer)
updateFeeHint(amountHint, amtStr, wallet, payload.TypeTransfer)
}

onSend := func() {
Expand Down
10 changes: 5 additions & 5 deletions execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type Execution struct {

func newExecution(strict bool) *Execution {
execs := make(map[payload.Type]Executor)
execs[payload.PayloadTypeTransfer] = executor.NewTransferExecutor(strict)
execs[payload.PayloadTypeBond] = executor.NewBondExecutor(strict)
execs[payload.PayloadTypeSortition] = executor.NewSortitionExecutor(strict)
execs[payload.PayloadTypeUnbond] = executor.NewUnbondExecutor(strict)
execs[payload.PayloadTypeWithdraw] = executor.NewWithdrawExecutor(strict)
execs[payload.TypeTransfer] = executor.NewTransferExecutor(strict)
execs[payload.TypeBond] = executor.NewBondExecutor(strict)
execs[payload.TypeSortition] = executor.NewSortitionExecutor(strict)
execs[payload.TypeUnbound] = executor.NewUnbondExecutor(strict)
execs[payload.TypeWithdraw] = executor.NewWithdrawExecutor(strict)

return &Execution{
executors: execs,
Expand Down
10 changes: 5 additions & 5 deletions state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ func (m *MockState) Params() param.Params {

func (m *MockState) CalculateFee(_ int64, payloadType payload.Type) (int64, error) {
switch payloadType {
case payload.PayloadTypeTransfer,
payload.PayloadTypeBond,
payload.PayloadTypeWithdraw:
case payload.TypeTransfer,
payload.TypeBond,
payload.TypeWithdraw:
{
return m.ts.RandInt64(1e9), nil
}

case payload.PayloadTypeUnbond,
payload.PayloadTypeSortition:
case payload.TypeUnbound,
payload.TypeSortition:
{
return 0, nil
}
Expand Down
10 changes: 5 additions & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,15 @@ func (st *state) publishEvents(height uint32, block *block.Block) {

func (st *state) CalculateFee(amount int64, payloadType payload.Type) (int64, error) {
switch payloadType {
case payload.PayloadTypeTransfer,
payload.PayloadTypeBond,
payload.PayloadTypeWithdraw:
case payload.TypeTransfer,
payload.TypeBond,
payload.TypeWithdraw:
{
return execution.CalculateFee(amount, st.params), nil
}

case payload.PayloadTypeUnbond,
payload.PayloadTypeSortition:
case payload.TypeUnbound,
payload.TypeSortition:
{
return 0, nil
}
Expand Down
22 changes: 11 additions & 11 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,20 +755,20 @@ func TestCalcFee(t *testing.T) {
expectedFee int64
expectedErrCode int
}{
{1, payload.PayloadTypeTransfer, 1, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.PayloadTypeWithdraw, 1001, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.PayloadTypeBond, 1000, td.state1.params.MinimumFee, errors.ErrNone},
{1, payload.TypeTransfer, 1, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.TypeWithdraw, 1001, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.TypeBond, 1000, td.state1.params.MinimumFee, errors.ErrNone},

{1 * 1e9, payload.PayloadTypeTransfer, 1, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.PayloadTypeWithdraw, 100001, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.PayloadTypeBond, 100000, 100000, errors.ErrNone},
{1 * 1e9, payload.TypeTransfer, 1, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.TypeWithdraw, 100001, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.TypeBond, 100000, 100000, errors.ErrNone},

{1 * 1e12, payload.PayloadTypeTransfer, 1, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeWithdraw, 1000001, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeBond, 1000000, 1000000, errors.ErrNone},
{1 * 1e12, payload.TypeTransfer, 1, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.TypeWithdraw, 1000001, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.TypeBond, 1000000, 1000000, errors.ErrNone},

{1 * 1e12, payload.PayloadTypeSortition, 0, 0, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeUnbond, 0, 0, errors.ErrNone},
{1 * 1e12, payload.TypeSortition, 0, 0, errors.ErrInvalidFee},
{1 * 1e12, payload.TypeUnbound, 0, 0, errors.ErrNone},
}
for _, test := range tests {
fee, err := td.state2.CalculateFee(test.amount, test.pldType)
Expand Down
30 changes: 15 additions & 15 deletions txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type txPool struct {
func NewTxPool(conf *Config, broadcastCh chan message.Message) TxPool {
pending := make(map[payload.Type]*linkedmap.LinkedMap[tx.ID, *tx.Tx])

pending[payload.PayloadTypeTransfer] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.sendPoolSize())
pending[payload.PayloadTypeBond] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.bondPoolSize())
pending[payload.PayloadTypeUnbond] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.unbondPoolSize())
pending[payload.PayloadTypeWithdraw] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.withdrawPoolSize())
pending[payload.PayloadTypeSortition] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.sortitionPoolSize())
pending[payload.TypeTransfer] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.sendPoolSize())
pending[payload.TypeBond] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.bondPoolSize())
pending[payload.TypeUnbound] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.unbondPoolSize())
pending[payload.TypeWithdraw] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.withdrawPoolSize())
pending[payload.TypeSortition] = linkedmap.NewLinkedMap[tx.ID, *tx.Tx](conf.sortitionPoolSize())

pool := &txPool{
config: conf,
Expand Down Expand Up @@ -152,31 +152,31 @@ func (p *txPool) PrepareBlockTransactions() block.Txs {
defer p.lk.RUnlock()

// Appending one sortition transaction
poolSortition := p.pools[payload.PayloadTypeSortition]
poolSortition := p.pools[payload.TypeSortition]
for n := poolSortition.HeadNode(); n != nil; n = n.Next {
trxs = append(trxs, n.Data.Value)
}

// Appending bond transactions
poolBond := p.pools[payload.PayloadTypeBond]
poolBond := p.pools[payload.TypeBond]
for n := poolBond.HeadNode(); n != nil; n = n.Next {
trxs = append(trxs, n.Data.Value)
}

// Appending unbond transactions
poolUnbond := p.pools[payload.PayloadTypeUnbond]
poolUnbond := p.pools[payload.TypeUnbound]
for n := poolUnbond.HeadNode(); n != nil; n = n.Next {
trxs = append(trxs, n.Data.Value)
}

// Appending withdraw transactions
poolWithdraw := p.pools[payload.PayloadTypeWithdraw]
poolWithdraw := p.pools[payload.TypeWithdraw]
for n := poolWithdraw.HeadNode(); n != nil; n = n.Next {
trxs = append(trxs, n.Data.Value)
}

// Appending transfer transactions
poolSend := p.pools[payload.PayloadTypeTransfer]
poolSend := p.pools[payload.TypeTransfer]
for n := poolSend.HeadNode(); n != nil; n = n.Next {
trxs = append(trxs, n.Data.Value)
}
Expand Down Expand Up @@ -210,10 +210,10 @@ func (p *txPool) Size() int {

func (p *txPool) String() string {
return fmt.Sprintf("{💸 %v 🔐 %v 🔓 %v 🎯 %v 🧾 %v}",
p.pools[payload.PayloadTypeTransfer].Size(),
p.pools[payload.PayloadTypeBond].Size(),
p.pools[payload.PayloadTypeUnbond].Size(),
p.pools[payload.PayloadTypeSortition].Size(),
p.pools[payload.PayloadTypeWithdraw].Size(),
p.pools[payload.TypeTransfer].Size(),
p.pools[payload.TypeBond].Size(),
p.pools[payload.TypeUnbound].Size(),
p.pools[payload.TypeSortition].Size(),
p.pools[payload.TypeWithdraw].Size(),
)
}
2 changes: 1 addition & 1 deletion types/tx/payload/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BondPayload struct {
}

func (p *BondPayload) Type() Type {
return PayloadTypeBond
return TypeBond
}

func (p *BondPayload) Signer() crypto.Address {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/bond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestBondType(t *testing.T) {
pld := BondPayload{}
assert.Equal(t, pld.Type(), PayloadTypeBond)
assert.Equal(t, pld.Type(), TypeBond)
}

func TestBondDecoding(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions types/tx/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import (
type Type uint8

const (
PayloadTypeTransfer = Type(1)
PayloadTypeBond = Type(2)
PayloadTypeSortition = Type(3)
PayloadTypeUnbond = Type(4)
PayloadTypeWithdraw = Type(5)
TypeTransfer = Type(1)
TypeBond = Type(2)
TypeSortition = Type(3)
TypeUnbound = Type(4)
TypeWithdraw = Type(5)
)

func (t Type) String() string {
switch t {
case PayloadTypeTransfer:
case TypeTransfer:

Check warning on line 22 in types/tx/payload/payload.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/payload.go#L22

Added line #L22 was not covered by tests
return "transfer"
case PayloadTypeBond:
case TypeBond:

Check warning on line 24 in types/tx/payload/payload.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/payload.go#L24

Added line #L24 was not covered by tests
return "bond"
case PayloadTypeUnbond:
return "unbond"
case PayloadTypeWithdraw:
case TypeUnbound:
return "unbound"
case TypeWithdraw:

Check warning on line 28 in types/tx/payload/payload.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/payload.go#L26-L28

Added lines #L26 - L28 were not covered by tests
return "withdraw"
case PayloadTypeSortition:
case TypeSortition:

Check warning on line 30 in types/tx/payload/payload.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/payload.go#L30

Added line #L30 was not covered by tests
return "sortition"
}
return fmt.Sprintf("%d", t)
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/sortition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SortitionPayload struct {
}

func (p *SortitionPayload) Type() Type {
return PayloadTypeSortition
return TypeSortition
}

func (p *SortitionPayload) Signer() crypto.Address {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/sortition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestSortitionType(t *testing.T) {
pld := SortitionPayload{}
assert.Equal(t, pld.Type(), PayloadTypeSortition)
assert.Equal(t, pld.Type(), TypeSortition)
}

func TestSortitionDecoding(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TransferPayload struct {
}

func (p *TransferPayload) Type() Type {
return PayloadTypeTransfer
return TypeTransfer
}

func (p *TransferPayload) Signer() crypto.Address {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestTransferType(t *testing.T) {
pld := TransferPayload{}
assert.Equal(t, pld.Type(), PayloadTypeTransfer)
assert.Equal(t, pld.Type(), TypeTransfer)
}

func TestTransferDecoding(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/unbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type UnbondPayload struct {
}

func (p *UnbondPayload) Type() Type {
return PayloadTypeUnbond
return TypeUnbound

Check warning on line 17 in types/tx/payload/unbond.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/unbond.go#L17

Added line #L17 was not covered by tests
}

func (p *UnbondPayload) Signer() crypto.Address {
Expand Down
2 changes: 1 addition & 1 deletion types/tx/payload/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type WithdrawPayload struct {
}

func (p *WithdrawPayload) Type() Type {
return PayloadTypeWithdraw
return TypeWithdraw

Check warning on line 19 in types/tx/payload/withdraw.go

View check run for this annotation

Codecov / codecov/patch

types/tx/payload/withdraw.go#L19

Added line #L19 was not covered by tests
}

func (p *WithdrawPayload) Signer() crypto.Address {
Expand Down
22 changes: 11 additions & 11 deletions types/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ func (tx *Tx) DecodeWithNoSignatory(r io.Reader) error {
}

switch payload.Type(payloadType) {
case payload.PayloadTypeTransfer:
case payload.TypeTransfer:
tx.data.Payload = &payload.TransferPayload{}
case payload.PayloadTypeBond:
case payload.TypeBond:
tx.data.Payload = &payload.BondPayload{}
case payload.PayloadTypeUnbond:
case payload.TypeUnbound:
tx.data.Payload = &payload.UnbondPayload{}
case payload.PayloadTypeWithdraw:
case payload.TypeWithdraw:
tx.data.Payload = &payload.WithdrawPayload{}
case payload.PayloadTypeSortition:
case payload.TypeSortition:
tx.data.Payload = &payload.SortitionPayload{}

default:
Expand Down Expand Up @@ -412,29 +412,29 @@ func (tx *Tx) ID() ID {
}

func (tx *Tx) IsTransferTx() bool {
return tx.Payload().Type() == payload.PayloadTypeTransfer &&
return tx.Payload().Type() == payload.TypeTransfer &&
!tx.data.Payload.Signer().EqualsTo(crypto.TreasuryAddress)
}

func (tx *Tx) IsBondTx() bool {
return tx.Payload().Type() == payload.PayloadTypeBond
return tx.Payload().Type() == payload.TypeBond
}

func (tx *Tx) IsSubsidyTx() bool {
return tx.Payload().Type() == payload.PayloadTypeTransfer &&
return tx.Payload().Type() == payload.TypeTransfer &&
tx.data.Payload.Signer().EqualsTo(crypto.TreasuryAddress)
}

func (tx *Tx) IsSortitionTx() bool {
return tx.Payload().Type() == payload.PayloadTypeSortition
return tx.Payload().Type() == payload.TypeSortition
}

func (tx *Tx) IsUnbondTx() bool {
return tx.Payload().Type() == payload.PayloadTypeUnbond
return tx.Payload().Type() == payload.TypeUnbound
}

func (tx *Tx) IsWithdrawTx() bool {
return tx.Payload().Type() == payload.PayloadTypeWithdraw
return tx.Payload().Type() == payload.TypeWithdraw
}

// IsFreeTx will checks if transaction fee is 0.
Expand Down
16 changes: 8 additions & 8 deletions wallet/tx_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func (m *txBuilder) build() (*tx.Tx, error) {

var trx *tx.Tx
switch m.typ {
case payload.PayloadTypeTransfer:
case payload.TypeTransfer:
trx = tx.NewTransferTx(*m.stamp, m.seq, *m.from, *m.to, m.amount, m.fee, m.memo)
case payload.PayloadTypeBond:
case payload.TypeBond:
{
pub := m.pub
val, _ := m.client.getValidator(*m.to)
Expand All @@ -118,9 +118,9 @@ func (m *txBuilder) build() (*tx.Tx, error) {
}
trx = tx.NewBondTx(*m.stamp, m.seq, *m.from, *m.to, pub, m.amount, m.fee, m.memo)
}
case payload.PayloadTypeUnbond:
case payload.TypeUnbound:
trx = tx.NewUnbondTx(*m.stamp, m.seq, *m.from, m.memo)
case payload.PayloadTypeWithdraw:
case payload.TypeWithdraw:
trx = tx.NewWithdrawTx(*m.stamp, m.seq, *m.from, *m.to, m.amount, m.fee, m.memo)
}

Expand Down Expand Up @@ -150,8 +150,8 @@ func (m *txBuilder) setSequence() error {
}

switch m.typ {
case payload.PayloadTypeTransfer,
payload.PayloadTypeBond:
case payload.TypeTransfer,
payload.TypeBond:
{
acc, err := m.client.getAccount(*m.from)
if err != nil {
Expand All @@ -160,8 +160,8 @@ func (m *txBuilder) setSequence() error {
m.seq = acc.Sequence + 1
}

case payload.PayloadTypeUnbond,
payload.PayloadTypeWithdraw:
case payload.TypeUnbound,
payload.TypeWithdraw:
{
val, err := m.client.getValidator(*m.from)
if err != nil {
Expand Down
Loading

0 comments on commit 4054d5f

Please sign in to comment.