Commit d0dd5873 authored by zeroleak's avatar zeroleak
Browse files

API: add ApiWalletUtxosResponse.balance

parent 7f52b161
......@@ -113,6 +113,7 @@ Response:
balance: 0,
zpub: ""
},
balance: 0,
lastUpdate: 0
}
```
......
......@@ -7,13 +7,11 @@ import java.util.stream.Collectors;
public class ApiWallet {
private Collection<ApiUtxo> utxos;
private long lastUpdate;
private long balance;
private String zpub;
public ApiWallet(
Collection<WhirlpoolUtxo> whirlpoolUtxos,
long lastUpdate,
String zpub,
Comparator<WhirlpoolUtxo> comparator,
int mixsTargetMin) {
......@@ -23,7 +21,6 @@ public class ApiWallet {
.sorted(comparator)
.map(whirlpoolUtxo -> new ApiUtxo(whirlpoolUtxo, mixsTargetMin))
.collect(Collectors.toList());
this.lastUpdate = lastUpdate;
this.balance =
whirlpoolUtxos.stream().mapToLong(whirlpoolUtxo -> whirlpoolUtxo.getUtxo().value).sum();
this.zpub = zpub;
......@@ -33,10 +30,6 @@ public class ApiWallet {
return utxos;
}
public long getLastUpdate() {
return lastUpdate;
}
public long getBalance() {
return balance;
}
......
......@@ -14,6 +14,8 @@ public class ApiWalletUtxosResponse {
private ApiWallet deposit;
private ApiWallet premix;
private ApiWallet postmix;
private long balance;
private long lastUpdate;
public ApiWalletUtxosResponse(WhirlpoolWallet whirlpoolWallet) throws Exception {
Comparator<WhirlpoolUtxo> comparator =
......@@ -40,6 +42,8 @@ public class ApiWalletUtxosResponse {
this.deposit = computeApiWallet(WhirlpoolAccount.DEPOSIT, whirlpoolWallet, comparator);
this.premix = computeApiWallet(WhirlpoolAccount.PREMIX, whirlpoolWallet, comparator);
this.postmix = computeApiWallet(WhirlpoolAccount.POSTMIX, whirlpoolWallet, comparator);
this.balance = this.deposit.getBalance() + this.premix.getBalance() + this.postmix.getBalance();
this.lastUpdate = whirlpoolWallet.getUtxoSupplier().getLastUpdate();
}
private ApiWallet computeApiWallet(
......@@ -47,10 +51,9 @@ public class ApiWalletUtxosResponse {
WhirlpoolWallet whirlpoolWallet,
Comparator<WhirlpoolUtxo> comparator) {
Collection<WhirlpoolUtxo> utxos = whirlpoolWallet.getUtxoSupplier().findUtxos(account);
long lastUpdate = whirlpoolWallet.getUtxoSupplier().getLastUpdate();
String zpub = whirlpoolWallet.getWalletSupplier().getWallet(account).getZpub();
int mixsTargetMin = whirlpoolWallet.getConfig().getMixsTarget();
return new ApiWallet(utxos, lastUpdate, zpub, comparator, mixsTargetMin);
return new ApiWallet(utxos, zpub, comparator, mixsTargetMin);
}
public ApiWallet getDeposit() {
......@@ -64,4 +67,12 @@ public class ApiWalletUtxosResponse {
public ApiWallet getPostmix() {
return postmix;
}
public long getBalance() {
return balance;
}
public long getLastUpdate() {
return lastUpdate;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment