def get_preimage_script(self, txin): _type = txin.type() if _type == 'p2pkh': return txin.address.to_script_bytes().hex() elif _type == 'p2sh': pubkeys = [x_pubkey.to_public_key() for x_pubkey in txin.x_pubkeys] return multisig_script(pubkeys, txin.threshold).hex() elif _type == 'p2pk': x_pubkey = txin.x_pubkeys[0] output = P2PK_Output(x_pubkey.to_public_key()) return output.to_script_bytes().hex() else: raise RuntimeError('Unknown txin type', _type)
def get_preimage_script(self, txin): _type = txin['type'] if _type == 'p2pkh': return txin['address'].to_script_bytes().hex() elif _type == 'p2sh': pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin) return multisig_script(pubkeys, txin['num_sig']) elif _type == 'p2pk': output = P2PK_Output(PublicKey.from_hex(txin['pubkeys'][0])) return output.to_script_bytes().hex() elif _type == 'unknown': # this approach enables most P2SH smart contracts # (but take care if using OP_CODESEPARATOR) return txin['scriptCode'] else: raise RuntimeError('Unknown txin type', _type)