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

RpcServer: added GetContractState by contract id support #813

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

cschuchardt88
Copy link
Member

@cschuchardt88 cschuchardt88 commented Aug 28, 2023

closes #788

Also per neo-project/neo#2803 (comment)

Change Log

  • GetContractState now supports contract id. (On RcpServer)
  • GetContractState now supports contract id. (On RpcClient)

public async Task<ContractState> GetContractStateAsync(int id)
{
var result = await RpcSendAsync(GetRpcName(), id).ConfigureAwait(false);
return ContractStateFromJson((JObject)result);
Copy link
Member Author

@cschuchardt88 cschuchardt88 Aug 28, 2023

Choose a reason for hiding this comment

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

Note this doesn't use the "RpcContractState" class which is in the model folder. The function is using the function below it ("ContractStateFromJson", line 257). Should that be changed and updated? To use "RpcContractState" class? As you can see the new function and other one doesn't use the class; nothing does.

Copy link
Member

@superboyiii superboyiii Aug 30, 2023

Choose a reason for hiding this comment

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

Can't use the same method name as GetContractStateAsync(string hash), otherwise it will get GetContractStateAsync(string hash) as default when GetRpcName(), then id will be an invaild param.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just a overload for RcpClient and works fine. That's what we want to do. The method that was changed on RpcServer; GetContractState to allow contract id to be processed.

Example

var protocolSettings = ProtocolSettings.Load("config.json", true);
RpcClient rpcClient = new(new("http://127.0.0.1:20332"), "admin", "admin", protocolSettings);
var contractstate = await rpcClient.GetContractStateAsync(742).ConfigureAwait(false);
Console.WriteLine("ScriptHash is {0}.", contractstate.Hash);
Console.WriteLine("Press ENTER to exit . .  .");
Console.ReadLine();

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, just a fault on my code, it works as the expected!

@shargon
Copy link
Member

shargon commented Aug 28, 2023

@superboyiii could you test it?

@superboyiii
Copy link
Member

Test Pass
1693388383976

image

@Jim8y Jim8y merged commit c0de35f into neo-project:master Aug 30, 2023
2 checks passed
@cschuchardt88 cschuchardt88 deleted the getcontractstate-788 branch August 30, 2023 20:38
Jim8y added a commit to Jim8y/neo-modules that referenced this pull request Sep 3, 2023
* 'wss' of github.com:Liaojinghui/neo-modules:
  RpcServer:  added GetContractState by contract id support (neo-project#813)
  rpc: add FindStorage (neo-project#805)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support getcontractstate by ID for non-native contracts
6 participants