Skip to content

Commit

Permalink
txscript: Optimize ExtractWitnessProgramInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
cfromknecht committed Feb 5, 2021
1 parent f0b3095 commit 5c56138
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions txscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,16 @@ func IsNullData(script []byte) bool {
// 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) {
pops, err := parseScript(script)
if err != nil {
return 0, nil, err
}

// If at this point, the scripts doesn't resemble a witness program,
// then we'll exit early as there isn't a valid version or program to
// extract.
if !isWitnessProgram(pops) {
version, program, valid := extractWitnessProgramInfo(script)
if !valid {
return 0, nil, fmt.Errorf("script is not a witness program, " +
"unable to extract version or witness program")
}

witnessVersion := asSmallInt(pops[0].opcode.value)
witnessProgram := pops[1].data

return witnessVersion, witnessProgram, nil
return version, program, nil
}

// IsPushOnlyScript returns whether or not the passed script only pushes data
Expand Down

0 comments on commit 5c56138

Please sign in to comment.