question: public BigInteger calculateFee ( Wallet wallet ) { BigInteger totalOut = BigInteger . ZERO ; BigInteger totalIn = BigInteger . ZERO ; for ( TransactionInput input : getInputs ( ) ) { TransactionOutput connected = input . getConnectedOutput ( wallet . unspent ) ; if ( connected == null ) connected = input . getConnectedOutput ( wallet . spent ) ; if ( connected == null ) connected = input . getConnectedOutput ( wallet . pending ) ; if ( connected == null ) continue ; totalIn = totalIn . add ( connected . getValue ( ) ) ; } List < TransactionOutput > outputs = getOutputs ( ) ; for ( TransactionOutput output : outputs ) { totalOut = totalOut . add ( output . getValue ( ) ) ; } return totalIn . subtract ( totalOut ) ; }
target:  Calculate the fee for a spend