Skip to content

Commit

Permalink
update to v0.2.3 (#4)
Browse files Browse the repository at this point in the history
* update from cryptogarageinc v0.2.5

Co-authored-by: k-matsuzawa <[email protected]>
  • Loading branch information
ko-matsu and k-matsuzawa authored Dec 1, 2020
1 parent 5c3776b commit ad6a2c4
Show file tree
Hide file tree
Showing 22 changed files with 722 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_pre-merge_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
doxygen-ubuntu:
name: doxygen-ubuntu
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install_doxygen
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_pre-merge_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
doxygen-ubuntu:
name: doxygen-ubuntu
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install_doxygen
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_pre-merge_sprint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
doxygen-ubuntu:
name: doxygen-ubuntu
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: install_doxygen
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.3
62 changes: 38 additions & 24 deletions cfd/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# @file address.py
# @brief address function implements file.
# @note Copyright 2020 CryptoGarage
import typing
from .util import get_util, CfdError, JobHandle, to_hex_string
from .key import Network, Pubkey
from .script import HashType, Script
Expand All @@ -15,27 +16,35 @@ class Address:
##
# @var address
# address string
address: str
##
# @var locking_script
# locking script (scriptPubkey)
locking_script: typing.Union[str, 'Script']
##
# @var pubkey
# pubkey for pubkey hash.
pubkey: typing.Union[str, 'Pubkey']
##
# @var redeem_script
# redeem script for script hash.
redeem_script: typing.Union[str, 'Script']
##
# @var p2sh_wrapped_script
# witness locking script for p2sh.
p2sh_wrapped_script: typing.Union[str, 'Script']
##
# @var hash_type
# hash type.
hash_type: 'HashType'
##
# @var network
# network.
network: 'Network'
##
# @var witness_version
# witness version.
witness_version: int

##
# @brief constructor.
Expand All @@ -48,27 +57,32 @@ class Address:
# @param[in] p2sh_wrapped_script witness locking script for p2sh
def __init__(
self,
address,
address: str,
locking_script,
hash_type=HashType.P2SH,
network=Network.MAINNET,
pubkey='',
redeem_script='',
p2sh_wrapped_script=''):
_locking_script = to_hex_string(locking_script)
_redeem_script = to_hex_string(redeem_script)
_pubkey = to_hex_string(pubkey)
self.address = address
self.locking_script = locking_script
self.pubkey = pubkey
self.redeem_script = redeem_script
self.locking_script = _locking_script if len(
_locking_script) == 0 else Script(locking_script)
self.pubkey = _pubkey if len(_pubkey) == 0 else Pubkey(pubkey)
self.redeem_script = _redeem_script if len(
_redeem_script) == 0 else Script(redeem_script)
self.p2sh_wrapped_script = p2sh_wrapped_script
self.hash_type = hash_type
self.network = network
self.hash_type = HashType.get(hash_type)
self.network = Network.get(network)
self.witness_version = -1
if p2sh_wrapped_script and len(p2sh_wrapped_script) > 2:
if int(locking_script[0:2], 16) < 16:
if int(_locking_script[0:2], 16) < 16:
self.witness_version = int(p2sh_wrapped_script[0:2])
elif len(locking_script) > 2:
if int(locking_script[0:2], 16) < 16:
self.witness_version = int(locking_script[0:2])
elif len(_locking_script) > 2:
if int(_locking_script[0:2], 16) < 16:
self.witness_version = int(_locking_script[0:2])

##
# @brief get string.
Expand All @@ -87,10 +101,10 @@ class AddressUtil:
# @param[in] hash_type hash type
# @return address object.
@classmethod
def parse(cls, address, hash_type=HashType.P2WPKH):
def parse(cls, address, hash_type=HashType.P2WPKH) -> 'Address':
util = get_util()
with util.create_handle() as handle:
network, _hash_type, witness_version,\
network, _hash_type, _witness_version,\
locking_script, _ = util.call_func(
'CfdGetAddressInfo', handle.get_handle(), str(address))
_hash_type = HashType.get(_hash_type)
Expand All @@ -114,7 +128,7 @@ def parse(cls, address, hash_type=HashType.P2WPKH):
# @param[in] network network
# @return address object.
@classmethod
def p2pkh(cls, pubkey, network=Network.MAINNET):
def p2pkh(cls, pubkey, network=Network.MAINNET) -> 'Address':
return cls.from_pubkey_hash(
pubkey, HashType.P2PKH, network)

Expand All @@ -124,7 +138,7 @@ def p2pkh(cls, pubkey, network=Network.MAINNET):
# @param[in] network network
# @return address object.
@classmethod
def p2wpkh(cls, pubkey, network=Network.MAINNET):
def p2wpkh(cls, pubkey, network=Network.MAINNET) -> 'Address':
return cls.from_pubkey_hash(
pubkey, HashType.P2WPKH, network)

Expand All @@ -134,7 +148,7 @@ def p2wpkh(cls, pubkey, network=Network.MAINNET):
# @param[in] network network
# @return address object.
@classmethod
def p2sh_p2wpkh(cls, pubkey, network=Network.MAINNET):
def p2sh_p2wpkh(cls, pubkey, network=Network.MAINNET) -> 'Address':
return cls.from_pubkey_hash(
pubkey, HashType.P2SH_P2WPKH, network)

Expand All @@ -144,7 +158,7 @@ def p2sh_p2wpkh(cls, pubkey, network=Network.MAINNET):
# @param[in] network network
# @return address object.
@classmethod
def p2sh(cls, redeem_script, network=Network.MAINNET):
def p2sh(cls, redeem_script, network=Network.MAINNET) -> 'Address':
return cls.from_script_hash(
redeem_script, HashType.P2SH, network)

Expand All @@ -154,7 +168,7 @@ def p2sh(cls, redeem_script, network=Network.MAINNET):
# @param[in] network network
# @return address object.
@classmethod
def p2wsh(cls, redeem_script, network=Network.MAINNET):
def p2wsh(cls, redeem_script, network=Network.MAINNET) -> 'Address':
return cls.from_script_hash(
redeem_script, HashType.P2WSH, network)

Expand All @@ -164,7 +178,7 @@ def p2wsh(cls, redeem_script, network=Network.MAINNET):
# @param[in] network network
# @return address object.
@classmethod
def p2sh_p2wsh(cls, redeem_script, network=Network.MAINNET):
def p2sh_p2wsh(cls, redeem_script, network=Network.MAINNET) -> 'Address':
return cls.from_script_hash(
redeem_script, HashType.P2SH_P2WSH, network)

Expand All @@ -179,7 +193,7 @@ def from_pubkey_hash(
cls,
pubkey,
hash_type,
network=Network.MAINNET):
network=Network.MAINNET) -> 'Address':
_pubkey = str(pubkey)
_hash_type = HashType.get(hash_type)
_network = Network.get(network)
Expand Down Expand Up @@ -208,7 +222,7 @@ def from_script_hash(
cls,
redeem_script,
hash_type,
network=Network.MAINNET):
network=Network.MAINNET) -> 'Address':
_script = str(redeem_script)
_hash_type = HashType.get(hash_type)
_network = Network.get(network)
Expand Down Expand Up @@ -236,10 +250,10 @@ def from_script_hash(
@classmethod
def multisig(
cls,
require_num,
require_num: int,
pubkey_list,
hash_type,
network=Network.MAINNET):
network=Network.MAINNET) -> 'Address':
if isinstance(require_num, int) is False:
raise CfdError(
error_code=1, message='Error: Invalid require_num type.')
Expand Down Expand Up @@ -290,7 +304,7 @@ def multisig(
def from_locking_script(
cls,
locking_script,
network=Network.MAINNET):
network=Network.MAINNET) -> 'Address':
_script = str(locking_script)
_network = Network.get(network)
util = get_util()
Expand All @@ -311,7 +325,7 @@ def get_multisig_address_list(
cls,
redeem_script,
hash_type,
network=Network.MAINNET):
network=Network.MAINNET) -> typing.List['Address']:
_script = str(redeem_script)
_hash_type = HashType.get(hash_type)
_network = Network.get(network)
Expand Down
18 changes: 13 additions & 5 deletions cfd/confidential_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# @file confidential_address.py
# @brief elements confidential address function implements file.
# @note Copyright 2020 CryptoGarage
import typing
from .address import Address, AddressUtil
from .key import Pubkey
from .util import get_util, to_hex_string, CfdError


