use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class RaiseFeeDialogFragment method doRaiseFee.
private void doRaiseFee(final KeyParameter encryptionKey) {
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try {
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
wallet.commitTx(transactionToSend);
BlockchainService.broadcastTransaction(activity, transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final KeyCrypterException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method initStateFromBitcoinUri.
private void initStateFromBitcoinUri(final Uri bitcoinUri) {
final String input = bitcoinUri.toString();
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
updateStateFrom(paymentIntent);
}
@Override
protected void handlePrivateKey(final VersionedChecksummedBytes key) {
throw new UnsupportedOperationException();
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
throw new UnsupportedOperationException();
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, activityDismissListener, 0, messageResId, messageArgs);
}
}.parse();
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method onActivityResult.
@Override
public void onActivityResult(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 handlePrivateKey(final VersionedChecksummedBytes key) {
privateKeyToSweep = key;
setState(State.DECODE_KEY);
maybeDecodeKey();
}
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
cannotClassify(input);
}
@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();
}
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method handleSweep.
private void handleSweep() {
setState(State.PREPARATION);
final SendRequest sendRequest = SendRequest.emptyWallet(application.getWallet().freshReceiveAddress());
sendRequest.feePerKb = fees.get(FeeCategory.NORMAL);
new SendCoinsOfflineTask(walletToSweep, backgroundHandler) {
@Override
protected void onSuccess(final Transaction transaction) {
sentTransaction = transaction;
setState(State.SENDING);
sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);
application.processDirectTransaction(sentTransaction);
}
@Override
protected void onInsufficientMoney(@Nullable final Coin missing) {
setState(State.FAILED);
showInsufficientMoneyDialog();
}
@Override
protected void onEmptyWalletFailed() {
setState(State.FAILED);
showInsufficientMoneyDialog();
}
@Override
protected void onFailure(final Exception exception) {
setState(State.FAILED);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_error_msg);
dialog.setMessage(exception.toString());
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
@Override
protected void onInvalidEncryptionKey() {
// cannot happen
throw new RuntimeException();
}
private void showInsufficientMoneyDialog() {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.sweep_wallet_fragment_insufficient_money_title);
dialog.setMessage(R.string.sweep_wallet_fragment_insufficient_money_msg);
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
}.sendCoinsOffline(// send asynchronously
sendRequest);
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class BlockListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
final StoredBlock storedBlock = getItem(position);
final Block header = storedBlock.getHeader();
holder.miningRewardAdjustmentView.setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
holder.miningDifficultyAdjustmentView.setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);
final int height = storedBlock.getHeight();
holder.heightView.setText(Integer.toString(height));
final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
else
holder.timeView.setText(R.string.block_row_now);
holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));
final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
int iTransactionView = 0;
final Sha256Hash blockHash = header.getHash();
for (final Transaction tx : transactions) {
if (tx.getAppearsInHashes().containsKey(blockHash)) {
final View view;
if (iTransactionView < transactionChildCount) {
view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
} else {
view = inflater.inflate(R.layout.block_row_transaction, null);
holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
}
bindView(view, tx);
iTransactionView++;
}
}
final int leftoverTransactionViews = transactionChildCount - iTransactionView;
if (leftoverTransactionViews > 0)
holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);
if (onClickListener != null) {
holder.menuView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickListener.onBlockMenuClick(v, storedBlock);
}
});
}
}
Aggregations