use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class BalanceWithConfirmationTextField method setup.
public void setup(Address address, BSFormatter formatter) {
this.formatter = formatter;
confidenceListener = new AddressConfidenceListener(address) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
updateConfidence(confidence);
}
};
walletService.addAddressConfidenceListener(confidenceListener);
updateConfidence(walletService.getConfidenceForAddress(address));
balanceListener = new BalanceListener(address) {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance(balance);
}
};
walletService.addBalanceListener(balanceListener);
updateBalance(walletService.getBalanceForAddress(address));
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class BroadcastAfterLockTime method broadcastTx.
private void broadcastTx() {
Log.traceCall();
Transaction payoutTx = trade.getPayoutTx();
checkNotNull(payoutTx, "payoutTx must not be null at BroadcastAfterLockTime.broadcastTx");
Transaction payoutTxFromWallet = processModel.getWalletService().getWallet().getTransaction(payoutTx.getHash());
log.debug("payoutTxFromWallet:" + payoutTxFromWallet);
if (payoutTxFromWallet != null)
payoutTx = payoutTxFromWallet;
TransactionConfidence.ConfidenceType confidenceType = payoutTx.getConfidence().getConfidenceType();
log.debug("payoutTx confidenceType:" + confidenceType);
if (confidenceType.equals(TransactionConfidence.ConfidenceType.BUILDING) || confidenceType.equals(TransactionConfidence.ConfidenceType.PENDING)) {
log.debug("payoutTx already building:" + payoutTx);
trade.setState(Trade.State.PAYOUT_BROAD_CASTED);
complete();
} else {
log.debug("do broadcast tx " + payoutTx);
processModel.getTradeWalletService().broadcastTx(payoutTx, new FutureCallback<Transaction>() {
@Override
public void onSuccess(Transaction transaction) {
log.debug("BroadcastTx succeeded. Transaction:" + transaction);
trade.setState(Trade.State.PAYOUT_BROAD_CASTED);
complete();
}
@Override
public void onFailure(@NotNull Throwable t) {
log.error("BroadcastTx failed. Error:" + t.getMessage());
failed(t);
}
});
}
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class CreateTakeOfferFeeTx method run.
@Override
protected void run() {
try {
runInterceptHook();
User user = processModel.getUser();
NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(user.getAcceptedArbitratorAddresses(), processModel.getOffer());
log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
Arbitrator selectedArbitrator = user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateTakeOfferFeeTx");
WalletService walletService = processModel.getWalletService();
String id = model.getOffer().getId();
AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
AddressEntry changeAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE);
Address fundingAddress = addressEntry.getAddress();
Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
Address changeAddress = changeAddressEntry.getAddress();
Transaction createTakeOfferFeeTx = processModel.getTradeWalletService().createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTrade(), processModel.getUseSavingsWallet(), FeePolicy.getTakeOfferFee(), selectedArbitrator.getBtcAddress());
processModel.setTakeOfferFeeTx(createTakeOfferFeeTx);
trade.setTakeOfferFeeTxId(createTakeOfferFeeTx.getHashAsString());
complete();
} catch (Throwable t) {
failed(t);
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method onActivityResultResumed.
private void onActivityResultResumed(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN) {
if (resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
setState(null);
updateStateFrom(paymentIntent);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, null, R.string.button_scan, messageResId, messageArgs);
}
}.parse();
}
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST) {
if (paymentIntent.isBluetoothPaymentRequestUrl())
requestPaymentRequest();
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT) {
if (paymentIntent.isBluetoothPaymentUrl())
directPaymentEnableView.setChecked(resultCode == Activity.RESULT_OK);
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsOfflineTask method sendCoinsOffline.
public final void sendCoinsOffline(final SendRequest sendRequest) {
backgroundHandler.post(new Runnable() {
@Override
public void run() {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
try {
log.info("sending: {}", sendRequest);
// can take long
final Transaction transaction = wallet.sendCoinsOffline(sendRequest);
log.info("send successful, transaction committed: {}", transaction.getHashAsString());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onSuccess(transaction);
}
});
} catch (final InsufficientMoneyException x) {
final Coin missing = x.missing;
if (missing != null)
log.info("send failed, {} missing", missing.toFriendlyString());
else
log.info("send failed, insufficient coins");
callbackHandler.post(new Runnable() {
@Override
public void run() {
onInsufficientMoney(x.missing);
}
});
} catch (final ECKey.KeyIsEncryptedException x) {
log.info("send failed, key is encrypted: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
} catch (final KeyCrypterException x) {
log.info("send failed, key crypter exception: {}", x.getMessage());
final boolean isEncrypted = wallet.isEncrypted();
callbackHandler.post(new Runnable() {
@Override
public void run() {
if (isEncrypted)
onInvalidEncryptionKey();
else
onFailure(x);
}
});
} catch (final CouldNotAdjustDownwards x) {
log.info("send failed, could not adjust downwards: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onEmptyWalletFailed();
}
});
} catch (final CompletionException x) {
log.info("send failed, cannot complete: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
}
}
});
}
Aggregations