@@ -55,12 +55,13 @@ type ScriptClass byte
5555
5656// Classes of script payment known about in the blockchain.
5757const (
58- NonStandardTy ScriptClass = iota // None of the recognized forms.
59- PubKeyTy // Pay pubkey.
60- PubKeyHashTy // Pay pubkey hash.
61- ScriptHashTy // Pay to script hash.
62- MultiSigTy // Multi signature.
63- NullDataTy // Empty data-only (provably prunable).
58+ NonStandardTy ScriptClass = iota // None of the recognized forms.
59+ PubKeyTy // Pay pubkey.
60+ PubKeyHashTy // Pay pubkey hash.
61+ ScriptHashTy // Pay to script hash.
62+ ScriptHash32Ty // Pay to script hash 32
63+ MultiSigTy // Multi signature.
64+ NullDataTy // Empty data-only (provably prunable).
6465)
6566
6667// scriptClassToName houses the human-readable strings which describe each
@@ -186,6 +187,8 @@ func typeOfScript(pops []parsedOpcode) ScriptClass {
186187 return PubKeyHashTy
187188 } else if isScriptHash (pops ) {
188189 return ScriptHashTy
190+ } else if isScriptHash32 (pops ) {
191+ return ScriptHash32Ty
189192 } else if isMultiSig (pops ) {
190193 return MultiSigTy
191194 } else if isNullData (pops ) {
@@ -355,6 +358,13 @@ func payToScriptHashScript(scriptHash []byte) ([]byte, error) {
355358 AddOp (OP_EQUAL ).Script ()
356359}
357360
361+ // payToScriptHashScript creates a new script to pay a transaction output to a
362+ // script hash. It is expected that the input is a valid hash.
363+ func payToScriptHashScript32 (scriptHash []byte ) ([]byte , error ) {
364+ return NewScriptBuilder ().AddOp (OP_HASH256 ).AddData (scriptHash ).
365+ AddOp (OP_EQUAL ).Script ()
366+ }
367+
358368// payToPubkeyScript creates a new script to pay a transaction output to a
359369// public key. It is expected that the input is a valid pubkey.
360370func payToPubKeyScript (serializedPubKey []byte ) ([]byte , error ) {
@@ -392,6 +402,12 @@ func PayToAddrScript(addr bchutil.Address) ([]byte, error) {
392402 nilAddrErrStr )
393403 }
394404 return payToScriptHashScript (addr .ScriptAddress ())
405+ case * bchutil.AddressScriptHash32 :
406+ if addr == nil {
407+ return nil , scriptError (ErrUnsupportedAddress ,
408+ nilAddrErrStr )
409+ }
410+ return payToScriptHashScript32 (addr .ScriptAddress ())
395411 case * bchutil.AddressPubKey :
396412 if addr == nil {
397413 return nil , scriptError (ErrUnsupportedAddress ,
@@ -512,6 +528,18 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script
512528 addrs = append (addrs , addr )
513529 }
514530
531+ case ScriptHash32Ty :
532+ // A pay-to-script-hash32 script is of the form:
533+ // OP_HASH256 <scripthash> OP_EQUAL
534+ // Therefore the script hash is the 2nd item on the stack.
535+ // Skip the script hash if it's invalid for some reason.
536+ requiredSigs = 1
537+ addr , err := bchutil .NewAddressScriptHash32FromHash (pops [1 ].data ,
538+ chainParams )
539+ if err == nil {
540+ addrs = append (addrs , addr )
541+ }
542+
515543 case MultiSigTy :
516544 // A multi-signature script is of the form:
517545 // <numsigs> <pubkey> <pubkey> <pubkey>... <numpubkeys> OP_CHECKMULTISIG
0 commit comments