using System.Text.Json.Serialization;
using Managing.Domain.Accounts;
namespace Managing.Infrastructure.Evm.Models.Proxy
{
///
/// Base response structure from the Web3Proxy API
///
public class Web3ProxyResponse
{
///
/// Whether the operation was successful
///
[JsonPropertyName("success")]
public bool Success { get; set; }
///
/// Error message if not successful
///
[JsonPropertyName("error")]
public string Error { get; set; }
}
///
/// Generic response with data payload
///
/// Type of data in the response
public class Web3ProxyDataResponse : Web3ProxyResponse
{
///
/// The response data if successful
///
[JsonPropertyName("data")]
public T Data { get; set; }
}
///
/// Base error response from Web3Proxy API
///
public class Web3ProxyError
{
///
/// Error type
///
[JsonPropertyName("type")]
public string Type { get; set; }
///
/// Error message
///
[JsonPropertyName("message")]
public string Message { get; set; }
///
/// Error stack trace
///
[JsonPropertyName("stack")]
public string Stack { get; set; }
///
/// HTTP status code (added by service)
///
[JsonIgnore]
public int StatusCode { get; set; }
///
/// Returns a formatted error message with type and message
///
public string FormattedMessage => $"{Type}: {Message}";
}
///
/// API response containing error details
///
public class Web3ProxyErrorResponse : Web3ProxyResponse
{
///
/// Error details (for structured errors)
///
[JsonPropertyName("err")]
public Web3ProxyError ErrorDetails { get; set; }
}
///
/// Represents a Web3Proxy API exception with error details
///
public class Web3ProxyException : Exception
{
///
/// The error details from the API
///
public Web3ProxyError Error { get; }
///
/// Simple error message from API
///
public string ApiErrorMessage { get; }
///
/// Creates a new Web3ProxyException from a structured error
///
/// The error details
public Web3ProxyException(Web3ProxyError error)
: base(error?.Message ?? "An error occurred in the Web3Proxy API")
{
Error = error;
}
///
/// Creates a new Web3ProxyException from a simple error message
///
/// The error message
public Web3ProxyException(string errorMessage)
: base(errorMessage)
{
ApiErrorMessage = errorMessage;
}
///
/// Creates a new Web3ProxyException with a custom message
///
/// Custom error message
/// The error details
public Web3ProxyException(string message, Web3ProxyError error)
: base(message)
{
Error = error;
}
}
///
/// Response for token sending operations
///
public class Web3ProxyTokenSendResponse : Web3ProxyResponse
{
///
/// Transaction hash if successful
///
[JsonPropertyName("hash")]
public string Hash { get; set; }
}
///
/// Response for wallet balance operations
///
public class Web3ProxyBalanceResponse : Web3ProxyResponse
{
///
/// List of wallet balances if successful
///
[JsonPropertyName("balances")]
public List Balances { get; set; }
}
}