@@ -4,6 +4,7 @@ pub mod ord;
4
4
5
5
use bitcoincore_rpc:: bitcoin:: hashes:: hex:: FromHex ;
6
6
use bitcoincore_rpc:: bitcoin:: { Address , Network , Script } ;
7
+ use bitcoincore_rpc_json:: bitcoin:: Witness ;
7
8
use chainhook_types:: {
8
9
BitcoinBlockData , OrdinalInscriptionRevealData , OrdinalInscriptionTransferData ,
9
10
OrdinalOperation , TransactionIdentifier ,
@@ -47,69 +48,73 @@ use self::ord::inscription_id::InscriptionId;
47
48
48
49
pub fn parse_ordinal_operations (
49
50
tx : & BitcoinTransactionFullBreakdown ,
50
- _block_height : u64 ,
51
- _ctx : & Context ,
51
+ block_height : u64 ,
52
+ ctx : & Context ,
52
53
) -> Vec < OrdinalOperation > {
53
54
// This should eventually become a loop once/if there is settlement on https://github.com/casey/ord/issues/2000.
54
55
let mut operations = vec ! [ ] ;
55
56
for ( input_index, input) in tx. vin . iter ( ) . enumerate ( ) {
56
- if let Some ( ref witnesses) = input. txinwitness {
57
- for bytes in witnesses. iter ( ) {
58
- let script = Script :: from ( bytes. to_vec ( ) ) ;
59
- let parser = InscriptionParser {
60
- instructions : script. instructions ( ) . peekable ( ) ,
61
- } ;
62
-
63
- let inscription = match parser. parse_script ( ) {
64
- Ok ( inscription) => inscription,
65
- Err ( _) => continue ,
66
- } ;
57
+ if let Some ( ref witness_data) = input. txinwitness {
58
+ let witness = Witness :: from_vec ( witness_data. clone ( ) ) ;
59
+ let inscription = match InscriptionParser :: parse ( & witness) {
60
+ Ok ( inscription) => inscription,
61
+ Err ( e) => {
62
+ ctx. try_log ( |logger| {
63
+ slog:: warn!(
64
+ logger,
65
+ "Inscription parsing error at block {}: #{:?}" ,
66
+ block_height,
67
+ e
68
+ )
69
+ } ) ;
70
+ continue ;
71
+ }
72
+ } ;
67
73
68
- let inscription_id = InscriptionId {
69
- txid : tx. txid . clone ( ) ,
70
- index : input_index as u32 ,
71
- } ;
74
+ let inscription_id = InscriptionId {
75
+ txid : tx. txid . clone ( ) ,
76
+ index : input_index as u32 ,
77
+ } ;
72
78
73
- let inscription_output_value = tx
74
- . vout
75
- . get ( 0 )
76
- . and_then ( |o| Some ( o. value . to_sat ( ) ) )
77
- . unwrap_or ( 0 ) ;
79
+ let inscription_output_value = tx
80
+ . vout
81
+ . get ( 0 )
82
+ . and_then ( |o| Some ( o. value . to_sat ( ) ) )
83
+ . unwrap_or ( 0 ) ;
78
84
79
- let no_content_bytes = vec ! [ ] ;
80
- let inscription_content_bytes = inscription. body ( ) . unwrap_or ( & no_content_bytes) ;
85
+ let no_content_bytes = vec ! [ ] ;
86
+ let inscription_content_bytes = inscription. body ( ) . unwrap_or ( & no_content_bytes) ;
81
87
82
- let inscriber_address = if let Ok ( authors) = Address :: from_script (
83
- & tx. vout [ 0 ] . script_pub_key . script ( ) . unwrap ( ) ,
84
- bitcoincore_rpc:: bitcoin:: Network :: Bitcoin ,
85
- ) {
86
- Some ( authors. to_string ( ) )
87
- } else {
88
- None
89
- } ;
88
+ let inscriber_address = if let Ok ( authors) = Address :: from_script (
89
+ & tx. vout [ 0 ] . script_pub_key . script ( ) . unwrap ( ) ,
90
+ bitcoincore_rpc:: bitcoin:: Network :: Bitcoin ,
91
+ ) {
92
+ Some ( authors. to_string ( ) )
93
+ } else {
94
+ None
95
+ } ;
90
96
91
- let payload = OrdinalInscriptionRevealData {
92
- content_type : inscription. content_type ( ) . unwrap_or ( "unknown" ) . to_string ( ) ,
93
- content_bytes : format ! ( "0x{}" , hex:: encode( & inscription_content_bytes) ) ,
94
- content_length : inscription_content_bytes. len ( ) ,
95
- inscription_id : inscription_id. to_string ( ) ,
96
- inscriber_address,
97
- inscription_output_value,
98
- inscription_fee : 0 ,
99
- inscription_input_index : input_index,
100
- inscription_number : 0 ,
101
- ordinal_number : 0 ,
102
- ordinal_block_height : 0 ,
103
- ordinal_offset : 0 ,
104
- transfers_pre_inscription : 0 ,
105
- satpoint_post_inscription : format ! ( "{}:0:0" , tx. txid. clone( ) ) ,
106
- } ;
97
+ let payload = OrdinalInscriptionRevealData {
98
+ content_type : inscription. content_type ( ) . unwrap_or ( "unknown" ) . to_string ( ) ,
99
+ content_bytes : format ! ( "0x{}" , hex:: encode( & inscription_content_bytes) ) ,
100
+ content_length : inscription_content_bytes. len ( ) ,
101
+ inscription_id : inscription_id. to_string ( ) ,
102
+ inscriber_address,
103
+ inscription_output_value,
104
+ inscription_fee : 0 ,
105
+ inscription_input_index : input_index,
106
+ inscription_number : 0 ,
107
+ ordinal_number : 0 ,
108
+ ordinal_block_height : 0 ,
109
+ ordinal_offset : 0 ,
110
+ transfers_pre_inscription : 0 ,
111
+ satpoint_post_inscription : format ! ( "{}:0:0" , tx. txid. clone( ) ) ,
112
+ } ;
107
113
108
- if input_index == 0 {
109
- operations. push ( OrdinalOperation :: InscriptionRevealed ( payload) ) ;
110
- } else {
111
- operations. push ( OrdinalOperation :: CursedInscriptionRevealed ( payload) ) ;
112
- }
114
+ if input_index == 0 {
115
+ operations. push ( OrdinalOperation :: InscriptionRevealed ( payload) ) ;
116
+ } else {
117
+ operations. push ( OrdinalOperation :: CursedInscriptionRevealed ( payload) ) ;
113
118
}
114
119
}
115
120
}
0 commit comments