diff --git a/blockchain_parser/script.py b/blockchain_parser/script.py index ac0a6b1..f7fc2c4 100644 --- a/blockchain_parser/script.py +++ b/blockchain_parser/script.py @@ -70,8 +70,12 @@ def operations(self): """ if self._operations is None: # Some coinbase scripts are garbage, they could not be valid - self._operations = list(self.script) - + try: + self._operations = list(self.script) + except CScriptTruncatedPushDataError: + self._operations = "[INVALID]" + except CScriptInvalidError: + self._operations = "[INVALID]" return self._operations @property @@ -132,4 +136,24 @@ def is_multisig(self): def is_unknown(self): return not self.is_pubkeyhash() and not self.is_pubkey() \ and not self.is_p2sh() and not self.is_multisig() \ - and not self.is_return() + and not self.is_return() and not self.is_p2wpkh()\ + and not self.is_p2wsh() + + # add by hzx + def is_p2wpkh(self): + if len(self.operations) == 2: + a = bytes(self.operations[0]) + b = bytes(self.operations[1]) + return len(a)==0 and len(b) == 20 + + return False + + # add by hzx + def is_p2wsh(self): + if len(self.operations) == 2: + a = bytes(self.operations[0]) + b = bytes(self.operations[1]) + return len(a)==0 and len(b) == 32 + + return False +