@@ -157,19 +157,6 @@ pub(crate) struct TransactionInfo {
157
157
pub ( crate ) starting_timestamp : u128 ,
158
158
}
159
159
160
- pub ( crate ) struct InscriptionInfo {
161
- pub ( crate ) children : Vec < InscriptionId > ,
162
- pub ( crate ) entry : InscriptionEntry ,
163
- pub ( crate ) parents : Vec < InscriptionId > ,
164
- pub ( crate ) output : Option < TxOut > ,
165
- pub ( crate ) satpoint : SatPoint ,
166
- pub ( crate ) inscription : Inscription ,
167
- pub ( crate ) previous : Option < InscriptionId > ,
168
- pub ( crate ) next : Option < InscriptionId > ,
169
- pub ( crate ) rune : Option < SpacedRune > ,
170
- pub ( crate ) charms : u16 ,
171
- }
172
-
173
160
pub ( crate ) trait BitcoinCoreRpcResultExt < T > {
174
161
fn into_option ( self ) -> Result < Option < T > > ;
175
162
}
@@ -1801,15 +1788,11 @@ impl Index {
1801
1788
)
1802
1789
}
1803
1790
1804
- pub fn inscription_info_benchmark ( index : & Index , inscription_number : i32 ) {
1805
- Self :: inscription_info ( index, query:: Inscription :: Number ( inscription_number) ) . unwrap ( ) ;
1806
- }
1807
-
1808
1791
pub ( crate ) fn inscription_info (
1809
- index : & Index ,
1792
+ & self ,
1810
1793
query : query:: Inscription ,
1811
- ) -> Result < Option < InscriptionInfo > > {
1812
- let rtx = index . database . begin_read ( ) ?;
1794
+ ) -> Result < Option < ( api :: Inscription , Option < TxOut > , Inscription ) > > {
1795
+ let rtx = self . database . begin_read ( ) ?;
1813
1796
1814
1797
let sequence_number = match query {
1815
1798
query:: Inscription :: Id ( id) => rtx
@@ -1842,7 +1825,7 @@ impl Index {
1842
1825
. value ( ) ,
1843
1826
) ;
1844
1827
1845
- let Some ( transaction) = index . get_transaction ( entry. id . txid ) ? else {
1828
+ let Some ( transaction) = self . get_transaction ( entry. id . txid ) ? else {
1846
1829
return Ok ( None ) ;
1847
1830
} ;
1848
1831
@@ -1866,7 +1849,7 @@ impl Index {
1866
1849
{
1867
1850
None
1868
1851
} else {
1869
- let Some ( transaction) = index . get_transaction ( satpoint. outpoint . txid ) ? else {
1852
+ let Some ( transaction) = self . get_transaction ( satpoint. outpoint . txid ) ? else {
1870
1853
return Ok ( None ) ;
1871
1854
} ;
1872
1855
@@ -1943,18 +1926,50 @@ impl Index {
1943
1926
Charm :: Lost . set ( & mut charms) ;
1944
1927
}
1945
1928
1946
- Ok ( Some ( InscriptionInfo {
1947
- children,
1948
- entry,
1949
- parents,
1929
+ let effective_mime_type = if let Some ( delegate_id) = inscription. delegate ( ) {
1930
+ let delegate_result = self . get_inscription_by_id ( delegate_id) ;
1931
+ if let Ok ( Some ( delegate) ) = delegate_result {
1932
+ delegate. content_type ( ) . map ( str:: to_string)
1933
+ } else {
1934
+ inscription. content_type ( ) . map ( str:: to_string)
1935
+ }
1936
+ } else {
1937
+ inscription. content_type ( ) . map ( str:: to_string)
1938
+ } ;
1939
+
1940
+ Ok ( Some ( (
1941
+ api:: Inscription {
1942
+ address : output
1943
+ . as_ref ( )
1944
+ . and_then ( |o| {
1945
+ self
1946
+ . settings
1947
+ . chain ( )
1948
+ . address_from_script ( & o. script_pubkey )
1949
+ . ok ( )
1950
+ } )
1951
+ . map ( |address| address. to_string ( ) ) ,
1952
+ charms : Charm :: charms ( charms) ,
1953
+ children,
1954
+ content_length : inscription. content_length ( ) ,
1955
+ content_type : inscription. content_type ( ) . map ( |s| s. to_string ( ) ) ,
1956
+ effective_content_type : effective_mime_type,
1957
+ fee : entry. fee ,
1958
+ height : entry. height ,
1959
+ id : entry. id ,
1960
+ next,
1961
+ number : entry. inscription_number ,
1962
+ parents,
1963
+ previous,
1964
+ rune,
1965
+ sat : entry. sat ,
1966
+ satpoint,
1967
+ timestamp : timestamp ( entry. timestamp . into ( ) ) . timestamp ( ) ,
1968
+ value : output. as_ref ( ) . map ( |o| o. value ) ,
1969
+ } ,
1950
1970
output,
1951
- satpoint,
1952
1971
inscription,
1953
- previous,
1954
- next,
1955
- rune,
1956
- charms,
1957
- } ) )
1972
+ ) ) )
1958
1973
}
1959
1974
1960
1975
pub ( crate ) fn get_inscription_entry (
@@ -2104,6 +2119,61 @@ impl Index {
2104
2119
. collect ( ) ,
2105
2120
)
2106
2121
}
2122
+
2123
+ pub ( crate ) fn get_output_info ( & self , outpoint : OutPoint ) -> Result < Option < ( api:: Output , TxOut ) > > {
2124
+ let sat_ranges = self . list ( outpoint) ?;
2125
+
2126
+ let indexed;
2127
+
2128
+ let txout = if outpoint == OutPoint :: null ( ) || outpoint == unbound_outpoint ( ) {
2129
+ let mut value = 0 ;
2130
+
2131
+ if let Some ( ranges) = & sat_ranges {
2132
+ for ( start, end) in ranges {
2133
+ value += end - start;
2134
+ }
2135
+ }
2136
+
2137
+ indexed = true ;
2138
+
2139
+ TxOut {
2140
+ value,
2141
+ script_pubkey : ScriptBuf :: new ( ) ,
2142
+ }
2143
+ } else {
2144
+ indexed = self . contains_output ( & outpoint) ?;
2145
+
2146
+ let Some ( tx) = self . get_transaction ( outpoint. txid ) ? else {
2147
+ return Ok ( None ) ;
2148
+ } ;
2149
+
2150
+ let Some ( output) = tx. output . into_iter ( ) . nth ( outpoint. vout as usize ) else {
2151
+ return Ok ( None ) ;
2152
+ } ;
2153
+
2154
+ output
2155
+ } ;
2156
+
2157
+ let inscriptions = self . get_inscriptions_on_output ( outpoint) ?;
2158
+
2159
+ let runes = self . get_rune_balances_for_outpoint ( outpoint) ?;
2160
+
2161
+ let spent = self . is_output_spent ( outpoint) ?;
2162
+
2163
+ Ok ( Some ( (
2164
+ api:: Output :: new (
2165
+ self . settings . chain ( ) ,
2166
+ inscriptions,
2167
+ outpoint,
2168
+ txout. clone ( ) ,
2169
+ indexed,
2170
+ runes,
2171
+ sat_ranges,
2172
+ spent,
2173
+ ) ,
2174
+ txout,
2175
+ ) ) )
2176
+ }
2107
2177
}
2108
2178
2109
2179
#[ cfg( test) ]
0 commit comments