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

chore: fix lint #380

Merged
merged 1 commit into from
Jun 24, 2024
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
4 changes: 2 additions & 2 deletions api/messager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,11 @@ func (m *MessageImp) Version(_ context.Context) (venusTypes.Version, error) {
}, nil
}

func (m *MessageImp) SetLogLevel(ctx context.Context, subSystem, level string) error {
func (m *MessageImp) SetLogLevel(_ context.Context, subSystem, level string) error {
return logging.SetLogLevel(subSystem, level)
}

func (m *MessageImp) LogList(ctx context.Context) ([]string, error) {
func (m *MessageImp) LogList(_ context.Context) ([]string, error) {
return logging.GetSubsystems(), nil
}

Expand Down
47 changes: 24 additions & 23 deletions cli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,30 +430,31 @@ var updateFilledMessageCmd = &cli.Command{
}
defer closer()

var id string
if id = ctx.String("id"); len(id) > 0 {
} else if signedCidStr := ctx.String("signed_cid"); len(signedCidStr) > 0 {
signedCid, err := cid.Decode(signedCidStr)
if err != nil {
return err
}
msg, err := client.GetMessageBySignedCid(ctx.Context, signedCid)
if err != nil {
return err
}
id = msg.ID
} else if unsignedCidStr := ctx.String("unsigned_cid"); len(unsignedCidStr) > 0 {
unsignedCid, err := cid.Decode(unsignedCidStr)
if err != nil {
return err
}
msg, err := client.GetMessageByUnsignedCid(ctx.Context, unsignedCid)
if err != nil {
return err
id := ctx.String("id")
if len(id) == 0 {
if signedCidStr := ctx.String("signed_cid"); len(signedCidStr) > 0 {
signedCid, err := cid.Decode(signedCidStr)
if err != nil {
return err
}
msg, err := client.GetMessageBySignedCid(ctx.Context, signedCid)
if err != nil {
return err
}
id = msg.ID
} else if unsignedCidStr := ctx.String("unsigned_cid"); len(unsignedCidStr) > 0 {
unsignedCid, err := cid.Decode(unsignedCidStr)
if err != nil {
return err
}
msg, err := client.GetMessageByUnsignedCid(ctx.Context, unsignedCid)
if err != nil {
return err
}
id = msg.ID
} else {
return fmt.Errorf("value of query must be entered")
}
id = msg.ID
} else {
return fmt.Errorf("value of query must be entered")
}

_, err = client.UpdateFilledMessageByID(ctx.Context, id)
Expand Down
4 changes: 2 additions & 2 deletions cli/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ var SendCmd = &cli.Command{
return fmt.Errorf("'send' expects two arguments, target and amount")
}

client, close, err := getAPI(ctx)
client, closer, err := getAPI(ctx)
if err != nil {
return err
}
defer close()
defer closer()

var params types.QuickSendParams

Expand Down
8 changes: 4 additions & 4 deletions gateway/mock_gateway_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (m *MockWalletProxy) RemoveAddress(account string, addrs []address.Address)
return nil
}

func (m *MockWalletProxy) WalletHas(ctx context.Context, addr address.Address, accounts []string) (bool, error) {
func (m *MockWalletProxy) WalletHas(_ context.Context, addr address.Address, accounts []string) (bool, error) {
m.l.Lock()
defer m.l.Unlock()

Expand All @@ -90,7 +90,7 @@ func (m *MockWalletProxy) WalletHas(ctx context.Context, addr address.Address, a
return false, nil
}

func (m *MockWalletProxy) WalletSign(ctx context.Context, addr address.Address, accounts []string, toSign []byte, meta types.MsgMeta) (*crypto.Signature, error) {
func (m *MockWalletProxy) WalletSign(ctx context.Context, addr address.Address, accounts []string, toSign []byte, _ types.MsgMeta) (*crypto.Signature, error) {
has, err := m.WalletHas(ctx, addr, accounts)
if err != nil {
return nil, err
Expand All @@ -104,11 +104,11 @@ func (m *MockWalletProxy) WalletSign(ctx context.Context, addr address.Address,
}, nil
}

func (m *MockWalletProxy) ListWalletInfo(ctx context.Context) ([]*gtypes.WalletDetail, error) {
func (m *MockWalletProxy) ListWalletInfo(_ context.Context) ([]*gtypes.WalletDetail, error) {
panic("implement me")
}

func (m *MockWalletProxy) ListWalletInfoByWallet(ctx context.Context, wallet string) (*gtypes.WalletDetail, error) {
func (m *MockWalletProxy) ListWalletInfoByWallet(_ context.Context, _ string) (*gtypes.WalletDetail, error) {
panic("implement me")
}

Expand Down
2 changes: 1 addition & 1 deletion integration_test/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAddressAPI(t *testing.T) {
}
tokenSign, err := genToken(playLoad)
assert.NoError(t, err)
authClient.EXPECT().Verify(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, token string) (*auth.VerifyResponse, error) {
authClient.EXPECT().Verify(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, token string) (*auth.VerifyResponse, error) {
if token == tokenSign {
return playLoad, nil
}
Expand Down
21 changes: 10 additions & 11 deletions integration_test/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestHasMessageByUid(t *testing.T) {
defer p.closer()

t.Run("test has message by uid", func(t *testing.T) {
testHasMessageByUid(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs)
testHasMessageByUid(p.ctx, t, p.apiAdmin, p.addrs)
})
assert.NoError(t, p.ms.stop(p.ctx))
}
Expand Down Expand Up @@ -98,10 +98,10 @@ func TestMessageAPI(t *testing.T) {
testGetMessageByFromAndNonce(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs)
})
t.Run("test list message by from state", func(t *testing.T) {
testListMessageByFromState(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs)
testListMessageByFromState(p.ctx, t, p.apiAdmin, p.addrs)
})
t.Run("test list message by address", func(t *testing.T) {
testListMessageByAddress(p.ctx, t, p.apiAdmin, p.apiSign)
testListMessageByAddress(p.ctx, t, p.apiAdmin)
})
t.Run("test list failed message", func(t *testing.T) {
testListFailedMessage(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs, p.blockDelay)
Expand All @@ -113,7 +113,7 @@ func TestMessageAPI(t *testing.T) {
testUpdateMessageStateByID(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs, p.blockDelay)
})
t.Run("test update all filled message", func(t *testing.T) {
testUpdateAllFilledMessage(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs, p.blockDelay)
testUpdateAllFilledMessage(p.ctx, t, p.apiAdmin, p.addrs, p.blockDelay)
})
t.Run("test replace message", func(t *testing.T) {
testReplaceMessage(p.ctx, t, p.apiAdmin, p.apiSign, p.addrs, p.blockDelay)
Expand Down Expand Up @@ -164,7 +164,7 @@ func testPushMessageWithID(ctx context.Context, t *testing.T, api, apiSign messa
}
}

func testHasMessageByUid(ctx context.Context, t *testing.T, api, apiSign messager.IMessager, addrs []address.Address) {
func testHasMessageByUid(ctx context.Context, t *testing.T, api messager.IMessager, addrs []address.Address) {
msgs := genMessageWithAddress(addrs)
for _, msg := range msgs {
id, err := api.PushMessageWithId(ctx, msg.ID, &msg.Message, nil)
Expand Down Expand Up @@ -330,7 +330,7 @@ func testListMessage(ctx context.Context, t *testing.T, api, apiSign messager.IM
}
}

func testListMessageByFromState(ctx context.Context, t *testing.T, api, apiSign messager.IMessager, addrs []address.Address) {
func testListMessageByFromState(ctx context.Context, t *testing.T, api messager.IMessager, addrs []address.Address) {
// insert message
genMessagesAndWait(ctx, t, api, addrs)
genMessagesAndWait(ctx, t, api, addrs)
Expand Down Expand Up @@ -403,7 +403,7 @@ func testListMessageByFromState(ctx context.Context, t *testing.T, api, apiSign
}
}

func testListMessageByAddress(ctx context.Context, t *testing.T, api, apiSign messager.IMessager) {
func testListMessageByAddress(ctx context.Context, t *testing.T, api messager.IMessager) {
allMsgs, err := api.ListMessage(ctx, &types.MsgQueryParams{})
assert.NoError(t, err)
msgIDs := make(map[address.Address][]string)
Expand Down Expand Up @@ -552,7 +552,7 @@ func testUpdateMessageStateByID(ctx context.Context, t *testing.T, api, apiSign
}
}

func testUpdateAllFilledMessage(ctx context.Context, t *testing.T, api, apiSign messager.IMessager, addrs []address.Address, blockDelay time.Duration) {
func testUpdateAllFilledMessage(ctx context.Context, t *testing.T, api messager.IMessager, addrs []address.Address, blockDelay time.Duration) {
msgs := genMessageWithAddress(addrs)
for _, msg := range msgs {
id, err := api.PushMessageWithId(ctx, msg.ID, &msg.Message, nil)
Expand Down Expand Up @@ -805,8 +805,7 @@ func checkUnsignedMsg(t *testing.T, expect, actual *shared.Message) {
assert.Equal(t, expect.Params, actual.Params)
assert.Equal(t, testhelper.ResolveAddr(t, expect.From), actual.From)
// todo: finish estimate gas
if actual.Nonce > 0 {
} else {
if actual.Nonce == 0 {
assert.Equal(t, expect.GasLimit, actual.GasLimit)
assert.Equal(t, expect.GasFeeCap, actual.GasFeeCap)
assert.Equal(t, expect.GasPremium, actual.GasPremium)
Expand Down Expand Up @@ -874,7 +873,7 @@ func prepare(t *testing.T) *testParams {
}
tokenSign, err := genToken(playLoad)
assert.NoError(t, err)
authClient.EXPECT().Verify(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, token string) (*auth.VerifyResponse, error) {
authClient.EXPECT().Verify(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, token string) (*auth.VerifyResponse, error) {
if token == tokenSign {
return playLoad, nil
}
Expand Down
16 changes: 8 additions & 8 deletions models/mysql/actor_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func (s *mysqlActorCfgRepo) SaveActorCfg(ctx context.Context, actorCfg *types.Ac
return errors.New("code cid is undefined")
}

return s.DB.Save(fromActorCfg(actorCfg)).Error
return s.DB.WithContext(ctx).Save(fromActorCfg(actorCfg)).Error
}

func (s *mysqlActorCfgRepo) HasActorCfg(ctx context.Context, methodType *types.MethodType) (bool, error) {
var count int64
if err := s.DB.Table("actor_cfg").Where("code = ? and method = ?", mtypes.NewDBCid(methodType.Code),
if err := s.DB.WithContext(ctx).Table("actor_cfg").Where("code = ? and method = ?", mtypes.NewDBCid(methodType.Code),
methodType.Method).Count(&count).Error; err != nil {
return false, err
}
Expand All @@ -105,7 +105,7 @@ func (s *mysqlActorCfgRepo) HasActorCfg(ctx context.Context, methodType *types.M

func (s *mysqlActorCfgRepo) GetActorCfgByMethodType(ctx context.Context, methodType *types.MethodType) (*types.ActorCfg, error) {
var a mysqlActorCfg
if err := s.DB.Take(&a, "code = ? and method = ?", mtypes.NewDBCid(methodType.Code), methodType.Method).Error; err != nil {
if err := s.DB.WithContext(ctx).Take(&a, "code = ? and method = ?", mtypes.NewDBCid(methodType.Code), methodType.Method).Error; err != nil {
return nil, err
}

Expand All @@ -114,7 +114,7 @@ func (s *mysqlActorCfgRepo) GetActorCfgByMethodType(ctx context.Context, methodT

func (s *mysqlActorCfgRepo) GetActorCfgByID(ctx context.Context, id shared.UUID) (*types.ActorCfg, error) {
var a mysqlActorCfg
if err := s.DB.Take(&a, "id = ?", id).Error; err != nil {
if err := s.DB.WithContext(ctx).Take(&a, "id = ?", id).Error; err != nil {
return nil, err
}

Expand All @@ -123,7 +123,7 @@ func (s *mysqlActorCfgRepo) GetActorCfgByID(ctx context.Context, id shared.UUID)

func (s *mysqlActorCfgRepo) ListActorCfg(ctx context.Context) ([]*types.ActorCfg, error) {
var list []*mysqlActorCfg
if err := s.DB.Find(&list).Error; err != nil {
if err := s.DB.WithContext(ctx).Find(&list).Error; err != nil {
return nil, err
}

Expand All @@ -136,11 +136,11 @@ func (s *mysqlActorCfgRepo) ListActorCfg(ctx context.Context) ([]*types.ActorCfg
}

func (s *mysqlActorCfgRepo) DelActorCfgByMethodType(ctx context.Context, methodType *types.MethodType) error {
return s.DB.Delete(mysqlActorCfg{}, "code = ? and method = ?", mtypes.NewDBCid(methodType.Code), methodType.Method).Error
return s.DB.WithContext(ctx).Delete(mysqlActorCfg{}, "code = ? and method = ?", mtypes.NewDBCid(methodType.Code), methodType.Method).Error
}

func (s *mysqlActorCfgRepo) DelActorCfgById(ctx context.Context, id shared.UUID) error {
return s.DB.Delete(mysqlActorCfg{}, "id = ?", id).Error
return s.DB.WithContext(ctx).Delete(mysqlActorCfg{}, "id = ?", id).Error
}

func (s *mysqlActorCfgRepo) UpdateSelectSpecById(ctx context.Context, id shared.UUID, spec *types.ChangeGasSpecParams) error {
Expand Down Expand Up @@ -168,5 +168,5 @@ func (s *mysqlActorCfgRepo) UpdateSelectSpecById(ctx context.Context, id shared.

updateColumns["updated_at"] = time.Now()

return s.DB.Model((*mysqlActorCfg)(nil)).Where("id = ?", id).UpdateColumns(updateColumns).Error
return s.DB.WithContext(ctx).Model((*mysqlActorCfg)(nil)).Where("id = ?", id).UpdateColumns(updateColumns).Error
}
24 changes: 12 additions & 12 deletions models/mysql/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func newMysqlAddressRepo(db *gorm.DB) *mysqlAddressRepo {
}

func (s mysqlAddressRepo) SaveAddress(ctx context.Context, a *types.Address) error {
return s.DB.Save(fromAddress(a)).Error
return s.DB.WithContext(ctx).Save(fromAddress(a)).Error
}

func (s mysqlAddressRepo) GetAddress(ctx context.Context, addr address.Address) (*types.Address, error) {
var a mysqlAddress
if err := s.DB.Take(&a, "addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).Error; err != nil {
if err := s.DB.WithContext(ctx).Take(&a, "addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).Error; err != nil {
return nil, err
}

Expand All @@ -104,7 +104,7 @@ func (s mysqlAddressRepo) GetAddress(ctx context.Context, addr address.Address)

func (s mysqlAddressRepo) GetAddressByID(ctx context.Context, id shared.UUID) (*types.Address, error) {
var a mysqlAddress
if err := s.DB.Where("id = ? and is_deleted = ?", id, repo.NotDeleted).First(&a).Error; err != nil {
if err := s.DB.WithContext(ctx).Where("id = ? and is_deleted = ?", id, repo.NotDeleted).First(&a).Error; err != nil {
return nil, err
}

Expand All @@ -113,7 +113,7 @@ func (s mysqlAddressRepo) GetAddressByID(ctx context.Context, id shared.UUID) (*

func (s mysqlAddressRepo) GetOneRecord(ctx context.Context, addr address.Address) (*types.Address, error) {
var a mysqlAddress
if err := s.DB.Take(&a, "addr = ?", addr.String()).Error; err != nil {
if err := s.DB.WithContext(ctx).Take(&a, "addr = ?", addr.String()).Error; err != nil {
return nil, err
}

Expand All @@ -122,7 +122,7 @@ func (s mysqlAddressRepo) GetOneRecord(ctx context.Context, addr address.Address

func (s mysqlAddressRepo) HasAddress(ctx context.Context, addr address.Address) (bool, error) {
var count int64
if err := s.DB.Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
if err := s.DB.WithContext(ctx).Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
Count(&count).Error; err != nil {
return false, err
}
Expand All @@ -131,7 +131,7 @@ func (s mysqlAddressRepo) HasAddress(ctx context.Context, addr address.Address)

func (s mysqlAddressRepo) ListAddress(ctx context.Context) ([]*types.Address, error) {
var list []*mysqlAddress
if err := s.DB.Find(&list, "is_deleted = ?", repo.NotDeleted).Error; err != nil {
if err := s.DB.WithContext(ctx).Find(&list, "is_deleted = ?", repo.NotDeleted).Error; err != nil {
return nil, err
}

Expand All @@ -149,7 +149,7 @@ func (s mysqlAddressRepo) ListAddress(ctx context.Context) ([]*types.Address, er

func (s mysqlAddressRepo) ListActiveAddress(ctx context.Context) ([]*types.Address, error) {
var list []*mysqlAddress
if err := s.DB.Find(&list, "is_deleted = ? and state = ?", repo.NotDeleted, types.AddressStateAlive).Error; err != nil {
if err := s.DB.WithContext(ctx).Find(&list, "is_deleted = ? and state = ?", repo.NotDeleted, types.AddressStateAlive).Error; err != nil {
return nil, err
}

Expand All @@ -166,22 +166,22 @@ func (s mysqlAddressRepo) ListActiveAddress(ctx context.Context) ([]*types.Addre
}

func (s mysqlAddressRepo) DelAddress(ctx context.Context, addr address.Address) error {
return s.DB.Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
return s.DB.WithContext(ctx).Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
UpdateColumns(map[string]interface{}{"is_deleted": repo.Deleted, "state": types.AddressStateRemoved, "updated_at": time.Now()}).Error
}

func (s mysqlAddressRepo) UpdateNonce(ctx context.Context, addr address.Address, nonce uint64) error {
return s.DB.Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
return s.DB.WithContext(ctx).Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
UpdateColumns(map[string]interface{}{"nonce": nonce, "updated_at": time.Now()}).Error
}

func (s mysqlAddressRepo) UpdateState(ctx context.Context, addr address.Address, state types.AddressState) error {
return s.DB.Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
return s.DB.WithContext(ctx).Model(&mysqlAddress{}).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
UpdateColumns(map[string]interface{}{"state": state, "updated_at": time.Now()}).Error
}

func (s mysqlAddressRepo) UpdateSelectMsgNum(ctx context.Context, addr address.Address, num uint64) error {
return s.DB.Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
return s.DB.WithContext(ctx).Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).
UpdateColumns(map[string]interface{}{"sel_msg_num": num, "updated_at": time.Now()}).Error
}

Expand All @@ -208,5 +208,5 @@ func (s mysqlAddressRepo) UpdateFeeParams(ctx context.Context, addr address.Addr

updateColumns["updated_at"] = time.Now()

return s.DB.Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).UpdateColumns(updateColumns).Error
return s.DB.WithContext(ctx).Model((*mysqlAddress)(nil)).Where("addr = ? and is_deleted = ?", addr.String(), repo.NotDeleted).UpdateColumns(updateColumns).Error
}
8 changes: 4 additions & 4 deletions models/mysql/shared_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func newMysqlSharedParamsRepo(db *gorm.DB) mysqlSharedParamsRepo {

func (s mysqlSharedParamsRepo) GetSharedParams(ctx context.Context) (*types.SharedSpec, error) {
var ssp mysqlSharedParams
if err := s.DB.Take(&ssp).Error; err != nil {
if err := s.DB.WithContext(ctx).Take(&ssp).Error; err != nil {
return nil, err
}
return ssp.SharedParams(), nil
Expand All @@ -72,17 +72,17 @@ func (s mysqlSharedParamsRepo) SetSharedParams(ctx context.Context, params *type
var ssp mysqlSharedParams
// make sure ID is 1
params.ID = 1
if err := s.DB.Where("id = ?", 1).Take(&ssp).Error; err != nil {
if err := s.DB.WithContext(ctx).Where("id = ?", 1).Take(&ssp).Error; err != nil {
if err == gorm.ErrRecordNotFound {
if err := s.DB.Save(fromSharedParams(*params)).Error; err != nil {
if err := s.DB.WithContext(ctx).Save(fromSharedParams(*params)).Error; err != nil {
return 0, err
}
return params.ID, nil
}
return 0, err
}

if err := s.DB.Save(fromSharedParams(*params)).Error; err != nil {
if err := s.DB.WithContext(ctx).Save(fromSharedParams(*params)).Error; err != nil {
return 0, err
}

Expand Down
Loading
Loading