diff --git a/CHANGELOG.md b/CHANGELOG.md index c1563f9..aef0a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/Casper.Network.SDK/Casper.Network.SDK.csproj b/Casper.Network.SDK/Casper.Network.SDK.csproj index 7fbcff5..699e5d0 100644 --- a/Casper.Network.SDK/Casper.Network.SDK.csproj +++ b/Casper.Network.SDK/Casper.Network.SDK.csproj @@ -2,9 +2,9 @@ net5.0 - 1.1.0.0 - 1.1.0 - 1.1.0 + 1.1.1.0 + 1.1.1 + 1.1.1 Casper.Network.SDK make-software https://github.com/make-software/casper-net-sdk @@ -20,7 +20,7 @@ - + diff --git a/Casper.Network.SDK/JsonRpc/CasperMethods.cs b/Casper.Network.SDK/JsonRpc/CasperMethods.cs index dc737ec..0834a1d 100644 --- a/Casper.Network.SDK/JsonRpc/CasperMethods.cs +++ b/Casper.Network.SDK/JsonRpc/CasperMethods.cs @@ -10,34 +10,16 @@ public class GetStateRootHash : RpcMethod /// Returns a state root hash at a given Block /// /// Block hash for which the state root is queried. Null for the most recent. - 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 - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null} - }; } /// /// Returns the state root hash at a given Block /// /// Block height for which the state root is queried. - 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 - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier} - }; } } @@ -67,34 +49,16 @@ public class GetAuctionInfo : RpcMethod /// Returns the bids and validators at a given block. /// /// Block hash for which the auction info is queried. Null for the most recent auction info. - public GetAuctionInfo(string blockHash) : base("state_get_auction_info") + public GetAuctionInfo(string blockHash) : base("state_get_auction_info", blockHash) { - var blockIdentifier = new Dictionary - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null} - }; } /// /// Returns the bids and validators at a given block. /// /// Block height for which the auction info is queried. - public GetAuctionInfo(int height) : base("state_get_auction_info") + public GetAuctionInfo(int height) : base("state_get_auction_info", height) { - var blockIdentifier = new Dictionary - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier} - }; } } @@ -105,18 +69,9 @@ public class GetAccountInfo : RpcMethod /// /// The public key of the account. /// A block hash for which the information of the account is queried. Null for most recent information. - 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 - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null}, - {"public_key", publicKey} - }; + this.Parameters.Add("public_key", publicKey); } /// @@ -124,18 +79,9 @@ public GetAccountInfo(string publicKey, string blockHash = null) : base("state_g /// /// The public key of the account. /// A block height for which the information of the account is queried. - 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 - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier}, - {"public_key", publicKey} - }; + this.Parameters.Add("public_key", publicKey); } } @@ -244,34 +190,16 @@ public class GetBlock : RpcMethod /// Retrieves a Block from the network by its hash. /// /// Hash of the block to retrieve. Null for the most recent block. - public GetBlock(string blockHash) : base("chain_get_block") + public GetBlock(string blockHash) : base("chain_get_block", blockHash) { - var blockIdentifier = new Dictionary - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null} - }; } /// /// Retrieves a Block from the network by its height number. /// /// Height of the block to retrieve. - public GetBlock(int height) : base("chain_get_block") + public GetBlock(int height) : base("chain_get_block", height) { - var blockIdentifier = new Dictionary - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier} - }; } } @@ -281,34 +209,16 @@ public class GetBlockTransfers : RpcMethod /// Retrieves all transfers for a Block from the network /// /// Hash of the block to retrieve the transfers from. Null for the most recent block - public GetBlockTransfers(string blockHash) : base("chain_get_block_transfers") + public GetBlockTransfers(string blockHash) : base("chain_get_block_transfers", blockHash) { - var blockIdentifier = new Dictionary - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null} - }; } /// /// Retrieves all transfers for a Block from the network /// /// Height of the block to retrieve the transfers from. - public GetBlockTransfers(int height) : base("chain_get_block_transfers") + public GetBlockTransfers(int height) : base("chain_get_block_transfers", height) { - var blockIdentifier = new Dictionary - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier} - }; } } @@ -318,34 +228,16 @@ public class GetEraInfoBySwitchBlock : RpcMethod /// Retrieves an EraInfo from the network given a switch block /// /// Block hash of a switch block. - 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 - { - {"Hash", blockHash} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockHash != null ? blockIdentifier : null} - }; } /// /// Retrieves an EraInfo from the network given a switch block. /// /// Block height of a switch block. - 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 - { - {"Height", height} - }; - - this.Parameters = new Dictionary - { - {"block_identifier", blockIdentifier} - }; } } @@ -476,4 +368,4 @@ public GetRpcSchema() : base("rpc.discover") { } } -} \ No newline at end of file +} diff --git a/Casper.Network.SDK/JsonRpc/RpcMethod.cs b/Casper.Network.SDK/JsonRpc/RpcMethod.cs index 75c03f1..3e17c8d 100644 --- a/Casper.Network.SDK/JsonRpc/RpcMethod.cs +++ b/Casper.Network.SDK/JsonRpc/RpcMethod.cs @@ -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(), + _ => new Dictionary + { + { + "block_identifier", new Dictionary + { + {"Hash", blockHash} + } + } + } + }; + } + + public RpcMethod(string method, int blockHeight) + { + this.Method = method; + + var blockIdentifier = new Dictionary + { + {"Height", blockHeight} + }; + + this.Parameters = new Dictionary + { + {"block_identifier", blockIdentifier} + }; + } + /// /// Converts an RpcMethod derived object a JSON string that can be sent to the network /// @@ -65,4 +99,4 @@ public string Serialize() return JsonSerializer.Serialize(this, typeof(RpcMethod), SerializerOptions); } } -} \ No newline at end of file +}