txscript.ParsePkScript(scriptBytes) returns "unsupported script type" #14

Closed
opened 2022-01-19 20:48:09 +01:00 by roylee17 · 2 comments
roylee17 commented 2022-01-19 20:48:09 +01:00 (Migrated from github.com)

For example, transaction 5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba

 $ lbcctl getrawtransaction 5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba 1

{
  "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100e1f505000000002321024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac00000000",
  "txid": "5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba",
  "hash": "5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba",
  "size": 98,
  "vsize": 98,
  "weight": 392,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "coinbase": "510101",
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 1,
      "n": 0,
      "scriptPubKey": {
        "asm": "024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9 OP_CHECKSIG",
        "hex": "21024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac",
        "reqSigs": 1,
        "type": "pubkey",
        "subtype": "",
        "isclaim": false,
        "issupport": false,
        "addresses": [
          "bZi1WEjGtsdAwuZTnNNTCAZLxhHkiHec4m"
        ]
      }
    }
  ],
  "blockhash": "decb9e2cca03a419fd9cca0cb2b1d5ad11b088f22f8f38556d93ac4358b86c24",
  "confirmations": 1097697,
  "time": 1466646588,
  "blocktime": 1466646588
}

Decoding in code:

    outputScript := "21024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac"
    scriptBytes, _ := hex.DecodeString(outputScript)
    pk, err := txscript.ParsePkScript(scriptBytes)
unsupported script type
For example, transaction `5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba` ``` $ lbcctl getrawtransaction 5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba 1 { "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100e1f505000000002321024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac00000000", "txid": "5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba", "hash": "5dda81f42196d2647a173b008d729cf778d3f609adf84610837f039c2f8e88ba", "size": 98, "vsize": 98, "weight": 392, "version": 1, "locktime": 0, "vin": [ { "coinbase": "510101", "sequence": 4294967295 } ], "vout": [ { "value": 1, "n": 0, "scriptPubKey": { "asm": "024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9 OP_CHECKSIG", "hex": "21024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac", "reqSigs": 1, "type": "pubkey", "subtype": "", "isclaim": false, "issupport": false, "addresses": [ "bZi1WEjGtsdAwuZTnNNTCAZLxhHkiHec4m" ] } } ], "blockhash": "decb9e2cca03a419fd9cca0cb2b1d5ad11b088f22f8f38556d93ac4358b86c24", "confirmations": 1097697, "time": 1466646588, "blocktime": 1466646588 } ``` Decoding in code: ``` Go outputScript := "21024ca653fc094c95aa409430caf2eee08fa6e5fbbe78431e0ec9e7cd80193d98f9ac" scriptBytes, _ := hex.DecodeString(outputScript) pk, err := txscript.ParsePkScript(scriptBytes) ``` ``` unsupported script type ```
roylee17 commented 2022-01-19 21:46:58 +01:00 (Migrated from github.com)

Inside the ParsePkScript(), it does detect the scriptClass as PubKeyTy, which is not consider a "Script" type in the isSupportedScriptType()

Guess it can write something similar to ParsePKscript for your case (handle PubKeyTy)

// ParsePkScript parses an output script into the PkScript struct.
// ErrUnsupportedScriptType is returned when attempting to parse an unsupported
// script type.
func ParsePkScript(pkScript []byte) (PkScript, error) {
	var outputScript PkScript
	scriptClass, _, _, err := ExtractPkScriptAddrs(
		pkScript, &chaincfg.MainNetParams,
	)
	if err != nil {
		return outputScript, fmt.Errorf("unable to parse script type: "+
			"%v", err)
	}

	if !isSupportedScriptType(scriptClass) {
		return outputScript, ErrUnsupportedScriptType
	}
        ...
func isSupportedScriptType(class ScriptClass) bool {
	switch class {
	case PubKeyHashTy, WitnessV0PubKeyHashTy, ScriptHashTy,
		WitnessV0ScriptHashTy:
		return true
	default:
		return false
	}
}
Inside the `ParsePkScript()`, it does detect the `scriptClass` as `PubKeyTy`, which is not consider a "Script" type in the `isSupportedScriptType()` Guess it can write something similar to `ParsePKscript` for your case (handle PubKeyTy) ``` // ParsePkScript parses an output script into the PkScript struct. // ErrUnsupportedScriptType is returned when attempting to parse an unsupported // script type. func ParsePkScript(pkScript []byte) (PkScript, error) { var outputScript PkScript scriptClass, _, _, err := ExtractPkScriptAddrs( pkScript, &chaincfg.MainNetParams, ) if err != nil { return outputScript, fmt.Errorf("unable to parse script type: "+ "%v", err) } if !isSupportedScriptType(scriptClass) { return outputScript, ErrUnsupportedScriptType } ... ``` ``` func isSupportedScriptType(class ScriptClass) bool { switch class { case PubKeyHashTy, WitnessV0PubKeyHashTy, ScriptHashTy, WitnessV0ScriptHashTy: return true default: return false } } ```
lyoshenka commented 2022-01-19 23:53:04 +01:00 (Migrated from github.com)

the solution was to use txscript.ExtractPkScriptAddrs instead

the solution was to use txscript.ExtractPkScriptAddrs instead
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/lbcd#14
No description provided.