Skip to content

Commit

Permalink
Merge pull request #50 from make-software/casper-node-v155
Browse files Browse the repository at this point in the history
Update SDK to Casper node v155
  • Loading branch information
mrkara authored Jan 4, 2024
2 parents c3725a2 + 94c3bc2 commit 661286a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 10 deletions.
20 changes: 20 additions & 0 deletions Casper.Network.SDK.Test/NctlGetXTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ public async Task GetAccountTest()
var response = await _client.GetAccountInfo(_faucetKey.PublicKey, blockHeight);
var accountInfo = response.Parse();
Assert.IsNotEmpty(accountInfo.Account.AccountHash.ToString());

var response2 = await _client.GetAccountInfo(_faucetKey.PublicKey.ToAccountHex(), blockHeight);

Check warning on line 58 in Casper.Network.SDK.Test/NctlGetXTest.cs

View workflow job for this annotation

GitHub Actions / buildntest

'NetCasperClient.GetAccountInfo(string, int)' is obsolete: 'For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, '

Check warning on line 58 in Casper.Network.SDK.Test/NctlGetXTest.cs

View workflow job for this annotation

GitHub Actions / buildntest

'NetCasperClient.GetAccountInfo(string, int)' is obsolete: 'For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, '
var accountInfo2 = response2.Parse();
Assert.AreEqual(accountInfo.Account.AccountHash.ToString(), accountInfo2.Account.AccountHash.ToString());

var response3 = await _client.GetAccountInfo(new AccountHashKey(_faucetKey.PublicKey), blockHeight);
var accountInfo3 = response3.Parse();
Assert.AreEqual(accountInfo.Account.AccountHash.ToString(), accountInfo3.Account.AccountHash.ToString());

var response4 = await _client.GetAccountInfo(_faucetKey.PublicKey, blockHash);
var accountInfo4 = response4.Parse();
Assert.AreEqual(accountInfo.Account.AccountHash.ToString(), accountInfo4.Account.AccountHash.ToString());

var response5 = await _client.GetAccountInfo(_faucetKey.PublicKey.ToAccountHex(), blockHash);

Check warning on line 70 in Casper.Network.SDK.Test/NctlGetXTest.cs

View workflow job for this annotation

GitHub Actions / buildntest

'NetCasperClient.GetAccountInfo(string, string)' is obsolete: 'For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, '

Check warning on line 70 in Casper.Network.SDK.Test/NctlGetXTest.cs

View workflow job for this annotation

GitHub Actions / buildntest

'NetCasperClient.GetAccountInfo(string, string)' is obsolete: 'For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, '
var accountInfo5 = response5.Parse();
Assert.AreEqual(accountInfo.Account.AccountHash.ToString(), accountInfo5.Account.AccountHash.ToString());

var response6 = await _client.GetAccountInfo(new AccountHashKey(_faucetKey.PublicKey), blockHash);
var accountInfo6 = response6.Parse();
Assert.AreEqual(accountInfo.Account.AccountHash.ToString(), accountInfo6.Account.AccountHash.ToString());

var resp = await _client.GetAccountBalance(_faucetKey.PublicKey, stateRootHash);
var accountBalance = resp.Parse();
Expand Down
10 changes: 9 additions & 1 deletion Casper.Network.SDK.Test/NctlQueryGlobalStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ public async Task QueryAccountHash()
var accountHash = GlobalStateKey.FromString(_faucetKey.PublicKey.GetAccountHash());

var rpcResponse = await _client.QueryGlobalState(accountHash);
var account = rpcResponse.Parse().StoredValue.Account;
var result = rpcResponse.Parse();
var account = result.StoredValue.Account;

Assert.AreEqual(accountHash.ToHexString(), account.AccountHash.ToHexString());

_mainPurse = account.MainPurse;

var rpcResponse2 = await _client.QueryGlobalState(
accountHash,
result.BlockHeader.StateRootHash);
var result2 = rpcResponse2.Parse();
var account2 = result2.StoredValue.Account;
Assert.AreEqual(accountHash.ToHexString(), account2.AccountHash.ToHexString());
}

[Test, Order(2)]
Expand Down
52 changes: 49 additions & 3 deletions Casper.Network.SDK/JsonRpc/CasperMethods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using Casper.Network.SDK.JsonRpc;
using Casper.Network.SDK.Types;
using Org.BouncyCastle.Utilities.Encoders;

