Exemplo n.º 1
0
 /** Returns a human readable debug string. */
 @Override
 public String toString() {
   try {
     Script script = getScriptPubKey();
     StringBuilder buf = new StringBuilder("TxOut of ");
     buf.append(Coin.valueOf(value).toFriendlyString());
     if (script.isSentToAddress() || script.isPayToScriptHash())
       buf.append(" to ").append(script.getToAddress(params));
     else if (script.isSentToRawPubKey())
       buf.append(" to pubkey ").append(Utils.HEX.encode(script.getPubKey()));
     else if (script.isSentToMultiSig()) buf.append(" to multisig");
     else buf.append(" (unknown type)");
     buf.append(" script:");
     buf.append(script);
     return buf.toString();
   } catch (ScriptException e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 2
0
 /** Returns true if this output is to a key, or an address we have the keys for, in the wallet. */
 public boolean isMine(Wallet wallet) {
   try {
     Script script = getScriptPubKey();
     if (script.isSentToRawPubKey()) {
       byte[] pubkey = script.getPubKey();
       return wallet.isPubKeyMine(pubkey);
     }
     if (script.isPayToScriptHash()) {
       return wallet.isPayToScriptHashMine(script.getPubKeyHash());
     } else {
       byte[] pubkeyHash = script.getPubKeyHash();
       return wallet.isPubKeyHashMine(pubkeyHash);
     }
   } catch (ScriptException e) {
     // Just means we didn't understand the output of this transaction: ignore it.
     log.debug("Could not parse tx output script: {}", e.toString());
     return false;
   }
 }
Exemplo n.º 3
0
  public Address getAddressForOutput(TransactionOutput out) {
    try {
      Script script = out.getScriptPubKey();
      if (script.isSentToRawPubKey()) {
        byte[] key = out.getScriptPubKey().getPubKey();
        byte[] address_bytes = com.google.bitcoin.core.Utils.sha256hash160(key);
        Address a = new Address(params, address_bytes);
        return a;
      } else {
        Address a = script.getToAddress(params);
        return a;
      }
    } catch (ScriptException e) {

      // System.out.println(out.getParentTransaction().getHash() + " - " + out);
      // e.printStackTrace();
      // jelly.getEventLog().log("Unable process tx output: " +
      // out.getParentTransaction().getHash());
    }
    return null;
  }