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


Java TransactionOutput类代码示例

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


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

示例1: isStandard

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
/**
 * <p>Checks if a transaction is considered "standard" by the reference client's IsStandardTx and AreInputsStandard
 * functions.</p>
 *
 * <p>Note that this method currently only implements a minimum of checks. More to be added later.</p>
 */
public static RuleViolation isStandard(Transaction tx) {
    // TODO: Finish this function off.
    if (tx.getVersion() > 1 || tx.getVersion() < 1) {
        log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion());
        return RuleViolation.VERSION;
    }

    final List<TransactionOutput> outputs = tx.getOutputs();
    for (int i = 0; i < outputs.size(); i++) {
        TransactionOutput output = outputs.get(i);
        if (output.getMinNonDustValue().compareTo(output.getValue()) > 0) {
            log.warn("TX considered non-standard due to output {} being dusty", i);
            return RuleViolation.DUST;
        }
    }

    return RuleViolation.NONE;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:25,代码来源:DefaultRiskAnalysis.java

示例2: select

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public CoinSelection select(BigInteger biTarget, LinkedList<TransactionOutput> candidates) {
    long target = biTarget.longValue();
    HashSet<TransactionOutput> selected = new HashSet<TransactionOutput>();
    // Sort the inputs by age*value so we get the highest "coindays" spent.
    // TODO: Consider changing the wallets internal format to track just outputs and keep them ordered.
    ArrayList<TransactionOutput> sortedOutputs = new ArrayList<TransactionOutput>(candidates);
    // When calculating the wallet balance, we may be asked to select all possible coins, if so, avoid sorting
    // them in order to improve performance.
    if (!biTarget.equals(NetworkParameters.MAX_MONEY)) {
        sortOutputs(sortedOutputs);
    }
    // Now iterate over the sorted outputs until we have got as close to the target as possible or a little
    // bit over (excessive value will be change).
    long total = 0;
    for (TransactionOutput output : sortedOutputs) {
        if (total >= target) break;
        // Only pick chain-included transactions, or transactions that are ours and pending.
        if (!shouldSelect(output.getParentTransaction())) continue;
        selected.add(output);
        total += output.getValue().longValue();
    }
    // Total may be lower than target here, if the given candidates were insufficient to create to requested
    // transaction.
    return new CoinSelection(BigInteger.valueOf(total), selected);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:26,代码来源:DefaultCoinSelector.java

示例3: OpenTx

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public OpenTx(LotteryTx commitTx, ECKey sk, List<byte[]> pks, Address address, 
		byte[] secret, BigInteger fee, boolean testnet) throws VerificationException {
	NetworkParameters params = getNetworkParameters(testnet);
	int noPlayers = commitTx.getOutputs().size();
	tx = new Transaction(params);
	BigInteger value = BigInteger.ZERO;
	for (TransactionOutput out : commitTx.getOutputs()) {
		tx.addInput(out);
		value = value.add(out.getValue());
	}
	tx.addOutput(value.subtract(fee), address);
	for (int k = 0; k < noPlayers; ++k) {
		byte[] sig = sign(k, sk).encodeToBitcoin();
		tx.getInput(k).setScriptSig(new ScriptBuilder()
											.data(sig)
											.data(sk.getPubKey())
											.data(sig) // wrong signature in a good format
											.data(pks.get(k))
											.data(secret)
											.build());
		tx.getInput(k).verify();
	}
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:25,代码来源:OpenTx.java

示例4: ComputeTx

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public ComputeTx(List<PutMoneyTx> inputs, List<byte[]> pks, List<byte[]> hashes, 
									int minLength, BigInteger fee, boolean testnet) throws VerificationException {
	this.pks = pks;
	this.hashes = hashes;
	this.testnet = testnet;
	this.minLength = minLength;
	this.noPlayers = inputs.size();
	tx = new Transaction(getNetworkParameters(testnet));
	BigInteger stake = BigInteger.ZERO;
	for (int k = 0; k < noPlayers; ++k) {
		TransactionOutput in = inputs.get(k).getOut();
		tx.addInput(in);
		stake = stake.add(in.getValue());
	}
	
	tx.addOutput(stake.subtract(fee), calculateOutScript());
	signatures = new ArrayList<byte[]>();
	for (int k = 0; k < noPlayers; ++k) {
		signatures.add(null);
	}
	tx.verify();
}
 
开发者ID:lukmaz,项目名称:BitcoinLottery,代码行数:23,代码来源:ComputeTx.java

示例5: isStandard

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
/**
 * <p>Checks if a transaction is considered "standard" by the reference client's IsStandardTx and AreInputsStandard
 * functions.</p>
 *
 * <p>Note that this method currently only implements a minimum of checks. More to be added later.</p>
 */
public static RuleViolation isStandard(Transaction tx) {
    // TODO: Finish this function off.
    if (tx.getVersion() > 1 || tx.getVersion() < 1) {
        log.warn("TX considered non-standard due to unknown version number {}", tx.getVersion());
        return RuleViolation.VERSION;
    }

    final List<TransactionOutput> outputs = tx.getOutputs();
    for (int i = 0; i < outputs.size(); i++) {
        TransactionOutput output = outputs.get(i);
        if (MIN_ANALYSIS_NONDUST_OUTPUT.compareTo(output.getValue()) > 0) {
            log.warn("TX considered non-standard due to output {} being dusty", i);
            return RuleViolation.DUST;
        }
    }

    return RuleViolation.NONE;
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:25,代码来源:DefaultRiskAnalysis.java

示例6: addTxOut

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public void addTxOut(TransactionOutput out, int vout)
    {
        Transaction parent = out.getParentTransaction();

        ContentValues params = new ContentValues();
        params.put(this.txid, parent.getHashAsString());

        // the line below is producing same vout between multiple
//        params.put(this.vout, parent.getOutputs().indexOf(out));
        params.put(this.vout, vout);

        params.put(this.value, out.getValue().longValue());
        params.put(this.raw, out.bitcoinSerialize());
        params.put(this.status, this.unspent);

        Log.d("DB", "addTxOut(): " + params.toString());

        db.insertOrThrow(db_table_txouts, null, params);
    }
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:20,代码来源:AhimsaDB.java

示例7: isRelevant

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public boolean isRelevant(TransactionOutput out)
    {
        try {
            Script script = out.getScriptPubKey();
            if (script.isSentToRawPubKey())
            {
                return Arrays.equals(key.getPubKey(), script.getPubKey());
            }
            if (script.isPayToScriptHash())
            {
//                return wallet.isPayToScriptHashMine(script.getPubKeyHash());
                return false; // unsupported. todo: support
            }
            else
            {
                return Arrays.equals(key.getPubKeyHash(), script.getPubKeyHash());
            }
        }
        catch (ScriptException e)
        {
            // Just means we didn't understand the output of this transaction: ignore it.
            Log.e(TAG, "Could not parse tx output script: {}", e);
            return false;
        }
    }
 
开发者ID:alexkuck,项目名称:ahimsa-app,代码行数:26,代码来源:AhimsaWallet.java

示例8: getFirstToAddress

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
@CheckForNull
public static Address getFirstToAddress(@Nonnull final Transaction tx)
{
	try
	{
		for (final TransactionOutput output : tx.getOutputs())
		{
			return output.getScriptPubKey().getToAddress(Constants.NETWORK_PARAMETERS);
		}

		throw new IllegalStateException();
	}
	catch (final ScriptException x)
	{
		return null;
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:18,代码来源:WalletUtils.java

示例9: isInternal

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public static boolean isInternal(@Nonnull final Transaction tx)
{
	if (tx.isCoinBase())
		return false;

	final List<TransactionOutput> outputs = tx.getOutputs();
	if (outputs.size() != 1)
		return false;

	try
	{
		final TransactionOutput output = outputs.get(0);
		final Script scriptPubKey = output.getScriptPubKey();
		if (!scriptPubKey.isSentToRawPubKey())
			return false;

		return true;
	}
	catch (final ScriptException x)
	{
		return false;
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:24,代码来源:WalletUtils.java

示例10: getLargestSpendableOutput

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
public static int getLargestSpendableOutput(Transaction t, Address a)
        throws Exception {

    BigInteger largestOutputSize = new BigInteger("0");
    int largestOutput = -1;

    for (int i = 0; i < t.getOutputs().size(); ++i) {
        TransactionOutput o = t.getOutput(i);
        if (o.isAvailableForSpending()) {
            if (Arrays.equals(o.getScriptPubKey().getPubKeyHash(), a.getHash160())) {
                if (o.getValue().compareTo(largestOutputSize) > 0) {
                    largestOutputSize = o.getValue();
                    largestOutput = i;
                }
            }
        }
    }

    return largestOutput;
}
 
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:21,代码来源:WalletUtils.java

示例11: sortOutputs

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
@VisibleForTesting static void sortOutputs(ArrayList<TransactionOutput> outputs) {
    Collections.sort(outputs, new Comparator<TransactionOutput>() {
        public int compare(TransactionOutput a, TransactionOutput b) {
            int depth1 = 0;
            int depth2 = 0;
            TransactionConfidence conf1 = a.getParentTransaction().getConfidence();
            TransactionConfidence conf2 = b.getParentTransaction().getConfidence();
            if (conf1.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
                depth1 = conf1.getDepthInBlocks();
            if (conf2.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
                depth2 = conf2.getDepthInBlocks();
            BigInteger aValue = a.getValue();
            BigInteger bValue = b.getValue();
            BigInteger aCoinDepth = aValue.multiply(BigInteger.valueOf(depth1));
            BigInteger bCoinDepth = bValue.multiply(BigInteger.valueOf(depth2));
            int c1 = bCoinDepth.compareTo(aCoinDepth);
            if (c1 != 0) return c1;
            // The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size.
            int c2 = bValue.compareTo(aValue);
            if (c2 != 0) return c2;
            // They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering.
            BigInteger aHash = a.getParentTransaction().getHash().toBigInteger();
            BigInteger bHash = b.getParentTransaction().getHash().toBigInteger();
            return aHash.compareTo(bHash);
        }
    });
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:28,代码来源:DefaultCoinSelector.java

示例12: isOutputOneWeRequested

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
private boolean isOutputOneWeRequested(TransactionOutput output) {
    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested ----------------------------------- ");
	try {
		BitcoinScript toOutputScript = new BitcoinScript(output.getScriptBytes());

   		byte[] program = toOutputScript.getProgram();
	    String scriptHex = new String(Hex.encode(program));
	    BigInteger value = output.getValue();
	    
	    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested self.request_outputs: " + this.request_outputs.toString());
	    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested scriptHex: " + scriptHex);
	    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested value: " + value);

	    for (int i = 0; i < this.request_outputs.size(); i++) {
	    	JSONObject request_output = (JSONObject) this.request_outputs.get(i);
	    	String script = (String) request_output.get("script");
	    	String valueStr = SharedCoin.getIntegerStringFromIntegerString(request_output, "value");

	    	//Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested TransactionOutput script: " + script);
		    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested TransactionOutput value: " + valueStr);

	    	if (script.equals(scriptHex) && valueStr.equals(value.toString())) {
			    //Log.d("SharedCoin", "SharedCoin sOutputOneWeRequested return true: ");
	    		return true;
	    	}
    	}
	    
	} catch (Exception e) {
		e.printStackTrace();
	}
    
          return false;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:34,代码来源:SharedCoin.java

示例13: isOutputChange

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
private boolean isOutputChange(TransactionOutput output) {

			try {
				BitcoinScript toOutputScript = new BitcoinScript(output.getScriptBytes());

	    		byte[] program = toOutputScript.getProgram();
			    String scriptHex = new String(Hex.encode(program));
			    BigInteger value = output.getValue();
			    
			    Log.d("SharedCoin", "SharedCoin isOutputChange self.request_outputs: " + this.request_outputs.toString());
			    Log.d("SharedCoin", "SharedCoin isOutputChange scriptHex: " + scriptHex);
			    Log.d("SharedCoin", "SharedCoin isOutputChange value: " + value);

			    for (int i = 0; i < this.request_outputs.size(); i++) {
			    	JSONObject request_output = (JSONObject) this.request_outputs.get(i);
			    	String script = (String) request_output.get("script");
			    	String valueStr = SharedCoin.getIntegerStringFromIntegerString(request_output, "value");
			    	if (script.equals(scriptHex) && valueStr.equals(value.toString())) {
			        	return request_output.get("exclude_from_fee") == null ? false : (Boolean) request_output.get("exclude_from_fee");	
			    	}
		    	}
			    
			} catch (Exception e) {
				e.printStackTrace();
			}
		    
            return false;
		}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:29,代码来源:SharedCoin.java

示例14: determineOutputsToOfferNextStage

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void determineOutputsToOfferNextStage(String tx_hex, ObjectSuccessCallback objectSuccessCallback) {
	try {
    	Log.d("SharedCoin", "SharedCoin determineOutputsToOfferNextStage ");		

		Transaction tx = new Transaction(this.sharedCoin.params, Hex.decode(tx_hex.getBytes()), 0, null, false, true, Message.UNKNOWN_LENGTH);
    	List<TransactionOutput> transactionOutputs = tx.getOutputs();

		JSONArray outpoints_to_offer_next_stage = new JSONArray();
    	Log.d("SharedCoin", "SharedCoin determineOutputsToOfferNextStage transactionOutputs.size() " + transactionOutputs.size());		
		
		for (int i = 0; i < transactionOutputs.size(); i++) {					
			TransactionOutput output = transactionOutputs.get(i);

			Log.d("SharedCoin", "SharedCoin determineOutputsToOfferNextStage i " + i);		

    		if (isOutputOneWeRequested(output)) {
    			if (isOutputChange(output)) {   			
					JSONObject dict = new JSONObject();
					dict.put("hash", null);
					dict.put("index", (long) i);
					dict.put("value", output.getValue().toString());
		    		outpoints_to_offer_next_stage.add(dict);
    			}		    			
    		}
		}
		Log.d("SharedCoin", "SharedCoin determineOutputsToOfferNextStage outpoints_to_offer_next_stage.size " + outpoints_to_offer_next_stage.size());		

		objectSuccessCallback.onSuccess(outpoints_to_offer_next_stage);
		
	} catch (ProtocolException e) {
		objectSuccessCallback.onFail(e.getLocalizedMessage());
		e.printStackTrace();
	}			
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:36,代码来源:SharedCoin.java

示例15: isStandard

import com.google.bitcoin.core.TransactionOutput; //导入依赖的package包/类
/**
 * <p>Checks if a transaction is considered "standard" by the reference client's IsStandardTx and AreInputsStandard
 * functions.</p>
 *
 * <p>Note that this method currently only implements a minimum of checks. More to be added later.</p>
 *
 * @return Either null if the transaction is standard, or the first transaction found which is considered nonstandard
 */
public Transaction isStandard(Transaction tx) {
    if (tx.getVersion() > 1 || tx.getVersion() < 1)
        return tx;

    for (TransactionOutput output : tx.getOutputs()) {
        if (output.getMinNonDustValue().compareTo(output.getValue()) > 0)
            return tx;
    }

    return null;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:20,代码来源:DefaultRiskAnalysis.java


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