WIP: next hard fork #5

Draft
BrannonKing wants to merge 178 commits from WIP-HF-2022 into master
2 changed files with 25 additions and 5 deletions
Showing only changes of commit c771f4fb38 - Show all commits

View file

@ -72,11 +72,7 @@ func IsPayToPubKey(script []byte) bool {
// IsPayToPubKeyHash returns true if the script is in the standard // IsPayToPubKeyHash returns true if the script is in the standard
// pay-to-pubkey-hash (P2PKH) format, false otherwise. // pay-to-pubkey-hash (P2PKH) format, false otherwise.
func IsPayToPubKeyHash(script []byte) bool { func IsPayToPubKeyHash(script []byte) bool {
pops, err := parseScript(script) return isPubKeyHashScript(script)
if err != nil {
return false
}
return isPubkeyHash(pops)
} }
// IsPayToScriptHash returns true if the script is in the standard // IsPayToScriptHash returns true if the script is in the standard

View file

@ -143,6 +143,30 @@ func isPubKeyScript(script []byte) bool {
return extractPubKey(script) != nil return extractPubKey(script) != nil
} }
// extractPubKeyHash extracts the public key hash from the passed script if it
// is a standard pay-to-pubkey-hash script. It will return nil otherwise.
func extractPubKeyHash(script []byte) []byte {
// A pay-to-pubkey-hash script is of the form:
// OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY OP_CHECKSIG
if len(script) == 25 &&
script[0] == OP_DUP &&
script[1] == OP_HASH160 &&
script[2] == OP_DATA_20 &&
script[23] == OP_EQUALVERIFY &&
script[24] == OP_CHECKSIG {
return script[3:23]
}
return nil
}
// isPubKeyHashScript returns whether or not the passed script is a standard
// pay-to-pubkey-hash script.
func isPubKeyHashScript(script []byte) bool {
return extractPubKeyHash(script) != nil
}
// isPubkey returns true if the script passed is a pay-to-pubkey transaction, // isPubkey returns true if the script passed is a pay-to-pubkey transaction,
// false otherwise. // false otherwise.
func isPubkey(pops []parsedOpcode) bool { func isPubkey(pops []parsedOpcode) bool {