Skip to content

Commit

Permalink
Merge pull request #5 from bitsoex/AddWalletAddressSearch
Browse files Browse the repository at this point in the history
Add wallet address search
  • Loading branch information
charlycrs authored Oct 16, 2019
2 parents 652d4db + e1b7345 commit 047fce9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bitgo-java-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin:'java'
apply plugin:'idea'

group = 'com.bitso'
version='SNAPSHOT'
version='0.0.8'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Optional<String> login(String email, String password, String otp, boolean extens
*/
Optional<Wallet> getWallet(String coin, String wid) throws IOException;

/**
* Get the wallet by providing an address and currency.
* See https://www.bitgo.com/api/v2/?shell#operation/v2.wallet.getwalletbyaddress
*/
Optional<Wallet> getWalletByAddress(String coin, String waddress) throws IOException;

/**
* Invokes the sendmany method see https://www.bitgo.com/api/v2/?shell#send-transaction-to-many
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class BitGoClientImpl implements BitGoClient {
private static final String SEND_MANY_URL = "/$COIN/wallet/$WALLET/sendmany";
private static final String LIST_WALLETS_URL = "/$COIN/wallet";
private static final String GET_WALLET_URL = "/$COIN/wallet/";
private static final String GET_WALLET_ADDRESS_URL = GET_WALLET_URL + "address/";
private static final String CURRENT_USER_PROFILE_URL = "/user/me";
private static final String GET_WALLET_TRANSFER_URL = "/$COIN/wallet/$WALLET/transfer/$TRANSFER";
private static final String GET_WALLET_TRANSFER_SEQ_URL = "/$COIN/wallet/$WALLET/transfer/sequenceId/$SEQUENCE";
Expand Down Expand Up @@ -91,6 +92,17 @@ public Optional<Wallet> getWallet(String coin, String wid) throws IOException {
return Optional.of(resp);
}

@Override
public Optional<Wallet> getWalletByAddress(String coin, String waddress) throws IOException {
String url = baseUrl + GET_WALLET_ADDRESS_URL.replace("$COIN", coin) + waddress;

HttpURLConnection conn = httpGet(url);

final Wallet resp = SerializationUtil.mapper.readValue(conn.getInputStream(), Wallet.class);
log.trace("Wallet address {} getWallet response: {}", waddress, resp);
return Optional.of(resp);
}

@Override
public Optional<SendCoinsResponse> sendMany(String coin, String walletId, String walletPass,
Map<String, BigDecimal> recipients,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public class TestClientV2 {

public static final String WALLET_ID = System.getenv("WALLET_ID");
public static final String WALLET_PASSPHRASE = System.getenv("WALLET_PASSPHRASE");
public static final String WALLET_ADDRESS = System.getenv("WALLET_ADDRESS");
public static final String TOKEN = System.getenv("TOKEN");
private static final String COIN = System.getenv("COIN");
private static final String TLTC_TEST_FAUCET_ADDRESS = "mgTbDyNGwJeewjdXmU9cRQe8WDauVqn4WK";
private final BitGoClient client = new BitGoClientImpl(TOKEN, "https://localhost:3080/api/v2", true);
private final BitGoClient client = new BitGoClientImpl(TOKEN, "http://localhost:3080/api/v2", true);


@Test
Expand Down Expand Up @@ -67,6 +68,13 @@ public void getWallets() throws IOException {
Assert.assertFalse(wallets.isEmpty());
}

@Test
public void getWalletByAddress() throws Exception {
Optional<Wallet> wallet = client.getWalletByAddress(COIN, WALLET_ADDRESS);
Assert.assertNotNull(wallet);
Assert.assertFalse(wallet.isEmpty());
}

@Test
public void currentUserProfile() throws IOException {
final Optional<Map<String, Object>> profile = client.getCurrentUserProfile();
Expand Down

0 comments on commit 047fce9

Please sign in to comment.