当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.setPurpose方法代码示例

本文整理汇总了Java中org.bitcoinj.core.Transaction.setPurpose方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.setPurpose方法的具体用法?Java Transaction.setPurpose怎么用?Java Transaction.setPurpose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.core.Transaction的用法示例。


在下文中一共展示了Transaction.setPurpose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: childPaysForParent

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
 * Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already
 * completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is
 * currently only supported by a few miners, so use with care.
 */
public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) {
    TransactionOutput outputToSpend = null;
    for (final TransactionOutput output : parentTransaction.getOutputs()) {
        if (output.isMine(wallet) && output.isAvailableForSpending()
                && output.getValue().isGreaterThan(feeRaise)) {
            outputToSpend = output;
            break;
        }
    }
    // TODO spend another confirmed output of own wallet if needed
    checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us");

    final Transaction tx = new Transaction(parentTransaction.getParams());
    tx.addInput(outputToSpend);
    tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE));
    tx.setPurpose(Transaction.Purpose.RAISE_FEE);
    final SendRequest req = forTx(tx);
    req.completed = true;
    return req;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:26,代码来源:SendRequest.java

示例2: doRaiseFee

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
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);
        application.broadcastTransaction(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");
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:36,代码来源:RaiseFeeDialogFragment.java

示例3: rekeyOneBatch

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
@Nullable
private Transaction rekeyOneBatch(long timeSecs, @Nullable KeyParameter aesKey, List<Transaction> others, boolean sign) {
    lock.lock();
    try {
        // Build the transaction using some custom logic for our special needs. Last parameter to
        // KeyTimeCoinSelector is whether to ignore pending transactions or not.
        //
        // We ignore pending outputs because trying to rotate these is basically racing an attacker, and
        // we're quite likely to lose and create stuck double spends. Also, some users who have 0.9 wallets
        // have already got stuck double spends in their wallet due to the Bloom-filtering block reordering
        // bug that was fixed in 0.10, thus, making a re-key transaction depend on those would cause it to
        // never confirm at all.
        CoinSelector keyTimeSelector = new KeyTimeCoinSelector(this, timeSecs, true);
        FilteringCoinSelector selector = new FilteringCoinSelector(keyTimeSelector);
        for (Transaction other : others)
            selector.excludeOutputsSpentBy(other);
        // TODO: Make this use the standard SendRequest.
        CoinSelection toMove = selector.select(Coin.ZERO, calculateAllSpendCandidates());
        if (toMove.valueGathered.equals(Coin.ZERO)) return null;  // Nothing to do.
        maybeUpgradeToHD(aesKey);
        Transaction rekeyTx = new Transaction(params);
        for (TransactionOutput output : toMove.gathered) {
            rekeyTx.addInput(output);
        }
        // When not signing, don't waste addresses.
        rekeyTx.addOutput(toMove.valueGathered, sign ? freshReceiveAddress() : currentReceiveAddress());
        if (!adjustOutputDownwardsForFee(rekeyTx, toMove, Transaction.DEFAULT_TX_FEE, true)) {
            log.error("Failed to adjust rekey tx for fees.");
            return null;
        }
        rekeyTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
        rekeyTx.setPurpose(Transaction.Purpose.KEY_ROTATION);
        SendRequest req = SendRequest.forTx(rekeyTx);
        req.aesKey = aesKey;
        if (sign)
            signTransaction(req);
        // KeyTimeCoinSelector should never select enough inputs to push us oversize.
        checkState(rekeyTx.unsafeBitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
        return rekeyTx;
    } catch (VerificationException e) {
        throw new RuntimeException(e);  // Cannot happen.
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:46,代码来源:Wallet.java


注:本文中的org.bitcoinj.core.Transaction.setPurpose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。