Accept segwit addresses when sending non-BSQ funds

This commit is contained in:
Oscar Guindzberg 2020-10-12 17:23:20 -03:00
parent 41b2e6a56d
commit 864700775b
No known key found for this signature in database
GPG key ID: 209796BF2E1D4F75

View file

@ -513,7 +513,7 @@ public class BsqWalletService extends WalletService implements DaoStateListener
public Transaction getPreparedSendBsqTx(String receiverAddress, Coin receiverAmount) public Transaction getPreparedSendBsqTx(String receiverAddress, Coin receiverAmount)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException { throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException {
return getPreparedSendTx(receiverAddress, receiverAmount, bsqCoinSelector); return getPreparedSendTx(receiverAddress, receiverAmount, bsqCoinSelector, false);
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -522,17 +522,21 @@ public class BsqWalletService extends WalletService implements DaoStateListener
public Transaction getPreparedSendBtcTx(String receiverAddress, Coin receiverAmount) public Transaction getPreparedSendBtcTx(String receiverAddress, Coin receiverAmount)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException { throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException {
return getPreparedSendTx(receiverAddress, receiverAmount, nonBsqCoinSelector); return getPreparedSendTx(receiverAddress, receiverAmount, nonBsqCoinSelector, true);
} }
private Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount, CoinSelector coinSelector) private Transaction getPreparedSendTx(String receiverAddress, Coin receiverAmount, CoinSelector coinSelector,
boolean allowSegwitOuput)
throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException { throws AddressFormatException, InsufficientBsqException, WalletException, TransactionVerificationException, BsqChangeBelowDustException {
daoKillSwitch.assertDaoIsNotDisabled(); daoKillSwitch.assertDaoIsNotDisabled();
Transaction tx = new Transaction(params); Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(receiverAmount), checkArgument(Restrictions.isAboveDust(receiverAmount),
"The amount is too low (dust limit)."); "The amount is too low (dust limit).");
tx.addOutput(receiverAmount, LegacyAddress.fromBase58(params, receiverAddress)); if (allowSegwitOuput) {
tx.addOutput(receiverAmount, Address.fromString(params, receiverAddress));
} else {
tx.addOutput(receiverAmount, LegacyAddress.fromBase58(params, receiverAddress));
}
SendRequest sendRequest = SendRequest.forTx(tx); SendRequest sendRequest = SendRequest.forTx(tx);
sendRequest.fee = Coin.ZERO; sendRequest.fee = Coin.ZERO;
sendRequest.feePerKb = Coin.ZERO; sendRequest.feePerKb = Coin.ZERO;