Skip to content

Commit

Permalink
Add support endpoint for balance of multiple addresses at a given hei…
Browse files Browse the repository at this point in the history
…ght (#74)
  • Loading branch information
suadzh authored Mar 19, 2021
1 parent 3f78472 commit aaa7ec9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
47 changes: 47 additions & 0 deletions src/main/java/com/wavesplatform/wavesj/Balance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.wavesplatform.wavesj;

import com.fasterxml.jackson.annotation.JsonProperty;
import im.mak.waves.transactions.account.Address;

import java.util.Objects;

public class Balance {
private final Address address;
private final long balance;

public Balance(@JsonProperty("id") Address address,
@JsonProperty("balance") long balance) {
this.address = Common.notNull(address, "Id");
this.balance = balance;
}

public Address getAddress() {
return address;
}

public long getBalance() {
return balance;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Balance)) return false;
Balance balance1 = (Balance) o;
return getBalance() == balance1.getBalance() &&
Objects.equals(getAddress(), balance1.getAddress());
}

@Override
public int hashCode() {
return Objects.hash(getAddress(), getBalance());
}

@Override
public String toString() {
return "Balance{" +
"address=" + address +
", balance=" + balance +
'}';
}
}
13 changes: 12 additions & 1 deletion src/main/java/com/wavesplatform/wavesj/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ public long getBalance(Address address, int confirmations) throws IOException, N
.get("balance").asLong();
}

//todo getBalances(height, Address...) for several addresses at height
public List<Balance> getBalances(List<Address> addresses) throws IOException, NodeException {
RequestBuilder request = get("/addresses/balance");
addresses.forEach(address -> request.addParameter("address", address.toString()));
return asType(request, TypeRef.BALANCES);
}

public List<Balance> getBalances(List<Address> addresses, int height) throws IOException, NodeException {
RequestBuilder request = get("/addresses/balance");
addresses.forEach(address -> request.addParameter("address", address.toString()));
request.addParameter("height", String.valueOf(height));
return asType(request, TypeRef.BALANCES);
}

public BalanceDetails getBalanceDetails(Address address) throws IOException, NodeException {
return asType(get("/addresses/balance/details/" + address.toString()), TypeRef.BALANCE_DETAILS);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/wavesplatform/wavesj/json/TypeRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TypeRef {

public static final TypeReference<List<AssetDetails>> ASSETS_DETAILS = new TypeReference<List<AssetDetails>>() {};

public static final TypeReference<List<Balance>> BALANCES = new TypeReference<List<Balance>>() {};

public static final TypeReference<BalanceDetails> BALANCE_DETAILS = new TypeReference<BalanceDetails>() {};

public static final TypeReference<Block> BLOCK = new TypeReference<Block>() {};
Expand Down

0 comments on commit aaa7ec9

Please sign in to comment.