txscript: Optimize ExtractPkScriptAddrs stakechange.

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 stake-change-tagged
pay-to-pubkey-hash and pay-to-script-hash scripts.
This commit is contained in:
Dave Collins 2019-03-13 01:12:37 -05:00
parent a754af9145
commit c9bce2a0fb
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2

View File

@ -1521,27 +1521,24 @@ func ExtractPkScriptAddrs(version uint16, pkScript []byte,
return StakeRevocationTy, scriptHashToAddrs(hash, chainParams), 1, nil
}
// Check for stake change script. Only stake-change-tagged
// pay-to-pubkey-hash and pay-to-script-hash are allowed.
if hash := extractStakePubKeyHash(pkScript, OP_SSTXCHANGE); hash != nil {
return StakeSubChangeTy, pubKeyHashToAddrs(hash, chainParams), 1, nil
}
if hash := extractStakeScriptHash(pkScript, OP_SSTXCHANGE); hash != nil {
return StakeSubChangeTy, scriptHashToAddrs(hash, chainParams), 1, nil
}
// Fall back to slow path. Ultimately these are intended to be replaced by
// faster variants based on the unparsed raw scripts.
var addrs []dcrutil.Address
var requiredSigs int
var err error
scriptClass := typeOfScript(version, pkScript)
switch scriptClass {
case StakeSubChangeTy:
// A pay-to-stake-submission-change-hash script is of the form:
// OP_SSTXCHANGE ... P2PKH or P2SH
var localAddrs []dcrutil.Address
_, localAddrs, requiredSigs, err =
ExtractPkScriptAddrs(version, getStakeOutSubscript(pkScript),
chainParams)
if err == nil {
addrs = append(addrs, localAddrs...)
}
case NullDataTy:
// Null data transactions have no addresses or required
// signatures.