14
14
import java .util .HashMap ;
15
15
import java .util .Map ;
16
16
import java .util .Optional ;
17
+ import java .util .concurrent .TimeUnit ;
17
18
18
19
/**
19
20
* Implementation of the BitGo client.
@@ -74,7 +75,7 @@ public Optional<Map<String, Object>> getCurrentUserProfile() throws IOException
74
75
* @throws IOException
75
76
*/
76
77
@ Override
77
- public WalletTransactionResponse listWalletTransactions (String walletId , long skip , int limit ) throws IOException {
78
+ public WalletTransactionResponse listWalletTransactions (String walletId , long skip , int limit , Long minHeight , Long maxHeight , Integer minConfirms ) throws IOException {
78
79
if (limit > 250 ) limit = 250 ;
79
80
if (limit < 0 ) limit = 0 ;
80
81
@@ -83,8 +84,32 @@ public WalletTransactionResponse listWalletTransactions(String walletId, long sk
83
84
Map <String , String > reqPropMap = new HashMap <>();
84
85
reqPropMap .put ("skip" , Long .toString (skip ));
85
86
reqPropMap .put ("limit" , Integer .toString (limit ));
86
-
87
- HttpURLConnection conn = httpGet (url , reqPropMap );
87
+ if (minHeight != null ) reqPropMap .put ("minHeight" , minHeight .toString ());
88
+ if (maxHeight != null ) reqPropMap .put ("maxHeight" , maxHeight .toString ());
89
+ if (minConfirms != null ) reqPropMap .put ("minConfirms" , minConfirms .toString ());
90
+
91
+ HttpURLConnection conn = null ;
92
+
93
+ //TODO make these parameters configurable, apply to all our calls, not just this one.
94
+ int retryCounter = 0 ;
95
+ while (retryCounter < 3 ) {
96
+ conn = httpGet (url , reqPropMap );
97
+ if (conn .getResponseCode () == HttpURLConnection .HTTP_OK ) {
98
+ break ;
99
+ } else if (conn .getResponseCode () >= 500 && conn .getResponseCode () < 600 ) { //524 only?
100
+ long sleepTimeMillis = TimeUnit .SECONDS .toMillis (5 );
101
+ log .info ("Got responseCode={} with message={}, sleeping for {}ms, retryCounter={}" , conn .getResponseCode (), conn .getResponseMessage (), sleepTimeMillis , retryCounter );
102
+ try {
103
+ Thread .sleep (sleepTimeMillis );
104
+ } catch (InterruptedException e ) {
105
+ log .error ("Error" , e );
106
+ }
107
+ retryCounter ++;
108
+ } else {
109
+ //Some other exception, don't retry
110
+ break ;
111
+ }
112
+ }
88
113
89
114
final WalletTransactionResponse resp = SerializationUtil .mapper .readValue (conn .getInputStream (), WalletTransactionResponse .class );
90
115
log .trace ("listWalletTransactions response: {}" , resp );
0 commit comments