mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Wallet: Add some convenience methods for spending unconfirmed transactions.
This commit is contained in:
parent
f1845dd552
commit
5eebca2c7d
@ -295,6 +295,24 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This coin selector will select any transaction at all, regardless of where it came from or whether it was
|
||||
* confirmed yet.
|
||||
*/
|
||||
public static class AllowUnconfirmedCoinSelector extends DefaultCoinSelector {
|
||||
@Override protected boolean shouldSelect(Transaction tx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static AllowUnconfirmedCoinSelector instance;
|
||||
public static AllowUnconfirmedCoinSelector get() {
|
||||
// This doesn't have to be thread safe as the object has no state, so discarded duplicates are harmless.
|
||||
if (instance == null)
|
||||
instance = new AllowUnconfirmedCoinSelector();
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private transient CoinSelector coinSelector = new DefaultCoinSelector();
|
||||
|
||||
// The keyCrypter for the wallet. This specifies the algorithm used for encrypting and decrypting the private keys.
|
||||
@ -1403,8 +1421,8 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given event listener object. Returns true if the listener was removed,
|
||||
* false if that listener was never added.
|
||||
* Removes the given event listener object. Returns true if the listener was removed, false if that listener
|
||||
* was never added.
|
||||
*/
|
||||
public boolean removeEventListener(WalletEventListener listener) {
|
||||
return eventListeners.remove(listener);
|
||||
@ -3048,6 +3066,15 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper for <tt>setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get())</tt>. If this method
|
||||
* is called on the wallet then transactions will be used for spending regardless of their confidence. This can
|
||||
* be dangerous - only use this if you absolutely know what you're doing!
|
||||
*/
|
||||
public void allowSpendingUnconfirmedTransactions() {
|
||||
setCoinSelector(Wallet.AllowUnconfirmedCoinSelector.get());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Boilerplate for running event listeners - unlocks the wallet, runs, re-locks.
|
||||
|
@ -426,11 +426,7 @@ public class WalletTool {
|
||||
Wallet.SendRequest req = Wallet.SendRequest.forTx(t);
|
||||
req.fee = fee;
|
||||
if (allowUnconfirmed) {
|
||||
wallet.setCoinSelector(new Wallet.DefaultCoinSelector() {
|
||||
@Override protected boolean shouldSelect(Transaction tx) {
|
||||
return true; // Accept any transaction that's spendable.
|
||||
}
|
||||
});
|
||||
wallet.allowSpendingUnconfirmedTransactions();
|
||||
}
|
||||
if (password != null) {
|
||||
if (!wallet.checkPassword(password)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user