code: public boolean isMine(TransactionBag transactionBag) {
          try {
              Script script = getScriptPubKey();
              if (ScriptPattern.isP2PK(script))
                  return transactionBag.isPubKeyMine(ScriptPattern.extractKeyFromP2PK(script));
              else if (ScriptPattern.isP2SH(script))
                  return transactionBag.isPayToScriptHashMine(ScriptPattern.extractHashFromP2SH(script));
              else if (ScriptPattern.isP2PKH(script))
                  return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromP2PKH(script),
                          Script.ScriptType.P2PKH);
              else if (ScriptPattern.isP2WPKH(script))
                  return transactionBag.isPubKeyHashMine(ScriptPattern.extractHashFromP2WH(script),
                          Script.ScriptType.P2WPKH);
              else
                  return false;
          } catch (ScriptException e) {
              // Just means we didn't understand the output of this transaction: ignore it.
              log.debug("Could not parse tx {} output script: {}",
                      parent != null ? ((Transaction) parent).getTxId() : "(no parent)", e.toString());
              return false;
          }
      }
docs: Returns true if this output is to a key, or an address we have the keys for, in the wallet.