1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![deny(unused_crate_dependencies)]
pub mod cli;
pub(crate) mod commands;
mod database;
pub mod executor;
pub mod ffi;
pub(crate) mod queries;
mod service;

pub use database::Database;
pub use executor::{Executor, IndexEnv, WasmIndexExecutor};
pub use fuel_indexer_database::IndexerDatabaseError;
pub use fuel_indexer_lib::{
    config::IndexerConfig,
    manifest::{Manifest, ManifestError, Module},
};
pub use fuel_indexer_schema::{db::IndexerSchemaDbError, FtColumn};
pub use service::get_start_block;
pub use service::IndexerService;
use thiserror::Error;
use wasmer::{ExportError, InstantiationError, RuntimeError};

// Required for vendored openssl
use openssl as _;

pub mod prelude {
    pub use super::{
        Database, Executor, FtColumn, IndexEnv, IndexerConfig, IndexerError,
        IndexerResult, IndexerService, Manifest, Module, WasmIndexExecutor,
    };
    pub use async_std::sync::{Arc, Mutex};
    pub use fuel_indexer_lib::config::{DatabaseConfig, FuelClientConfig, WebApiConfig};
    pub use fuel_indexer_types::*;
}

pub type IndexerResult<T> = core::result::Result<T, IndexerError>;

#[derive(Error, Debug)]
pub enum IndexerError {
    #[error("Compiler error: {0:#?}")]
    CompileError(#[from] wasmer::CompileError),
    #[error("Error from sqlx: {0:#?}")]
    SqlxError(#[from] sqlx::Error),
    #[error("Error instantiating wasm interpreter: {0:#?}")]
    InstantiationError(#[from] InstantiationError),
    #[error("Error finding exported symbol: {0:#?}")]
    ExportError(#[from] ExportError),
    #[error("Error executing function: {0:#?}")]
    RuntimeError(#[from] RuntimeError),
    #[error("Run time limit exceeded error")]
    RunTimeLimitExceededError,
    #[error("IO Error: {0:#?}")]
    IoError(#[from] std::io::Error),
    #[error("FFI Error {0:?}")]
    FFIError(#[from] ffi::FFIError),
    #[error("Missing handler")]
    MissingHandler,
    #[error("Database error {0:?}")]
    DatabaseError(#[from] IndexerDatabaseError),
    #[error("Invalid address {0:?}")]
    InvalidAddress(#[from] std::net::AddrParseError),
    #[error("Join Error {0:?}")]
    JoinError(#[from] tokio::task::JoinError),
    #[error("Error initializing executor")]
    ExecutorInitError,
    #[error("Error executing handler")]
    HandlerError,
    #[error("Invalid port {0:?}")]
    InvalidPortNumber(#[from] core::num::ParseIntError),
    #[error("No open transaction for {0}. Was a transaction started?")]
    NoTransactionError(String),
    #[error("Indexer schema error: {0:?}")]
    SchemaError(#[from] IndexerSchemaDbError),
    #[error("Manifest error: {0:?}")]
    ManifestError(#[from] ManifestError),
    #[error("Error creating wasm executor.")]
    WasmExecutionInstantiationError,
    #[error("Native execution runtime error.")]
    NativeExecutionRuntimeError,
    #[error("Tokio time error: {0:?}")]
    Elapsed(#[from] tokio::time::error::Elapsed),
    #[error("Invalid schema: {0:?}")]
    SchemaVersionMismatch(String),
    #[error(transparent)]
    Other(#[from] anyhow::Error),
    // The following errors actually signify a successful completion.
    #[error("Kill switch has been flipped. <('.')>")]
    KillSwitch,
    #[error("End block has been met.")]
    EndBlockMet,
}