common/src/main/java/lighthouse/wallet/PledgingWallet.java
public void completeContractWithFee(Project project, Set<LHProtos.Pledge> pledges, @Nullable KeyParameter aesKey,
                                        TransactionBroadcast.ProgressCallback progress, Consumer<Throwable> error,
                                        Executor callbackExecutor) throws InsufficientMoneyException {
        // The chances of having a fee shaped output are minimal, so we always create a dependency tx here.
        // We x2 it to avoid problems with sitting right on the dust threshold for older peers.
        final Coin feeSize = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(2);
        log.info("Completing contract with fee: sending dependency tx");
        Transaction contract = project.completeContract(pledges);
        Wallet.SendRequest request = Wallet.SendRequest.to(freshReceiveKey().toAddress(params), feeSize);
        request.aesKey = aesKey;
        Wallet.SendResult result = sendCoins(vTransactionBroadcaster, request);

        TransactionBroadcast.ProgressCallback mergingCallback = new TransactionBroadcast.ProgressCallback() {
            double total, last;

            @Override
            public void onBroadcastProgress(double val) {
                // Progress will increment from 0.0 to 1.0 for the dep tx, and then reset to 0.0 and do it again.
                // But we want to present the user with a smooth 0.0 to 1.0 progress bar. So we aggregate them here.
                if (val < last)
                    last = 0.0;
                total += val - last;
                last = val;
                progress.onBroadcastProgress(total / 2.0);
            }
        };

        result.broadcast.setProgressCallback(mergingCallback, callbackExecutor);

        // The guava API is better for this than what the Java 8 guys produced, sigh.
        Futures.addCallback(result.broadcastComplete, new FutureCallback<Transaction>() {
                @Override
                public void onSuccess(@Nullable Transaction tx) {
                    // Runs on a bitcoinj thread when the dependency was broadcast.
                    // Find the right output size and add it as a regular input (that covers the rest).
                    log.info("Dependency broadcast complete");
                    TransactionOutput feeOut = tx.getOutputs().stream()
                            .filter(output -> output.getValue().equals(feeSize)).findAny().get();
                    contract.addInput(feeOut);
                    // Sign the final output we added.
                    SendRequest req = SendRequest.forTx(contract);
                    req.aesKey = aesKey;
                    signTransaction(req);
                    log.info("Prepared final contract: {}", contract);
                    TransactionBroadcast broadcast = vTransactionBroadcaster.broadcastTransaction(contract);
                    broadcast.setProgressCallback(mergingCallback, callbackExecutor);
                    Futures.addCallback(broadcast.future(), new FutureCallback<Transaction>() {
                        @Override
                        public void onSuccess(@Nullable Transaction result) {
                            log.info("Successfully broadcast claim");
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            log.error("Error broadcasting claim!", t);
                            error.accept(t);
                        }
                    }, callbackExecutor);
                }

                @Override
                public void onFailure(Throwable t) {
                    log.error("Dependency broadcast failed!", t);
                    callbackExecutor.execute(() -> error.accept(t));
                }
        });
    }
/**
     * Runs completeContract to get a feeless contract, then attaches an extra input of size MIN_FEE, potentially
     * creating and broadcasting a tx to create an output of the right size first (as we cannot add change outputs
     * to an assurance contract). The returned future completes once both dependency and contract are broadcast OK.
     */
Runs completeContract to get a feeless contract, then attaches an extra input of size MIN_FEE, potentially
creating and broadcasting a tx to create an output of the right size first (as we cannot add change outputs
to an assurance contract). The returned future completes once both dependency and contract are broadcast OK.
Runs completeContract to get a feeless contract then attaches an extra input of size MIN_FEE potentially creating and broadcasting a tx to create an output of the right size first ( as we cannot add change outputs to an assurance contract ) . The returned future completes once both dependency and contract are broadcast OK .
public void completeContractWithFee(Project project, Set<LHProtos.Pledge> pledges, @Nullable KeyParameter aesKey,
                                        TransactionBroadcast.ProgressCallback progress, Consumer<Throwable> error,
                                        Executor callbackExecutor) throws InsufficientMoneyException {
        final Coin feeSize = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(2);
        log.info("Completing contract with fee: sending dependency tx");
        Transaction contract = project.completeContract(pledges);
        Wallet.SendRequest request = Wallet.SendRequest.to(freshReceiveKey().toAddress(params), feeSize);
        request.aesKey = aesKey;
        Wallet.SendResult result = sendCoins(vTransactionBroadcaster, request);
        TransactionBroadcast.ProgressCallback mergingCallback = new TransactionBroadcast.ProgressCallback() {
            double total, last;
            @Override
            public void onBroadcastProgress(double val) {
                if (val < last)
                    last = 0.0;
                total += val - last;
                last = val;
                progress.onBroadcastProgress(total / 2.0);
            }
        };
        result.broadcast.setProgressCallback(mergingCallback, callbackExecutor);
        Futures.addCallback(result.broadcastComplete, new FutureCallback<Transaction>() {
                @Override
                public void onSuccess(@Nullable Transaction tx) {
                    log.info("Dependency broadcast complete");
                    TransactionOutput feeOut = tx.getOutputs().stream()
                            .filter(output -> output.getValue().equals(feeSize)).findAny().get();
                    contract.addInput(feeOut);
                    SendRequest req = SendRequest.forTx(contract);
                    req.aesKey = aesKey;
                    signTransaction(req);
                    log.info("Prepared final contract: {}", contract);
                    TransactionBroadcast broadcast = vTransactionBroadcaster.broadcastTransaction(contract);
                    broadcast.setProgressCallback(mergingCallback, callbackExecutor);
                    Futures.addCallback(broadcast.future(), new FutureCallback<Transaction>() {
                        @Override
                        public void onSuccess(@Nullable Transaction result) {
                            log.info("Successfully broadcast claim");
                        }
                        @Override
                        public void onFailure(Throwable t) {
                            log.error("Error broadcasting claim!", t);
                            error.accept(t);
                        }
                    }, callbackExecutor);
                }
                @Override
                public void onFailure(Throwable t) {
                    log.error("Dependency broadcast failed!", t);
                    callbackExecutor.execute(() -> error.accept(t));
                }
        });
    }
