Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 047fce9

Browse files
authored
Merge pull request #5 from bitsoex/AddWalletAddressSearch
Add wallet address search
2 parents 652d4db + e1b7345 commit 047fce9

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

bitgo-java-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin:'java'
22
apply plugin:'idea'
33

44
group = 'com.bitso'
5-
version='SNAPSHOT'
5+
version='0.0.8'
66

77
repositories {
88
mavenCentral()

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,

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public class TestClientV2 {
3131

3232
public static final String WALLET_ID = System.getenv("WALLET_ID");
3333
public static final String WALLET_PASSPHRASE = System.getenv("WALLET_PASSPHRASE");
34+
public static final String WALLET_ADDRESS = System.getenv("WALLET_ADDRESS");
3435
public static final String TOKEN = System.getenv("TOKEN");
3536
private static final String COIN = System.getenv("COIN");
3637
private static final String TLTC_TEST_FAUCET_ADDRESS = "mgTbDyNGwJeewjdXmU9cRQe8WDauVqn4WK";
37-
private final BitGoClient client = new BitGoClientImpl(TOKEN, "https://localhost:3080/api/v2", true);
38+
private final BitGoClient client = new BitGoClientImpl(TOKEN, "http://localhost:3080/api/v2", true);
3839

3940

4041
@Test
@@ -67,6 +68,13 @@ public void getWallets() throws IOException {
6768
Assert.assertFalse(wallets.isEmpty());
6869
}
6970

71+
@Test
72+
public void getWalletByAddress() throws Exception {
73+
Optional<Wallet> wallet = client.getWalletByAddress(COIN, WALLET_ADDRESS);
74+
Assert.assertNotNull(wallet);
75+
Assert.assertFalse(wallet.isEmpty());
76+
}
77+
7078
@Test
7179
public void currentUserProfile() throws IOException {
7280
final Optional<Map<String, Object>> profile = client.getCurrentUserProfile();

0 commit comments

Comments
 (0)