package org.bitcoinj.quorums;

import org.bitcoinj.core.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by hashengineering on 5/1/19.
 */
public class LLMQBackgroundThread extends Thread {
    private static final Logger log = LoggerFactory.getLogger(LLMQBackgroundThread.class);

    Context context;
    public LLMQBackgroundThread(Context context) {
        this.context = context;
    }

    int debugTimer = 0;

    @Override
    public void run() {
        Context.propagate(context);
        try {
            context.signingManager.addRecoveredSignatureListener(context.instantSendManager);
            context.signingManager.addRecoveredSignatureListener(context.chainLockHandler);
            while (!isInterrupted()) {
                boolean didWork = false;

                didWork |= context.instantSendManager.processPendingInstantSendLocks();

                didWork |= context.signingManager.processPendingRecoveredSigs();

                context.signingManager.cleanup();



                if (!didWork) {
                    Thread.sleep(100);
                } else {
                    debugTimer++;
                    if(debugTimer % 100 == 0) {
                        log.info(context.instantSendManager.toString());
                    }
                }
            }
        } catch (InterruptedException x) {
            //let the thread stop
            context.signingManager.removeRecoveredSignatureListener(context.instantSendManager);
            context.signingManager.removeRecoveredSignatureListener(context.chainLockHandler);
        }
    }
}

@@ -1115,20 +1115,10 @@
    %7D
- else %7B%0A    
+%0A%0A
     
@@ -1159,20 +1159,16 @@
         
-    
 if(debug
@@ -1175,17 +1175,17 @@
 Timer %25 
-1
+2
 00 == 0)
@@ -1183,28 +1183,24 @@
 200 == 0) %7B%0A
-    
             
@@ -1268,33 +1268,94 @@
                 
-%7D
+if(debugTimer == 1000)%0A                        debugTimer = 0;
 %0A               
@@ -1349,32 +1349,33 @@
               %7D%0A
+%0A
             %7D%0A  

Change reporting of InstantSendManager