namespace Casper.Network.SDK.JsonRpc
{
Expand Down Expand Up @@ -69,6 +71,48 @@ public class GetAccountInfo : RpcMethod
/// </summary>
/// <param name="publicKey">The public key of the account.</param>
/// <param name="blockHash">A block hash for which the information of the account is queried. Null for most recent information.</param>
public GetAccountInfo(PublicKey publicKey, string blockHash = null) : base("state_get_account_info", blockHash)
{
this.Parameters.Add("account_identifier", publicKey);
}

/// <summary>
/// Returns the information of an Account in the network.
/// </summary>
/// <param name="publicKey">The public key of the account.</param>
/// <param name="height">A block height for which the information of the account is queried.</param>
public GetAccountInfo(PublicKey publicKey, int height) : base("state_get_account_info", height)
{
this.Parameters.Add("account_identifier", publicKey);
}

/// <summary>
/// Returns the information of an Account in the network.
/// </summary>
/// <param name="accountHash">The account hash of the account.</param>
/// <param name="blockHash">A block hash for which the information of the account is queried. Null for most recent information.</param>
public GetAccountInfo(AccountHashKey accountHash, string blockHash = null) : base("state_get_account_info", blockHash)
{
this.Parameters.Add("account_identifier", accountHash.ToString());
}

/// <summary>
/// Returns the information of an Account in the network.
/// </summary>
/// <param name="accountHash">The account hash of the account.</param>
/// <param name="height">A block height for which the information of the account is queried.</param>
public GetAccountInfo(AccountHashKey accountHash, int height) : base("state_get_account_info", height)
{
// this.Parameters.Add("account_identifier", Hex.ToHexString(accountHash.GetBytes()));
this.Parameters.Add("account_identifier", accountHash.ToString());
}

/// <summary>
/// Returns the information of an Account in the network.
/// </summary>
/// <param name="publicKey">The public key of the account.</param>
/// <param name="blockHash">A block hash for which the information of the account is queried. Null for most recent information.</param>
[Obsolete("For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, ", false)]
public GetAccountInfo(string publicKey, string blockHash = null) : base("state_get_account_info", blockHash)
{
this.Parameters.Add("public_key", publicKey);
Expand All @@ -79,6 +123,7 @@ public GetAccountInfo(string publicKey, string blockHash = null) : base("state_g
/// </summary>
/// <param name="publicKey">The public key of the account.</param>
/// <param name="height">A block height for which the information of the account is queried.</param>
[Obsolete("For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey", false)]
public GetAccountInfo(string publicKey, int height) : base("state_get_account_info", height)
{
this.Parameters.Add("public_key", publicKey);
Expand Down Expand Up @@ -111,16 +156,17 @@ public class QueryGlobalState : RpcMethod
/// A query to the global state that returns a stored value from the network.
/// </summary>
/// <param name="key">A global state key formatted as a string to query the value from the network.</param>
/// <param name="stateIdentifier">A block hash, a block height or a state root hash value.</param>
/// <param name="stateIdentifier">(Optional) A block hash, a block height or a state root hash value.</param>
/// <param name="path">The path components starting from the key as base (use '/' as separator).</param>
public QueryGlobalState(string key, StateIdentifier stateIdentifier, string[] path = null) : base("query_global_state")
public QueryGlobalState(string key, StateIdentifier stateIdentifier = null, string[] path = null) : base("query_global_state")
{
this.Parameters = new Dictionary<string, object>
{
{"state_identifier", stateIdentifier.GetParam()},
{"path", path ?? new string[] { }},
{"key", key}
};
if(stateIdentifier != null)
this.Parameters.Add("state_identifier", stateIdentifier.GetParam());
}
}

Expand Down
36 changes: 30 additions & 6 deletions Casper.Network.SDK/NetCasperClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ public async Task<RpcResponse<GetAuctionInfoResult>> GetAuctionInfo(int blockHei
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey publicKey,
string blockHash = null)
{
var method = new GetAccountInfo(publicKey.ToAccountHex(), blockHash);
var method = new GetAccountInfo(publicKey, blockHash);
return await SendRpcRequestAsync<GetAccountInfoResult>(method);
}

/// <summary>
/// Request the information of an Account in the network.
/// </summary>
/// <param name="accountHash">The account hash of the account.</param>
/// <param name="blockHash">A block hash for which the information of the account is queried. Null for most recent information.</param>
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(AccountHashKey accountHash,
string blockHash = null)
{
var method = new GetAccountInfo(accountHash, blockHash);
return await SendRpcRequestAsync<GetAccountInfoResult>(method);
}

Expand All @@ -123,6 +135,7 @@ public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey pu
/// </summary>
/// <param name="publicKey">The public key of the account formatted as a string.</param>
/// <param name="blockHash">A block hash for which the information of the account is queried. Null for most recent information.</param>
[Obsolete("For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, ", false)]
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(string publicKey,
string blockHash = null)
{
Expand All @@ -137,7 +150,18 @@ public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(string publi
/// <param name="blockHeight">A block height for which the information of the account is queried.</param>
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey publicKey, int blockHeight)
{
var method = new GetAccountInfo(publicKey.ToAccountHex(), blockHeight);
var method = new GetAccountInfo(publicKey, blockHeight);
return await SendRpcRequestAsync<GetAccountInfoResult>(method);
}

/// <summary>
/// Request the information of an Account in the network.
/// </summary>
/// <param name="accountHash">The account hash of the account.</param>
/// <param name="blockHeight">A block height for which the information of the account is queried.</param>
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(AccountHashKey accountHash, int blockHeight)
{
var method = new GetAccountInfo(accountHash, blockHeight);
return await SendRpcRequestAsync<GetAccountInfoResult>(method);
}

Expand All @@ -146,6 +170,7 @@ public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(PublicKey pu
/// </summary>
/// <param name="publicKey">The public key of the account formatted as an hex-string.</param>
/// <param name="blockHeight">A block height for which the information of the account is queried.</param>
[Obsolete("For Casper node v1.5.5 or newer use the new method signature with PublicKey or AccountHashKey, ", false)]
public async Task<RpcResponse<GetAccountInfoResult>> GetAccountInfo(string publicKey, int blockHeight)
{
var method = new GetAccountInfo(publicKey, blockHeight);
Expand Down Expand Up @@ -192,10 +217,9 @@ public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalState(string k
public async Task<RpcResponse<QueryGlobalStateResult>> QueryGlobalState(string key, string stateRootHash = null,
string path = null)
{
if (stateRootHash == null)
stateRootHash = await GetStateRootHash();

var method = new QueryGlobalState(key, StateIdentifier.WithStateRootHash(stateRootHash), path?.Split(new char[] {'/'}));
var method = new QueryGlobalState(key,
stateRootHash != null? StateIdentifier.WithStateRootHash(stateRootHash) : null,
path?.Split(new char[] {'/'}));
return await SendRpcRequestAsync<QueryGlobalStateResult>(method);
}

Expand Down

0 comments on commit 661286a

Please sign in to comment.