Commit fdeec878 authored by zeroleak's avatar zeroleak
Browse files

/rest/pools: add tx0FeeTarget

parent a7a51a15
......@@ -7,7 +7,10 @@ Required headers:
## Pools
### List pools: ```GET /rest/pools```
### List pools: ```GET /rest/pools[?tx0FeeTarget=BLOCKS_24]```
Parameters:
* (optional) tx0FeeTarget: tx0 fee target for tx0BalanceMin computation
Response:
```
{
......
......@@ -10,22 +10,21 @@ import com.samourai.whirlpool.client.whirlpool.beans.Pool;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
public class PoolsController extends AbstractRestController {
@Autowired private CliWalletService cliWalletService;
@RequestMapping(value = CliApiEndpoint.REST_POOLS, method = RequestMethod.GET)
public ApiPoolsResponse pools(@RequestHeader HttpHeaders headers) throws Exception {
public ApiPoolsResponse pools(
@RequestParam(value = "tx0FeeTarget", defaultValue = "BLOCKS_24")
Tx0FeeTarget tx0FeeTarget, // Tx0FeeTarget.MIN
@RequestHeader HttpHeaders headers)
throws Exception {
checkHeaders(headers);
WhirlpoolWallet whirlpoolWallet = cliWalletService.getSessionWallet();
Collection<Pool> pools = whirlpoolWallet.getPools(false);
Tx0FeeTarget feeTarget = Tx0FeeTarget.DEFAULT;
int feePremix = whirlpoolWallet.getFeePremix();
return new ApiPoolsResponse(pools, feeTarget, feePremix, whirlpoolWallet);
return new ApiPoolsResponse(pools, tx0FeeTarget, whirlpoolWallet);
}
}
......@@ -11,19 +11,16 @@ public class ApiPoolsResponse {
private Collection<ApiPool> pools;
public ApiPoolsResponse(
Collection<Pool> pools,
Tx0FeeTarget feeTarget,
int feePremix,
WhirlpoolWallet whirlpoolWallet) {
Collection<Pool> pools, Tx0FeeTarget feeTarget, WhirlpoolWallet whirlpoolWallet) {
this.pools =
pools
.stream()
.map(pool -> computeApiPool(pool, feeTarget, feePremix, whirlpoolWallet))
.map(pool -> computeApiPool(pool, feeTarget, whirlpoolWallet))
.collect(Collectors.toList());
}
private ApiPool computeApiPool(
Pool pool, Tx0FeeTarget feeTarget, int feePremix, WhirlpoolWallet whirlpoolWallet) {
Pool pool, Tx0FeeTarget feeTarget, WhirlpoolWallet whirlpoolWallet) {
long tx0BalanceMin = whirlpoolWallet.computeTx0SpendFromBalanceMin(pool, feeTarget, 1);
return new ApiPool(pool, tx0BalanceMin);
}
......
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