def pay_script_hash(self, script_hash): # this checks that factory function correctly sets up the script src1 = OutputScript.pay_script_hash(unhexlify(script_hash)) self.assertEqual(src1.template.name, 'pay_script_hash') self.assertEqual(hexlify(src1.values['script_hash']), script_hash) # now we test that it will round trip src2 = OutputScript(src1.source) self.assertEqual(src2.template.name, 'pay_script_hash') self.assertEqual(hexlify(src2.values['script_hash']), script_hash) return hexlify(src1.source)
def pay_claim_name_pubkey_hash(self, name, claim, pubkey_hash): # this checks that factory function correctly sets up the script src1 = OutputScript.pay_claim_name_pubkey_hash(name, unhexlify(claim), unhexlify(pubkey_hash)) self.assertEqual(src1.template.name, 'claim_name+pay_pubkey_hash') self.assertEqual(src1.values['claim_name'], name) self.assertEqual(hexlify(src1.values['claim']), claim) self.assertEqual(hexlify(src1.values['pubkey_hash']), pubkey_hash) # now we test that it will round trip src2 = OutputScript(src1.source) self.assertEqual(src2.template.name, 'claim_name+pay_pubkey_hash') self.assertEqual(src2.values['claim_name'], name) self.assertEqual(hexlify(src2.values['claim']), claim) self.assertEqual(hexlify(src2.values['pubkey_hash']), pubkey_hash) return hexlify(src1.source)
def claim_address_handler(cls, script): '''Parse a claim script, returns the address ''' output = OutputScript(script) if output.is_pay_pubkey_hash: return cls.P2PKH_address_from_hash160(output.values['pubkey_hash']) if output.is_pay_script_hash: return cls.P2SH_address_from_hash160(output.values['script_hash']) if output.is_pay_pubkey: return cls.P2PKH_address_from_pubkey(output.values['pubkey']) if output.is_return_data: return None return None