Search in sources :

Example 11 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class WalletAddressDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Bundle args = getArguments();
    final Address address = (Address) args.getSerializable(KEY_ADDRESS);
    final String addressStr = address.toBase58();
    final String addressLabel = args.getString(KEY_ADDRESS_LABEL);
    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.wallet_address_dialog);
    dialog.setCanceledOnTouchOutside(true);
    final String uri = BitcoinURI.convertToBitcoinURI(address, null, addressLabel, null);
    final BitmapDrawable bitmap = new BitmapDrawable(getResources(), Qr.bitmap(uri));
    bitmap.setFilterBitmap(false);
    final ImageView imageView = (ImageView) dialog.findViewById(R.id.wallet_address_dialog_image);
    imageView.setImageDrawable(bitmap);
    final View labelButtonView = dialog.findViewById(R.id.wallet_address_dialog_label_button);
    final TextView labelView = (TextView) dialog.findViewById(R.id.wallet_address_dialog_label);
    final CharSequence label = WalletUtils.formatHash(addressStr, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE);
    labelView.setText(label);
    labelButtonView.setVisibility(View.VISIBLE);
    labelButtonView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            final ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(activity);
            builder.setType("text/plain");
            builder.setText(addressStr);
            builder.setChooserTitle(R.string.bitmap_fragment_share);
            builder.startChooser();
            log.info("wallet address shared via intent: {}", addressStr);
        }
    });
    final View hintView = dialog.findViewById(R.id.wallet_address_dialog_hint);
    hintView.setVisibility(getResources().getBoolean(R.bool.show_wallet_address_dialog_hint) ? View.VISIBLE : View.GONE);
    final View dialogView = dialog.findViewById(R.id.wallet_address_dialog_group);
    dialogView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            dismissAllowingStateLoss();
        }
    });
    return dialog;
}
Also used : Address(org.bitcoinj.core.Address) Bundle(android.os.Bundle) OnClickListener(android.view.View.OnClickListener) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Dialog(android.app.Dialog) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 12 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class SampleActivity method handleRequest.

private void handleRequest() {
    try {
        final String[] addresses = donationAddresses();
        final NetworkParameters params = Address.getParametersFromAddress(addresses[0]);
        final Protos.Output.Builder output1 = Protos.Output.newBuilder();
        output1.setAmount(AMOUNT);
        output1.setScript(ByteString.copyFrom(ScriptBuilder.createOutputScript(new Address(params, addresses[0])).getProgram()));
        final Protos.Output.Builder output2 = Protos.Output.newBuilder();
        output2.setAmount(AMOUNT);
        output2.setScript(ByteString.copyFrom(ScriptBuilder.createOutputScript(new Address(params, addresses[1])).getProgram()));
        final Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
        paymentDetails.setNetwork(params.getPaymentProtocolId());
        paymentDetails.addOutputs(output1);
        paymentDetails.addOutputs(output2);
        paymentDetails.setMemo(MEMO);
        paymentDetails.setTime(System.currentTimeMillis());
        final Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
        paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
        BitcoinIntegration.requestForResult(SampleActivity.this, REQUEST_CODE, paymentRequest.build().toByteArray());
    } catch (final AddressFormatException x) {
        throw new RuntimeException(x);
    }
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) Address(org.bitcoinj.core.Address) NetworkParameters(org.bitcoinj.core.NetworkParameters) ByteString(com.google.protobuf.ByteString)

Example 13 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class MultiAddressesCoinSelector method matchesRequirement.

@Override
protected boolean matchesRequirement(TransactionOutput transactionOutput) {
    if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash()) {
        boolean confirmationCheck = allowUnconfirmedSpend || false;
        if (!allowUnconfirmedSpend && transactionOutput.getParentTransaction() != null && transactionOutput.getParentTransaction().getConfidence() != null) {
            final TransactionConfidence.ConfidenceType confidenceType = transactionOutput.getParentTransaction().getConfidence().getConfidenceType();
            confirmationCheck = confidenceType == TransactionConfidence.ConfidenceType.BUILDING;
            if (!confirmationCheck)
                log.error("Tx is not in blockchain yet. confidenceType=" + confidenceType);
        }
        Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
        log.trace("matchesRequiredAddress(es)?");
        log.trace(addressOutput.toString());
        log.trace(addressEntries.toString());
        for (AddressEntry entry : addressEntries) {
            if (addressOutput.equals(entry.getAddress()) && confirmationCheck)
                return true;
        }
        log.trace("No match found at matchesRequiredAddress addressOutput / addressEntries " + addressOutput.toString() + " / " + addressEntries.toString());
        return false;
    } else {
        log.warn("transactionOutput.getScriptPubKey() not isSentToAddress or isPayToScriptHash");
        return false;
    }
}
Also used : Address(org.bitcoinj.core.Address) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 14 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class TradeWalletCoinSelector method matchesRequirement.

