syntax = "proto3";

package soma.rpc;

// The status of an executed transaction.
message ExecutionStatus {
  // Indicates if the transaction was successful or not.
  optional bool success = 1;

  // The error if `success` is false.
  optional ExecutionError error = 2;
}

// An error that can occur during the execution of a transaction.
message ExecutionError {
  // A human readable description of the error
  optional string description = 1;

  enum ExecutionErrorKind {
    EXECUTION_ERROR_KIND_UNKNOWN = 0;

    //
    // General errors.
    //

    // Insufficient gas.
    INSUFFICIENT_GAS = 1;

    // Invalid owner for object.
    INVALID_OWNERSHIP = 2;

    // Object not found.
    OBJECT_NOT_FOUND = 3;

    // Invalid object type.
    INVALID_OBJECT_TYPE = 4;

    // Invalid transaction type
    INVALID_TRANSACTION_TYPE = 5;

    // Invalid arguments for transaction
    INVALID_ARGUMENTS = 6;

    //
    // Validator errors.
    //

    // Adding avalidator that already exists
    DUPLICATE_VALIDATOR = 7;

    // Trying to remove a validator that doesn't exist
    NOT_A_VALIDATOR = 8;

    // Removing a validator that was already removed
    VALIDATOR_ALREADY_REMOVED = 9;

    // Advancing to unexpected epoch
    ADVANCED_TO_WRONG_EPOCH = 10;

    //
    // Model errors.
    //

    // Model not found
    MODEL_NOT_FOUND = 11;

    // Sender is not the model owner
    NOT_MODEL_OWNER = 12;

    // Model is not in active state
    MODEL_NOT_ACTIVE = 13;

    //
    // Coin errors.
    //

    // Insufficient coin balance for requested operation.
    INSUFFICIENT_COIN_BALANCE = 14;

    // Coin balance overflowed an u64.
    COIN_BALANCE_OVERFLOW = 15;

    //
    // Staking errors.
    //

    // Validator not found
    VALIDATOR_NOT_FOUND = 16;

    // Staking pool not found
    STAKING_POOL_NOT_FOUND = 18;

    // Validator cannot report oneself
    CANNOT_REPORT_ONESELF = 19;

    // Unreported record cannot be undone
    REPORT_RECORD_NOT_FOUND = 20;

    //
    // Other errors.
    //

    INPUT_OBJECT_DELETED = 21;

    CERTIFICATE_DENIED = 22;

    SHARED_OBJECT_CONGESTION = 23;

    // Other error.
    OTHER_ERROR = 24;

    //
    // Additional model errors.
    //

    // Model is not in pending (committed) state
    MODEL_NOT_PENDING = 25;

    // Model is already inactive
    MODEL_ALREADY_INACTIVE = 26;

    // Model reveal epoch mismatch
    MODEL_REVEAL_EPOCH_MISMATCH = 27;

    // Model weights URL commitment mismatch
    MODEL_WEIGHTS_URL_MISMATCH = 28;

    // Model has no pending update
    MODEL_NO_PENDING_UPDATE = 29;

    // Model architecture version mismatch
    MODEL_ARCHITECTURE_VERSION_MISMATCH = 30;

    // Model commission rate exceeds maximum
    MODEL_COMMISSION_RATE_TOO_HIGH = 31;

    // Model minimum stake requirement not met
    MODEL_MIN_STAKE_NOT_MET = 32;

    //
    // Target errors.
    //

    // No active models available for target generation
    NO_ACTIVE_MODELS = 33;

    // Target not found
    TARGET_NOT_FOUND = 34;

    // Target is not open for submissions
    TARGET_NOT_OPEN = 35;

    // Target has expired
    TARGET_EXPIRED = 36;

    // Target is not filled
    TARGET_NOT_FILLED = 37;

    // Challenge window is still open
    CHALLENGE_WINDOW_OPEN = 38;

    // Target rewards have already been claimed
    TARGET_ALREADY_CLAIMED = 39;

    //
    // Submission errors.
    //

    // Model is not assigned to target
    MODEL_NOT_IN_TARGET = 40;

    // Embedding dimension mismatch
    EMBEDDING_DIMENSION_MISMATCH = 41;

    // Distance score exceeds threshold
    DISTANCE_EXCEEDS_THRESHOLD = 42;

    // Insufficient bond for submission
    INSUFFICIENT_BOND = 43;

    // Insufficient emission pool balance
    INSUFFICIENT_EMISSION_BALANCE = 44;

    //
    // Challenge errors.
    //

    // Challenge window has closed
    CHALLENGE_WINDOW_CLOSED = 45;

    // Insufficient challenger bond
    INSUFFICIENT_CHALLENGER_BOND = 46;

    // Challenge not found
    CHALLENGE_NOT_FOUND = 47;

    // Challenge is not pending
    CHALLENGE_NOT_PENDING = 48;

    // Challenge has expired
    CHALLENGE_EXPIRED = 49;

    // Invalid challenge result
    INVALID_CHALLENGE_RESULT = 50;

    // Invalid challenge quorum
    INVALID_CHALLENGE_QUORUM = 51;

    // Data exceeds maximum allowed size
    DATA_EXCEEDS_MAX_SIZE = 52;

    // Challenge already exists for this target
    CHALLENGE_ALREADY_EXISTS = 53;
  }

  optional ExecutionErrorKind kind = 2;

  oneof error_details {
    string object_id = 3;
    string other_error = 4;
  }
}
