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


Java Transaction.addOutput方法代码示例

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


在下文中一共展示了Transaction.addOutput方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sendBroadcastAnnouncement

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
public void sendBroadcastAnnouncement(BroadcastAnnouncement ba, File f, ProofMessage pm, int lockTime) throws InsufficientMoneyException {
	//build transaction
	Transaction tx = new Transaction(params);
	
	Script s = ba.buildScript();
	System.out.println("Script size is " + s.SIG_SIZE);
	//System.out.println(s.getScriptType());
	ECKey psnymKey = new ECKey();
	long unixTime = System.currentTimeMillis() / 1000L;
	//TODO use bitcoin nets median time
	tx.setLockTime(CLTVScriptPair.currentBitcoinBIP113Time(bc)-1);
	CLTVScriptPair sp = new CLTVScriptPair(psnymKey, CLTVScriptPair.currentBitcoinBIP113Time(bc)+lockTime);
	w.importKey(psnymKey);
	tx.addOutput(new TransactionOutput(params, tx, pm.getLastTransactionOutput().getValue().subtract(estimateBroadcastFee()), sp.getPubKeyScript().getProgram()));
	tx.addOutput(Coin.ZERO, s);
	tx.addInput(pm.getLastTransactionOutput());
	tx.getInput(0).setSequenceNumber(3); //the concrete value doesn't matter, this is just for cltv
	tx.getInput(0).setScriptSig(pm.getScriptPair().calculateSigScript(tx, 0, w));
	
	try {
		w.commitTx(tx);
		w.saveToFile(f);
	} catch (IOException e1) {
		e1.printStackTrace();
	}
	
	TransactionBroadcast broadcast = pg.broadcastTransaction(tx);
	pm.addTransaction(tx, 0, sp);
	pm.writeToFile();
	System.out.println("save broadcast announcement to file");
	
	

}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:35,代码来源:TransactionGenerator.java

示例3: 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

示例4: 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

示例5: toSendRequest

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
public SendRequest toSendRequest() {
    final Transaction transaction = new Transaction(Constants.NETWORK_PARAMETERS);
    for (final PaymentIntent.Output output : outputs)
        transaction.addOutput(output.amount, output.script);
    return SendRequest.forTx(transaction);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:7,代码来源:PaymentIntent.java

示例6: buildRevokeContract

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/**
 * Revoke a contract sending back to provider the coin
 */
public static Transaction buildRevokeContract(final String providerAddress, final String userAddress, final TransactionOutput prevOut, NetworkParameters networkParameters) throws Exception {
	
	if (providerAddress == null) {
		
		throw new Exception("Provider address is null");
		
	}
	
	if (userAddress == null) {
		
		throw new Exception("User address is null");
		
	}
	
	Coin coinValue = prevOut.getValue().subtract(FEE);
	
	Coin totalCoinOut = Coin.ZERO;
	
	Coin coinDivided = Coin.valueOf(coinValue.getValue() / 2);
	
       final Transaction transaction = new Transaction(networkParameters);
       
       // provider output
       TransactionOutput outputToProvider = new TransactionOutput(networkParameters, transaction, coinDivided, Address.fromBase58(networkParameters, providerAddress));
       transaction.addOutput(outputToProvider);
       
       // user output
       TransactionOutput outputToUser = new TransactionOutput(networkParameters, transaction, coinDivided, Address.fromBase58(networkParameters, userAddress));
       transaction.addOutput(outputToUser);
       
       // add value
       totalCoinOut = totalCoinOut.add(coinValue);
       
       try {
		
		// Connect all input
       	transaction.addInput(prevOut).setScriptSig(ScriptBuilder.createInputScript(TransactionSignature.dummy()));
           	
       	return transaction;

       } catch (Exception ex) {

          throw new Exception("Exception while building revoke contract", ex);

       }

}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:51,代码来源:ContractUtils.java


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