Add useCustomTxFeeRate field to TxFeeRateInfo proto wrapper

This is set from the core preferences.isUseCustomWithdrawalTxFee(),
and simplifies fee changing logic in the API.
This commit is contained in:
ghubstan 2020-12-01 17:14:08 -03:00
parent 2989f1be3f
commit faf030fbc5
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
7 changed files with 34 additions and 32 deletions

View File

@ -16,6 +16,7 @@ import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.seednode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
@ -43,8 +44,8 @@ public class BtcTxFeeRateTest extends MethodTest {
TxFeeRateInfo txFeeRateInfo = getTxFeeRate(alicedaemon);
log.debug("{} -> Fee rate with no preference: {}", testName(testInfo), txFeeRateInfo);
assertFalse(txFeeRateInfo.isUseCustomTxFeeRate());
assertTrue(txFeeRateInfo.getStdTxFeeRate() > 0);
assertEquals(-1, txFeeRateInfo.getCustomTxFeeRate());
}
@Test
@ -53,8 +54,9 @@ public class BtcTxFeeRateTest extends MethodTest {
TxFeeRateInfo txFeeRateInfo = setTxFeeRate(alicedaemon, 10);
log.debug("{} -> Fee rates with custom preference: {}", testName(testInfo), txFeeRateInfo);
assertTrue(txFeeRateInfo.getStdTxFeeRate() > 0);
assertTrue(txFeeRateInfo.isUseCustomTxFeeRate());
assertEquals(10, txFeeRateInfo.getCustomTxFeeRate());
assertTrue(txFeeRateInfo.getStdTxFeeRate() > 0);
}
@Test
@ -63,8 +65,8 @@ public class BtcTxFeeRateTest extends MethodTest {
TxFeeRateInfo txFeeRateInfo = unsetTxFeeRate(alicedaemon);
log.debug("{} -> Fee rate with no preference: {}", testName(testInfo), txFeeRateInfo);
assertFalse(txFeeRateInfo.isUseCustomTxFeeRate());
assertTrue(txFeeRateInfo.getStdTxFeeRate() > 0);
assertEquals(-1, txFeeRateInfo.getCustomTxFeeRate());
}
@AfterAll

View File

