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
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Error types pertaining to deserializing Stardust snapshots
use std::convert::Infallible;

use iota_stardust_sdk::types::block::output::FoundryId;
use packable::error::UnknownTagError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum StardustError {
    #[error("unsupported Hornet snapshot version: expected {0}, got {1}")]
    UnsupportedHornetSnapshotVersion(u8, u8),
    #[error("invalid snapshot kind: {0}")]
    InvalidHornetSnapshotKind(u8),
    #[error("invalid Hornet genesis snapshot: milestone diff count must be 0, but was {0}")]
    InvalidHornetGenesisSnapshot(u32),
    #[error("block error: {0}")]
    Block(#[from] iota_stardust_sdk::types::block::Error),
    #[error("{0}")]
    UnknownTag(#[from] UnknownTagError<u8>),
    #[error(
        "cannot convert `FoundryOutput` with `FoundryId` {foundry_id} to `NativeTokenPackageData`: {err}"
    )]
    FoundryConversionError {
        foundry_id: FoundryId,
        err: anyhow::Error,
    },
    #[error("framework packages path not found")]
    FrameworkPackagesPathNotFound,
    #[error(
        "failed to derive valid move identifier from symbol `{symbol}`, invalid identifier: `{identifier}`"
    )]
    InvalidMoveIdentifierDerived { symbol: String, identifier: String },
    #[error("melting tokens must not be greater than minted tokens")]
    MeltingTokensMustNotBeGreaterThanMintedTokens,
    #[error("circulating supply must not be greater than maximum supply")]
    CirculatingSupplyMustNotBeGreaterThanMaximumSupply,
    #[error("Hornet Stardust snapshot parameters not found")]
    HornetSnapshotParametersNotFound,
}

impl From<Infallible> for StardustError {
    fn from(_: Infallible) -> Self {
        unreachable!()
    }
}