public void completeContractWithFee ( Project project , Set < LHProtos . Pledge > pledges , @ Nullable KeyParameter aesKey , TransactionBroadcast . ProgressCallback progress , Consumer < Throwable > error , Executor callbackExecutor ) throws InsufficientMoneyException { final Coin feeSize = Transaction . REFERENCE_DEFAULT_MIN_TX_FEE . multiply ( 2 ) ; log . info ( "Completing contract with fee: sending dependency tx" ) ; Transaction contract = project . completeContract ( pledges ) ; Wallet . SendRequest request = Wallet . SendRequest . to ( freshReceiveKey ( ) . toAddress ( params ) , feeSize ) ; request . aesKey = aesKey ; Wallet . SendResult result = sendCoins ( vTransactionBroadcaster , request ) ; TransactionBroadcast . ProgressCallback mergingCallback = new TransactionBroadcast . ProgressCallback ( ) { double total , last ; @ Override public void onBroadcastProgress ( double val ) { if ( val < last ) last = 0.0 ; total += val - last ; last = val ; progress . onBroadcastProgress ( total / 2.0 ) ; } } ; result . broadcast . setProgressCallback ( mergingCallback , callbackExecutor ) ; Futures . addCallback ( result . broadcastComplete , new FutureCallback < Transaction > ( ) { @ Override public void onSuccess ( @ Nullable Transaction tx ) { log . info ( "Dependency broadcast complete" ) ; TransactionOutput feeOut = tx . getOutputs ( ) . stream ( ) . filter ( output -> output . getValue ( ) . equals ( feeSize ) ) . findAny ( ) . get ( ) ; contract . addInput ( feeOut ) ; SendRequest req = SendRequest . forTx ( contract ) ; req . aesKey = aesKey ; signTransaction ( req ) ; log . info ( "Prepared final contract: {}" , contract ) ; TransactionBroadcast broadcast = vTransactionBroadcaster . broadcastTransaction ( contract ) ; broadcast . setProgressCallback ( mergingCallback , callbackExecutor ) ; Futures . addCallback ( broadcast . future ( ) , new FutureCallback < Transaction > ( ) { @ Override public void onSuccess ( @ Nullable Transaction result ) { log . info ( "Successfully broadcast claim" ) ; } @ Override public void onFailure ( Throwable t ) { log . error ( "Error broadcasting claim!" , t ) ; error . accept ( t ) ; } } , callbackExecutor ) ; } @ Override public void onFailure ( Throwable t ) { log . error ( "Dependency broadcast failed!" , t ) ; callbackExecutor . execute ( ( ) -> error . accept ( t ) ) ; } } ) ; }
Runs completeContract to get a feeless contract, then attaches an extra input of size MIN_FEE, potentially
 creating and broadcasting a tx to create an output of the right size first (as we cannot add change outputs
 to an assurance contract).
Runs completeContract to get a feeless contract then attaches an extra input of size MIN_FEE potentially creating and broadcasting a tx to create an output of the right size first ( as we cannot add change outputs to an assurance contract ) .
// The chances of having a fee shaped output are minimal, so we always create a dependency tx here. // We x2 it to avoid problems with sitting right on the dust threshold for older peers. // Progress will increment from 0.0 to 1.0 for the dep tx, and then reset to 0.0 and do it again. // But we want to present the user with a smooth 0.0 to 1.0 progress bar. So we aggregate them here. // The guava API is better for this than what the Java 8 guys produced, sigh. // Runs on a bitcoinj thread when the dependency was broadcast. // Find the right output size and add it as a regular input (that covers the rest). // Sign the final output we added.