Skip to content

Disable special address #4537

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type (
// CoreService provides api interface for user to interact with blockchain data
CoreService interface {
// Account returns the metadata of an account
Account(addr address.Address) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error)
Account(string) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error)
// ChainMeta returns blockchain metadata
ChainMeta() (*iotextypes.ChainMeta, string, error)
// ServerMeta gets the server metadata
Expand Down Expand Up @@ -306,14 +306,17 @@ func newCoreService(
}

// Account returns the metadata of an account
func (core *coreService) Account(addr address.Address) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error) {
func (core *coreService) Account(addrStr string) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error) {
ctx, span := tracer.NewSpan(context.Background(), "coreService.Account")
defer span.End()
addrStr := addr.String()
if addrStr == address.RewardingPoolAddr || addrStr == address.StakingBucketPoolAddr {
return core.getProtocolAccount(ctx, addrStr)
}
span.AddEvent("accountutil.AccountStateWithHeight")
addr, err := address.FromString(addrStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addrStr is 0x encode format from web3 request, instead of io encode

Copy link
Member Author

@dustinxie dustinxie Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest commit

if err != nil {
return nil, nil, status.Error(codes.FailedPrecondition, err.Error())
}
ctx = genesis.WithGenesisContext(ctx, core.bc.Genesis())
state, tipHeight, err := accountutil.AccountStateWithHeight(ctx, core.sf, addr)
if err != nil {
Expand Down Expand Up @@ -1068,7 +1071,6 @@ func (core *coreService) ActionsByAddress(addr address.Address, start uint64, co
if count > core.cfg.RangeQueryLimit {
return nil, status.Error(codes.InvalidArgument, "range exceeds the limit")
}

actions, err := core.indexer.GetActionsByAddress(hash.BytesToHash160(addr.Bytes()), start, count)
if err != nil {
if errors.Cause(err) == db.ErrBucketNotExist || errors.Cause(err) == db.ErrNotExist {
Expand Down
6 changes: 1 addition & 5 deletions api/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ func (svr *gRPCHandler) SuggestGasPrice(ctx context.Context, in *iotexapi.Sugges
func (svr *gRPCHandler) GetAccount(ctx context.Context, in *iotexapi.GetAccountRequest) (*iotexapi.GetAccountResponse, error) {
span := tracer.SpanFromContext(ctx)
defer span.End()
addr, err := address.FromString(in.Address)
if err != nil {
return nil, err
}
accountMeta, blockIdentifier, err := svr.coreService.Account(addr)
accountMeta, blockIdentifier, err := svr.coreService.Account(in.Address)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func TestGrpcServer_GetAccount(t *testing.T) {
request := &iotexapi.GetAccountRequest{
Address: "9254d943485d0fb859ff63c5581acc44f00fc2110343ac0445b99dfe39a6f1a5",
}

core.EXPECT().Account(gomock.Any()).Return(nil, nil, expectedErr)
_, err := grpcSvr.GetAccount(context.Background(), request)
require.Contains(err.Error(), expectedErr.Error())
require.ErrorContains(err, expectedErr.Error())
})
}

Expand Down
4 changes: 2 additions & 2 deletions api/web3server.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (svr *web3Handler) getBalance(in *gjson.Result) (interface{}, error) {
if err != nil {
return nil, err
}
accountMeta, _, err := svr.coreService.Account(ioAddr)
accountMeta, _, err := svr.coreService.Account(ioAddr.String())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -611,7 +611,7 @@ func (svr *web3Handler) getCode(in *gjson.Result) (interface{}, error) {
if err != nil {
return nil, err
}
accountMeta, _, err := svr.coreService.Account(ioAddr)
accountMeta, _, err := svr.coreService.Account(ioAddr.String())
if err != nil {
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions api/web3server_integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,9 @@ func getBlockByNumber(t *testing.T, handler *hTTPHandler) {
func getBalance(t *testing.T, handler *hTTPHandler) {
require := require.New(t)
result := serveTestHTTP(require, handler, "eth_getBalance", `["0xDa7e12Ef57c236a06117c5e0d04a228e7181CF36"]`)
ans, ok := new(big.Int).SetString("9999999999999999999999999991", 10)
require.True(ok)
actual, ok := result.(string)
require.True(ok)
ans, ok = new(big.Int).SetString("9999999999999999999999999991", 10)
ans, ok := new(big.Int).SetString("9999999999999999999999999991", 10)
require.True(ok)
require.Equal("0x"+fmt.Sprintf("%x", ans), actual)
}
Expand Down
6 changes: 1 addition & 5 deletions api/web3server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ func (svr *web3Handler) checkContractAddr(to string) (bool, error) {
if to == "" {
return true, nil
}
ioAddr, err := address.FromString(to)
if err != nil {
return false, err
}
accountMeta, _, err := svr.coreService.Account(ioAddr)
accountMeta, _, err := svr.coreService.Account(to)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/iotexproject/go-fsm v1.0.0
github.com/iotexproject/go-p2p v0.3.7-0.20240327085559-423bb9cc8f5f
github.com/iotexproject/go-pkgs v0.1.13
github.com/iotexproject/iotex-address v0.2.8
github.com/iotexproject/iotex-address v0.2.9-0.20241020230354-523f3f51b5f9
github.com/iotexproject/iotex-antenna-go/v2 v2.5.1
github.com/iotexproject/iotex-election v0.3.5-0.20210611041425-20ddf674363d
github.com/iotexproject/iotex-proto v0.6.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@ github.com/iotexproject/go-pkgs v0.1.13 h1:bK48DVenkfYkC4TRoqL77RLFRBE1MUfscCW49
github.com/iotexproject/go-pkgs v0.1.13/go.mod h1:t5X9kQ1VL5H+L+DC5GmohXnFKlcxaTcRnIBBuydcsTQ=
github.com/iotexproject/iotex-address v0.2.4/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
github.com/iotexproject/iotex-address v0.2.7/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
github.com/iotexproject/iotex-address v0.2.8 h1:jaTR5pZe/ljiYW4OqHl9NKPs0h1o91Gi6FILOTaBCXw=
github.com/iotexproject/iotex-address v0.2.8/go.mod h1:K78yPSMB4K7gF/iQ7djT1amph0RBrP3rSkFfH7gNG70=
github.com/iotexproject/iotex-address v0.2.9-0.20241020230354-523f3f51b5f9 h1:WeEbCkm4t2I3RxsRZXzHUkDGE1VlGvDUIMR3S3nJFLw=
github.com/iotexproject/iotex-address v0.2.9-0.20241020230354-523f3f51b5f9/go.mod h1:LEpPNy+jJbMKaQ6XLEPBUkoyyllHgW9js1YdixMQL9k=
github.com/iotexproject/iotex-antenna-go/v2 v2.5.1-0.20210604061028-2c2056a5bfdb/go.mod h1:NqFzRL8RtA3xfXGpYbs0IY71HDiD6Dh2hD9iYngKLIU=
github.com/iotexproject/iotex-antenna-go/v2 v2.5.1 h1:Z7X0qXxc/4hSSE3koBaFRpLAdiD6MlCxKbn7iAdI+xQ=
github.com/iotexproject/iotex-antenna-go/v2 v2.5.1/go.mod h1:8pDZcM45M0gY6jm3PoM20rzoD2Z0vg3Hg64RS4c3qx0=
Expand Down
8 changes: 4 additions & 4 deletions test/mock/mock_apicoreservice/mock_apicoreservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading