inject DaoKillSwitch

This commit is contained in:
Christoph Sturm 2019-09-24 16:56:40 +02:00
parent 490eaab6d9
commit 9cd5c9f83f
2 changed files with 13 additions and 9 deletions

View File

@ -82,11 +82,13 @@ import static org.bitcoinj.core.TransactionConfidence.ConfidenceType.PENDING;
@Slf4j
public class BsqWalletService extends WalletService implements DaoStateListener {
public interface WalletTransactionsChangeListener {
void onWalletTransactionsChange();
}
private final DaoKillSwitch daoKillSwitch;
private final BsqCoinSelector bsqCoinSelector;
private final NonBsqCoinSelector nonBsqCoinSelector;
private final DaoStateService daoStateService;
@ -124,7 +126,8 @@ public class BsqWalletService extends WalletService implements DaoStateListener
DaoStateService daoStateService,
UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService,
Preferences preferences,
FeeService feeService) {
FeeService feeService,
DaoKillSwitch daoKillSwitch) {
super(walletsSetup,
preferences,
feeService);
@ -133,6 +136,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
this.nonBsqCoinSelector = nonBsqCoinSelector;
this.daoStateService = daoStateService;
this.unconfirmedBsqChangeOutputListService = unconfirmedBsqChangeOutputListService;
this.daoKillSwitch = daoKillSwitch;
walletsSetup.addSetupCompletedHandler(() -> {
wallet = walletsSetup.getBsqWallet();
@ -528,7 +532,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
private Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount, CoinSelector coinSelector)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(receiverAmount),
"The amount is too low (dust limit).");
@ -583,7 +587,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
}
private Transaction getPreparedBurnFeeTx(Coin fee, boolean requireChangeOutput) throws InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
final Transaction tx = new Transaction(params);
addInputsAndChangeOutputForTx(tx, fee, bsqCoinSelector, requireChangeOutput);
// printTx("getPreparedFeeTx", tx);
@ -635,7 +639,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
// We create a tx with Bsq inputs for the fee, one output for the stake and optional one BSQ change output.
// As the fee amount will be missing in the output those BSQ fees are burned.
public Transaction getPreparedBlindVoteTx(Coin fee, Coin stake) throws InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, stake, getUnusedAddress()));
addInputsAndChangeOutputForTx(tx, fee.add(stake), bsqCoinSelector, false);
@ -649,7 +653,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////
public Transaction getPreparedVoteRevealTx(TxOutput stakeTxOutput) {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
final Coin stake = Coin.valueOf(stakeTxOutput.getValue());
Transaction blindVoteTx = getTransaction(stakeTxOutput.getTxId());
@ -668,7 +672,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////
public Transaction getPreparedLockupTx(Coin lockupAmount) throws AddressFormatException, InsufficientBsqException {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(lockupAmount), "The amount is too low (dust limit).");
tx.addOutput(new TransactionOutput(params, tx, lockupAmount, getUnusedAddress()));
@ -682,7 +686,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
///////////////////////////////////////////////////////////////////////////////////////////
public Transaction getPreparedUnlockTx(TxOutput lockupTxOutput) throws AddressFormatException {
DaoKillSwitch.assertDaoIsNotDisabled();
daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params);
// Unlocking means spending the full value of the locked txOutput to another txOutput with the same value
Coin amountToUnlock = Coin.valueOf(lockupTxOutput.getValue());

View File

@ -70,8 +70,8 @@ public class DaoKillSwitch implements DaoSetupService {
daoDisabled = requireUpdateToNewVersion || filter.isDisableDao();
}
public static void assertDaoIsNotDisabled() {
if (INSTANCE.isDaoDisabled()) {
public void assertDaoIsNotDisabled() {
if (isDaoDisabled()) {
throw new DaoDisabledException("The DAO features have been disabled by the Bisq developers. " +
"Please check out the Bisq Forum for further information.");
}