mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 10:12:19 +01:00
DefaultRiskAnalysis: extract output testing into a separate method also, and add a (presently unused) new rule violation type.
This commit is contained in:
parent
5fc98d2c07
commit
a8f85d1158
@ -107,7 +107,8 @@ public class DefaultRiskAnalysis implements RiskAnalysis {
|
||||
NONE,
|
||||
VERSION,
|
||||
DUST,
|
||||
SHORTEST_POSSIBLE_PUSHDATA
|
||||
SHORTEST_POSSIBLE_PUSHDATA,
|
||||
NONEMPTY_STACK // Not yet implemented (for post 0.12)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,16 +127,10 @@ public class DefaultRiskAnalysis implements RiskAnalysis {
|
||||
final List<TransactionOutput> outputs = tx.getOutputs();
|
||||
for (int i = 0; i < outputs.size(); i++) {
|
||||
TransactionOutput output = outputs.get(i);
|
||||
if (MIN_ANALYSIS_NONDUST_OUTPUT.compareTo(output.getValue()) > 0) {
|
||||
log.warn("TX considered non-standard due to output {} being dusty", i);
|
||||
return RuleViolation.DUST;
|
||||
}
|
||||
for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) {
|
||||
if (chunk.isPushData() && !chunk.isShortestPossiblePushData()) {
|
||||
log.warn("TX considered non-standard due to output {} having a longer than necessary data push: {}",
|
||||
i, chunk);
|
||||
return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
|
||||
}
|
||||
RuleViolation violation = isOutputStandard(output);
|
||||
if (violation != RuleViolation.NONE) {
|
||||
log.warn("TX considered non-standard due to output {} violating rule {}", i, violation);
|
||||
return violation;
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +147,19 @@ public class DefaultRiskAnalysis implements RiskAnalysis {
|
||||
return RuleViolation.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the output to see if the script violates a standardness rule. Not complete.
|
||||
*/
|
||||
public static RuleViolation isOutputStandard(TransactionOutput output) {
|
||||
if (MIN_ANALYSIS_NONDUST_OUTPUT.compareTo(output.getValue()) > 0)
|
||||
return RuleViolation.DUST;
|
||||
for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) {
|
||||
if (chunk.isPushData() && !chunk.isShortestPossiblePushData())
|
||||
return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA;
|
||||
}
|
||||
return RuleViolation.NONE;
|
||||
}
|
||||
|
||||
/** Checks if the given input passes some of the AreInputsStandard checks. Not complete. */
|
||||
public static RuleViolation isInputStandard(TransactionInput input) {
|
||||
for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
|
||||
|
Loading…
Reference in New Issue
Block a user