Skip to content

Commit c923db1

Browse files
fix sync error
1 parent e020ab2 commit c923db1

3 files changed

Lines changed: 20 additions & 75 deletions

File tree

x/distribution/handler.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ func NewHandler(k keeper.Keeper) msg.Handler {
2727
}
2828
}
2929

30-
// These functions assume everything has been authenticated (ValidateBasic passed, and signatures checked)
31-
func handleMsgModifyWithdrawAccountId(ctx chainTypes.Context, msg types.MsgSetWithdrawAccountId, k keeper.Keeper) (*sdk.Result, error) {
32-
checkAcc := func(acc AccountID) bool {
33-
_, ok := acc.ToName()
34-
if ok {
35-
return k.AccKeeper.IsAccountExist(ctx.Context(), acc)
36-
}
37-
return false
30+
func CheckIsFindAccount(ctx chainTypes.Context, k keeper.Keeper, acc AccountID) bool {
31+
_, ok := acc.ToName()
32+
if ok {
33+
return k.AccKeeper.IsAccountExist(ctx.Context(), acc)
3834
}
35+
return false
36+
}
3937

40-
types.FindAcc = checkAcc
41-
38+
// These functions assume everything has been authenticated (ValidateBasic passed, and signatures checked)
39+
func handleMsgModifyWithdrawAccountId(ctx chainTypes.Context, msg types.MsgSetWithdrawAccountId, k keeper.Keeper) (*sdk.Result, error) {
4240
dataMsg, _ := msg.GetData()
4341
ctx.RequireAuth(dataMsg.DelegatorAccountid)
44-
ExistOk := checkAcc(dataMsg.WithdrawAccountid)
45-
if ExistOk {
42+
if existOk := CheckIsFindAccount(ctx, k, dataMsg.WithdrawAccountid); existOk {
4643
err := k.SetWithdrawAddr(ctx.Context(), dataMsg.DelegatorAccountid, dataMsg.WithdrawAccountid)
4744
if err != nil {
4845
return nil, err
@@ -58,7 +55,7 @@ func handleMsgModifyWithdrawAccountId(ctx chainTypes.Context, msg types.MsgSetWi
5855
return &sdk.Result{Events: ctx.EventManager().Events()}, nil
5956
} else {
6057
ctx.Logger().Error("handleMsgModifyWithdrawAccountId, not found",
61-
"WithdrawAccountid", dataMsg.WithdrawAccountid, "ExistOk", ExistOk)
58+
"WithdrawAccountid", dataMsg.WithdrawAccountid, "ExistOk", existOk)
6259
}
6360

6461
return nil, types.ErrSetWithdrawAddrDisabled

x/distribution/keeper/msg_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package keeper
22

33
import (
4+
"testing"
5+
46
chainTypes "github.com/KuChainNetwork/kuchain/chain/types"
57
"github.com/KuChainNetwork/kuchain/x/distribution/types"
6-
"testing"
78

89
"github.com/stretchr/testify/require"
910
)
@@ -27,14 +28,6 @@ func TestMsgSetWithdrawAddress(t *testing.T) {
2728
{emptyAcc, emptyAcc, false},
2829
}
2930

30-
types.FindAcc = func(acc chainTypes.AccountID) bool {
31-
_, ok := acc.ToName()
32-
if ok {
33-
return ak.IsAccountExist(ctx, acc)
34-
}
35-
return false
36-
}
37-
3831
for i, tc := range tests {
3932
Name, _ := tc.delegatorAddr.ToName()
4033
Auth, _ := ak.GetAuth(ctx, Name)
@@ -65,13 +58,6 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
6558
{Acc2, emptyAcc, false},
6659
{emptyAcc, emptyAcc, false},
6760
}
68-
types.FindAcc = func(acc chainTypes.AccountID) bool {
69-
_, ok := acc.ToName()
70-
if ok {
71-
return ak.IsAccountExist(ctx, acc)
72-
}
73-
return false
74-
}
7561

7662
for i, tc := range tests {
7763
Name, _ := tc.delegatorAddr.ToName()
@@ -101,14 +87,6 @@ func TestMsgWithdrawValidatorCommission(t *testing.T) {
10187
{emptyAcc, false},
10288
}
10389

104-
types.FindAcc = func(acc chainTypes.AccountID) bool {
105-
_, ok := acc.ToName()
106-
if ok {
107-
return ak.IsAccountExist(ctx, acc)
108-
}
109-
return false
110-
}
111-
11290
for i, tc := range tests {
11391
Name, _ := tc.validatorAddr.ToName()
11492
Auth, _ := ak.GetAuth(ctx, Name)

x/distribution/types/msg.go

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
99
)
1010

11-
type findAccount func(acc chainType.AccountID) bool
12-
13-
var FindAcc findAccount
14-
1511
// Verify interface at compile time
1612
var _, _, _ sdk.Msg = &MsgSetWithdrawAccountId{}, &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorCommission{}
1713

@@ -54,13 +50,9 @@ func (m MsgSetWithdrawAccountId) ValidateBasic() error {
5450
if data.DelegatorAccountid.Equal(&data.WithdrawAccountid) {
5551
return chainType.ErrKuMsgDataSameAccount
5652
}
57-
58-
if FindAcc != nil {
59-
if !FindAcc(data.WithdrawAccountid) {
60-
return chainType.ErrKuMsgDataNotFindAccount
61-
}
62-
}
6353
}
54+
} else {
55+
return err
6456
}
6557

6658
return m.KuMsg.ValidateTransfer()
@@ -103,24 +95,9 @@ type MsgWithdrawDelegatorReward struct {
10395
}
10496

10597
func (m MsgWithdrawDelegatorReward) ValidateBasic() error {
106-
data, err := m.GetData()
107-
if err == nil {
108-
_, ok := data.DelegatorAccountId.ToName()
109-
if ok {
110-
if FindAcc != nil {
111-
if !FindAcc(data.DelegatorAccountId) {
112-
return chainType.ErrKuMsgDataNotFindAccount
113-
}
114-
}
115-
}
116-
_, ok = data.ValidatorAccountId.ToName()
117-
if ok {
118-
if FindAcc != nil {
119-
if !FindAcc(data.ValidatorAccountId) {
120-
return chainType.ErrKuMsgDataNotFindAccount
121-
}
122-
}
123-
}
98+
_, err := m.GetData()
99+
if err != nil {
100+
return err
124101
}
125102

126103
return m.KuMsg.ValidateTransfer()
@@ -178,16 +155,9 @@ func (m MsgWithdrawValidatorCommission) GetData() (MsgWithdrawValidatorCommissio
178155
}
179156

180157
func (m MsgWithdrawValidatorCommission) ValidateBasic() error {
181-
data, err := m.GetData()
182-
if err == nil {
183-
_, ok := data.ValidatorAccountId.ToName()
184-
if ok {
185-
if FindAcc != nil {
186-
if !FindAcc(data.ValidatorAccountId) {
187-
return chainType.ErrKuMsgDataNotFindAccount
188-
}
189-
}
190-
}
158+
_, err := m.GetData()
159+
if err != nil {
160+
return err
191161
}
192162

193163
return m.KuMsg.ValidateTransfer()

0 commit comments

Comments
 (0)