- Update tests and client for new validator performance data
Updated CSPRCloudNetTests.cs
:
- Added assertion to check
Score
values are not null. - Replaced
AverageScore
ordering checks withScore
ordering checks.
Updated CasperCloudRestClient.cs
:
- Changed return type of
GetHistoricalValidatorsAveragePerformanceAsync
toPaginatedResponse<RelativeValidatorPerformanceData>
. - Updated endpoint call, method signature, and documentation to reflect new return type.
These changes ensure compatibility with updated data structures and API responses, improving the accuracy and reliability of tests and client methods.
- Fixed mainnet baseUrl
- Fixed an issue where mainnet endpoints were using testnet baseurl.
- Changes:
- GetAccountInfo endpoint replaced with GetAccountInfoAsync
- Initial Release
The library is targeting both .NET Standard 2.0
and .NET Standard 2.1
for optimal compatibility
- Implementation of Streaming API
Package Manager
NuGet\Install-Package CSPR.Cloud.Net
.NET CLI
dotnet add package CSPR.Cloud.Net
The CasperCloudRestClient
class provides an easy way to interact with the CSPR Cloud API for both Mainnet and Testnet environments. Below are the steps to initialize and use the client in your application.
To create an instance of the CasperCloudRestClient
, you need to provide your API key. Optionally, you can also pass a custom HttpClient
and ILoggerFactory
for logging purposes.
Ensure you have the necessary dependencies in your project. Typically, this includes:
HttpClient
ILoggerFactory
from Microsoft.Extensions.Logging
Create an instance of the CasperCloudClientConfig
class with your API key.
public class CasperCloudClientConfig
{
public string ApiKey { get; set; }
public CasperCloudClientConfig(string apiKey)
{
if (string.IsNullOrEmpty(apiKey))
throw new ArgumentException("API key is required.", nameof(apiKey));
ApiKey = apiKey;
}
}
Initialize the CasperCloudRestClient
with your configuration, and optionally pass in a custom HttpClient
and ILoggerFactory
.
using System.Net.Http;
using Microsoft.Extensions.Logging;
// Configuration with API key
var config = new CasperCloudClientConfig("your-api-key");
// Optional: Custom HttpClient
HttpClient customHttpClient = new HttpClient();
// Optional: LoggerFactory for logging
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
// Create the CasperCloudRestClient
var restClient = new CasperCloudRestClient(config, customHttpClient, loggerFactory);
Use the Mainnet
and Testnet
properties to access different endpoints. For example:
// Accessing the Account endpoint on Testnet
var accountData = await restClient.Testnet.Account.GetAccountAsync("public-key");
// Accessing the Block endpoint on Mainnet
var blockData = await restClient.Mainnet.Block.GetBlockAsync("block-hash");
"CsprCloud": {
"ApiKey": "your-api-key"
}
context.Services.AddSingleton(resolver =>
{
var apiKey = configuration.GetSection("CsprCloud:ApiKey").Value;
return new CasperCloudRestClient(new CasperCloudClientConfig(apiKey));
});
public class IndexModel : PageModel
{
private readonly CasperCloudRestClient _restClient;
public IndexModel(CasperCloudRestClient restClient)
{
_restClient = restClient;
}
public async Task OnGet()
{
var result = await _restClient.Mainnet.Account.GetAccountInfoAsync("bb436216f3f56b073fc712c024a01c1291292e9533a03ddabc67ef85360b00bf");
}
}
Most of the endpoints require optional request parameters wrapped in a RequestParameters
class, which includes three possible components:
- FilterParameters: Used to filter the results.
- SortingParameters: Used to sort the results.
- OptionalParameters: Used to include additional data in the results.
Parameters and properties differ for each request depending on the endpoint.
Here's an example of how to initialize and use parameterized requests for the Validators
endpoint:
// Initialize the request parameters
var parameters = new ValidatorsRequestParameters
{
// Result is filtered for EraId = 14027 and IsActive = true
FilterParameters = new ValidatorsFilterParameters
{
EraId = "14027",
IsActive = true
},
// Result will include AccountInfo, CentralizedAccountInfo and AveragePerformance Entities
OptionalParameters = new ValidatorsOptionalParameters
{
AccountInfo = true,
CentralizedAccountInfo = true,
AveragePerformance = true,
},
// Result is sorted by Total Stake because it is set to true and the Sort Direction is Descending
SortingParameters = new ValidatorsSortingParameters
{
OrderByTotalStake = true,
SortType = SortType.Descending
}
};
// Execute the request
var result = await _restClient.Testnet.Validator.GetValidatorsAsync(parameters);
Below are some examples of demonstrating how to use the CasperCloudRestClient
.
For more detailed examples of all endpoints, please refer to the CSPRCloudNetTests.cs file.
var config = new CasperCloudClientConfig("your-api-key");
_restClient = new CasperCloudRestClient(config);
// Without parameters
var result = await _restClient.Testnet.Account.GetAccountAsync(_testPublicKey);
// With parameters
var parameters = new AccountInfosRequestParameters
{
FilterParameters = new AccountInfosFilterParameters
{
AccountHashes = new List<string>
{
"first-account-hash",
"second-account-hash"
}
}
};
var result = await _restClient.Testnet.Account.GetAccountInfosAsync(parameters);
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
MIT License
BTC: 1NxUuEQcR4Scw8ge3oto6ykLqBpe9LGikS
ETH: 0x9cda155f73220073a9f024daaa72eb06b5c06c86
CSPR Public Key: 01a0cbbd2f6402c98c745b6d318d15c0b68feef6a17af48ae35e683f05a4e6cbcc