Skip to content

Commit 3e32958

Browse files
author
kushal256
authored
Merge pull request #3 from bitsoex/v1
V1 changes
2 parents 2b3bee3 + 59fd601 commit 3e32958

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

bitgo-java-api/src/main/java/com/bitso/bitgo/v1/BitGoClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface BitGoClient {
1919
Optional<Map<String, Object>> getCurrentUserProfile() throws IOException;
2020

2121

22-
WalletTransactionResponse listWalletTransactions(String walletId, long skip, int limit) throws IOException;
22+
WalletTransactionResponse listWalletTransactions(String walletId, long skip, int limit, Long minHeight, Long maxHeight, Integer minConfirms) throws IOException;
2323

2424
WalletAddressResponse listWalletAddress(String walletId, long skip, int limit) throws IOException;
2525
}

bitgo-java-api/src/main/java/com/bitso/bitgo/v1/BitGoClientImpl.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.HashMap;
1515
import java.util.Map;
1616
import java.util.Optional;
17+
import java.util.concurrent.TimeUnit;
1718

1819
/**
1920
* Implementation of the BitGo client.
@@ -74,7 +75,7 @@ public Optional<Map<String, Object>> getCurrentUserProfile() throws IOException
7475
* @throws IOException
7576
*/
7677
@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 {
7879
if (limit > 250) limit = 250;
7980
if (limit < 0) limit = 0;
8081

@@ -83,8 +84,32 @@ public WalletTransactionResponse listWalletTransactions(String walletId, long sk
8384
Map<String, String> reqPropMap = new HashMap<>();
8485
reqPropMap.put("skip", Long.toString(skip));
8586
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+
}
88113

89114
final WalletTransactionResponse resp = SerializationUtil.mapper.readValue(conn.getInputStream(), WalletTransactionResponse.class);
90115
log.trace("listWalletTransactions response: {}", resp);

bitgo-java-api/src/test/java/com/bitso/bitgo/util/TestClientV1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void listWalletAddress() throws IOException {
4444

4545
@Test
4646
public void listWalletTransfers() throws IOException {
47-
final WalletTransactionResponse resp = client.listWalletTransactions(WALLET_ID, 0, 250);
47+
final WalletTransactionResponse resp = client.listWalletTransactions(WALLET_ID, 0, 250, null, null, null);
4848
System.out.println("list.size() = " + resp.getTransactions().size());
4949
System.out.println("list = " + resp.getTransactions());
5050
assertTrue(resp.getTransactions().size() > 0);

0 commit comments

Comments
 (0)