Esempio n. 1
0
async def parse_extra_fields(extra_buff):
    """
    Parses extra buffer to the extra fields vector
    :param extra_buff:
    :return:
    """
    extras = []
    rw = MemoryReaderWriter(bytes(extra_buff))
    ar2 = xmrserialize.Archive(rw, False)
    while len(rw.get_buffer()) > 0:
        extras.append(await ar2.variant(elem_type=TxExtraField))
    return extras
Esempio n. 2
0
async def add_additional_tx_pub_keys_to_extra(tx_extra,
                                              additional_pub_keys=None,
                                              pub_enc=None):
    """
    Adds all pubkeys to the extra
    :param tx_extra:
    :param additional_pub_keys:
    :param pub_enc: None
    :return:
    """
    pubs_msg = TxExtraAdditionalPubKeys(
        data=pub_enc
        if pub_enc else [crypto.encodepoint(x) for x in additional_pub_keys])

    rw = MemoryReaderWriter()
    ar = xmrserialize.Archive(rw, True)

    # format: variant_tag (0x4) | array len varint | 32B | 32B | ...
    await ar.variant(pubs_msg, TxExtraField)
    tx_extra += bytes(rw.get_buffer())
    return tx_extra
Esempio n. 3
0
async def remove_field_from_tx_extra(extra, mtype):
    """
    Removes extra field of fiven type from the buffer
    Reserializes with skipping the given mtype.
    :param extra:
    :param mtype:
    :return:
    """
    if len(extra) == 0:
        return []

    reader = MemoryReaderWriter(extra)
    writer = MemoryReaderWriter()
    ar_read = xmrserialize.Archive(reader, False)
    ar_write = xmrserialize.Archive(writer, True)
    while len(reader.get_buffer()) > 0:
        c_extras = await ar_read.variant(elem_type=TxExtraField)
        if not isinstance(c_extras, mtype):
            await ar_write.variant(c_extras, elem_type=TxExtraField)

    return writer.get_buffer()