@@ -19,57 +19,6 @@ use core::fmt;
1919
2020use crate :: types:: * ;
2121
22- /// Errors returned by [`libbitcoinconsensus`].
23- ///
24- /// The error variant identifiers mimic those from `libbitcoinconsensus`.
25- ///
26- /// [`libbitcoinconsensus`]: <https://github.com/bitcoin/bitcoin/blob/master/doc/shared-libraries.md#errors>
27- #[ allow( non_camel_case_types) ]
28- #[ derive( Debug ) ]
29- #[ repr( C ) ]
30- pub enum Error {
31- /// Default value, passed to `libbitcoinconsensus` as a return parameter.
32- ERR_SCRIPT = 0 ,
33- /// An invalid index for `txTo`.
34- ERR_TX_INDEX ,
35- /// `txToLen` did not match with the size of `txTo`.
36- ERR_TX_SIZE_MISMATCH ,
37- /// An error deserializing `txTo`.
38- ERR_TX_DESERIALIZE ,
39- /// Input amount is required if WITNESS is used.
40- ERR_AMOUNT_REQUIRED ,
41- /// Script verification `flags` are invalid (i.e. not part of the libconsensus interface).
42- ERR_INVALID_FLAGS ,
43- }
44-
45- impl fmt:: Display for Error {
46- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
47- use self :: Error :: * ;
48-
49- let s = match * self {
50- ERR_SCRIPT => "error value was not set (value still 0)" ,
51- ERR_TX_INDEX => "an invalid index for txTo" ,
52- ERR_TX_SIZE_MISMATCH => "txToLen did not match with the size of txTo" ,
53- ERR_TX_DESERIALIZE => "an error deserializing txTo" ,
54- ERR_AMOUNT_REQUIRED => "input amount is required if WITNESS is used" ,
55- ERR_INVALID_FLAGS => "script verification flags are invalid" ,
56- } ;
57- f. write_str ( s)
58- }
59- }
60-
61- #[ cfg( feature = "std" ) ]
62- impl std:: error:: Error for Error {
63- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
64- use self :: Error :: * ;
65-
66- match * self {
67- ERR_SCRIPT | ERR_TX_INDEX | ERR_TX_SIZE_MISMATCH | ERR_TX_DESERIALIZE
68- | ERR_AMOUNT_REQUIRED | ERR_INVALID_FLAGS => None ,
69- }
70- }
71- }
72-
7322/// Do not enable any verification.
7423pub const VERIFY_NONE : c_uint = 0 ;
7524/// Evaluate P2SH (BIP16) subscripts.
@@ -207,6 +156,57 @@ pub fn verify_with_flags(
207156 }
208157}
209158
159+ /// Errors returned by [`libbitcoinconsensus`].
160+ ///
161+ /// The error variant identifiers mimic those from `libbitcoinconsensus`.
162+ ///
163+ /// [`libbitcoinconsensus`]: <https://github.com/bitcoin/bitcoin/blob/master/doc/shared-libraries.md#errors>
164+ #[ allow( non_camel_case_types) ]
165+ #[ derive( Debug ) ]
166+ #[ repr( C ) ]
167+ pub enum Error {
168+ /// Default value, passed to `libbitcoinconsensus` as a return parameter.
169+ ERR_SCRIPT = 0 ,
170+ /// An invalid index for `txTo`.
171+ ERR_TX_INDEX ,
172+ /// `txToLen` did not match with the size of `txTo`.
173+ ERR_TX_SIZE_MISMATCH ,
174+ /// An error deserializing `txTo`.
175+ ERR_TX_DESERIALIZE ,
176+ /// Input amount is required if WITNESS is used.
177+ ERR_AMOUNT_REQUIRED ,
178+ /// Script verification `flags` are invalid (i.e. not part of the libconsensus interface).
179+ ERR_INVALID_FLAGS ,
180+ }
181+
182+ impl fmt:: Display for Error {
183+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
184+ use self :: Error :: * ;
185+
186+ let s = match * self {
187+ ERR_SCRIPT => "error value was not set (value still 0)" ,
188+ ERR_TX_INDEX => "an invalid index for txTo" ,
189+ ERR_TX_SIZE_MISMATCH => "txToLen did not match with the size of txTo" ,
190+ ERR_TX_DESERIALIZE => "an error deserializing txTo" ,
191+ ERR_AMOUNT_REQUIRED => "input amount is required if WITNESS is used" ,
192+ ERR_INVALID_FLAGS => "script verification flags are invalid" ,
193+ } ;
194+ f. write_str ( s)
195+ }
196+ }
197+
198+ #[ cfg( feature = "std" ) ]
199+ impl std:: error:: Error for Error {
200+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
201+ use self :: Error :: * ;
202+
203+ match * self {
204+ ERR_SCRIPT | ERR_TX_INDEX | ERR_TX_SIZE_MISMATCH | ERR_TX_DESERIALIZE
205+ | ERR_AMOUNT_REQUIRED | ERR_INVALID_FLAGS => None ,
206+ }
207+ }
208+ }
209+
210210#[ cfg( test) ]
211211mod tests {
212212 extern crate rustc_serialize as serialize;
0 commit comments