當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientChannelProperties類代碼示例

本文整理匯總了Java中org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties的典型用法代碼示例。如果您正苦於以下問題:Java ClientChannelProperties類的具體用法?Java ClientChannelProperties怎麽用?Java ClientChannelProperties使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientChannelProperties類屬於org.bitcoinj.protocols.channels.IPaymentChannelClient包,在下文中一共展示了ClientChannelProperties類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initiate

import org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties; //導入依賴的package包/類
@Override
public synchronized void initiate(@Nullable KeyParameter userKey, ClientChannelProperties clientChannelProperties) throws ValueOutOfRangeException, InsufficientMoneyException {
    final NetworkParameters params = wallet.getParams();
    Transaction template = new Transaction(params);
    // 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.
    Script redeemScript =
            ScriptBuilder.createCLTVPaymentChannelOutput(BigInteger.valueOf(expiryTime), myKey, serverKey);
    TransactionOutput transactionOutput = template.addOutput(totalValue,
            ScriptBuilder.createP2SHOutputScript(redeemScript));
    if (transactionOutput.isDust())
        throw new ValueOutOfRangeException("totalValue too small to use");
    SendRequest req = SendRequest.forTx(template);
    req.coinSelector = AllowUnconfirmedCoinSelector.get();
    req.shuffleOutputs = false;   // TODO: Fix things so shuffling is usable.
    req = clientChannelProperties.modifyContractSendRequest(req);
    if (userKey != null) req.aesKey = userKey;
    wallet.completeTx(req);
    Coin multisigFee = req.tx.getFee();
    contract = 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 because the
    // CheckLockTimeVerify opcode requires a lock time to be specified and the input to have a non-final sequence
    // number (so that the lock time is not disabled).
    refundTx = new Transaction(params);
    // by using this sequence value, we avoid extra full replace-by-fee and relative lock time processing.
    refundTx.addInput(contract.getOutput(0)).setSequenceNumber(TransactionInput.NO_SEQUENCE - 1L);
    refundTx.setLockTime(expiryTime);
    if (Context.get().isEnsureMinRequiredFee()) {
        // Must pay min fee.
        final Coin 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;
    }

    TransactionSignature refundSignature =
            refundTx.calculateSignature(0, myKey.maybeDecrypt(userKey),
                    getSignedScript(), Transaction.SigHash.ALL, false);
    refundTx.getInput(0).setScriptSig(ScriptBuilder.createCLTVPaymentChannelP2SHRefund(refundSignature, redeemScript));

    refundTx.getConfidence().setSource(TransactionConfidence.Source.SELF);
    log.info("initiated channel with contract {}", contract.getHashAsString());
    stateMachine.transition(State.SAVE_STATE_IN_WALLET);
    // Client should now call getIncompleteRefundTransaction() and send it to the server.
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:53,代碼來源:PaymentChannelV2ClientState.java

示例2: initiate

import org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties; //導入依賴的package包/類
/**
 * Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
 * time using {@link PaymentChannelV1ClientState#getIncompleteRefundTransaction} and
 * {@link PaymentChannelV1ClientState#getContract()}.
 * By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.
 * @param userKey Key derived from a user password, needed for any signing when the wallet is encrypted.
 *                The wallet KeyCrypter is assumed.
 * @param clientChannelProperties Modify the channel's configuration.
 *
 * @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
 */
@Override
public synchronized void initiate(@Nullable KeyParameter userKey, ClientChannelProperties clientChannelProperties) 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, serverKey);
    // 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.isDust())
        throw new ValueOutOfRangeException("totalValue too small to use");
    SendRequest req = SendRequest.forTx(template);
    req.coinSelector = AllowUnconfirmedCoinSelector.get();
    req.shuffleOutputs = false;   // TODO: Fix things so shuffling is usable.
    req = clientChannelProperties.modifyContractSendRequest(req);
    if (userKey != null) req.aesKey = userKey;
    wallet.completeTx(req);
    Coin multisigFee = req.tx.getFee();
    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);
    // don't disable lock time. the sequence will be included in the server's signature and thus won't be changeable.
    // by using this sequence value, we avoid extra full replace-by-fee and relative lock time processing.
    refundTx.addInput(multisigOutput).setSequenceNumber(TransactionInput.NO_SEQUENCE - 1L);
    refundTx.setLockTime(expiryTime);
    if (Context.get().isEnsureMinRequiredFee()) {
        // Must pay min fee.
        final Coin 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());
    stateMachine.transition(State.INITIATED);
    // Client should now call getIncompleteRefundTransaction() and send it to the server.
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:62,代碼來源:PaymentChannelV1ClientState.java

示例3: initiate

import org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties; //導入依賴的package包/類
/**
 * Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
 * time using {@link PaymentChannelV1ClientState#getIncompleteRefundTransaction} and
 * {@link PaymentChannelClientState#getContract()}.
 * By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.
 * @param userKey Key derived from a user password, needed for any signing when the wallet is encrypted.
 *                The wallet KeyCrypter is assumed.
 * @param clientChannelProperties Modify the channel's configuration.
 *
 * @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 abstract void initiate(@Nullable KeyParameter userKey, ClientChannelProperties clientChannelProperties) throws ValueOutOfRangeException, InsufficientMoneyException;
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:14,代碼來源:PaymentChannelClientState.java


注:本文中的org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。