Expand All @@ -13,20 +16,23 @@ class ConfidentialAddress:
##
# @var confidential_address
# confidential address string
confidential_address: str
##
# @var address
# address
address: 'Address'
##
# @var confidential_key
# confidential key
confidential_key: 'Pubkey'

##
# @brief check confidential address.
# @param[in] confidential_address confidential address
# @retval True confidential address
# @retval False other
@classmethod
def valid(cls, confidential_address):
def valid(cls, confidential_address) -> bool:
util = get_util()
try:
with util.create_handle() as handle:
Expand All @@ -42,7 +48,7 @@ def valid(cls, confidential_address):
# @param[in] confidential_address confidential address
# @return ConfidentialAddress object
@classmethod
def parse(cls, confidential_address):
def parse(cls, confidential_address) -> 'ConfidentialAddress':
util = get_util()
with util.create_handle() as handle:
_addr, _key, _ = util.call_func(
Expand All @@ -55,8 +61,10 @@ def parse(cls, confidential_address):
# @param[in] address address address
# @param[in] confidential_key confidential key
def __init__(self, address, confidential_key):
self.address = address
self.confidential_key = confidential_key
self.address = address if isinstance(
address, Address) else AddressUtil.parse(address)
self.confidential_key = confidential_key if isinstance(
confidential_key, Pubkey) else Pubkey(confidential_key)
util = get_util()
with util.create_handle() as handle:
self.confidential_address = util.call_func(
Expand All @@ -66,7 +74,7 @@ def __init__(self, address, confidential_key):
##
# @brief get string.
# @return confidential address.
def __str__(self):
def __str__(self) -> str:
return self.confidential_address


Expand Down
Loading

0 comments on commit ad6a2c4

Please sign in to comment.