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;
}
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);
}
}
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;
}
}
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;
}
}
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);
}
}
Aggregations