Skip to content

Commit 79237dc

Browse files
committed
Add method and impl to search a wallet by address
1 parent 652d4db commit 79237dc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Optional<String> login(String email, String password, String otp, boolean extens
3131
*/
3232
Optional<Wallet> getWallet(String coin, String wid) throws IOException;
3333

34+
/**
35+
* Get the wallet by providing an address and currency.
36+
* See https://www.bitgo.com/api/v2/?shell#operation/v2.wallet.getwalletbyaddress
37+
*/
38+
Optional<Wallet> getWalletByAddress(String coin, String waddress) throws IOException;
39+
3440
/**
3541
* Invokes the sendmany method see https://www.bitgo.com/api/v2/?shell#send-transaction-to-many
3642
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class BitGoClientImpl implements BitGoClient {
3737
private static final String SEND_MANY_URL = "/$COIN/wallet/$WALLET/sendmany";
3838
private static final String LIST_WALLETS_URL = "/$COIN/wallet";
3939
private static final String GET_WALLET_URL = "/$COIN/wallet/";
40+
private static final String GET_WALLET_ADDRESS_URL = GET_WALLET_URL + "address/";
4041
private static final String CURRENT_USER_PROFILE_URL = "/user/me";
4142
private static final String GET_WALLET_TRANSFER_URL = "/$COIN/wallet/$WALLET/transfer/$TRANSFER";
4243
private static final String GET_WALLET_TRANSFER_SEQ_URL = "/$COIN/wallet/$WALLET/transfer/sequenceId/$SEQUENCE";
@@ -91,6 +92,17 @@ public Optional<Wallet> getWallet(String coin, String wid) throws IOException {
9192
return Optional.of(resp);
9293
}
9394

95+
@Override
96+
public Optional<Wallet> getWalletByAddress(String coin, String waddress) throws IOException {
97+
String url = baseUrl + GET_WALLET_ADDRESS_URL.replace("$COIN", coin) + waddress;
98+
99+
HttpURLConnection conn = httpGet(url);
100+
101+
final Wallet resp = SerializationUtil.mapper.readValue(conn.getInputStream(), Wallet.class);
102+
log.trace("Wallet address {} getWallet response: {}", waddress, resp);
103+
return Optional.of(resp);
104+
}
105+
94106
@Override
95107
public Optional<SendCoinsResponse> sendMany(String coin, String walletId, String walletPass,
96108
Map<String, BigDecimal> recipients,

0 commit comments

Comments
 (0)