txscript: Optimize ExtractPkScriptAddrs pubkey.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for pay-to-pubkey scripts.
This commit is contained in:
parent
16bd6633b6
commit
0e810b4ef4
1 changed files with 10 additions and 11 deletions
|
@ -858,6 +858,16 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
|
|||
return ScriptHashTy, scriptHashToAddrs(hash, chainParams), 1, nil
|
||||
}
|
||||
|
||||
// Check for pay-to-pubkey script.
|
||||
if data := extractPubKey(pkScript); data != nil {
|
||||
var addrs []btcutil.Address
|
||||
addr, err := btcutil.NewAddressPubKey(data, chainParams)
|
||||
if err == nil {
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
return PubKeyTy, addrs, 1, nil
|
||||
}
|
||||
|
||||
// Fall back to slow path. Ultimately these are intended to be replaced by
|
||||
// faster variants based on the unparsed raw scripts.
|
||||
|
||||
|
@ -887,17 +897,6 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
|
|||
addrs = append(addrs, addr)
|
||||
}
|
||||
|
||||
case PubKeyTy:
|
||||
// A pay-to-pubkey script is of the form:
|
||||
// <pubkey> OP_CHECKSIG
|
||||
// Therefore the pubkey is the first item on the stack.
|
||||
// Skip the pubkey if it's invalid for some reason.
|
||||
requiredSigs = 1
|
||||
addr, err := btcutil.NewAddressPubKey(pops[0].data, chainParams)
|
||||
if err == nil {
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
|
||||
case WitnessV0ScriptHashTy:
|
||||
// A pay-to-witness-script-hash script is of the form:
|
||||
// OP_0 <32-byte hash>
|
||||
|
|
Loading…
Reference in a new issue