mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
MockTransactionBroadcast: add to wallet.
This commit is contained in:
parent
2468100937
commit
c36989cfce
@ -18,7 +18,10 @@ package com.google.bitcoin.utils;
|
|||||||
|
|
||||||
import com.google.bitcoin.core.Transaction;
|
import com.google.bitcoin.core.Transaction;
|
||||||
import com.google.bitcoin.core.TransactionBroadcaster;
|
import com.google.bitcoin.core.TransactionBroadcaster;
|
||||||
|
import com.google.bitcoin.core.VerificationException;
|
||||||
import com.google.bitcoin.core.Wallet;
|
import com.google.bitcoin.core.Wallet;
|
||||||
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@ -31,6 +34,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
*/
|
*/
|
||||||
public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
||||||
private final ReentrantLock lock = Threading.lock("mock tx broadcaster");
|
private final ReentrantLock lock = Threading.lock("mock tx broadcaster");
|
||||||
|
private final Wallet wallet;
|
||||||
|
|
||||||
public static class TxFuturePair {
|
public static class TxFuturePair {
|
||||||
public Transaction tx;
|
public Transaction tx;
|
||||||
@ -49,6 +53,7 @@ public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
|||||||
// so inversions can be caught.
|
// so inversions can be caught.
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
this.wallet = wallet;
|
||||||
wallet.getPendingTransactions();
|
wallet.getPendingTransactions();
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@ -62,6 +67,20 @@ public class MockTransactionBroadcaster implements TransactionBroadcaster {
|
|||||||
try {
|
try {
|
||||||
SettableFuture<Transaction> result = SettableFuture.create();
|
SettableFuture<Transaction> result = SettableFuture.create();
|
||||||
broadcasts.put(new TxFuturePair(tx, result));
|
broadcasts.put(new TxFuturePair(tx, result));
|
||||||
|
Futures.addCallback(result, new FutureCallback<Transaction>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Transaction result) {
|
||||||
|
try {
|
||||||
|
wallet.receivePending(result, null);
|
||||||
|
} catch (VerificationException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable t) {
|
||||||
|
}
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user