Skip to content

[Fix]: getnativecontract throws null reference exception if contract not active#3920

Merged
shargon merged 2 commits intoneo-project:masterfrom
Wi1l-B0t:fix.getnativecontract-null
May 5, 2025
Merged

[Fix]: getnativecontract throws null reference exception if contract not active#3920
shargon merged 2 commits intoneo-project:masterfrom
Wi1l-B0t:fix.getnativecontract-null

Conversation

@Wi1l-B0t
Copy link
Contributor

@Wi1l-B0t Wi1l-B0t commented May 2, 2025

Description

Fixes #3917

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

{
JArray jArray = new();
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount) ?? throw new RpcException(RpcError.InternalServerError.WithData("Can't get next block validators."));
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines are too long.

Copy link
Member

Choose a reason for hiding this comment

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

These changes are not related to the getnativecontracts problem, usually we use a separate PRs to fix this type of issues because it's a separate problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes are not related to the getnativecontracts problem, usually we use a separate PRs to fix this type of issues because it's a separate problem.

Just add a '\n'

Copy link
Member

Choose a reason for hiding this comment

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

Even just for this.

{
return new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(system.StoreView, p.Hash).ToJson()));
var storeView = system.StoreView;
var contractStates = NativeContract.Contracts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix on here

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

The fix itself is valid.

{
JArray jArray = new();
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount) ?? throw new RpcException(RpcError.InternalServerError.WithData("Can't get next block validators."));
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount)
Copy link
Member

Choose a reason for hiding this comment

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

These changes are not related to the getnativecontracts problem, usually we use a separate PRs to fix this type of issues because it's a separate problem.

@shargon shargon merged commit 0a60b93 into neo-project:master May 5, 2025
7 checks passed
@Wi1l-B0t Wi1l-B0t deleted the fix.getnativecontract-null branch May 5, 2025 14:37
@superboyiii superboyiii mentioned this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPC getnativecontract will try to get unregistered native contract before harkfork height which cause null point return

3 participants