@@ -11,6 +11,7 @@ use std::{collections::BTreeMap, env};
11
11
12
12
pub struct Cardano {
13
13
api : BlockfrostAPI ,
14
+ client : reqwest:: Client ,
14
15
network : Network ,
15
16
network_prefix : String ,
16
17
project_id : String ,
@@ -43,6 +44,7 @@ impl Cardano {
43
44
let api = BlockfrostAPI :: new ( project_id. as_str ( ) , Default :: default ( ) ) ;
44
45
Cardano {
45
46
api,
47
+ client : reqwest:: Client :: new ( ) ,
46
48
network : if project_id. starts_with ( MAINNET_PREFIX ) {
47
49
Network :: Mainnet
48
50
} else {
@@ -140,36 +142,39 @@ impl Cardano {
140
142
} )
141
143
. collect :: < Vec < _ > > ( ) ;
142
144
143
- let client = reqwest:: Client :: new ( ) ;
144
-
145
145
let mut txs: Vec < Tx > = vec ! [ ] ;
146
146
for tx_hash in history {
147
- // NOTE: Not part of the Rust SDK somehow...
148
- let response = client
149
- . get ( & format ! (
150
- "https://cardano-{}.blockfrost.io/api/v0/txs/{}/cbor" ,
151
- self . network_prefix, tx_hash
152
- ) )
153
- . header ( "Accept" , "application/json" )
154
- . header ( "project_id" , self . project_id . as_str ( ) )
155
- . send ( )
156
- . await
157
- . unwrap ( ) ;
158
- match response. status ( ) {
159
- reqwest:: StatusCode :: OK => {
160
- let TxByHash { cbor } = response. json :: < TxByHash > ( ) . await . unwrap ( ) ;
161
- let tx = cbor:: decode ( & hex:: decode ( cbor) . unwrap ( ) ) . unwrap ( ) ;
162
- txs. push ( tx) ;
163
- }
164
- status => {
165
- panic ! ( "unexpected response status from Blockfrost: {}" , status) ;
166
- }
167
- } ;
147
+ if let Some ( tx) = self . transaction_by_hash ( & tx_hash) . await {
148
+ txs. push ( tx)
149
+ }
168
150
}
169
-
170
151
txs
171
152
}
172
153
154
+ pub async fn transaction_by_hash ( & self , tx_hash : & str ) -> Option < Tx > {
155
+ // NOTE: Not part of the Rust SDK somehow...
156
+ let response = self
157
+ . client
158
+ . get ( & format ! (
159
+ "https://cardano-{}.blockfrost.io/api/v0/txs/{}/cbor" ,
160
+ self . network_prefix, tx_hash
161
+ ) )
162
+ . header ( "Accept" , "application/json" )
163
+ . header ( "project_id" , self . project_id . as_str ( ) )
164
+ . send ( )
165
+ . await
166
+ . unwrap ( ) ;
167
+
168
+ match response. status ( ) {
169
+ reqwest:: StatusCode :: OK => {
170
+ let TxByHash { cbor } = response. json :: < TxByHash > ( ) . await . unwrap ( ) ;
171
+ let tx = cbor:: decode ( & hex:: decode ( cbor) . unwrap ( ) ) . unwrap ( ) ;
172
+ Some ( tx)
173
+ }
174
+ _ => None ,
175
+ }
176
+ }
177
+
173
178
pub async fn resolve ( & self , input : & TransactionInput ) -> Option < PostAlonzoTransactionOutput > {
174
179
let utxo = self
175
180
. api
0 commit comments