Commit f91e6950 authored by zeroleak's avatar zeroleak
Browse files

ApiTx0PreviewRequest: add .mixFeeTarget + rename .feeTarget -> tx0FeeTarget

parent 94695c98
......@@ -13,9 +13,10 @@ It can be used by whirlpool-gui or any REST client.
## Pools
### List pools: ```GET /rest/pools[?tx0FeeTarget=BLOCKS_24]```
### List pools: ```GET /rest/pools[?tx0FeeTarget=BLOCKS_24&?mixFeeTarget=BLOCKS_24]```
Parameters:
* (optional) tx0FeeTarget: tx0 fee target for tx0BalanceMin computation
* (optional) mixFeeTarget: mix fee target for tx0BalanceMin computation
Response:
```
......@@ -138,14 +139,16 @@ Response:
### Tx0 preview ```POST /rest/tx0/preview```
Payload:
* inputs {hash, index} (mandatory): utxos to spend for tx0
* feeTarget (mandatory): fee target for tx0
* tx0FeeTarget (mandatory): fee target for tx0
* mixFeeTarget (mandatory): fee target for mix
* poolId (optional): override utxo's poolId
```
{
inputs: [
{hash:"c7f456d5ff002faa89dadec01cc5eb98bb00fdefb92031890324ec127f9d1541", index:5}
],
feeTarget: "BLOCKS_4",
tx0FeeTarget: "BLOCKS_4",
mixFeeTarget: "BLOCKS_6",
poolId: "0.01btc"
}
```
......@@ -161,14 +164,16 @@ Response:
### Tx0 ```POST /rest/tx0```
Payload:
* inputs {hash, index} (mandatory): utxos to spend for tx0
* feeTarget (mandatory): fee target for tx0
* tx0FeeTarget (mandatory): fee target for tx0
* mixFeeTarget (mandatory): fee target for mix
* poolId (optional): override utxo's poolId
```
{
inputs: [
{hash:"c7f456d5ff002faa89dadec01cc5eb98bb00fdefb92031890324ec127f9d1541", index:5}
],
feeTarget: "BLOCKS_4",
tx0FeeTarget: "BLOCKS_4",
mixFeeTarget: "BLOCKS_6",
poolId: "0.01btc"
}
```
......
......@@ -22,11 +22,13 @@ public class PoolsController extends AbstractRestController {
public ApiPoolsResponse pools(
@RequestParam(value = "tx0FeeTarget", defaultValue = "BLOCKS_24")
Tx0FeeTarget tx0FeeTarget, // Tx0FeeTarget.MIN
@RequestParam(value = "mixFeeTarget", defaultValue = "BLOCKS_24")
Tx0FeeTarget mixFeeTarget, // Tx0FeeTarget.MIN
@RequestHeader HttpHeaders headers)
throws Exception {
checkHeaders(headers);
WhirlpoolWallet whirlpoolWallet = cliWalletService.getSessionWallet();
Collection<Pool> pools = whirlpoolWallet.getPoolSupplier().getPools();
return new ApiPoolsResponse(pools, tx0FeeTarget, whirlpoolWallet);
return new ApiPoolsResponse(pools, tx0FeeTarget, mixFeeTarget, whirlpoolWallet);
}
}
......@@ -85,7 +85,8 @@ public class UtxoController extends AbstractRestController {
// tx0 preview
Tx0Config tx0Config = whirlpoolWallet.getTx0Config();
Tx0Preview tx0Preview =
whirlpoolWallet.tx0Preview(whirlpoolUtxos, pool, tx0Config, payload.feeTarget);
whirlpoolWallet.tx0Preview(
whirlpoolUtxos, pool, tx0Config, payload.tx0FeeTarget, payload.mixFeeTarget);
return new ApiTx0PreviewResponse(tx0Preview);
}
......@@ -106,7 +107,9 @@ public class UtxoController extends AbstractRestController {
// tx0
Tx0Config tx0Config = whirlpoolWallet.getTx0Config();
Tx0 tx0 = whirlpoolWallet.tx0(whirlpoolUtxos, pool, payload.feeTarget, tx0Config);
Tx0 tx0 =
whirlpoolWallet.tx0(
whirlpoolUtxos, pool, payload.tx0FeeTarget, payload.mixFeeTarget, tx0Config);
return new ApiTx0Response(tx0);
}
......
......@@ -11,17 +11,24 @@ public class ApiPoolsResponse {
private Collection<ApiPool> pools;
public ApiPoolsResponse(
Collection<Pool> pools, Tx0FeeTarget feeTarget, WhirlpoolWallet whirlpoolWallet) {
Collection<Pool> pools,
Tx0FeeTarget tx0FeeTarget,
Tx0FeeTarget mixFeeTarget,
WhirlpoolWallet whirlpoolWallet) {
this.pools =
pools
.stream()
.map(pool -> computeApiPool(pool, feeTarget, whirlpoolWallet))
.map(pool -> computeApiPool(pool, tx0FeeTarget, mixFeeTarget, whirlpoolWallet))
.collect(Collectors.toList());
}
private ApiPool computeApiPool(
Pool pool, Tx0FeeTarget feeTarget, WhirlpoolWallet whirlpoolWallet) {
long tx0BalanceMin = whirlpoolWallet.computeTx0SpendFromBalanceMin(pool, feeTarget);
Pool pool,
Tx0FeeTarget tx0FeeTarget,
Tx0FeeTarget mixFeeTarget,
WhirlpoolWallet whirlpoolWallet) {
long tx0BalanceMin =
whirlpoolWallet.computeTx0SpendFromBalanceMin(pool, tx0FeeTarget, mixFeeTarget);
return new ApiPool(pool, tx0BalanceMin);
}
......
......@@ -7,7 +7,8 @@ import javax.validation.constraints.NotNull;
public class ApiTx0PreviewRequest {
@NotEmpty public ApiUtxoRef[] inputs;
@NotNull public Tx0FeeTarget feeTarget;
@NotNull public Tx0FeeTarget tx0FeeTarget;
@NotNull public Tx0FeeTarget mixFeeTarget;
@NotEmpty public String poolId;
public ApiTx0PreviewRequest() {}
......
......@@ -3,7 +3,9 @@ package com.samourai.whirlpool.cli.api.protocol.rest;
import com.samourai.whirlpool.client.tx0.Tx0Preview;
public class ApiTx0PreviewResponse {
private long minerFee;
private long tx0MinerFee;
private long mixMinerFee;
private long premixMinerFee;
private long feeValue;
private long feeChange;
private long premixValue;
......@@ -12,7 +14,9 @@ public class ApiTx0PreviewResponse {
private int feeDiscountPercent;
public ApiTx0PreviewResponse(Tx0Preview tx0Preview) {
this.minerFee = tx0Preview.getMinerFee();
this.tx0MinerFee = tx0Preview.getTx0MinerFee();
this.mixMinerFee = tx0Preview.getMixMinerFee();
this.premixMinerFee = tx0Preview.getPremixMinerFee();
this.feeValue = tx0Preview.getFeeValue();
this.feeChange = tx0Preview.getFeeChange();
this.premixValue = tx0Preview.getPremixValue();
......@@ -21,8 +25,16 @@ public class ApiTx0PreviewResponse {
this.feeDiscountPercent = tx0Preview.getFeeDiscountPercent();
}
public long getMinerFee() {
return minerFee;
public long getTx0MinerFee() {
return tx0MinerFee;
}
public long getMixMinerFee() {
return mixMinerFee;
}
public long getPremixMinerFee() {
return premixMinerFee;
}
public long getFeeValue() {
......
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