Example #1
0
 def encode_tlv(t, v):
     return Tlv(t, v).encode()
Example #2
0
 def pop_tlv(byte_string):
     return Tlv.pop(byte_string)
Example #3
0
 def iter_tlvs(byte_string):
     assert Namespace.tlvs_are_valid(byte_string), "bad byte_string?"
     while len(byte_string) > 0:
         tlv, byte_string, _ = Tlv.pop(byte_string)
         yield tlv
Example #4
0
 def _encode_art_no(art_no):
     encoded = Namespace.encode_tu16(art_no)
     return Tlv(ART_TLV_TYPE, encoded).encode()
Example #5
0
     {'stream': ""}, # empty byte stream is counted as invalid by this lib
     {'stream': "fd"},
     {'stream': "fd01"},
     {'stream': "fd000100"},
     {'stream': "fd0101"},
     {'stream': "0ffd26"},
     {'stream': "0ffd2602"},
     {'stream': "0ffd000100"},
     {'stream': "0ffd0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
]


if __name__ == "__main__":
    print("testing valid cases")
    for test in TLV_VALID_TESTS:
        peek_tlv, peek_err = Tlv.peek(h2b(test['stream']))
        pop_tlv, remainder, pop_err = Tlv.pop(h2b(test['stream']))


        assert peek_err is None
        assert peek_tlv.t == test['t']
        assert peek_tlv.l == test['l']
        assert peek_tlv.v == h2b(test['v'])

        assert pop_err is None
        assert pop_tlv.t == test['t']
        assert pop_tlv.l == test['l']
        assert pop_tlv.v == h2b(test['v'])
        assert remainder == h2b(test['r'])

    print("done testing valid cases")
Example #6
0
 def _encode_pixels(pixels):
     encoded = b''.join([p.to_bin() for p in pixels])
     return Tlv(PIXEL_TLV_TYPE, encoded).encode()
Example #7
0
 def encode_payment_data(payment_secret, total_msat):
     body = (Namespace.encode_bytes(payment_secret) +
             Namespace.encode_tu64(total_msat))
     return Tlv(8, body).encode()
Example #8
0
 def encode_short_channel_id(short_channel_id):
     t = Tlv(6, Namespace.encode_short_channel_id(short_channel_id))
     return t.encode()
Example #9
0
 def encode_outgoing_cltv_value(outgoing_cltv_value):
     return Tlv(4, Namespace.encode_tu32(outgoing_cltv_value)).encode()
Example #10
0
 def encode_amt_to_forward(amt_to_forward):
     return Tlv(2, Namespace.encode_tu64(amt_to_forward)).encode()