use std::result::Result as StdResult;
use thegraph_core::alloy::primitives::Address;
use thiserror::Error as ThisError;
use crate::receipt::ReceiptError;
#[derive(ThisError, Debug)]
pub enum Error {
#[error("Aggregating receipt results in overflow")]
AggregateOverflow,
#[error("Failed to get current system time: {source_error_message} ")]
InvalidSystemTime { source_error_message: String },
#[error(transparent)]
WalletError(#[from] thegraph_core::alloy::signers::Error),
#[error(transparent)]
SignatureError(#[from] tap_eip712_message::Eip712Error),
#[error("Expected address {expected} but received {received}")]
VerificationFailed {
expected: Address,
received: Address,
},
#[error("Received RAV does not match expected RAV")]
InvalidReceivedRav {
received_rav: String,
expected_rav: String,
},
#[error("Error from adapter.\n Caused by: {source_error}")]
AdapterError { source_error: anyhow::Error },
#[error("Failed to produce rav request, no valid receipts")]
NoValidReceiptsForRavRequest,
#[error("Previous RAV allocation id ({prev_id}) doesn't match the allocation id from the new receipt ({new_id}).")]
RavAllocationIdMismatch { prev_id: String, new_id: String },
#[error("All receipts should have the same allocation id, but they don't")]
RavAllocationIdNotUniform,
#[error("Duplicate receipt signature: {0}")]
DuplicateReceiptSignature(String),
#[error(
"Receipt timestamp ({receipt_ts}) is less or equal than previous rav timestamp ({rav_ts})"
)]
ReceiptTimestampLowerThanRav { rav_ts: u64, receipt_ts: u64 },
#[error("Timestamp range error: min_timestamp_ns: {min_timestamp_ns}, max_timestamp_ns: {max_timestamp_ns}. Adjust timestamp buffer.")]
TimestampRangeError {
min_timestamp_ns: u64,
max_timestamp_ns: u64,
},
#[error("Receipt error: {0}")]
ReceiptError(#[from] ReceiptError),
#[error("Recovered sender address invalid {address}")]
InvalidRecoveredSigner { address: Address },
#[error("Failed to check the signer: {0}")]
FailedToVerifySigner(String),
}
pub type Result<T> = StdResult<T, Error>;