@ -71,7 +71,7 @@ import java.util.List;
import lombok.extern.slf4j.Slf4j;
import static bisq.cli.CurrencyFormat.formatTxFeeRate;
import static bisq.cli.CurrencyFormat.formatTxFeeRateInfo;
import static bisq.cli.CurrencyFormat.toSatoshis;
import static bisq.cli.NegativeNumberOptions.hasNegativeNumberOptions;
import static bisq.cli.TableFormat.*;
@ -276,7 +276,7 @@ public class CliMain {
case gettxfeerate: {
var request = GetTxFeeRateRequest.newBuilder().build();
var reply = walletsService.getTxFeeRate(request);
out.println(formatTxFeeRate(reply.getTxFeeRateInfo()));
out.println(formatTxFeeRateInfo(reply.getTxFeeRateInfo()));
return;
}
case settxfeerate: {
@ -294,13 +294,13 @@ public class CliMain {
.setTxFeeRatePreference(txFeeRate)
.build();
var reply = walletsService.setTxFeeRatePreference(request);
out.println(formatTxFeeRate(reply.getTxFeeRateInfo()));
out.println(formatTxFeeRateInfo(reply.getTxFeeRateInfo()));
return;
}
case unsettxfeerate: {
var request = UnsetTxFeeRatePreferenceRequest.newBuilder().build();
var reply = walletsService.unsetTxFeeRatePreference(request);
out.println(formatTxFeeRate(reply.getTxFeeRateInfo()));
out.println(formatTxFeeRateInfo(reply.getTxFeeRateInfo()));
return;
}
case createoffer: {

View File

@ -53,21 +53,14 @@ public class CurrencyFormat {
return BSQ_FORMAT.format(BigDecimal.valueOf(sats).divide(BSQ_SATOSHI_DIVISOR));
}
public static String formatTxFeeRate(TxFeeRateInfo txFeeRateInfo) {
String stdTxFeeRate = formatTxFeeRate(txFeeRateInfo.getStdTxFeeRate());
String customTxFeeRate = txFeeRateInfo.getCustomTxFeeRate() < 0
? formatTxFeeRate(txFeeRateInfo.getCustomTxFeeRate())
: null;
String formatString;
if (customTxFeeRate == null)
formatString = format("tx fee rate: %s sats/byte", stdTxFeeRate);
public static String formatTxFeeRateInfo(TxFeeRateInfo txFeeRateInfo) {
if (txFeeRateInfo.getUseCustomTxFeeRate())
return format("custom tx fee rate: %s sats/byte, network rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getCustomTxFeeRate()),
formatFeeSatoshis(txFeeRateInfo.getStdTxFeeRate()));
else
formatString = format("custom tx fee rate: %s sats/byte, network rate: %s sats/byte",
customTxFeeRate,
stdTxFeeRate);
return formatString;
return format("tx fee rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getStdTxFeeRate()));
}
static String formatAmountRange(long minAmount, long amount) {
@ -107,7 +100,7 @@ public class CurrencyFormat {
}
@SuppressWarnings("BigDecimalMethodWithoutRoundingCalled")
private static String formatTxFeeRate(long sats) {
private static String formatFeeSatoshis(long sats) {
return BTC_TX_FEE_FORMAT.format(BigDecimal.valueOf(sats).divide(SATOSHI_DIVISOR));
}
}

View File

@ -204,12 +204,9 @@ class CoreWalletsService {
throw new IllegalStateException("could not request fees from fee service.", e);
}
Coin stdTxFeeRate = feeService.getTxFeePerVbyte();
Coin customTxFeeRate = preferences.isUseCustomWithdrawalTxFee()
? Coin.valueOf(preferences.getWithdrawalTxFeeInVbytes())
: Coin.NEGATIVE_SATOSHI;
return new TxFeeRateInfo(stdTxFeeRate.value, customTxFeeRate.value);
return new TxFeeRateInfo(feeService.getTxFeePerVbyte().value,
preferences.getWithdrawalTxFeeInVbytes(),
preferences.isUseCustomWithdrawalTxFee());
}
TxFeeRateInfo setTxFeeRatePreference(long txFeeRate) {

View File

@ -28,10 +28,14 @@ public class TxFeeRateInfo implements Payload {
private final long stdTxFeeRate;
private final long customTxFeeRate;
private final boolean useCustomTxFeeRate;
public TxFeeRateInfo(long stdTxFeeRate, long customTxFeeRate) {
public TxFeeRateInfo(long stdTxFeeRate,
long customTxFeeRate,
boolean useCustomTxFeeRate) {
this.stdTxFeeRate = stdTxFeeRate;
this.customTxFeeRate = customTxFeeRate;
this.useCustomTxFeeRate = useCustomTxFeeRate;
}
//////////////////////////////////////////////////////////////////////////////////////
@ -43,19 +47,23 @@ public class TxFeeRateInfo implements Payload {
return bisq.proto.grpc.TxFeeRateInfo.newBuilder()
.setStdTxFeeRate(stdTxFeeRate)
.setCustomTxFeeRate(customTxFeeRate)
.setUseCustomTxFeeRate(useCustomTxFeeRate)
.build();
}
@SuppressWarnings("unused")
public static TxFeeRateInfo fromProto(bisq.proto.grpc.TxFeeRateInfo proto) {
return new TxFeeRateInfo(proto.getStdTxFeeRate(), proto.getCustomTxFeeRate());
return new TxFeeRateInfo(proto.getStdTxFeeRate(),
proto.getCustomTxFeeRate(),
proto.getUseCustomTxFeeRate());
}
@Override
public String toString() {
return "TxFeeRateInfo{"
+ "stdTxFeeRate=" + stdTxFeeRate + " sats/byte"
+ ", customWithdrawalTxFeeRate=" + customTxFeeRate + " sats/byte"
+ ", customTxFeeRate=" + customTxFeeRate + " sats/byte"
+ ", useCustomTxFeeRate=" + useCustomTxFeeRate
+ "}";
}
}

View File

@ -863,7 +863,8 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
}
public long getWithdrawalTxFeeInVbytes() {
return Math.max(prefPayload.getWithdrawalTxFeeInVbytes(), Config.baseCurrencyNetwork().getDefaultMinFeePerVbyte());
return Math.max(prefPayload.getWithdrawalTxFeeInVbytes(),
Config.baseCurrencyNetwork().getDefaultMinFeePerVbyte());
}
public boolean isDaoFullNode() {

View File

@ -440,6 +440,7 @@ message AddressBalanceInfo {
message TxFeeRateInfo {
uint64 stdTxFeeRate = 1;
uint64 customTxFeeRate = 2;
bool useCustomTxFeeRate = 3;
}
///////////////////////////////////////////////////////////////////////////////////////////