Skip to content

Commit

Permalink
Merge branch 'master' into Fix-nep11-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y authored Sep 4, 2023
2 parents 9e634d0 + c0de35f commit e5b9439
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ public async Task<ContractState> GetContractStateAsync(string hash)
return ContractStateFromJson((JObject)result);
}

/// <summary>
/// Queries contract information, according to the contract id.
/// </summary>
public async Task<ContractState> GetContractStateAsync(int id)
{
var result = await RpcSendAsync(GetRpcName(), id).ConfigureAwait(false);
return ContractStateFromJson((JObject)result);
}

public static ContractState ContractStateFromJson(JObject json)
{
return new ContractState
Expand Down
14 changes: 11 additions & 3 deletions src/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,17 @@ protected virtual JToken GetBlockHeader(JArray _params)
[RpcMethod]
protected virtual JToken GetContractState(JArray _params)
{
UInt160 script_hash = ToScriptHash(_params[0].AsString());
ContractState contract = NativeContract.ContractManagement.GetContract(system.StoreView, script_hash);
return contract?.ToJson() ?? throw new RpcException(-100, "Unknown contract");
if (int.TryParse(_params[0].AsString(), out int contractId))
{
var contracts = NativeContract.ContractManagement.GetContractById(system.StoreView, contractId);
return contracts?.ToJson() ?? throw new RpcException(-100, "Unknown contract");
}
else
{
UInt160 script_hash = ToScriptHash(_params[0].AsString());
ContractState contract = NativeContract.ContractManagement.GetContract(system.StoreView, script_hash);
return contract?.ToJson() ?? throw new RpcException(-100, "Unknown contract");
}
}

private static UInt160 ToScriptHash(string keyword)
Expand Down

0 comments on commit e5b9439

Please sign in to comment.