Skip to content

Commit

Permalink
Merge pull request #26 from make-software/sdk-v111
Browse files Browse the repository at this point in the history
Minor release to add compatibility with RPC implementation in casper node v1.5.0.
  • Loading branch information
mrkara authored Oct 19, 2022
2 parents 6f27bde + 544cb65 commit 3cd061a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 128 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Fixed: any bug fixes)
[comment]: <> (Security: in case of vulnerabilities)

## [1.1.1]

### Fixed
* Skip `block_identifier` param if `Hash` value is `null` in RPC requests to be compatible with Casper node v150.

## [1.1.0]

### Added
Expand All @@ -28,5 +33,6 @@ All notable changes to this project will be documented in this file. The format
### Added
* Initial release of Casper .NET SDK.

[1.1.1]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.1
[1.1.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.1.0
[1.0.0]: https://github.com/make-software/casper-net-sdk/releases/tag/v1.0.0
8 changes: 4 additions & 4 deletions Casper.Network.SDK/Casper.Network.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>
<PackageVersion>1.1.0</PackageVersion>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<FileVersion>1.1.1</FileVersion>
<PackageVersion>1.1.1</PackageVersion>
<Title>Casper.Network.SDK</Title>
<Authors>make-software</Authors>
<PackageProjectUrl>https://github.com/make-software/casper-net-sdk</PackageProjectUrl>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.NetCore" Version="1.8.8" />
<PackageReference Include="BouncyCastle.NetCore" Version="1.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
138 changes: 15 additions & 123 deletions Casper.Network.SDK/JsonRpc/CasperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,16 @@ public class GetStateRootHash : RpcMethod
/// Returns a state root hash at a given Block
/// </summary>
/// <param name="blockHash">Block hash for which the state root is queried. Null for the most recent.</param>
public GetStateRootHash(string blockHash = null) : base("chain_get_state_root_hash")
public GetStateRootHash(string blockHash = null) : base("chain_get_state_root_hash", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null}
};
}

/// <summary>
/// Returns the state root hash at a given Block
/// </summary>
/// <param name="height">Block height for which the state root is queried.</param>
public GetStateRootHash(int height) : base("chain_get_state_root_hash")
public GetStateRootHash(int height) : base("chain_get_state_root_hash", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}
}

Expand Down Expand Up @@ -67,34 +49,16 @@ public class GetAuctionInfo : RpcMethod
/// Returns the bids and validators at a given block.
/// </summary>
/// <param name="blockHash">Block hash for which the auction info is queried. Null for the most recent auction info.</param>
public GetAuctionInfo(string blockHash) : base("state_get_auction_info")
public GetAuctionInfo(string blockHash) : base("state_get_auction_info", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null}
};
}

/// <summary>
/// Returns the bids and validators at a given block.
/// </summary>
/// <param name="height">Block height for which the auction info is queried.</param>
public GetAuctionInfo(int height) : base("state_get_auction_info")
public GetAuctionInfo(int height) : base("state_get_auction_info", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}
}

Expand All @@ -105,37 +69,19 @@ 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(string publicKey, string blockHash = null) : base("state_get_account_info")
public GetAccountInfo(string publicKey, string blockHash = null) : base("state_get_account_info", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null},
{"public_key", publicKey}
};
this.Parameters.Add("public_key", 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(string publicKey, int height) : base("state_get_account_info")
public GetAccountInfo(string publicKey, int height) : base("state_get_account_info", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier},
{"public_key", publicKey}
};
this.Parameters.Add("public_key", publicKey);
}
}

Expand Down Expand Up @@ -244,34 +190,16 @@ public class GetBlock : RpcMethod
/// Retrieves a Block from the network by its hash.
/// </summary>
/// <param name="blockHash">Hash of the block to retrieve. Null for the most recent block.</param>
public GetBlock(string blockHash) : base("chain_get_block")
public GetBlock(string blockHash) : base("chain_get_block", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null}
};
}

/// <summary>
/// Retrieves a Block from the network by its height number.
/// </summary>
/// <param name="height">Height of the block to retrieve.</param>
public GetBlock(int height) : base("chain_get_block")
public GetBlock(int height) : base("chain_get_block", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}
}

Expand All @@ -281,34 +209,16 @@ public class GetBlockTransfers : RpcMethod
/// Retrieves all transfers for a Block from the network
/// </summary>
/// <param name="blockHash">Hash of the block to retrieve the transfers from. Null for the most recent block</param>
public GetBlockTransfers(string blockHash) : base("chain_get_block_transfers")
public GetBlockTransfers(string blockHash) : base("chain_get_block_transfers", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null}
};
}

/// <summary>
/// Retrieves all transfers for a Block from the network
/// </summary>
/// <param name="height">Height of the block to retrieve the transfers from.</param>
public GetBlockTransfers(int height) : base("chain_get_block_transfers")
public GetBlockTransfers(int height) : base("chain_get_block_transfers", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}
}

Expand All @@ -318,34 +228,16 @@ public class GetEraInfoBySwitchBlock : RpcMethod
/// Retrieves an EraInfo from the network given a switch block
/// </summary>
/// <param name="blockHash">Block hash of a switch block.</param>
public GetEraInfoBySwitchBlock(string blockHash) : base("chain_get_era_info_by_switch_block")
public GetEraInfoBySwitchBlock(string blockHash) : base("chain_get_era_info_by_switch_block", blockHash)
{
var blockIdentifier = new Dictionary<string, string>
{
{"Hash", blockHash}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockHash != null ? blockIdentifier : null}
};
}

/// <summary>
/// Retrieves an EraInfo from the network given a switch block.
/// </summary>
/// <param name="height">Block height of a switch block.</param>
public GetEraInfoBySwitchBlock(int height) : base("chain_get_era_info_by_switch_block")
public GetEraInfoBySwitchBlock(int height) : base("chain_get_era_info_by_switch_block", height)
{
var blockIdentifier = new Dictionary<string, int>
{
{"Height", height}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}
}

Expand Down Expand Up @@ -476,4 +368,4 @@ public GetRpcSchema() : base("rpc.discover")
{
}
}
}
}
36 changes: 35 additions & 1 deletion Casper.Network.SDK/JsonRpc/RpcMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ public RpcMethod(string method)
this.Method = method;
}

public RpcMethod(string method, string blockHash)
{
this.Method = method;

this.Parameters = blockHash switch
{
null => new Dictionary<string, object>(),
_ => new Dictionary<string, object>
{
{
"block_identifier", new Dictionary<string, string>
{
{"Hash", blockHash}
}
}
}
};
}

public RpcMethod(string method, int blockHeight)
{
this.Method = method;

var blockIdentifier = new Dictionary<string, int>
{
{"Height", blockHeight}
};

this.Parameters = new Dictionary<string, object>
{
{"block_identifier", blockIdentifier}
};
}

/// <summary>
/// Converts an RpcMethod derived object a JSON string that can be sent to the network
/// </summary>
Expand All @@ -65,4 +99,4 @@ public string Serialize()
return JsonSerializer.Serialize(this, typeof(RpcMethod), SerializerOptions);
}
}
}
}

0 comments on commit 3cd061a

Please sign in to comment.