Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

RpcServer: added GetContractState by contract id support#813

Merged
Jim8y merged 2 commits intoneo-project:masterfrom
cschuchardt88:getcontractstate-788
Aug 30, 2023
Merged

RpcServer: added GetContractState by contract id support#813
Jim8y merged 2 commits intoneo-project:masterfrom
cschuchardt88:getcontractstate-788

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 shargon requested a review from superboyiii August 28, 2023 11:32
@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
@cschuchardt88 cschuchardt88 deleted the getcontractstate-788 branch August 30, 2023 20:38
Jim8y pushed 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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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