|
3 | 3 | # @file address.py |
4 | 4 | # @brief address function implements file. |
5 | 5 | # @note Copyright 2020 CryptoGarage |
6 | | -from typing import Union, Optional, List |
| 6 | +from typing import Tuple, Union, Optional, List |
7 | 7 | from .util import get_util, CfdError, JobHandle, to_hex_string |
8 | 8 | from .key import Network, Pubkey, SchnorrPubkey |
9 | 9 | from .script import HashType, Script |
@@ -386,6 +386,46 @@ def get_multisig_address_list( |
386 | 386 | addr_list.append(_addr) |
387 | 387 | return addr_list |
388 | 388 |
|
| 389 | + ## |
| 390 | + # @brief get pegin address. |
| 391 | + # @param[in] fedpeg_script fedpeg script |
| 392 | + # @param[in] pubkey pubkey |
| 393 | + # @param[in] redeem_script redeem script |
| 394 | + # @param[in] hash_type script hash type |
| 395 | + # @param[in] mainchain_network mainchain network type |
| 396 | + # @retval [0] pegin address. |
| 397 | + # @retval [1] claim script. |
| 398 | + # @retval [2] tweaked fedpeg script. |
| 399 | + @classmethod |
| 400 | + def get_pegin_address( |
| 401 | + cls, |
| 402 | + fedpeg_script: Union['Script', str], |
| 403 | + pubkey='', |
| 404 | + redeem_script='', |
| 405 | + hash_type: Union['HashType', str] = HashType.P2SH_P2WSH, |
| 406 | + mainchain_network=Network.MAINNET, |
| 407 | + ) -> Tuple['Address', 'Script', 'Script']: |
| 408 | + _fedpeg_script = to_hex_string(fedpeg_script) |
| 409 | + _hash_type = HashType.get(hash_type) |
| 410 | + _network = Network.get(mainchain_network) |
| 411 | + _pubkey = '' if pubkey is None else to_hex_string(pubkey) |
| 412 | + _script = '' if redeem_script is None else to_hex_string(redeem_script) |
| 413 | + if (not _pubkey) and (not _script): |
| 414 | + raise CfdError( |
| 415 | + error_code=1, |
| 416 | + message='Error: Both pubkey and redeem_script is empty.') |
| 417 | + elif not _script: |
| 418 | + _ = Pubkey(_pubkey) # check pubkey |
| 419 | + |
| 420 | + util = get_util() |
| 421 | + with util.create_handle() as handle: |
| 422 | + addr, claim_script, tweaked_fedpeg = util.call_func( |
| 423 | + 'CfdGetPeginAddress', |
| 424 | + handle.get_handle(), _network.value, _fedpeg_script, |
| 425 | + _hash_type.value, _pubkey, _script) |
| 426 | + return cls.parse(addr), Script(claim_script), Script( |
| 427 | + tweaked_fedpeg) |
| 428 | + |
389 | 429 |
|
390 | 430 | ## |
391 | 431 | # All import target. |
|
0 commit comments