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
//! Errors returned by the stateless contract API.
use thiserror::Error;
/// Errors returned by the stateless contract functions.
///
/// Variants carry plain strings so they can cross FFI and binding boundaries
/// without exposing internal library error types.
#[derive(Debug, Error)]
pub enum ContractError {
/// The offer message, or data used to build one, is invalid.
#[error("invalid offer: {0}")]
InvalidOffer(String),
/// The accept message, or data used to build one, is invalid.
#[error("invalid accept: {0}")]
InvalidAccept(String),
/// The sign message, or data used to build one, is invalid.
#[error("invalid sign: {0}")]
InvalidSign(String),
/// A funding input is malformed or references missing data.
#[error("invalid funding input: {0}")]
InvalidFundingInput(String),
/// The PSBT does not match the funding transaction rebuilt from the wire messages.
#[error("PSBT mismatch: {0}")]
PsbtMismatch(String),
/// A PSBT input that must be signed does not have a finalized witness.
#[error("PSBT input {input_index} does not have a finalized witness")]
MissingFinalizedInput {
/// The index of the input in the funding transaction.
input_index: usize,
},
/// The script type of a funding input is not supported for signing.
#[error("PSBT input {input_index} has an unsupported script type")]
UnsupportedScriptType {
/// The index of the input in the funding transaction.
input_index: usize,
},
/// An oracle attestation is malformed, forged, or does not correspond to
/// the announcement of the oracle it claims to come from.
#[error("invalid attestation: {0}")]
InvalidAttestation(String),
/// No contract outcome corresponds to the supplied oracle attestations, so
/// there is no CET to sign.
#[error("no contract outcome matches the given attestations")]
NoMatchingOutcome,
/// Descriptor parsing, derivation, or signing failed.
#[error("descriptor error: {0}")]
Descriptor(String),
/// A wallet implementation failed to sign a funding input.
#[error("wallet error: {0}")]
Wallet(String),
/// BIP32 key derivation failed.
#[error("BIP32 error: {0}")]
Bip32(String),
/// A DLC transaction or signature operation failed.
#[error("DLC error: {0}")]
Dlc(String),
/// Contract funding-key derivation failed (bad mnemonic, missing private
/// key, or an invalid derived key).
#[error("contract key error: {0}")]
Key(String),
}
impl From<bitcoin::bip32::Error> for ContractError {
fn from(error: bitcoin::bip32::Error) -> Self {
ContractError::Bip32(error.to_string())
}
}
impl From<ddk_dlc::Error> for ContractError {
fn from(error: ddk_dlc::Error) -> Self {
ContractError::Dlc(error.to_string())
}
}
impl From<ddk_manager::error::Error> for ContractError {
fn from(error: ddk_manager::error::Error) -> Self {
ContractError::Dlc(error.to_string())
}
}