本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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) {
}
}
示例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);
}
示例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;
}
}
示例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();
}
}
}
}
示例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;
}