How to use the scalecodec.types.U16 function in scalecodec

To help you get started, we’ve selected a few scalecodec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkascan / py-scale-codec / scalecodec / utils / ss58.py View on Github external
def ss58_decode_account_index(address, valid_address_type=None):

    account_index_bytes = ss58_decode(address, valid_address_type)

    if len(account_index_bytes) == 2:
        return U8(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 4:
        return U16(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 8:
        return U32(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 16:
        return U64(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    else:
        raise ValueError("Invalid account index length")
github polkascan / polkascan-pre-harvester / app / utils / ss58.py View on Github external
def ss58_decode_account_index(address, valid_address_type=42):

    account_index_bytes = ss58_decode(address, valid_address_type)

    if len(account_index_bytes) == 2:
        return U8(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 4:
        return U16(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 8:
        return U32(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    if len(account_index_bytes) == 16:
        return U64(ScaleBytes('0x{}'.format(account_index_bytes))).decode()
    else:
        raise ValueError("Invalid account index length")
github polkascan / polkascan-pre-harvester / app / utils / ss58.py View on Github external
def ss58_encode_account_index(account_index, address_type=42):

    if 0 <= account_index <= 2**8 - 1:
        account_idx_encoder = U8()
    elif 2**8 <= account_index <= 2**16 - 1:
        account_idx_encoder = U16()
    elif 2**16 <= account_index <= 2**32 - 1:
        account_idx_encoder = U32()
    elif 2**32 <= account_index <= 2**64 - 1:
        account_idx_encoder = U64()
    else:
        raise ValueError("Value too large for an account index")

    return ss58_encode(account_idx_encoder.encode(account_index).data, address_type)
github polkascan / py-scale-codec / scalecodec / utils / ss58.py View on Github external
def ss58_encode_account_index(account_index, address_type=42):

    if 0 <= account_index <= 2**8 - 1:
        account_idx_encoder = U8()
    elif 2**8 <= account_index <= 2**16 - 1:
        account_idx_encoder = U16()
    elif 2**16 <= account_index <= 2**32 - 1:
        account_idx_encoder = U32()
    elif 2**32 <= account_index <= 2**64 - 1:
        account_idx_encoder = U64()
    else:
        raise ValueError("Value too large for an account index")

    return ss58_encode(account_idx_encoder.encode(account_index).data, address_type)