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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#![deny(
clippy::expect_used,
clippy::unwrap_used,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces
)]
mod compact_text;
mod json;
mod raw_text;
mod stringified_object;
mod transaction_utils;
pub use dubp_documents::dubp_wallet;
pub mod prelude {
pub use crate::compact_text::certifications::parse_compact_certifications;
pub use crate::compact_text::identities::parse_compact_identities;
pub use crate::compact_text::memberships::parse_compact_memberships;
pub use crate::compact_text::revoked::parse_compact_revocations;
pub use crate::compact_text::ParseCompactDocError;
pub use crate::json::transactions::{parse_json_transactions, ParseJsonTxError};
pub use crate::raw_text::{ParseFromRawText, Rule};
pub use crate::stringified_object::FromStringObject;
pub use crate::TextParseError;
}
pub use crate::raw_text::wallet_script::wallet_script_from_str;
pub use crate::transaction_utils::tx_unlock_v10_from_str;
pub(crate) use crate::json::DefaultHasher;
pub(crate) use crate::prelude::*;
pub(crate) use crate::raw_text::{FromPestPair, RawDocumentsParser};
pub(crate) use crate::transaction_utils::{tx_input_v10_from_str, tx_output_v10_from_str};
pub(crate) use dubp_documents::certification::{
v10::CertificationDocumentV10Builder, CertificationDocument, CertificationDocumentV10,
CompactCertificationDocumentV10,
};
pub(crate) use dubp_documents::dubp_common::crypto::bases::BaseConversionError;
pub(crate) use dubp_documents::dubp_common::crypto::hashs::Hash;
pub(crate) use dubp_documents::dubp_common::crypto::keys::*;
pub(crate) use dubp_documents::dubp_common::prelude::*;
pub(crate) use dubp_documents::identity::{
IdentityDocument, IdentityDocumentV10, IdentityDocumentV10Builder,
};
pub(crate) use dubp_documents::membership::{
MembershipDocument, MembershipDocumentV10, MembershipDocumentV10Builder, MembershipType,
};
pub(crate) use dubp_documents::prelude::*;
pub(crate) use dubp_documents::revocation::{
v10::RevocationDocumentV10Builder, CompactRevocationDocumentV10, RevocationDocument,
RevocationDocumentV10,
};
pub(crate) use dubp_documents::smallvec::{smallvec as svec, SmallVec};
pub(crate) use dubp_documents::transaction::{
v10::TransactionInputUnlocksV10, TransactionDocument, TransactionDocumentBuilder,
TransactionDocumentV10, TransactionDocumentV10Builder, TransactionDocumentV10Stringified,
TransactionInputV10, TransactionOutputV10, UTXOConditions,
};
pub(crate) use dubp_wallet::prelude::*;
pub(crate) use pest::{
iterators::{Pair, Pairs},
Parser,
};
pub(crate) use pest_derive::Parser;
pub(crate) use std::{net::AddrParseError, num::ParseIntError, str::FromStr};
pub(crate) use thiserror::Error;
#[derive(Debug, Clone, Eq, Error, PartialEq)]
#[error("Grammar error: {0}")]
pub struct PestError(pub String);
impl<T: pest::RuleType> From<pest::error::Error<T>> for PestError {
fn from(e: pest::error::Error<T>) -> Self {
PestError(format!("{}", e))
}
}
#[derive(Debug, Clone, Eq, Error, PartialEq)]
pub enum TextParseError {
#[error("field {field}: {error}")]
BaseConversionError {
field: &'static str,
error: BaseConversionError,
},
#[error("BlockstampParseError: {0}")]
BlockstampParseError(BlockstampParseError),
#[error("Fail to parse compact doc (field '{field}'): {error}")]
CompactDoc {
field: &'static str,
error: ParseCompactDocError,
},
#[error("TextDocumentParseError: Invalid inner format: {0}")]
InvalidInnerFormat(String),
#[error("TextDocumentParseError: invalid ip: {0}")]
IpAddrError(AddrParseError),
#[error("TextDocumentParseError: {0}")]
PestError(PestError),
#[error("TextDocumentParseError: Unexpected rule: '{0}'")]
UnexpectedRule(String),
#[error("TextDocumentParseError: Unexpected version: '{0}'")]
UnexpectedVersion(String),
#[error("TextDocumentParseError: UnknownType.")]
UnknownType,
}
impl From<AddrParseError> for TextParseError {
fn from(e: AddrParseError) -> Self {
TextParseError::IpAddrError(e)
}
}
impl From<PestError> for TextParseError {
fn from(e: PestError) -> Self {
TextParseError::PestError(e)
}
}
impl<T: pest::RuleType> From<pest::error::Error<T>> for TextParseError {
fn from(e: pest::error::Error<T>) -> Self {
TextParseError::PestError(e.into())
}
}
#[cfg(test)]
pub mod tests {
use super::*;
use unwrap::unwrap;
#[inline(always)]
pub fn h(hash_str: &str) -> Hash {
unwrap!(Hash::from_hex(hash_str))
}
#[inline(always)]
pub fn pk(pk_b58: &str) -> ed25519::PublicKey {
unwrap!(PublicKey::from_base58(pk_b58))
}
}