Exemple #1
0
 def bech32_address(self, testnet=False):
     '''Returns the p2wpkh bech32 address string'''
     # first, we want the segwit version, which is 0 (or b'\x00')
     raw = b'\x00'
     # next, add the hash160 by using encode_varstr
     raw += encode_varstr(self.hash160())
     # return the encode_bech32_checksum of the raw witness program
     # remember to pass in testnet
     return encode_bech32_checksum(raw, testnet)
Exemple #2
0
 def address(self, testnet=False):
     '''Returns the address corresponding to the script'''
     if self.is_p2pkh_script_pubkey():  # p2pkh
         # hash160 is the 3rd element
         h160 = self.instructions[2]
         # convert to p2pkh address using h160_to_p2pkh_address (remember testnet)
         return h160_to_p2pkh_address(h160, testnet)
     elif self.is_p2sh_script_pubkey():  # p2sh
         # hash160 is the 2nd element
         h160 = self.instructions[1]
         # convert to p2sh address using h160_to_p2sh_address (remember testnet)
         return h160_to_p2sh_address(h160, testnet)
     elif self.is_p2wpkh_script_pubkey():  # p2sh
         # hash160 is the 2nd element
         witness_program = self.raw_serialize()
         # convert to bech32 address using encode_bech32_checksum
         return encode_bech32_checksum(witness_program, testnet)
     elif self.is_p2wsh_script_pubkey():  # p2sh
         # hash160 is the 2nd element
         witness_program = self.raw_serialize()
         # convert to bech32 address using encode_bech32_checksum
         return encode_bech32_checksum(witness_program, testnet)
Exemple #3
0
 def bech32_address(self, testnet=False):
     '''Returns the address string'''
     from script import p2wpkh_script
     h160 = self.hash160()
     raw = p2wpkh_script(h160).raw_serialize()
     return encode_bech32_checksum(raw, testnet)
Exemple #4
0
 def address(self, testnet=False):
     '''Generates a p2wsh address'''
     # grab the entire witness program
     witness_program = self.script_pubkey().raw_serialize()
     # convert to bech32 address using encode_bech32_checksum
     return encode_bech32_checksum(witness_program, testnet)
Exemple #5
0
 def address(self, testnet=False):
     '''return the bech32 address for the p2wpkh'''
     # witness program is the raw serialization
     witness_program = self.raw_serialize()
     # convert to bech32 address using encode_bech32_checksum
     return encode_bech32_checksum(witness_program, testnet)