mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Add apidocs for address
This commit is contained in:
parent
fc30d947cb
commit
099218b685
1 changed files with 51 additions and 0 deletions
|
@ -11,6 +11,14 @@ _IADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqr
|
||||||
|
|
||||||
|
|
||||||
class Address(object):
|
class Address(object):
|
||||||
|
"""Monero address.
|
||||||
|
|
||||||
|
Address of this class is the master address for a wallet.
|
||||||
|
|
||||||
|
:param address: a Monero address as string-like object
|
||||||
|
:param label: a label for the address (defaults to `None`)
|
||||||
|
"""
|
||||||
|
|
||||||
label = None
|
label = None
|
||||||
_valid_netbytes = (18, 53)
|
_valid_netbytes = (18, 53)
|
||||||
# NOTE: _valid_netbytes order is (real, testnet)
|
# NOTE: _valid_netbytes order is (real, testnet)
|
||||||
|
@ -34,15 +42,34 @@ class Address(object):
|
||||||
allowed=", ".join(map(lambda b: '%02x' % b, self._valid_netbytes))))
|
allowed=", ".join(map(lambda b: '%02x' % b, self._valid_netbytes))))
|
||||||
|
|
||||||
def is_testnet(self):
|
def is_testnet(self):
|
||||||
|
"""Returns `True` if the address belongs to testnet.
|
||||||
|
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
return self._decoded[0] == self._valid_netbytes[1]
|
return self._decoded[0] == self._valid_netbytes[1]
|
||||||
|
|
||||||
def get_view_key(self):
|
def get_view_key(self):
|
||||||
|
"""Returns public view key.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
return hexlify(self._decoded[33:65]).decode()
|
return hexlify(self._decoded[33:65]).decode()
|
||||||
|
|
||||||
def get_spend_key(self):
|
def get_spend_key(self):
|
||||||
|
"""Returns public spend key.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
return hexlify(self._decoded[1:33]).decode()
|
return hexlify(self._decoded[1:33]).decode()
|
||||||
|
|
||||||
def with_payment_id(self, payment_id=0):
|
def with_payment_id(self, payment_id=0):
|
||||||
|
"""Integrates payment id into the address.
|
||||||
|
|
||||||
|
:param payment_id: int, hexadecimal string or PaymentID (max 64-bit long)
|
||||||
|
|
||||||
|
:rtype: IntegratedAddress
|
||||||
|
:raises: TypeError if the payment id is too long
|
||||||
|
"""
|
||||||
payment_id = numbers.PaymentID(payment_id)
|
payment_id = numbers.PaymentID(payment_id)
|
||||||
if not payment_id.is_short():
|
if not payment_id.is_short():
|
||||||
raise TypeError("Integrated payment ID {0} has more than 64 bits".format(payment_id))
|
raise TypeError("Integrated payment ID {0} has more than 64 bits".format(payment_id))
|
||||||
|
@ -63,6 +90,11 @@ class Address(object):
|
||||||
|
|
||||||
|
|
||||||
class SubAddress(Address):
|
class SubAddress(Address):
|
||||||
|
"""Monero subaddress.
|
||||||
|
|
||||||
|
Any type of wallet address which is not the master one.
|
||||||
|
"""
|
||||||
|
|
||||||
_valid_netbytes = (42, 63)
|
_valid_netbytes = (42, 63)
|
||||||
|
|
||||||
def with_payment_id(self, _):
|
def with_payment_id(self, _):
|
||||||
|
@ -70,6 +102,11 @@ class SubAddress(Address):
|
||||||
|
|
||||||
|
|
||||||
class IntegratedAddress(Address):
|
class IntegratedAddress(Address):
|
||||||
|
"""Monero integrated address.
|
||||||
|
|
||||||
|
A master address integrated with payment id (short one, max 64 bit).
|
||||||
|
"""
|
||||||
|
|
||||||
_valid_netbytes = (19, 54)
|
_valid_netbytes = (19, 54)
|
||||||
|
|
||||||
def __init__(self, address):
|
def __init__(self, address):
|
||||||
|
@ -80,9 +117,16 @@ class IntegratedAddress(Address):
|
||||||
self._decode(address)
|
self._decode(address)
|
||||||
|
|
||||||
def get_payment_id(self):
|
def get_payment_id(self):
|
||||||
|
"""Returns the integrated payment id.
|
||||||
|
|
||||||
|
:rtype: PaymentID
|
||||||
|
"""
|
||||||
return numbers.PaymentID(hexlify(self._decoded[65:-4]).decode())
|
return numbers.PaymentID(hexlify(self._decoded[65:-4]).decode())
|
||||||
|
|
||||||
def get_base_address(self):
|
def get_base_address(self):
|
||||||
|
"""Returns the base address without payment id.
|
||||||
|
:rtype: Address
|
||||||
|
"""
|
||||||
prefix = 53 if self.is_testnet() else 18
|
prefix = 53 if self.is_testnet() else 18
|
||||||
data = bytearray([prefix]) + self._decoded[1:65]
|
data = bytearray([prefix]) + self._decoded[1:65]
|
||||||
checksum = keccak_256(data).digest()[:4]
|
checksum = keccak_256(data).digest()[:4]
|
||||||
|
@ -90,6 +134,13 @@ class IntegratedAddress(Address):
|
||||||
|
|
||||||
|
|
||||||
def address(addr, label=None):
|
def address(addr, label=None):
|
||||||
|
"""Discover the proper class and return instance for a given Monero address.
|
||||||
|
|
||||||
|
:param addr: the address as a string-like object
|
||||||
|
:param label: a label for the address (defaults to `None`)
|
||||||
|
|
||||||
|
:rtype: Address, SubAddress or IntegratedAddress
|
||||||
|
"""
|
||||||
addr = str(addr)
|
addr = str(addr)
|
||||||
if _ADDR_REGEX.match(addr):
|
if _ADDR_REGEX.match(addr):
|
||||||
netbyte = bytearray(unhexlify(base58.decode(addr)))[0]
|
netbyte = bytearray(unhexlify(base58.decode(addr)))[0]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue