本文整理了Java中org.bitcoinj.core.Transaction.getValueSentToMe()
方法的一些代码示例,展示了Transaction.getValueSentToMe()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.getValueSentToMe()
方法的具体详情如下:
包路径:org.bitcoinj.core.Transaction
类名称:Transaction
方法名:getValueSentToMe
[英]Calculates the sum of the outputs that are sending coins to a key in the wallet.
[中]计算将硬币发送到钱包钥匙的输出总和。
代码示例来源:origin: Coinomi/coinomi-android
public Value getValueReceived(TransactionWatcherWallet wallet) {
if (isTrimmed) {
return getValueReceived();
} else {
return type.value(tx.getValueSentToMe(wallet));
}
}
代码示例来源:origin: openwalletGH/openwallet-android
public Value getValueReceived(TransactionWatcherWallet wallet) {
if (isTrimmed) {
return getValueReceived();
} else {
return type.value(tx.getValueSentToMe(wallet));
}
}
代码示例来源:origin: fr.acinq/bitcoinj-core
private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
@Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
checkState(lock.isHeldByCurrentThread());
final Collection<Transaction> txns;
if (sortOrder != null) {
txns = new TreeSet<>(sortOrder);
txns.addAll(transactionMap.values());
} else {
txns = transactionMap.values();
}
for (Transaction tx : txns) {
try {
builder.append(tx.getValue(this).toFriendlyString());
builder.append(" total value (sends ");
builder.append(tx.getValueSentFromMe(this).toFriendlyString());
builder.append(" and receives ");
builder.append(tx.getValueSentToMe(this).toFriendlyString());
builder.append(")\n");
} catch (ScriptException e) {
// Ignore and don't print this line.
}
if (tx.hasConfidence())
builder.append(" confidence: ").append(tx.getConfidence()).append('\n');
builder.append(tx.toString(chain));
}
}
代码示例来源:origin: HashEngineering/dashj
private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
@Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
checkState(lock.isHeldByCurrentThread());
final Collection<Transaction> txns;
if (sortOrder != null) {
txns = new TreeSet<Transaction>(sortOrder);
txns.addAll(transactionMap.values());
} else {
txns = transactionMap.values();
}
for (Transaction tx : txns) {
try {
builder.append(tx.getValue(this).toFriendlyString());
builder.append(" total value (sends ");
builder.append(tx.getValueSentFromMe(this).toFriendlyString());
builder.append(" and receives ");
builder.append(tx.getValueSentToMe(this).toFriendlyString());
builder.append(")\n");
} catch (ScriptException e) {
// Ignore and don't print this line.
}
if (tx.hasConfidence())
builder.append(" confidence: ").append(tx.getConfidence()).append('\n');
builder.append(tx.toString(chain));
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
@Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
checkState(lock.isHeldByCurrentThread());
final Collection<Transaction> txns;
if (sortOrder != null) {
txns = new TreeSet<Transaction>(sortOrder);
txns.addAll(transactionMap.values());
} else {
txns = transactionMap.values();
}
for (Transaction tx : txns) {
try {
builder.append(tx.getValue(this).toFriendlyString());
builder.append(" total value (sends ");
builder.append(tx.getValueSentFromMe(this).toFriendlyString());
builder.append(" and receives ");
builder.append(tx.getValueSentToMe(this).toFriendlyString());
builder.append(")\n");
} catch (ScriptException e) {
// Ignore and don't print this line.
}
if (tx.hasConfidence())
builder.append(" confidence: ").append(tx.getConfidence()).append('\n');
builder.append(tx.toString(chain));
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs,
* and also returns true if tx has inputs that are spending outputs which are
* not ours but which are spent by pending transactions.</p>
*
* <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet,
* it will not be considered relevant.</p>
*/
public boolean isTransactionRelevant(Transaction tx) throws ScriptException {
lock.lock();
try {
return tx.getValueSentFromMe(this).signum() > 0 ||
tx.getValueSentToMe(this).signum() > 0 ||
!findDoubleSpendsAgainst(tx, transactions).isEmpty();
} finally {
lock.unlock();
}
}
代码示例来源:origin: HashEngineering/dashj
@Override
public void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
// Runs in the dedicated "user thread" (see bitcoinj docs for more info on this).
//
// The transaction "tx" can either be pending, or included into a block (we didn't see the broadcast).
Coin value = tx.getValueSentToMe(w);
System.out.println("Received tx for " + value.toFriendlyString() + ": " + tx);
System.out.println("Transaction will be forwarded after it confirms.");
// Wait until it's made it into the block chain (may run immediately if it's already there).
//
// For this dummy app of course, we could just forward the unconfirmed transaction. If it were
// to be double spent, no harm done. Wallet.allowSpendingUnconfirmedTransactions() would have to
// be called in onSetupCompleted() above. But we don't do that here to demonstrate the more common
// case of waiting for a block.
Futures.addCallback(tx.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() {
@Override
public void onSuccess(TransactionConfidence result) {
forwardCoins(tx);
}
@Override
public void onFailure(Throwable t) {
// This kind of future can't fail, just rethrow in case something weird happens.
throw new RuntimeException(t);
}
});
}
});
代码示例来源:origin: greenaddress/GreenBits
private void toStringHelper(StringBuilder builder, Map<Sha256Hash, Transaction> transactionMap,
@Nullable AbstractBlockChain chain, @Nullable Comparator<Transaction> sortOrder) {
checkState(lock.isHeldByCurrentThread());
final Collection<Transaction> txns;
if (sortOrder != null) {
txns = new TreeSet<>(sortOrder);
txns.addAll(transactionMap.values());
} else {
txns = transactionMap.values();
}
for (Transaction tx : txns) {
try {
builder.append(tx.getValue(this).toFriendlyString());
builder.append(" total value (sends ");
builder.append(tx.getValueSentFromMe(this).toFriendlyString());
builder.append(" and receives ");
builder.append(tx.getValueSentToMe(this).toFriendlyString());
builder.append(")\n");
} catch (ScriptException e) {
// Ignore and don't print this line.
}
if (tx.hasConfidence())
builder.append(" confidence: ").append(tx.getConfidence()).append('\n');
builder.append(tx.toString(chain));
}
}
代码示例来源:origin: HashEngineering/dashj
/**
* <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs,
* and also returns true if tx has inputs that are spending outputs which are
* not ours but which are spent by pending transactions.</p>
*
* <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet,
* it will not be considered relevant.</p>
*/
public boolean isTransactionRelevant(Transaction tx) throws ScriptException {
lock.lock();
try {
return tx.getValueSentFromMe(this).signum() > 0 ||
tx.getValueSentToMe(this).signum() > 0 ||
!findDoubleSpendsAgainst(tx, transactions).isEmpty();
} finally {
lock.unlock();
}
}
代码示例来源:origin: greenaddress/GreenBits
/**
* <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs,
* and also returns true if tx has inputs that are spending outputs which are
* not ours but which are spent by pending transactions.</p>
*
* <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet,
* it will not be considered relevant.</p>
*/
public boolean isTransactionRelevant(Transaction tx) throws ScriptException {
lock.lock();
try {
return tx.getValueSentFromMe(this).signum() > 0 ||
tx.getValueSentToMe(this).signum() > 0 ||
!findDoubleSpendsAgainst(tx, transactions).isEmpty();
} finally {
lock.unlock();
}
}
代码示例来源:origin: greenaddress/GreenBits
/**
* Returns the difference of {@link Transaction#getValueSentToMe(TransactionBag)} and {@link Transaction#getValueSentFromMe(TransactionBag)}.
*/
public Coin getValue(TransactionBag wallet) throws ScriptException {
// FIXME: TEMP PERF HACK FOR ANDROID - this crap can go away once we have a real payments API.
boolean isAndroid = Utils.isAndroidRuntime();
if (isAndroid && cachedValue != null && cachedForBag == wallet)
return cachedValue;
Coin result = getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
if (isAndroid) {
cachedValue = result;
cachedForBag = wallet;
}
return result;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
/**
* Returns the difference of {@link Transaction#getValueSentToMe(TransactionBag)} and {@link Transaction#getValueSentFromMe(TransactionBag)}.
*/
public Coin getValue(TransactionBag wallet) throws ScriptException {
// FIXME: TEMP PERF HACK FOR ANDROID - this crap can go away once we have a real payments API.
boolean isAndroid = Utils.isAndroidRuntime();
if (isAndroid && cachedValue != null && cachedForBag == wallet)
return cachedValue;
Coin result = getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
if (isAndroid) {
cachedValue = result;
cachedForBag = wallet;
}
return result;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* <p>Returns true if the given transaction sends coins to any of our keys, or has inputs spending any of our outputs,
* and also returns true if tx has inputs that are spending outputs which are
* not ours but which are spent by pending transactions.</p>
*
* <p>Note that if the tx has inputs containing one of our keys, but the connected transaction is not in the wallet,
* it will not be considered relevant.</p>
*/
public boolean isTransactionRelevant(Transaction tx) throws ScriptException {
lock.lock();
try {
if (watchMode && useSegwit())
return true;
return tx.getValueSentFromMe(this).signum() > 0 ||
tx.getValueSentToMe(this).signum() > 0 ||
!findDoubleSpendsAgainst(tx, transactions).isEmpty();
} finally {
lock.unlock();
}
}
代码示例来源:origin: HashEngineering/dashj
/**
* Returns the difference of {@link Transaction#getValueSentToMe(TransactionBag)} and {@link Transaction#getValueSentFromMe(TransactionBag)}.
*/
public Coin getValue(TransactionBag wallet) throws ScriptException {
// FIXME: TEMP PERF HACK FOR ANDROID - this crap can go away once we have a real payments API.
boolean isAndroid = Utils.isAndroidRuntime();
if (isAndroid && cachedValue != null && cachedForBag == wallet)
return cachedValue;
Coin result = getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
if (isAndroid) {
cachedValue = result;
cachedForBag = wallet;
}
return result;
}
代码示例来源:origin: fr.acinq/bitcoinj-core
/**
* Returns the difference of {@link Transaction#getValueSentToMe(TransactionBag)} and {@link Transaction#getValueSentFromMe(TransactionBag)}.
*/
public Coin getValue(TransactionBag wallet) throws ScriptException {
// FIXME: TEMP PERF HACK FOR ANDROID - this crap can go away once we have a real payments API.
boolean isAndroid = Utils.isAndroidRuntime();
if (isAndroid && cachedValue != null && cachedForBag == wallet)
return cachedValue;
Coin result = getValueSentToMe(wallet).subtract(getValueSentFromMe(wallet));
if (isAndroid) {
cachedValue = result;
cachedForBag = wallet;
}
return result;
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
return;
Coin valueSentToMe = tx.getValueSentToMe(this);
Coin valueSentFromMe = tx.getValueSentFromMe(this);
if (log.isInfoEnabled()) {
代码示例来源:origin: HashEngineering/dashj
private static void forwardCoins(Transaction tx) {
try {
Coin value = tx.getValueSentToMe(kit.wallet());
System.out.println("Forwarding " + value.toFriendlyString());
// Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
final Coin amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress, amountToSend);
checkNotNull(sendResult); // We should never try to send more coins than we have!
System.out.println("Sending ...");
// Register a callback that is invoked when the transaction has propagated across the network.
// This shows a second style of registering ListenableFuture callbacks, it works when you don't
// need access to the object the future returns.
sendResult.broadcastComplete.addListener(new Runnable() {
@Override
public void run() {
// The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
System.out.println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
}
}, MoreExecutors.sameThreadExecutor());
//MasternodeDB.dumpMasternodes();
FlatDB<MasternodeManager> mndb = new FlatDB<MasternodeManager>(kit.directory().getAbsolutePath(),"mncache.dat", "magicMasternodeCache");
mndb.dump(Context.get().masternodeManager);
} catch (KeyCrypterException | InsufficientMoneyException e) {
// We don't use encrypted wallets in this example - can never happen.
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: cash.bitcoinj/bitcoinj-core
boolean hasOutputsToMe = tx.getValueSentToMe(this).signum() > 0;
if (hasOutputsToMe) {
代码示例来源:origin: greenaddress/GreenBits
@Test
public void balances() throws Exception {
Coin nanos = COIN;
Transaction tx1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, nanos);
assertEquals(nanos, tx1.getValueSentToMe(wallet));
assertTrue(tx1.getWalletOutputs(wallet).size() >= 1);
// Send 0.10 to somebody else.
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 10));
// Reserialize.
Transaction send2 = PARAMS.getDefaultSerializer().makeTransaction(send1.bitcoinSerialize());
assertEquals(nanos, send2.getValueSentFromMe(wallet));
assertEquals(ZERO.subtract(valueOf(0, 10)), send2.getValue(wallet));
}
代码示例来源:origin: greenaddress/GreenBits
public void fragmentedReKeying() throws Exception {
// Send lots of small coins and check the fee is correct.
ECKey key = wallet.freshReceiveKey();
Address address = key.toAddress(PARAMS);
Utils.setMockClock();
Utils.rollMockClock(86400);
for (int i = 0; i < 800; i++) {
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, address);
}
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
Date compromise = Utils.now();
Utils.rollMockClock(86400);
wallet.freshReceiveKey();
wallet.setKeyRotationTime(compromise);
wallet.doMaintenance(null, true);
Transaction tx = broadcaster.waitForTransactionAndSucceed();
final Coin valueSentToMe = tx.getValueSentToMe(wallet);
Coin fee = tx.getValueSentFromMe(wallet).subtract(valueSentToMe);
assertEquals(Coin.valueOf(900000), fee);
assertEquals(KeyTimeCoinSelector.MAX_SIMULTANEOUS_INPUTS, tx.getInputs().size());
assertEquals(Coin.valueOf(599100000), valueSentToMe);
tx = broadcaster.waitForTransaction();
assertNotNull(tx);
assertEquals(200, tx.getInputs().size());
}
内容来源于网络,如有侵权,请联系作者删除!