Utils

Bytom Utils.

swap.providers.bytom.utils.amount_converter(amount: Union[int, float], symbol: str = 'NEU2BTM') → Union[int, float]

Amount converter

Parameters
  • amount (int, float) – Bytom amount.

  • symbol (str) – Bytom symbol, default to NEU2BTM.

Returns

float – BTM asset amount.

>>> from swap.providers.bytom.utils import amount_converter
>>> amount_converter(amount=10_000_000, symbol="NEU2BTM")
0.1
swap.providers.bytom.utils.is_network(network: str) → bool

Check Bytom network.

Parameters

network (str) – Bytom network.

Returns

bool – Bytom valid/invalid network.

>>> from swap.providers.bytom.utils import is_network
>>> is_network("solonet")
True
swap.providers.bytom.utils.is_address(address: str, network: Optional[str] = None) → bool

Check Bytom address.

Parameters
  • address (str) – Bytom address.

  • network (str) – Bytom network, defaults to None.

Returns

bool – Bytom valid/invalid address.

>>> from swap.providers.bytom.utils import is_address
>>> is_address("bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7", "mainnet")
True
swap.providers.bytom.utils.is_transaction_raw(transaction_raw: str) → bool

Check Bytom transaction raw.

Parameters

transaction_raw (str) – Bytom transaction raw.

Returns

bool – Bytom valid/invalid transaction raw.

>>> from swap.providers.bytom.utils import is_transaction_raw
>>> is_transaction_raw("...")
True
swap.providers.bytom.utils.decode_transaction_raw(transaction_raw: str, headers: dict = {}, timeout: int = 60) → dict

Decode Bytom transaction raw.

Parameters
  • transaction_raw (str) – Bytom transaction raw.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

dict – Decoded Bytom transaction raw.

>>> from swap.providers.bytom.utils import decode_transaction_raw
>>> decode_transaction_raw(transaction_raw)
{'fee': ..., 'type': '...', 'address': '...', 'transaction': {...}, 'unsigned_datas': [...], 'signatures': [...], 'network': '...'}
swap.providers.bytom.utils.submit_transaction_raw(transaction_raw: str, headers: dict = {}, timeout: int = 60) → dict

Submit Bytom transaction raw.

Parameters
  • transaction_raw (str) – Bytom transaction raw.

  • headers (dict) – Request headers, default to common headers.

  • timeout (int) – Request timeout, default to 60.

Returns

dict – Bytom submitted.

>>> from swap.providers.bytom.utils import submit_transaction_raw
>>> submit_transaction_raw(transaction_raw)
{'fee': ..., 'type': '...', 'transaction_id': '...', 'network': '...', 'date': '...'}
swap.providers.bytom.utils.get_address_type(address: str) → Optional[str]

Get Bytom address type.

Parameters

address (str) – Bytom address.

Returns

str – Bytom address type (P2WPKH, P2WSH).

>>> from swap.providers.bytom.utils import get_address_type
>>> get_address_type(address="bm1q9ndylx02syfwd7npehfxz4lddhzqsve2fu6vc7")
"p2wpkh"