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


Java AllowUnconfirmedCoinSelector类代码示例

本文整理汇总了Java中com.google.bitcoin.wallet.AllowUnconfirmedCoinSelector的典型用法代码示例。如果您正苦于以下问题:Java AllowUnconfirmedCoinSelector类的具体用法?Java AllowUnconfirmedCoinSelector怎么用?Java AllowUnconfirmedCoinSelector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initiate

import com.google.bitcoin.wallet.AllowUnconfirmedCoinSelector; //导入依赖的package包/类
/**
 * Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
 * time using {@link PaymentChannelClientState#getIncompleteRefundTransaction} and
 * {@link PaymentChannelClientState#getMultisigContract()}. The way the contract is crafted can be adjusted by
 * overriding {@link PaymentChannelClientState#editContractSendRequest(com.google.bitcoin.core.Wallet.SendRequest)}.
 * By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.
 *
 * @throws ValueOutOfRangeException if the value being used is too small to be accepted by the network
 * @throws InsufficientMoneyException if the wallet doesn't contain enough balance to initiate
 */
public synchronized void initiate() throws ValueOutOfRangeException, InsufficientMoneyException {
    final NetworkParameters params = wallet.getParams();
    Transaction template = new Transaction(params);
    // We always place the client key before the server key because, if either side wants some privacy, they can
    // use a fresh key for the the multisig contract and nowhere else
    List<ECKey> keys = Lists.newArrayList(myKey, serverMultisigKey);
    // There is also probably a change output, but we don't bother shuffling them as it's obvious from the
    // format which one is the change. If we start obfuscating the change output better in future this may
    // be worth revisiting.
    TransactionOutput multisigOutput = template.addOutput(totalValue, ScriptBuilder.createMultiSigOutputScript(2, keys));
    if (multisigOutput.getMinNonDustValue().compareTo(totalValue) > 0)
        throw new ValueOutOfRangeException("totalValue too small to use");
    Wallet.SendRequest req = Wallet.SendRequest.forTx(template);
    req.coinSelector = AllowUnconfirmedCoinSelector.get();
    editContractSendRequest(req);
    wallet.completeTx(req);
    BigInteger multisigFee = req.fee;
    multisigContract = req.tx;
    // Build a refund transaction that protects us in the case of a bad server that's just trying to cause havoc
    // by locking up peoples money (perhaps as a precursor to a ransom attempt). We time lock it so the server
    // has an assurance that we cannot take back our money by claiming a refund before the channel closes - this
    // relies on the fact that since Bitcoin 0.8 time locked transactions are non-final. This will need to change
    // in future as it breaks the intended design of timelocking/tx replacement, but for now it simplifies this
    // specific protocol somewhat.
    refundTx = new Transaction(params);
    refundTx.addInput(multisigOutput).setSequenceNumber(0);   // Allow replacement when it's eventually reactivated.
    refundTx.setLockTime(expiryTime);
    if (totalValue.compareTo(Utils.CENT) < 0) {
        // Must pay min fee.
        final BigInteger valueAfterFee = totalValue.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        if (Transaction.MIN_NONDUST_OUTPUT.compareTo(valueAfterFee) > 0)
            throw new ValueOutOfRangeException("totalValue too small to use");
        refundTx.addOutput(valueAfterFee, myKey.toAddress(params));
        refundFees = multisigFee.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    } else {
        refundTx.addOutput(totalValue, myKey.toAddress(params));
        refundFees = multisigFee;
    }
    refundTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    log.info("initiated channel with multi-sig contract {}, refund {}", multisigContract.getHashAsString(),
            refundTx.getHashAsString());
    state = State.INITIATED;
    // Client should now call getIncompleteRefundTransaction() and send it to the server.
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:55,代码来源:PaymentChannelClientState.java

示例2: initiate

import com.google.bitcoin.wallet.AllowUnconfirmedCoinSelector; //导入依赖的package包/类
/**
 * Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
 * time using {@link PaymentChannelClientState#getIncompleteRefundTransaction} and
 * {@link PaymentChannelClientState#getMultisigContract()}. The way the contract is crafted can be adjusted by
 * overriding {@link PaymentChannelClientState#editContractSendRequest(com.google.bitcoin.core.Wallet.SendRequest)}.
 * By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.
 *
 * @throws ValueOutOfRangeException if the value being used is too small to be accepted by the network
 * @throws InsufficientMoneyException if the wallet doesn't contain enough balance to initiate
 */
public synchronized void initiate() throws ValueOutOfRangeException, InsufficientMoneyException {
    final NetworkParameters params = wallet.getParams();
    Transaction template = new Transaction(params);
    // We always place the client key before the server key because, if either side wants some privacy, they can
    // use a fresh key for the the multisig contract and nowhere else
    List<ECKey> keys = Lists.newArrayList(myKey, serverMultisigKey);
    // There is also probably a change output, but we don't bother shuffling them as it's obvious from the
    // format which one is the change. If we start obfuscating the change output better in future this may
    // be worth revisiting.
    TransactionOutput multisigOutput = template.addOutput(totalValue, ScriptBuilder.createMultiSigOutputScript(2, keys));
    if (multisigOutput.getMinNonDustValue().compareTo(totalValue) > 0)
        throw new ValueOutOfRangeException("totalValue too small to use");
    Wallet.SendRequest req = Wallet.SendRequest.forTx(template);
    req.coinSelector = AllowUnconfirmedCoinSelector.get();
    editContractSendRequest(req);
    try {
        wallet.completeTx(req);
    } catch (CSExceptions.CannotEncode ex) {
        java.util.logging.Logger.getLogger(PaymentChannelClientState.class.getName()).log(Level.SEVERE, null, ex);
    }
    BigInteger multisigFee = req.fee;
    multisigContract = req.tx;
    // Build a refund transaction that protects us in the case of a bad server that's just trying to cause havoc
    // by locking up peoples money (perhaps as a precursor to a ransom attempt). We time lock it so the server
    // has an assurance that we cannot take back our money by claiming a refund before the channel closes - this
    // relies on the fact that since Bitcoin 0.8 time locked transactions are non-final. This will need to change
    // in future as it breaks the intended design of timelocking/tx replacement, but for now it simplifies this
    // specific protocol somewhat.
    refundTx = new Transaction(params);
    refundTx.addInput(multisigOutput).setSequenceNumber(0);   // Allow replacement when it's eventually reactivated.
    refundTx.setLockTime(expiryTime);
    if (totalValue.compareTo(Utils.CENT) < 0) {
        // Must pay min fee.
        final BigInteger valueAfterFee = totalValue.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        if (Transaction.MIN_NONDUST_OUTPUT.compareTo(valueAfterFee) > 0)
            throw new ValueOutOfRangeException("totalValue too small to use");
        refundTx.addOutput(valueAfterFee, myKey.toAddress(params));
        refundFees = multisigFee.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    } else {
        refundTx.addOutput(totalValue, myKey.toAddress(params));
        refundFees = multisigFee;
    }
    refundTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    log.info("initiated channel with multi-sig contract {}, refund {}", multisigContract.getHashAsString(),
            refundTx.getHashAsString());
    state = State.INITIATED;
    // Client should now call getIncompleteRefundTransaction() and send it to the server.
}
 
开发者ID:coinspark,项目名称:sparkbit-bitcoinj,代码行数:59,代码来源:PaymentChannelClientState.java

示例3: initiate

import com.google.bitcoin.wallet.AllowUnconfirmedCoinSelector; //导入依赖的package包/类
/**
 * Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
 * time using {@link PaymentChannelClientState#getIncompleteRefundTransaction} and
 * {@link PaymentChannelClientState#getMultisigContract()}. The way the contract is crafted can be adjusted by
 * overriding {@link PaymentChannelClientState#editContractSendRequest(com.google.bitcoin.core.Wallet.SendRequest)}.
 * By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.
 *
 * @throws ValueOutOfRangeException If the value being used cannot be afforded or is too small to be accepted by the network
 */
public synchronized void initiate() throws ValueOutOfRangeException {
    final NetworkParameters params = wallet.getParams();
    Transaction template = new Transaction(params);
    // We always place the client key before the server key because, if either side wants some privacy, they can
    // use a fresh key for the the multisig contract and nowhere else
    List<ECKey> keys = Lists.newArrayList(myKey, serverMultisigKey);
    // There is also probably a change output, but we don't bother shuffling them as it's obvious from the
    // format which one is the change. If we start obfuscating the change output better in future this may
    // be worth revisiting.
    TransactionOutput multisigOutput = template.addOutput(totalValue, ScriptBuilder.createMultiSigOutputScript(2, keys));
    if (multisigOutput.getMinNonDustValue().compareTo(totalValue) > 0)
        throw new ValueOutOfRangeException("totalValue too small to use");
    Wallet.SendRequest req = Wallet.SendRequest.forTx(template);
    req.coinSelector = AllowUnconfirmedCoinSelector.get();
    editContractSendRequest(req);
    if (!wallet.completeTx(req))
        throw new ValueOutOfRangeException("Cannot afford this channel");
    BigInteger multisigFee = req.fee;
    multisigContract = req.tx;
    // Build a refund transaction that protects us in the case of a bad server that's just trying to cause havoc
    // by locking up peoples money (perhaps as a precursor to a ransom attempt). We time lock it so the server
    // has an assurance that we cannot take back our money by claiming a refund before the channel closes - this
    // relies on the fact that since Bitcoin 0.8 time locked transactions are non-final. This will need to change
    // in future as it breaks the intended design of timelocking/tx replacement, but for now it simplifies this
    // specific protocol somewhat.
    refundTx = new Transaction(params);
    refundTx.addInput(multisigOutput).setSequenceNumber(0);   // Allow replacement when it's eventually reactivated.
    refundTx.setLockTime(expiryTime);
    if (totalValue.compareTo(Utils.CENT) < 0) {
        // Must pay min fee.
        final BigInteger valueAfterFee = totalValue.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        if (Transaction.MIN_NONDUST_OUTPUT.compareTo(valueAfterFee) > 0)
            throw new ValueOutOfRangeException("totalValue too small to use");
        refundTx.addOutput(valueAfterFee, myKey.toAddress(params));
        refundFees = multisigFee.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    } else {
        refundTx.addOutput(totalValue, myKey.toAddress(params));
        refundFees = multisigFee;
    }
    refundTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    log.info("initiated channel with multi-sig contract {}, refund {}", multisigContract.getHashAsString(),
            refundTx.getHashAsString());
    state = State.INITIATED;
    // Client should now call getIncompleteRefundTransaction() and send it to the server.
}
 
开发者ID:sserrano44,项目名称:bitcoinj-watcher-service,代码行数:55,代码来源:PaymentChannelClientState.java


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