use of bisq.core.btc.wallet.TxBroadcastException in project bisq-core by bisq-network.
the class CreateTakerFeeTx method run.
@Override
protected void run() {
try {
runInterceptHook();
User user = processModel.getUser();
NodeAddress selectedArbitratorNodeAddress = ArbitratorSelectionRule.select(user.getAcceptedArbitratorAddresses(), processModel.getOffer());
log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
Arbitrator selectedArbitrator = user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateTakeOfferFeeTx");
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
AddressEntry changeAddressEntry = walletService.getFreshAddressEntry();
Address fundingAddress = addressEntry.getAddress();
Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
Address changeAddress = changeAddressEntry.getAddress();
final TradeWalletService tradeWalletService = processModel.getTradeWalletService();
if (trade.isCurrencyForTakerFeeBtc()) {
tradeFeeTx = tradeWalletService.createBtcTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTradeAsLong(), processModel.isUseSavingsWallet(), trade.getTakerFee(), trade.getTxFee(), selectedArbitrator.getBtcAddress(), new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
// we delay one render frame to be sure we don't get called before the method call has
// returned (tradeFeeTx would be null in that case)
UserThread.execute(() -> {
if (!completed) {
processModel.setTakeOfferFeeTx(tradeFeeTx);
trade.setTakerFeeTxId(tradeFeeTx.getHashAsString());
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);
complete();
} else {
log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
}
});
}
@Override
public void onFailure(TxBroadcastException exception) {
if (!completed) {
failed(exception);
} else {
log.warn("We got the onFailure callback called after the timeout has been triggered a complete().");
}
}
});
} else {
final BsqWalletService bsqWalletService = processModel.getBsqWalletService();
Transaction preparedBurnFeeTx = processModel.getBsqWalletService().getPreparedBurnFeeTx(trade.getTakerFee());
Transaction txWithBsqFee = tradeWalletService.completeBsqTradingFeeTx(preparedBurnFeeTx, fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTradeAsLong(), processModel.isUseSavingsWallet(), trade.getTxFee());
Transaction signedTx = processModel.getBsqWalletService().signTx(txWithBsqFee);
WalletService.checkAllScriptSignaturesForTx(signedTx);
bsqWalletService.commitTx(signedTx);
// We need to create another instance, otherwise the tx would trigger an invalid state exception
// if it gets committed 2 times
tradeWalletService.commitTx(tradeWalletService.getClonedTransaction(signedTx));
bsqWalletService.broadcastTx(signedTx, new TxBroadcaster.Callback() {
@Override
public void onSuccess(@Nullable Transaction transaction) {
if (!completed) {
if (transaction != null) {
log.debug("Successfully sent tx with id " + transaction.getHashAsString());
trade.setTakerFeeTxId(transaction.getHashAsString());
processModel.setTakeOfferFeeTx(transaction);
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);
complete();
}
} else {
log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
}
}
@Override
public void onFailure(TxBroadcastException exception) {
if (!completed) {
log.error(exception.toString());
exception.printStackTrace();
trade.setErrorMessage("An error occurred.\n" + "Error message:\n" + exception.getMessage());
failed(exception);
} else {
log.warn("We got the onFailure callback called after the timeout has been triggered a complete().");
}
}
});
}
} catch (Throwable t) {
failed(t);
}
}
use of bisq.core.btc.wallet.TxBroadcastException in project bisq-core by bisq-network.
the class LockupService method publishLockupTx.
public void publishLockupTx(Coin lockupAmount, int lockTime, LockupType lockupType, BondedRole bondedRole, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
checkArgument(lockTime <= BondingConsensus.getMaxLockTime() && lockTime >= BondingConsensus.getMinLockTime(), "lockTime not in rage");
try {
byte[] hash = BondingConsensus.getHash(lockupType, bondedRole);
byte[] opReturnData = BondingConsensus.getLockupOpReturnData(lockTime, lockupType, hash);
final Transaction lockupTx = getLockupTx(lockupAmount, opReturnData);
// noinspection Duplicates
walletsManager.publishAndCommitBsqTx(lockupTx, new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
resultHandler.handleResult();
}
@Override
public void onTxMalleability(TxMalleabilityException exception) {
exceptionHandler.handleException(exception);
}
@Override
public void onFailure(TxBroadcastException exception) {
exceptionHandler.handleException(exception);
}
});
} catch (TransactionVerificationException | InsufficientMoneyException | WalletException | IOException exception) {
exceptionHandler.handleException(exception);
}
}
use of bisq.core.btc.wallet.TxBroadcastException in project bisq-core by bisq-network.
the class UnlockService method publishUnlockTx.
public void publishUnlockTx(String lockupTxId, ResultHandler resultHandler, ExceptionHandler exceptionHandler) {
try {
TxOutput lockupTxOutput = bsqStateService.getLockupTxOutput(lockupTxId).get();
final Transaction unlockTx = getUnlockTx(lockupTxOutput);
// noinspection Duplicates
walletsManager.publishAndCommitBsqTx(unlockTx, new TxBroadcaster.Callback() {
@Override
public void onSuccess(Transaction transaction) {
resultHandler.handleResult();
}
@Override
public void onTxMalleability(TxMalleabilityException exception) {
exceptionHandler.handleException(exception);
}
@Override
public void onFailure(TxBroadcastException exception) {
exceptionHandler.handleException(exception);
}
});
} catch (TransactionVerificationException | InsufficientMoneyException | WalletException exception) {
exceptionHandler.handleException(exception);
}
}
Aggregations