diff --git a/txscript/bench_test.go b/txscript/bench_test.go index 529d32f7..fda83771 100644 --- a/txscript/bench_test.go +++ b/txscript/bench_test.go @@ -312,3 +312,18 @@ func BenchmarkIsWitnessScriptHash(b *testing.B) { _ = IsPayToWitnessScriptHash(script) } } + +// BenchmarkIsNullDataScript benchmarks how long it takes to analyze a very +// large script to determine if it is a standard nulldata script. +func BenchmarkIsNullDataScript(b *testing.B) { + script, err := genComplexScript() + if err != nil { + b.Fatalf("failed to create benchmark script: %v", err) + } + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _ = IsNullData(script) + } +} diff --git a/txscript/script.go b/txscript/script.go index 5968cec7..7f812207 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -151,6 +151,16 @@ func isWitnessProgram(pops []parsedOpcode) bool { (len(pops[1].data) >= 2 && len(pops[1].data) <= 40) } +// IsNullData returns true if the passed script is a null data script, false +// otherwise. +func IsNullData(script []byte) bool { + pops, err := parseScript(script) + if err != nil { + return false + } + return isNullData(pops) +} + // ExtractWitnessProgramInfo attempts to extract the witness program version, // as well as the witness program itself from the passed script. func ExtractWitnessProgramInfo(script []byte) (int, []byte, error) {