diff --git a/txscript/bench_test.go b/txscript/bench_test.go index 6415c595a5..401b9683a5 100644 --- a/txscript/bench_test.go +++ b/txscript/bench_test.go @@ -144,3 +144,18 @@ func BenchmarkIsPubKeyScript(b *testing.B) { _ = IsPayToPubKey(script) } } + +// BenchmarkIsPubKeyHashScript benchmarks how long it takes to analyze a very +// large script to determine if it is a standard pay-to-pubkey-hash script. +func BenchmarkIsPubKeyHashScript(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++ { + _ = IsPayToPubKeyHash(script) + } +} diff --git a/txscript/script.go b/txscript/script.go index 00df52167b..fb4fc8bc88 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -69,6 +69,16 @@ func IsPayToPubKey(script []byte) bool { return isPubKeyScript(script) } +// IsPayToPubKeyHash returns true if the script is in the standard +// pay-to-pubkey-hash (P2PKH) format, false otherwise. +func IsPayToPubKeyHash(script []byte) bool { + pops, err := parseScript(script) + if err != nil { + return false + } + return isPubkeyHash(pops) +} + // IsPayToScriptHash returns true if the script is in the standard // pay-to-script-hash (P2SH) format, false otherwise. func IsPayToScriptHash(script []byte) bool {