Interface SecpResult<T>

Type Parameters:
T - type of the successful result
All Known Implementing Classes:
SecpResult.Err, SecpResult.Ok

public interface SecpResult<T>
Functional-style result for secp256k1 -- either SecpResult.Ok or SecpResult.Err. If result is Ok the success result is in SecpResult.Ok.result(), if a failure occurred the error code is in SecpResult.Err.code().
  • Method Details

    • ok

      static <T> SecpResult<T> ok(T result)
      Static constructor for SecpResult.Ok
      Type Parameters:
      T - result type
      Parameters:
      result - result value
      Returns:
      successful result
    • err

      static <T> SecpResult<T> err(int error_code)
      Static constructor for SecpResult.Err
      Type Parameters:
      T - expected result type
      Parameters:
      error_code - error code
      Returns:
      error result
    • checked

      static <T> SecpResult<T> checked(int error_code, Supplier<T> supplier)
      Create a result from an error code and a supplier function. If the error code is 1 (no error), the supplier function is invoked to produce a successful result. Otherwise, an error result is returned containing the error code.
      Type Parameters:
      T - result value type
      Parameters:
      error_code - error code
      supplier - value supplier
      Returns:
      result
    • get

      default T get()
      Get the result value or throw a RuntimeException
      Returns:
      result value
    • get

      default T get(String message)
      Get the result value or throw a RuntimeException
      Parameters:
      message - error message to include in exception
      Returns:
      result value