File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,30 @@ impl AsyncClient {
79
79
}
80
80
}
81
81
82
+ /// Get a [`Txid`] of a transaction given its index in a block with a given hash.
83
+ pub async fn get_txid_at_block_index (
84
+ & self ,
85
+ block_hash : & BlockHash ,
86
+ index : usize ,
87
+ ) -> Result < Option < Txid > , Error > {
88
+ let resp = self
89
+ . client
90
+ . get ( & format ! (
91
+ "{}/block/{}/txid/{}" ,
92
+ self . url,
93
+ block_hash. to_string( ) ,
94
+ index
95
+ ) )
96
+ . send ( )
97
+ . await ?;
98
+
99
+ if let StatusCode :: NOT_FOUND = resp. status ( ) {
100
+ return Ok ( None ) ;
101
+ }
102
+
103
+ Ok ( Some ( deserialize ( & Vec :: from_hex ( & resp. text ( ) . await ?) ?) ?) )
104
+ }
105
+
82
106
/// Get the status of a [`Transaction`] given its [`Txid`].
83
107
pub async fn get_tx_status ( & self , txid : & Txid ) -> Result < Option < TxStatus > , Error > {
84
108
let resp = self
Original file line number Diff line number Diff line change @@ -84,6 +84,34 @@ impl BlockingClient {
84
84
}
85
85
}
86
86
87
+ /// Get a [`Txid`] of a transaction given its index in a block with a given hash.
88
+ pub fn get_txid_at_block_index (
89
+ & self ,
90
+ block_hash : & BlockHash ,
91
+ index : usize ,
92
+ ) -> Result < Option < Txid > , Error > {
93
+ let resp = self
94
+ . agent
95
+ . get ( & format ! (
96
+ "{}/block/{}/txid/{}" ,
97
+ self . url,
98
+ block_hash. to_string( ) ,
99
+ index
100
+ ) )
101
+ . call ( ) ;
102
+
103
+ match resp {
104
+ Ok ( resp) => Ok ( Some ( deserialize ( & Vec :: from_hex ( & resp. into_string ( ) ?) ?) ?) ) ,
105
+ Err ( ureq:: Error :: Status ( code, _) ) => {
106
+ if is_status_not_found ( code) {
107
+ return Ok ( None ) ;
108
+ }
109
+ Err ( Error :: HttpResponse ( code) )
110
+ }
111
+ Err ( e) => Err ( Error :: Ureq ( e) ) ,
112
+ }
113
+ }
114
+
87
115
/// Get the status of a [`Transaction`] given its [`Txid`].
88
116
pub fn get_tx_status ( & self , txid : & Txid ) -> Result < Option < TxStatus > , Error > {
89
117
let resp = self
You can’t perform that action at this time.
0 commit comments