Ejemplo n.º 1
0
 @Override
 public CoinSelection select(Coin target, List<TransactionOutput> candidates) {
   try {
     LinkedList<TransactionOutput> gathered = Lists.newLinkedList();
     Coin valueGathered = Coin.ZERO;
     for (TransactionOutput output : candidates) {
       if (ignorePending && !isConfirmed(output)) continue;
       // Find the key that controls output, assuming it's a regular pay-to-pubkey or
       // pay-to-address output.
       // We ignore any other kind of exotic output on the assumption we can't spend it ourselves.
       final Script scriptPubKey = output.getScriptPubKey();
       ECKey controllingKey;
       if (scriptPubKey.isSentToRawPubKey()) {
         controllingKey = wallet.findKeyFromPubKey(scriptPubKey.getPubKey());
       } else if (scriptPubKey.isSentToAddress()) {
         controllingKey = wallet.findKeyFromPubHash(scriptPubKey.getPubKeyHash());
       } else {
         log.info("Skipping tx output {} because it's not of simple form.", output);
         continue;
       }
       checkNotNull(
           controllingKey, "Coin selector given output as candidate for which we lack the key");
       if (controllingKey.getCreationTimeSeconds() >= unixTimeSeconds) continue;
       // It's older than the cutoff time so select.
       valueGathered = valueGathered.add(output.getValue());
       gathered.push(output);
       if (gathered.size() >= MAX_SIMULTANEOUS_INPUTS) {
         log.warn(
             "Reached {} inputs, going further would yield a tx that is too large, stopping here.",
             gathered.size());
         break;
       }
     }
     return new CoinSelection(valueGathered, gathered);
   } catch (ScriptException e) {
     throw new RuntimeException(
         e); // We should never have problems understanding scripts in our wallet.
   }
 }
Ejemplo n.º 2
0
  private Result analyzeIsFinal() {
    // Transactions we create ourselves are, by definition, not at risk of double spending against
    // us.
    if (tx.getConfidence().getSource() == TransactionConfidence.Source.SELF) return Result.OK;

    final int height = wallet.getLastBlockSeenHeight();
    final long time = wallet.getLastBlockSeenTimeSecs();
    // If the transaction has a lock time specified in blocks, we consider that if the tx would
    // become final in the
    // next block it is not risky (as it would confirm normally).
    final int adjustedHeight = height + 1;

    if (!tx.isFinal(adjustedHeight, time)) {
      nonFinal = tx;
      return Result.NON_FINAL;
    }
    for (Transaction dep : dependencies) {
      if (!dep.isFinal(adjustedHeight, time)) {
        nonFinal = dep;
        return Result.NON_FINAL;
      }
    }
    return Result.OK;
  }
Ejemplo n.º 3
0
  private Result analyzeIsStandard() {
    // The IsStandard rules don't apply on testnet, because they're just a safety mechanism and we
    // don't want to
    // crush innovation with valueless test coins.
    if (!wallet.getNetworkParameters().getId().equals(NetworkParameters.ID_MAINNET))
      return Result.OK;

    RuleViolation ruleViolation = isStandard(tx);
    if (ruleViolation != RuleViolation.NONE) {
      nonStandard = tx;
      return Result.NON_STANDARD;
    }

    for (Transaction dep : dependencies) {
      ruleViolation = isStandard(dep);
      if (ruleViolation != RuleViolation.NONE) {
        nonStandard = dep;
        return Result.NON_STANDARD;
      }
    }

    return Result.OK;
  }