Returns the address corresponding to the script
(self, testnet=False)
| 276 | # end::source5[] |
| 277 | |
| 278 | def address(self, testnet=False): |
| 279 | '''Returns the address corresponding to the script''' |
| 280 | if self.is_p2pkh_script_pubkey(): # p2pkh |
| 281 | # hash160 is the 3rd cmd |
| 282 | h160 = self.cmds[2] |
| 283 | # convert to p2pkh address using h160_to_p2pkh_address (remember testnet) |
| 284 | return h160_to_p2pkh_address(h160, testnet) |
| 285 | elif self.is_p2sh_script_pubkey(): # p2sh |
| 286 | # hash160 is the 2nd cmd |
| 287 | h160 = self.cmds[1] |
| 288 | # convert to p2sh address using h160_to_p2sh_address (remember testnet) |
| 289 | return h160_to_p2sh_address(h160, testnet) |
| 290 | raise ValueError('Unknown ScriptPubKey') |
| 291 | |
| 292 | |
| 293 | class ScriptTest(TestCase): |