No project description provided
Project description
cfx-address
Conflux base32 address utilities
Full documentation -> https://conflux-fans.github.io/cfx-address/cfx_address.html#module-cfx_address
installation
pip install cfx-address
use Base32Address class methods
from cfx_address import Base32Address
validate a base32 address
Base32Address.is_valid_base32("0x1ecde7223747601823f7535d7968ba98b4881e09")
# False
Base32Address.validate("0x1ecde7223747601823f7535d7968ba98b4881e09")
# will raise an exception
encode and decode
# encode hex address to base32
Base32Address.encode_base32("0x1ecde7223747601823f7535d7968ba98b4881e09", network_id=1)
#'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'
# decode base32 address
Base32Address.decode("cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4")
# result:
# {'network_id': 1,
# 'hex_address': '0x1ecde7223747601823f7535d7968ba98b4881e09',
# 'address_type': 'user'}
utilities
address_str = "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4"
address_verbose_str = "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4"
assert Base32Address.equals(address_str, address_verbose_str)
Base32Address.calculate_mapped_evm_space_address(address_str)
Base32Address.zero_address(network_id=1)
Base32Address.shorten_base32_address(address_str)
Base32Address instances
instance initialization
address = Base32Address("cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4")
# 'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'
# Base32Address inherits from str
assert isinstance(address, str)
# init from hex address, in which case network_id is required
Base32Address("0x1ecde7223747601823f7535d7968ba98b4881e09", network_id=1029)
# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'
# change a base32 address to other network
Base32Address(address, network_id=1029)
# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'
# verbose option defaults to False
Base32Address(address, verbose=True)
# 'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4'
eq and properties
# __eq__ is implemented, address in same network is treated equal
assert address == "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4"
assert address == "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4"
assert "CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4" == address
assert "cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4" == address
# address in different network is not equal
mainnet_address = Base32Address(address, 1029)
assert mainnet_address == "cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu"
assert not address == mainnet_address
# properties
[
address.address_type,
address.network_id,
address.hex_address,
address.verbose_address,
address.short,
address.mapped_evm_space_address
]
# ['user',
# 1,
# '0x1ECdE7223747601823f7535d7968Ba98b4881E09',
# 'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4',
# 'cfxtest:aat...95j4',
# '0x349f086998cF4a0C5a00b853a0E93239D81A97f6',
# ]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfx_address-1.2.3.tar.gz
(14.3 kB
view details)
Built Distribution
File details
Details for the file cfx_address-1.2.3.tar.gz
.
File metadata
- Download URL: cfx_address-1.2.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc6a4628afcfec6b73a35726f2a7130b207592055c5f8cbf57fd310304e55c6 |
|
MD5 | 051247bf61123ff11ddd4b1f929d033c |
|
BLAKE2b-256 | d55f5268008c0e29d1bbfa72fd9c199952454145778e45d7d1c33b42170037d3 |
File details
Details for the file cfx_address-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: cfx_address-1.2.3-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77cf3c2fabdce4008f467da11dd93b6655088b56a7f17ba53857e06649e7bae4 |
|
MD5 | ced221e208bd0644a06b7e8773a1fc49 |
|
BLAKE2b-256 | 631a053db3dae673038c592f9a2a80e0f8a6d6bea11a882420115333fc3d2327 |