package org.bitcoinj.wallet;

import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.params.RegTestParams;

/**
 * Created by Eric on 1/15/2016.
 */
public class InstantXCoinSelector extends DefaultCoinSelector {

    boolean usingInstantX = false;
    public InstantXCoinSelector()
    {

    }
    public void setUsingInstantX(boolean usingInstantX)
    {
        this.usingInstantX = usingInstantX;
    }
    @Override
    protected boolean shouldSelect(Transaction tx) {
        if (tx != null) {
            return isSelectable(tx, usingInstantX);
        }
        return true;
    }
    public static boolean isSelectable(Transaction tx, boolean usingInstantX) {
        // Only pick chain-included transactions, or transactions that are ours and pending.
        TransactionConfidence confidence = tx.getConfidence();
        TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
        return (type.equals(TransactionConfidence.ConfidenceType.BUILDING) && ( usingInstantX ? confidence.getDepthInBlocks() >= 6 : true))||
                //type.equals(TransactionConfidence.ConfidenceType.INSTANTX_LOCKED) || //TODO:InstantX
                type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
                        confidence.getSource().equals(TransactionConfidence.Source.SELF) && ( usingInstantX ? false : true) &&
                        // In regtest mode we expect to have only one peer, so we won't see transactions propagate.
                        // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
                        (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
    }
}

@@ -1,8 +1,570 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 
@@ -736,12 +736,24 @@
  by 
-Eric
+Hash Engineering
  on 
@@ -1367,25 +1367,86 @@
 are 
-ours and pending.
+pending (whether ours or not).%0A        // InstantSend requires 6 confirmations
 %0A   
@@ -1664,25 +1664,24 @@
 ILDING) && (
- 
 usingInstant
@@ -1731,285 +1731,90 @@
 ue))
-%7C%7C%0A                //type.equals(TransactionConfidence.ConfidenceType.INSTANTX_LOCKED) %7C%7C //TODO:InstantX%0A                type.equals(TransactionConfidence.ConfidenceType.PENDING) &&%0A                        confidence.getSource().equals(TransactionConfidence.Source.SELF) && ( 
+ %7C%7C%0A                type.equals(TransactionConfidence.ConfidenceType.PENDING) && (
 usin

Allow sending of pending coins that were received. Add license notice.