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


Java TransactionOutput.getValue方法代码示例

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


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

示例1: select

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Override
public CoinSelection select(Coin target, List<TransactionOutput> candidates) {
    ArrayList<TransactionOutput> selected = new ArrayList<>();
    // 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<>(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.
    // TODO: Take in network parameters when instanatiated, and then test against the current network. Or just have a boolean parameter for "give me everything"
    if (!target.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.value) break;
        // Only pick chain-included transactions, or transactions that are ours and pending.
        if (!shouldSelect(output.getParentTransaction())) continue;
        selected.add(output);
        total += output.getValue().value;
    }
    // Total may be lower than target here, if the given candidates were insufficient to create to requested
    // transaction.
    return new CoinSelection(Coin.valueOf(total), selected);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:27,代码来源:DefaultCoinSelector.java

示例2: select

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Override
public CoinSelection select(Coin target, List<TransactionOutput> candidates) {
    ArrayList<TransactionOutput> selected = new ArrayList<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.
    // TODO: Take in network parameters when instanatiated, and then test against the current network. Or just have a boolean parameter for "give me everything"
    if (!target.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.value) break;
        // Only pick chain-included transactions, or transactions that are ours and pending.
        if (!shouldSelect(output.getParentTransaction())) continue;
        selected.add(output);
        total += output.getValue().value;
    }
    // Total may be lower than target here, if the given candidates were insufficient to create to requested
    // transaction.
    return new CoinSelection(Coin.valueOf(total), selected);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:27,代码来源:DefaultCoinSelector.java

示例3: select

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Override
public CoinSelection select(Coin biTarget, List<TransactionOutput> candidates) {
    long target = biTarget.value;
    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().value;
    }
    // Total may be lower than target here, if the given candidates were insufficient to create to requested
    // transaction.
    return new CoinSelection(Coin.valueOf(total), selected);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:27,代码来源:DefaultCoinSelector.java

示例4: broadCastTransaction

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Async
public void broadCastTransaction(Transaction t) {
    try {
        com.bitran.models.Transaction tx = new com.bitran.models.Transaction();
        tx.setTxid(t.getHashAsString());
        Long total = 0L;
        for (TransactionOutput to : t.getOutputs()) {
            Coin value = to.getValue();
            total += value.value;
        }
        tx.setAmount(total);
        String message = objectMapper.writeValueAsString(tx);

        TransactionSocket.sendTransaction(message);
        t = null;
        total = null;
        tx = null;
        message = null;

    } catch (IOException ex) {

    }
}
 
开发者ID:wwrrss,项目名称:bitran,代码行数:24,代码来源:BitcoinService.java

示例5: select

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Override
public CoinSelection select(Coin coin, List<TransactionOutput> list) {
    ArrayList<TransactionOutput> selected = new ArrayList<>();
    long total = 0;
    for (TransactionOutput txOut : list) {
        if (TransactionConfidence.ConfidenceType.BUILDING == txOut.getParentTransaction().getConfidence().getConfidenceType()) {
            total += txOut.getValue().value;
            selected.add(txOut);
        }
    }
    return new CoinSelection(Coin.valueOf(total), selected);
}
 
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:13,代码来源:CouponCoinSelector.java

示例6: sufficientFunds

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
@Override
public final boolean sufficientFunds(Address addr, long amount) throws CoinNetworkException, AddressFormatException, IOException {
    String address = addr.toString();

    List<Bitcoin.Transaction> transactions = getAddressTransactions(address);

    if (transactions.size() == 1) {
        Bitcoin.Transaction tx = transactions.get(0);
        if (!tx.confirmed) {
            return false;
        }
        long txAmount = 0;

        if (tx.bitcoinj == null) {
            try {
                tx.bitcoinj = getTransaction(tx.hash);
            } catch (IOException e) {
                return false;
            }
        }

        for (TransactionOutput output : tx.bitcoinj.getOutputs()) {

            /**
             * Every address in the outputs should be of type pay to public key hash, not pay to script hash
             */

            String addressP2pkh = output.getAddressFromP2PKHScript(netParams).toString();
            if (address.equals(addressP2pkh)) {
                txAmount += output.getValue().value;
            }
        }
        return txAmount >= amount;
    } else {
        return false;
    }
}
 
开发者ID:DanielKrawisz,项目名称:Shufflepuff,代码行数:38,代码来源:Bitcoin.java

示例7: send

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
static public void send(WalletOperation wo, Dispacher disp, Transaction tx, HowBalanceChanged howBalanceChanged) {
	if(howBalanceChanged == HowBalanceChanged.ReceivedCoins)
		for (TransactionOutput out : tx.getOutputs()){
			Script scr = out.getScriptPubKey();
			String addrStr = scr.getToAddress(wo.getNetworkParams()).toString();
			if(wo.isWatchingAddress(addrStr)){
				ATAddress add = wo.findAddressInAccounts(addrStr);
				if(add == null)
					continue;
		
				// incoming sum
				Coin receivedSum = out.getValue();
		
				ATAccount account = null;
				try {
					account = wo.getAccount(add.getAccountIndex());
					if(account.getAccountType() != WalletAccountType.AuthenticatorAccount)
						continue;
					PairedAuthenticator pairing = wo.getPairingObjectForAccountIndex(account.getIndex());
					SecretKey secretkey = new SecretKeySpec(Hex.decode(pairing.getAesKey()), "AES");						
					byte[] gcmID = pairing.getGCM().getBytes();
					assert(gcmID != null);
					Device d = new Device(pairing.getChainCode().getBytes(),
							pairing.getMasterPublicKey().getBytes(),
							gcmID,
							pairing.getPairingID().getBytes(),
							secretkey);
			
					System.out.println("Sending a Coins Received Notification");
					disp.dispachMessage(ATGCMMessageType.CoinsReceived, d, new String[]{ "Coins Received: " + receivedSum.toFriendlyString() });	
				} 
				catch (AccountWasNotFoundException | JSONException | IOException e1) {
					e1.printStackTrace();
				}
			}
		}
}
 
开发者ID:BitcoinAuthenticator,项目名称:Wallet,代码行数:38,代码来源:CoinsReceivedNotificationSender.java

示例8: TrimmedOutput

import org.bitcoinj.core.TransactionOutput; //导入方法依赖的package包/类
public TrimmedOutput(TransactionOutput output, long index, TrimmedTransaction tx) {
    super(output.getParams(), Preconditions.checkNotNull(tx), output.getValue(), output.getScriptBytes());
    this.index = index;
    this.txHash = null;
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:6,代码来源:TrimmedOutput.java


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