pyth_lazer_stellar_sdk/error.rs
1use soroban_sdk::contracterror;
2
3/// Errors returned by [`crate::parse_payload`] when decoding a verified Lazer
4/// payload. Declared as a `#[contracterror]` so consumers can propagate it
5/// directly from their own contract entrypoints.
6#[contracterror]
7#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
8#[repr(u32)]
9pub enum ParseError {
10 TruncatedData = 1,
11 InvalidPayloadLength = 2,
12 InvalidPayloadMagic = 3,
13 InvalidChannel = 4,
14 InvalidProperty = 5,
15 InvalidMarketSession = 6,
16}
17
18/// Errors returned by [`crate::PythLazerClient::verify_update`].
19///
20/// Covers both verifier-side failures reported by the on-chain
21/// `pyth-lazer-stellar` contract and parse failures on the returned payload
22/// bytes. The verifier-side discriminants match the on-chain contract's error
23/// codes so [`soroban_sdk::Env::try_invoke_contract`] converts them directly.
24#[contracterror]
25#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
26#[repr(u32)]
27pub enum VerifyError {
28 /// Envelope magic prefix did not match the LE-ECDSA format.
29 InvalidEnvelopeMagic = 3,
30 /// Envelope was shorter than the minimum size (71 bytes).
31 TruncatedEnvelope = 4,
32 /// Envelope's declared payload length did not match the remaining bytes.
33 InvalidEnvelopeLength = 5,
34 /// Recovered signer pubkey is not in the on-chain trusted set.
35 SignerNotTrusted = 6,
36 /// Recovered signer is trusted but its expiry has passed.
37 SignerExpired = 7,
38 /// Envelope's recovery_id byte was outside the valid range `[0, 3]`.
39 InvalidRecoveryId = 13,
40 /// Verified payload's magic prefix did not match.
41 InvalidPayloadMagic = 100,
42 /// Verified payload had trailing bytes after decoding finished.
43 InvalidPayloadLength = 101,
44 /// Verified payload ended mid-field during decoding.
45 TruncatedPayload = 102,
46 /// Verified payload had an unknown channel value.
47 InvalidChannel = 103,
48 /// Verified payload had an unknown feed property id.
49 InvalidProperty = 104,
50 /// Verified payload had an unknown market session value.
51 InvalidMarketSession = 105,
52 /// Verifier call trapped, or returned an error code this SDK does not
53 /// recognize. This is the fallback for non-typed host aborts (e.g. an
54 /// invalid signature triggers `secp256k1_recover` to trap rather than
55 /// returning a typed error).
56 InvokeFailed = 200,
57}
58
59impl From<ParseError> for VerifyError {
60 fn from(err: ParseError) -> Self {
61 match err {
62 ParseError::TruncatedData => VerifyError::TruncatedPayload,
63 ParseError::InvalidPayloadLength => VerifyError::InvalidPayloadLength,
64 ParseError::InvalidPayloadMagic => VerifyError::InvalidPayloadMagic,
65 ParseError::InvalidChannel => VerifyError::InvalidChannel,
66 ParseError::InvalidProperty => VerifyError::InvalidProperty,
67 ParseError::InvalidMarketSession => VerifyError::InvalidMarketSession,
68 }
69 }
70}