Commit 868db087 authored by zeroleak's avatar zeroleak
Browse files

add tx0Preview

parent a09bb923
......@@ -2,13 +2,11 @@ package com.samourai.whirlpool.cli.api.controllers.utxo;
import com.samourai.whirlpool.cli.api.controllers.AbstractRestController;
import com.samourai.whirlpool.cli.api.protocol.CliApiEndpoint;
import com.samourai.whirlpool.cli.api.protocol.rest.ApiTx0Request;
import com.samourai.whirlpool.cli.api.protocol.rest.ApiTx0Response;
import com.samourai.whirlpool.cli.api.protocol.rest.ApiUtxoConfigureRequest;
import com.samourai.whirlpool.cli.api.protocol.rest.*;
import com.samourai.whirlpool.cli.services.CliWalletService;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.tx0.Tx0;
import com.samourai.whirlpool.client.tx0.Tx0Config;
import com.samourai.whirlpool.client.tx0.Tx0Preview;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo;
import com.samourai.whirlpool.client.whirlpool.beans.Pool;
......@@ -52,6 +50,31 @@ public class UtxoController extends AbstractRestController {
return whirlpoolUtxo;
}
@RequestMapping(value = CliApiEndpoint.REST_UTXO_TX0_PREVIEW, method = RequestMethod.POST)
public ApiTx0PreviewResponse tx0Preview(
@RequestHeader HttpHeaders headers,
@PathVariable("hash") String utxoHash,
@PathVariable("index") int utxoIndex,
@Valid @RequestBody ApiTx0PreviewRequest payload)
throws Exception {
checkHeaders(headers);
// find utxo
WhirlpoolUtxo whirlpoolUtxo = findUtxo(utxoHash, utxoIndex);
WhirlpoolWallet whirlpoolWallet = cliWalletService.getSessionWallet();
Pool pool = whirlpoolWallet.findPoolById(payload.poolId);
if (pool == null) {
throw new NotifiableException("poolId is not valid");
}
// tx0 preview
Tx0Preview tx0Preview =
whirlpoolWallet.tx0Preview(
Lists.of(whirlpoolUtxo), pool, whirlpoolWallet.getTx0Config(), payload.feeTarget);
return new ApiTx0PreviewResponse(tx0Preview);
}
@RequestMapping(value = CliApiEndpoint.REST_UTXO_TX0, method = RequestMethod.POST)
public ApiTx0Response tx0(
@RequestHeader HttpHeaders headers,
......@@ -70,16 +93,16 @@ public class UtxoController extends AbstractRestController {
whirlpoolWallet.setMixsTarget(whirlpoolUtxo, payload.mixsTarget);
}
Tx0Config tx0Config = whirlpoolWallet.getTx0Config();
Pool pool = whirlpoolWallet.findPoolById(payload.poolId);
if (pool == null) {
throw new NotifiableException("poolId is not valid");
}
// tx0
Tx0 tx0 = whirlpoolWallet.tx0(Lists.of(whirlpoolUtxo), pool, tx0Config, payload.feeTarget);
return new ApiTx0Response(tx0.getTx().getHashAsString());
Tx0 tx0 =
whirlpoolWallet.tx0(
Lists.of(whirlpoolUtxo), pool, whirlpoolWallet.getTx0Config(), payload.feeTarget);
return new ApiTx0Response(tx0);
}
@RequestMapping(value = CliApiEndpoint.REST_UTXO_STARTMIX, method = RequestMethod.POST)
......
......@@ -20,6 +20,8 @@ public class CliApiEndpoint {
public static final String REST_UTXOS = REST_PREFIX + "utxos";
public static final String REST_UTXO_CONFIGURE = REST_PREFIX + "utxos/{hash}:{index}";
public static final String REST_UTXO_TX0 = REST_PREFIX + "utxos/{hash}:{index}/tx0";
public static final String REST_UTXO_TX0_PREVIEW =
REST_PREFIX + "utxos/{hash}:{index}/tx0Preview";
public static final String REST_UTXO_STARTMIX = REST_PREFIX + "utxos/{hash}:{index}/startMix";
public static final String REST_UTXO_STOPMIX = REST_PREFIX + "utxos/{hash}:{index}/stopMix";
......@@ -37,6 +39,7 @@ public class CliApiEndpoint {
REST_MIX_STOP,
REST_UTXOS,
REST_UTXO_CONFIGURE,
REST_UTXO_TX0_PREVIEW,
REST_UTXO_TX0,
REST_UTXO_STARTMIX,
REST_UTXO_STOPMIX
......
package com.samourai.whirlpool.cli.api.protocol.rest;
import com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget;
import javax.validation.constraints.NotNull;
public class ApiTx0PreviewRequest {
@NotNull public Tx0FeeTarget feeTarget;
@NotNull public String poolId;
public ApiTx0PreviewRequest() {}
}
package com.samourai.whirlpool.cli.api.protocol.rest;
import com.samourai.whirlpool.client.tx0.Tx0Preview;
public class ApiTx0PreviewResponse {
private long minerFee;
private long feeValue;
private long feeChange;
private long premixValue;
private long changeValue;
private int nbPremix;
public ApiTx0PreviewResponse(Tx0Preview tx0Preview) {
this.minerFee = tx0Preview.getMinerFee();
this.feeValue = tx0Preview.getFeeValue();
this.feeChange = tx0Preview.getFeeChange();
this.premixValue = tx0Preview.getPremixValue();
this.changeValue = tx0Preview.getChangeValue();
this.nbPremix = tx0Preview.getNbPremix();
}
public long getMinerFee() {
return minerFee;
}
public long getFeeValue() {
return feeValue;
}
public long getFeeChange() {
return feeChange;
}
public long getPremixValue() {
return premixValue;
}
public long getChangeValue() {
return changeValue;
}
public int getNbPremix() {
return nbPremix;
}
}
package com.samourai.whirlpool.cli.api.protocol.rest;
import com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget;
import javax.validation.constraints.NotNull;
public class ApiTx0Request {
@NotNull public Tx0FeeTarget feeTarget;
public String poolId;
public class ApiTx0Request extends ApiTx0PreviewRequest {
public Integer mixsTarget;
public ApiTx0Request() {}
......
package com.samourai.whirlpool.cli.api.protocol.rest;
public class ApiTx0Response {
import com.samourai.whirlpool.client.tx0.Tx0;
public class ApiTx0Response extends ApiTx0PreviewResponse {
private String txid;
public ApiTx0Response(String txid) {
this.txid = txid;
public ApiTx0Response(Tx0 tx0) {
super(tx0);
this.txid = tx0.getTx().getHashAsString();
}
public String getTxid() {
......
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