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
//! A lightweight parser for Bitcoin Ordinals inscriptions.
//!
//! This library allows you to parse and extract Ordinals inscriptions from Bitcoin
//! transactions without requiring the full Ord codebase.
//!
//! # Features
//!
//! - Parse Ordinals inscriptions from Bitcoin transactions
//! - Support for both classic and modern inscription formats
//! - Extract content type, body, and other metadata
//! - Detect JSON in text/plain content
//! - Low dependency footprint
//!
//! # Basic Example
//!
//! ```rust
//! use ordinals_parser::{parse_inscriptions_from_transaction, Inscription};
//! use bitcoin::Transaction;
//!
//! # fn example() {
//! // Load a Bitcoin transaction
//! let transaction: Transaction = /* ... */;
//!
//! // Parse inscriptions
//! let inscriptions = parse_inscriptions_from_transaction(&transaction);
//!
//! for inscription in inscriptions {
//! println!("Content type: {:?}", inscription.content_type());
//! println!("Content length: {:?}", inscription.content_length());
//!
//! if let Some(body) = inscription.body() {
//! // Work with inscription content
//! }
//! }
//! # }
//! ```
//!
//! # Working with JSON Inscriptions
//!
//! The library can detect and parse JSON content in both `application/json` and `text/plain` inscriptions:
//!
//! ```rust
//! use ordinals_parser::{parse_inscriptions_from_transaction};
//! use bitcoin::Transaction;
//! use serde_json::Value;
//!
//! # fn example() {
//! // Load a Bitcoin transaction
//! let transaction: Transaction = /* ... */;
//!
//! // Parse inscriptions
//! let inscriptions = parse_inscriptions_from_transaction(&transaction);
//!
//! for inscription in inscriptions {
//! if let (Some(content_type), Some(body)) = (inscription.content_type(), inscription.body()) {
//! // Check if it's JSON content
//! let is_json = content_type == "application/json" ||
//! (content_type.starts_with("text/plain") &&
//! if let Ok(text) = std::str::from_utf8(body) {
//! let trimmed = text.trim();
//! (trimmed.starts_with('{') && trimmed.ends_with('}')) ||
//! (trimmed.starts_with('[') && trimmed.ends_with(']'))
//! } else {
//! false
//! });
//!
//! if is_json {
//! if let Ok(text) = std::str::from_utf8(body) {
//! if let Ok(json) = serde_json::from_str::<Value>(text) {
//! // Process BRC-20, Ordinals Collections, etc.
//! println!("Found JSON content: {:?}", json);
//! }
//! }
//! }
//! }
//! }
//! # }
//! ```
//!
//! # Creating an Inscription
//!
//! ```rust
//! use ordinals_parser::InscriptionBuilder;
//!
//! # fn example() {
//! let inscription = InscriptionBuilder::new()
//! .content_type("text/plain;charset=utf-8")
//! .body("Hello, Ordinals!".as_bytes())
//! .build();
//!
//! // Convert to a script (for inclusion in a Bitcoin transaction)
//! let script = inscription.to_script();
//! # }
//! ```
/// Error handling module
/// Inscription envelope parsing
/// Inscription data structure
/// Inscription ID
/// Tags used in inscriptions
// Re-export important types
pub use crate;
pub use crate;
pub use crateInscriptionId;
pub use crate;
/// Parse all inscriptions from a Bitcoin transaction
///
/// This function examines all inputs in the transaction and extracts any
/// inscriptions found in their witness data.
///
/// # Parameters
///
/// * `tx` - A reference to a Bitcoin transaction
///
/// # Returns
///
/// A vector of `Inscription` objects found in the transaction
///
/// # Example
///
/// ```rust
/// use ordinals_parser::parse_inscriptions_from_transaction;
/// use bitcoin::Transaction;
///
/// // Load a Bitcoin transaction
/// let transaction: Transaction = /* ... */;
///
/// // Parse all inscriptions
/// let inscriptions = parse_inscriptions_from_transaction(&transaction);
/// ```