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


Java Transaction.getOutput方法代码示例

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


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

示例1: adjustOutputDownwardsForFee

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
/** Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size. */
private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb,
        boolean ensureMinRequiredFee) {
    final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection);
    Coin fee = feePerKb.multiply(size).divide(1000);
    if (ensureMinRequiredFee && fee.compareTo(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0)
        fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
    TransactionOutput output = tx.getOutput(0);
    output.setValue(output.getValue().subtract(fee));
    return !output.isDust();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:12,代码来源:Wallet.java

示例2: signTransaction

import org.bitcoinj.core.Transaction; //导入方法依赖的package包/类
@Override
	public synchronized String signTransaction(final String s_tx, final List<String> paths) throws NodeException {

		try {

			Wallet wallet = null;

			if (paths.get(0).startsWith("0")) {
				wallet = providerWallet;
			} else if (paths.get(0).startsWith("1")) {
				wallet = userWallet;
			} else {
				throw new NodeException("Unknown paths!");
			}

			UniquidKeyBag keyBag = new UniquidKeyBag();

			for (String path : paths) {
				
				ImmutableList<ChildNumber> list = NodeUtils.listFromPath(path);

				DeterministicKey signingKey = deterministicHierarchy.get(list, true, true);
			
				keyBag.addDeterministicKey(signingKey);
				
			}
			
			Transaction originalTransaction = uniquidNodeConfiguration.getNetworkParameters().getDefaultSerializer()
					.makeTransaction(Hex.decode(s_tx));

			SendRequest req = SendRequest.forTx(originalTransaction);

			Transaction tx = req.tx;

			int numInputs = tx.getInputs().size();
			for (int i = 0; i < numInputs; i++) {
				TransactionInput txIn = tx.getInput(i);

				// Fetch input tx from proper wallet
				Transaction inputTransaction = wallet.getTransaction(txIn.getOutpoint().getHash());

				if (inputTransaction == null) {
					
					throw new NodeException("Input TX not found in any wallet!");

				}

				TransactionOutput outputToUse = inputTransaction.getOutput(txIn.getOutpoint().getIndex());

				originalTransaction.getInput(i).connect(outputToUse);
				Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
				RedeemData redeemData = txIn.getConnectedRedeemData(keyBag);
				txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));

			}

			TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(tx);
			for (TransactionSigner signer : wallet.getTransactionSigners()) {
				if (!signer.signInputs(proposal, keyBag)) {
					LOGGER.info("{} returned false for the tx", signer.getClass().getName());
					throw new NodeException("Cannot sign TX!");
				}
			}

			// resolve missing sigs if any
			new MissingSigResolutionSigner(req.missingSigsMode).signInputs(proposal, keyBag);

			// commit tx in wallet!
			// This is not necessary! Kept here to remember
//			wallet.commitTx(originalTransaction);

			return Hex.toHexString(originalTransaction.bitcoinSerialize());

		} catch (Exception ex) {

			throw new NodeException("Exception while signing", ex);

		}
	}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:80,代码来源:UniquidNodeImpl.java


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