@Override
protected boolean matchesRequirement(TransactionOutput transactionOutput) {
    if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash()) {
        boolean confirmationCheck = allowUnconfirmedSpend || false;
        if (!allowUnconfirmedSpend && transactionOutput.getParentTransaction() != null && transactionOutput.getParentTransaction().getConfidence() != null) {
            final TransactionConfidence.ConfidenceType confidenceType = transactionOutput.getParentTransaction().getConfidence().getConfidenceType();
            confirmationCheck = confidenceType == TransactionConfidence.ConfidenceType.BUILDING;
            if (!confirmationCheck)
                log.error("Tx is not in blockchain yet. confidenceType=" + confidenceType);
        }
        Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
        log.trace("matchesRequiredAddress?");
        log.trace("addressOutput " + addressOutput.toString());
        log.trace("address " + address.toString());
        boolean matches = addressOutput.equals(address);
        if (!matches)
            log.trace("No match found at matchesRequiredAddress addressOutput / address " + addressOutput.toString() + " / " + address.toString());
        return matches && confirmationCheck;
    } else {
        log.warn("transactionOutput.getScriptPubKey() not isSentToAddress or isPayToScriptHash");
        return false;
    }
}
Also used : Address(org.bitcoinj.core.Address) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 15 with Address

use of org.bitcoinj.core.Address in project bitsquare by bitsquare.

the class OffererCreatesAndSignsDepositTxAsBuyer method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Offer offer = trade.getOffer();
        Coin securityDeposit = FeePolicy.getSecurityDeposit(offer);
        Coin buyerInputAmount = securityDeposit.add(FeePolicy.getFixedTxFeeForTrades(offer));
        Coin msOutputAmount = buyerInputAmount.add(securityDeposit).add(trade.getTradeAmount());
        log.debug("\n\n------------------------------------------------------------\n" + "Contract as json\n" + trade.getContractAsJson() + "\n------------------------------------------------------------\n");
        byte[] contractHash = Hash.getHash(trade.getContractAsJson());
        trade.setContractHash(contractHash);
        WalletService walletService = processModel.getWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry buyerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        buyerMultiSigAddressEntry.setCoinLockedInMultiSig(buyerInputAmount.subtract(FeePolicy.getFixedTxFeeForTrades(offer)));
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        PreparedDepositTxAndOffererInputs result = processModel.getTradeWalletService().offererCreatesAndSignsDepositTx(true, contractHash, buyerInputAmount, msOutputAmount, processModel.tradingPeer.getRawTransactionInputs(), processModel.tradingPeer.getChangeOutputValue(), processModel.tradingPeer.getChangeOutputAddress(), offererAddressEntry.getAddress(), changeAddress, buyerMultiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
        processModel.setPreparedDepositTx(result.depositTransaction);
        processModel.setRawTransactionInputs(result.rawOffererInputs);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) Offer(io.bitsquare.trade.offer.Offer) AddressEntry(io.bitsquare.btc.AddressEntry) PreparedDepositTxAndOffererInputs(io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs) WalletService(io.bitsquare.btc.WalletService)

Aggregations

Address (org.bitcoinj.core.Address)26 WalletService (io.bitsquare.btc.WalletService)8 Coin (org.bitcoinj.core.Coin)8 Transaction (org.bitcoinj.core.Transaction)8 AddressEntry (io.bitsquare.btc.AddressEntry)7 TextView (android.widget.TextView)5 View (android.view.View)3 Offer (io.bitsquare.trade.offer.Offer)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Inject (com.google.inject.Inject)2 Arbitrator (io.bitsquare.arbitration.Arbitrator)2 PreparedDepositTxAndOffererInputs (io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs)2 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)2 UserThread (io.bitsquare.common.UserThread)2 NodeAddress (io.bitsquare.p2p.NodeAddress)2 Trade (io.bitsquare.trade.Trade)2 InetSocketAddress (java.net.InetSocketAddress)2