Search in sources :

Example 11 with Transaction

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));
}
Also used : Coin(org.bitcoinj.core.Coin) AddressConfidenceListener(io.bitsquare.btc.listeners.AddressConfidenceListener) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 12 with Transaction

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);
            }
        });
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 13 with Transaction

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);
    }
}
Also used : User(io.bitsquare.user.User) NodeAddress(io.bitsquare.p2p.NodeAddress) Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) AddressEntry(io.bitsquare.btc.AddressEntry) NodeAddress(io.bitsquare.p2p.NodeAddress) Arbitrator(io.bitsquare.arbitration.Arbitrator) WalletService(io.bitsquare.btc.WalletService)

Example 14 with Transaction

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);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 15 with Transaction

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);
                    }
                });
            }
        }
    });
}
Also used : Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) CompletionException(org.bitcoinj.wallet.Wallet.CompletionException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) CouldNotAdjustDownwards(org.bitcoinj.wallet.Wallet.CouldNotAdjustDownwards) KeyCrypterException(org.bitcoinj.crypto.KeyCrypterException)

Aggregations

Transaction (org.bitcoinj.core.Transaction)39 Coin (org.bitcoinj.core.Coin)14 AddressEntry (io.bitsquare.btc.AddressEntry)8 WalletService (io.bitsquare.btc.WalletService)8 Address (org.bitcoinj.core.Address)8 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)7 VerificationException (org.bitcoinj.core.VerificationException)7 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)6 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)6 Popup (io.bitsquare.gui.main.overlays.popups.Popup)5 Trade (io.bitsquare.trade.Trade)4 VersionedChecksummedBytes (org.bitcoinj.core.VersionedChecksummedBytes)4 DialogInterface (android.content.DialogInterface)3 View (android.view.View)3 TextView (android.widget.TextView)3 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)3 Arbitrator (io.bitsquare.arbitration.Arbitrator)3 Nullable (javax.annotation.Nullable)3 RecyclerView (android.support.v7.widget.RecyclerView)2 Inject (com.google.inject.Inject)2