Exemple #1
0
def serialize(coin, icon):
    c = dict(coin)
    c['signed_message_header'] = c['signed_message_header'].encode()
    c['hash_genesis_block'] = unhexlify(c['hash_genesis_block'])
    c['icon'] = icon
    msg = CoinDef(**c)
    w = Writer()
    dump_message(w, msg)
    return bytes(w.buf)
def coindef_from_dict(coin):
    proto = CoinDef()
    for fname, _, fflags in CoinDef.FIELDS.values():
        val = coin.get(fname)
        if val is None and fflags & protobuf.FLAG_REPEATED:
            val = []
        elif fname == "signed_message_header":
            val = val.encode()
        elif fname == "hash_genesis_block":
            val = bytes.fromhex(val)
        setattr(proto, fname, val)

    return proto