mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
txscript: Optimize ExtractPkScriptAltSigType.
This converts the ExtractPkScriptAltSigType function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. It is important to note that this new implementation intentionally has the same semantic differences from the existing implementation as discussed in the relevant commits that introduced the extraction functions. The following is a before and after comparison of analyzing a typical script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkExtractAltSigType 497 12.8 -97.42% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkExtractAltSigType 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkExtractAltSigType 896 0 -100.00%
This commit is contained in:
parent
aaebc79459
commit
2fd1dcbbff
@ -1572,38 +1572,21 @@ func extractOneBytePush(po parsedOpcode) int {
|
||||
|
||||
// ExtractPkScriptAltSigType returns the signature scheme to use for an
|
||||
// alternative check signature script.
|
||||
//
|
||||
// NOTE: This function only attempts to identify version 0 scripts. Since the
|
||||
// function does not accept a script version, the results are undefined for
|
||||
// other script versions.
|
||||
func ExtractPkScriptAltSigType(pkScript []byte) (dcrec.SignatureType, error) {
|
||||
pops, err := parseScript(pkScript)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if pk, sigType := extractPubKeyAltDetails(pkScript); pk != nil {
|
||||
return sigType, nil
|
||||
}
|
||||
|
||||
isPKA := isPubkeyAlt(pops)
|
||||
isPKHA := isPubkeyHashAlt(pops)
|
||||
if !(isPKA || isPKHA) {
|
||||
return -1, fmt.Errorf("wrong script type")
|
||||
if pk, sigType := extractPubKeyHashAltDetails(pkScript); pk != nil {
|
||||
return sigType, nil
|
||||
}
|
||||
|
||||
sigTypeLoc := 1
|
||||
if isPKHA {
|
||||
sigTypeLoc = 4
|
||||
}
|
||||
|
||||
valInt := extractOneBytePush(pops[sigTypeLoc])
|
||||
if valInt < 0 {
|
||||
return 0, fmt.Errorf("bad type push")
|
||||
}
|
||||
val := dcrec.SignatureType(valInt)
|
||||
switch val {
|
||||
case dcrec.STEd25519:
|
||||
return val, nil
|
||||
case dcrec.STSchnorrSecp256k1:
|
||||
return val, nil
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
return -1, fmt.Errorf("bad signature scheme type")
|
||||
return -1, fmt.Errorf("not a standard pay-to-alt-pubkey or " +
|
||||
"pay-to-alt-pubkey-hash script")
|
||||
}
|
||||
|
||||
// AtomicSwapDataPushes houses the data pushes found in atomic swap contracts.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user