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

refactor: rename send to transfer. #469

Merged
merged 6 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="id_dialog_transaction_send">
<object class="GtkDialog" id="id_dialog_transaction_transfer">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Broadcasting Send transaction</property>
<property name="title" translatable="yes">Broadcasting Transfer transaction</property>
<property name="modal">True</property>
<property name="default-width">480</property>
<property name="type-hint">dialog</property>
Expand Down
4 changes: 2 additions & 2 deletions cmd/gtk/assets/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_Send</property>
<property name="label" translatable="yes">_Transfer</property>
<property name="use-underline">True</property>
<signal name="activate" handler="on_transaction_send" swapped="no"/>
<signal name="activate" handler="on_transaction_transfer" swapped="no"/>
</object>
</child>
<child>
Expand Down
6 changes: 3 additions & 3 deletions cmd/gtk/dialog_transaction_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/pactus-project/pactus/wallet"
)

//go:embed assets/ui/dialog_transaction_send.ui
var uiTransactionSendDialog []byte
//go:embed assets/ui/dialog_transaction_transfer.ui
var uiTransactionTransferDialog []byte

func broadcastTransactionSend(wallet *wallet.Wallet) {
builder, err := gtk.BuilderNewFromString(string(uiTransactionSendDialog))
builder, err := gtk.BuilderNewFromString(string(uiTransactionTransferDialog))
fatalErrorCheck(err)

dlg := getDialogObj(builder, "id_dialog_transaction_send")
Expand Down
12 changes: 6 additions & 6 deletions cmd/gtk/main_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func buildMainWindow(nodeModel *nodeModel, walletModel *walletModel, genesisTime
// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
"on_about_gtk": mw.onAboutGtk,
"on_about": mw.onAbout,
"on_quit": mw.onQuit,
"on_transaction_send": mw.OnTransactionSend,
"on_transaction_bond": mw.OnTransactionBond,
"on_about_gtk": mw.onAboutGtk,
"on_about": mw.onAbout,
"on_quit": mw.onQuit,
"on_transaction_transfer": mw.OnTransactionTransfer,
"on_transaction_bond": mw.OnTransactionBond,
}
builder.ConnectSignals(signals)

Expand All @@ -69,7 +69,7 @@ func (mw *mainWindow) onAbout() {
showAboutDialog()
}

func (mw *mainWindow) OnTransactionSend() {
func (mw *mainWindow) OnTransactionTransfer() {
broadcastTransactionSend(mw.widgetWallet.model.wallet)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
})
app.Command("tx", "Create, sign and publish a transaction", func(k *cli.Cmd) {
k.Command("bond", "Create, sign and publish a bond transaction", BondTx())
yenkhoon marked this conversation as resolved.
Show resolved Hide resolved
k.Command("send", "Create, sign and publish a send transaction", SendTx())
k.Command("send", "Create, sign and publish a send transaction", TransferTx())
yenkhoon marked this conversation as resolved.
Show resolved Hide resolved
b00f marked this conversation as resolved.
Show resolved Hide resolved
k.Command("unbond", "Create, sign and publish an unbond transaction", UnbondTx())
b00f marked this conversation as resolved.
Show resolved Hide resolved
k.Command("withdraw", "Create, sign and publish a withdraw transaction", WithdrawTx())
yenkhoon marked this conversation as resolved.
Show resolved Hide resolved
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/wallet/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pactus-project/pactus/wallet"
)

func SendTx() func(c *cli.Cmd) {
func TransferTx() func(c *cli.Cmd) {
return func(c *cli.Cmd) {
fromArg := c.String(cli.StringArg{
Name: "FROM",
Expand Down
2 changes: 1 addition & 1 deletion execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Execution struct {

func newExecution(strict bool) *Execution {
execs := make(map[payload.Type]Executor)
execs[payload.PayloadTypeSend] = executor.NewSendExecutor(strict)
execs[payload.PayloadTypeTransfer] = executor.NewTransferExecutor(strict)
execs[payload.PayloadTypeBond] = executor.NewBondExecutor(strict)
execs[payload.PayloadTypeSortition] = executor.NewSortitionExecutor(strict)
execs[payload.PayloadTypeUnbond] = executor.NewUnbondExecutor(strict)
Expand Down
6 changes: 3 additions & 3 deletions execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestLockTime(t *testing.T) {
})

t.Run("Should reject subsidy transactions with lock time", func(t *testing.T) {
pld := &payload.SendPayload{
pld := &payload.TransferPayload{
Sender: crypto.TreasuryAddress,
Receiver: crypto.GenerateTestAddress(),
Amount: 1234,
Expand All @@ -169,7 +169,7 @@ func TestLockTime(t *testing.T) {
acc := sb.MakeNewAccount(signer.Address())
acc.AddToBalance(10000)
sb.UpdateAccount(signer.Address(), acc)
pld := &payload.SendPayload{
pld := &payload.TransferPayload{
Sender: signer.Address(),
Receiver: crypto.GenerateTestAddress(),
Amount: 1234,
Expand All @@ -187,7 +187,7 @@ func TestLockTime(t *testing.T) {
acc := sb.MakeNewAccount(signer.Address())
acc.AddToBalance(10000)
sb.UpdateAccount(signer.Address(), acc)
pld := &payload.SendPayload{
pld := &payload.TransferPayload{
Sender: signer.Address(),
Receiver: crypto.GenerateTestAddress(),
Amount: 1234,
Expand Down
12 changes: 6 additions & 6 deletions execution/executor/send.go → execution/executor/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"github.com/pactus-project/pactus/util/errors"
)

type SendExecutor struct {
type TransferExecutor struct {
fee int64
strict bool
}

func NewSendExecutor(strict bool) *SendExecutor {
return &SendExecutor{strict: strict}
func NewTransferExecutor(strict bool) *TransferExecutor {
return &TransferExecutor{strict: strict}
}

func (e *SendExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error {
pld := trx.Payload().(*payload.SendPayload)
func (e *TransferExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error {
pld := trx.Payload().(*payload.TransferPayload)

if !e.strict && trx.IsSubsidyTx() {
// In not-strict mode all subsidy transactions for the current height are valid.
Expand Down Expand Up @@ -67,6 +67,6 @@ func (e *SendExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error {
return nil
}

func (e *SendExecutor) Fee() int64 {
func (e *TransferExecutor) Fee() int64 {
return e.fee
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func randomAmountAndFee(max int64) (int64, int64) {
return amt, fee
}

func TestExecuteSendTx(t *testing.T) {
func TestExecuteTransferTx(t *testing.T) {
setup(t)
exe := NewSendExecutor(true)
exe := NewTransferExecutor(true)

senderAddr, senderAcc := tSandbox.TestStore.RandomTestAcc()
senderBalance := senderAcc.Balance()
Expand Down Expand Up @@ -88,9 +88,9 @@ func TestExecuteSendTx(t *testing.T) {
checkTotalCoin(t, fee)
}

func TestSendToSelf(t *testing.T) {
func TestTransferToSelf(t *testing.T) {
setup(t)
exe := NewSendExecutor(true)
exe := NewTransferExecutor(true)

senderAddr, senderAcc := tSandbox.TestStore.RandomTestAcc()
senderBalance := senderAcc.Balance()
Expand All @@ -103,10 +103,10 @@ func TestSendToSelf(t *testing.T) {
assert.Equal(t, exe.Fee(), fee)
}

func TestSendNonStrictMode(t *testing.T) {
func TestTransferNonStrictMode(t *testing.T) {
setup(t)
exe1 := NewSendExecutor(true)
exe2 := NewSendExecutor(false)
exe1 := NewTransferExecutor(true)
exe2 := NewTransferExecutor(false)

receiver1 := crypto.GenerateTestAddress()

Expand Down
4 changes: 2 additions & 2 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestBlockSubsidyTx(t *testing.T) {
trx := tState1.createSubsidyTx(rewardAddr, 7)
assert.True(t, trx.IsSubsidyTx())
assert.Equal(t, trx.Payload().Value(), tState1.params.BlockReward+7)
assert.Equal(t, trx.Payload().(*payload.SendPayload).Sender, crypto.TreasuryAddress)
assert.Equal(t, trx.Payload().(*payload.SendPayload).Receiver, rewardAddr)
assert.Equal(t, trx.Payload().(*payload.TransferPayload).Sender, crypto.TreasuryAddress)
assert.Equal(t, trx.Payload().(*payload.TransferPayload).Receiver, rewardAddr)
}

func TestCommitBlocks(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type txPool struct {
func NewTxPool(conf *Config, broadcastCh chan message.Message) TxPool {
pendings := make(map[payload.Type]*linkedmap.LinkedMap)

pendings[payload.PayloadTypeSend] = linkedmap.NewLinkedMap(conf.sendPoolSize())
pendings[payload.PayloadTypeTransfer] = linkedmap.NewLinkedMap(conf.sendPoolSize())
pendings[payload.PayloadTypeBond] = linkedmap.NewLinkedMap(conf.bondPoolSize())
pendings[payload.PayloadTypeUnbond] = linkedmap.NewLinkedMap(conf.unbondPoolSize())
pendings[payload.PayloadTypeWithdraw] = linkedmap.NewLinkedMap(conf.withdrawPoolSize())
Expand Down Expand Up @@ -181,7 +181,7 @@ func (p *txPool) PrepareBlockTransactions() block.Txs {
}

// Appending send transactions
poolSend := p.pools[payload.PayloadTypeSend]
poolSend := p.pools[payload.PayloadTypeTransfer]
for e := poolSend.FirstElement(); e != nil; e = e.Next() {
trx := e.Value.(*linkedmap.Pair).Second.(*tx.Tx)
trxs = append(trxs, trx)
Expand Down Expand Up @@ -216,7 +216,7 @@ func (p *txPool) Size() int {

func (p *txPool) Fingerprint() string {
return fmt.Sprintf("{💸 %v 🔐 %v 🔓 %v 🎯 %v 🧾 %v}",
p.pools[payload.PayloadTypeSend].Size(),
p.pools[payload.PayloadTypeTransfer].Size(),
p.pools[payload.PayloadTypeBond].Size(),
p.pools[payload.PayloadTypeUnbond].Size(),
p.pools[payload.PayloadTypeSortition].Size(),
Expand Down
2 changes: 1 addition & 1 deletion types/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewSubsidyTx(stamp hash.Stamp, seq int32,
func NewSendTx(stamp hash.Stamp, seq int32,
sender, receiver crypto.Address,
amount, fee int64, memo string) *Tx {
pld := &payload.SendPayload{
pld := &payload.TransferPayload{
Sender: sender,
Receiver: receiver,
Amount: amount,
Expand Down
4 changes: 2 additions & 2 deletions types/tx/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type Type uint8

const (
PayloadTypeSend = Type(1)
PayloadTypeTransfer = Type(1)
PayloadTypeBond = Type(2)
PayloadTypeSortition = Type(3)
PayloadTypeUnbond = Type(4)
Expand All @@ -19,7 +19,7 @@ const (

func (t Type) String() string {
switch t {
case PayloadTypeSend:
case PayloadTypeTransfer:
return "send"
yenkhoon marked this conversation as resolved.
Show resolved Hide resolved
yenkhoon marked this conversation as resolved.
Show resolved Hide resolved
case PayloadTypeBond:
return "bond"
Expand Down
20 changes: 10 additions & 10 deletions types/tx/payload/send.go → types/tx/payload/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ import (
"github.com/pactus-project/pactus/util/encoding"
)

type SendPayload struct {
type TransferPayload struct {
Sender crypto.Address
Receiver crypto.Address
Amount int64
}

func (p *SendPayload) Type() Type {
return PayloadTypeSend
func (p *TransferPayload) Type() Type {
return PayloadTypeTransfer
}

func (p *SendPayload) Signer() crypto.Address {
func (p *TransferPayload) Signer() crypto.Address {
return p.Sender
}

func (p *SendPayload) Value() int64 {
func (p *TransferPayload) Value() int64 {
return p.Amount
}

func (p *SendPayload) SanityCheck() error {
func (p *TransferPayload) SanityCheck() error {
if err := p.Sender.SanityCheck(); err != nil {
return err
}
return p.Receiver.SanityCheck()
}

func (p *SendPayload) SerializeSize() int {
func (p *TransferPayload) SerializeSize() int {
if p.Sender.EqualsTo(crypto.TreasuryAddress) {
return 22 + encoding.VarIntSerializeSize(uint64(p.Amount))
}
return 42 + encoding.VarIntSerializeSize(uint64(p.Amount))
}

func (p *SendPayload) Encode(w io.Writer) error {
func (p *TransferPayload) Encode(w io.Writer) error {
// If the transaction is a subsidy transaction (sender is treasury address)
// compress the address to one byte.
// This helps to reduce the size of each block by 20 bytes.
Expand All @@ -63,7 +63,7 @@ func (p *SendPayload) Encode(w io.Writer) error {
return encoding.WriteVarInt(w, uint64(p.Amount))
}

func (p *SendPayload) Decode(r io.Reader) error {
func (p *TransferPayload) Decode(r io.Reader) error {
var sigType uint8
err := encoding.ReadElement(r, &sigType)
if err != nil {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (p *SendPayload) Decode(r io.Reader) error {
return nil
}

func (p *SendPayload) Fingerprint() string {
func (p *TransferPayload) Fingerprint() string {
return fmt.Sprintf("{Send 💸 %v->%v %v",
p.Sender.Fingerprint(),
p.Receiver.Fingerprint(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/stretchr/testify/assert"
)

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

func TestSendDecoding(t *testing.T) {
func TestTransferDecoding(t *testing.T) {
tests := []struct {
raw []byte
value int64
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSendDecoding(t *testing.T) {
}

for n, test := range tests {
pld := SendPayload{}
pld := TransferPayload{}
r := util.NewFixedReader(len(test.raw), test.raw)
err := pld.Decode(r)
if test.readErr != nil {
Expand Down
8 changes: 4 additions & 4 deletions types/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ func (tx *Tx) DecodeWithNoSignatory(r io.Reader) error {
}

switch payload.Type(payloadType) {
case payload.PayloadTypeSend:
tx.data.Payload = &payload.SendPayload{}
case payload.PayloadTypeTransfer:
tx.data.Payload = &payload.TransferPayload{}
case payload.PayloadTypeBond:
tx.data.Payload = &payload.BondPayload{}
case payload.PayloadTypeUnbond:
Expand Down Expand Up @@ -409,7 +409,7 @@ func (tx *Tx) ID() ID {
}

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

Expand All @@ -418,7 +418,7 @@ func (tx *Tx) IsBondTx() bool {
}

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

Expand Down
Loading