cfx-address


Namecfx-address JSON
Version 1.2.4 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-12-17 02:14:50
maintainerNone
docs_urlNone
authorThe Conflux foundation
requires_python>=3.7
licenseNone
keywords conflux base32 address
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cfx-address

Conflux base32 address utilities

Full documentation -> https://conflux-fans.github.io/cfx-address/cfx_address.html#module-cfx_address

## installation

```bash
pip install cfx-address
```

### use Base32Address class methods

```python
from cfx_address import Base32Address
```

#### validate a base32 address
``` python
Base32Address.is_valid_base32("0x1ecde7223747601823f7535d7968ba98b4881e09") 
# False
Base32Address.validate("0x1ecde7223747601823f7535d7968ba98b4881e09")
# will raise an exception
```

#### encode and decode

``` python
# 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

```python
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

```python
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

```python
# __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',
#  ]
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cfx-address",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "Conflux, base32, address",
    "author": "The Conflux foundation",
    "author_email": "wenda.zhang@confluxnetwork.org",
    "download_url": "https://files.pythonhosted.org/packages/05/6a/140ae9a62b3b9f7dfb06d8625466374f23cf3c038cd815b492c09ad2784b/cfx_address-1.2.4.tar.gz",
    "platform": null,
    "description": "# cfx-address\n\nConflux base32 address utilities\n\nFull documentation -> https://conflux-fans.github.io/cfx-address/cfx_address.html#module-cfx_address\n\n## installation\n\n```bash\npip install cfx-address\n```\n\n### use Base32Address class methods\n\n```python\nfrom cfx_address import Base32Address\n```\n\n#### validate a base32 address\n``` python\nBase32Address.is_valid_base32(\"0x1ecde7223747601823f7535d7968ba98b4881e09\") \n# False\nBase32Address.validate(\"0x1ecde7223747601823f7535d7968ba98b4881e09\")\n# will raise an exception\n```\n\n#### encode and decode\n\n``` python\n# encode hex address to base32\nBase32Address.encode_base32(\"0x1ecde7223747601823f7535d7968ba98b4881e09\", network_id=1)\n#'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'\n\n# decode base32 address\nBase32Address.decode(\"cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4\")\n# result:\n# {'network_id': 1,\n# 'hex_address': '0x1ecde7223747601823f7535d7968ba98b4881e09',\n# 'address_type': 'user'}\n```\n\n#### utilities\n\n```python\naddress_str = \"cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4\"\naddress_verbose_str = \"CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4\"\nassert Base32Address.equals(address_str, address_verbose_str)\n\nBase32Address.calculate_mapped_evm_space_address(address_str)\nBase32Address.zero_address(network_id=1)\nBase32Address.shorten_base32_address(address_str)\n```\n\n### Base32Address instances\n\n#### instance initialization\n\n```python\naddress = Base32Address(\"cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4\")\n# 'cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4'\n\n# Base32Address inherits from str\nassert isinstance(address, str)\n\n# init from hex address, in which case network_id is required\nBase32Address(\"0x1ecde7223747601823f7535d7968ba98b4881e09\", network_id=1029)\n# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'\n\n# change a base32 address to other network\nBase32Address(address, network_id=1029)\n# 'cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu'\n\n# verbose option defaults to False\nBase32Address(address, verbose=True)\n# 'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4'\n```\n\n#### __eq__ and properties\n\n```python\n# __eq__ is implemented, address in same network is treated equal\nassert address == \"cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4\"\nassert address == \"CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4\"\nassert \"CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4\" == address\nassert \"cfxtest:aatp533cg7d0agbd87kz48nj1mpnkca8be1rz695j4\" == address\n\n# address in different network is not equal\nmainnet_address = Base32Address(address, 1029)\nassert mainnet_address == \"cfx:aatp533cg7d0agbd87kz48nj1mpnkca8be7ggp3vpu\"\nassert not address == mainnet_address\n\n# properties\n[\n    address.address_type,\n    address.network_id,\n    address.hex_address,\n    address.verbose_address,\n    address.short,\n    address.mapped_evm_space_address\n]\n# ['user',\n#  1,\n#  '0x1ECdE7223747601823f7535d7968Ba98b4881E09',\n#  'CFXTEST:TYPE.USER:AATP533CG7D0AGBD87KZ48NJ1MPNKCA8BE1RZ695J4',\n#  'cfxtest:aat...95j4',\n#  '0x349f086998cF4a0C5a00b853a0E93239D81A97f6',\n#  ]\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "1.2.4",
    "project_urls": null,
    "split_keywords": [
        "conflux",
        " base32",
        " address"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "88f15620114f0b920027982bfc0d15b00f82765238bc8bc38c818c14c685b2cb",
                "md5": "2c5b6bc964e9ee81f5d6e101d5c7226f",
                "sha256": "7aeeb7963edca6e65f8586c7187a1159a8f61fd8d7a156d80cc5351bcc509ab3"
            },
            "downloads": -1,
            "filename": "cfx_address-1.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c5b6bc964e9ee81f5d6e101d5c7226f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14507,
            "upload_time": "2024-12-17T02:14:47",
            "upload_time_iso_8601": "2024-12-17T02:14:47.404860Z",
            "url": "https://files.pythonhosted.org/packages/88/f1/5620114f0b920027982bfc0d15b00f82765238bc8bc38c818c14c685b2cb/cfx_address-1.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "056a140ae9a62b3b9f7dfb06d8625466374f23cf3c038cd815b492c09ad2784b",
                "md5": "0d4bb883116fe9b172fe11aea70e1d91",
                "sha256": "7fd3e1154ed922117305c14eb2157e2f3cfb36b73403671e32840836f25f6526"
            },
            "downloads": -1,
            "filename": "cfx_address-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "0d4bb883116fe9b172fe11aea70e1d91",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 14371,
            "upload_time": "2024-12-17T02:14:50",
            "upload_time_iso_8601": "2024-12-17T02:14:50.135257Z",
            "url": "https://files.pythonhosted.org/packages/05/6a/140ae9a62b3b9f7dfb06d8625466374f23cf3c038cd815b492c09ad2784b/cfx_address-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 02:14:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cfx-address"
}
        
Elapsed time: 0.41581s