Esempio n. 1
0
 def encode_short_channel_id(short_channel_id):
     values = short_channel_id.split("x")
     assert len(values) == 3, "not a short_channel_id string"
     try:
         block_height = int(values[0])
         tx_index = int(values[1])
         output_index = int(values[2])
     except:
         assert False, "not a short_channel_id string"
     return i2b(block_height, 3) + i2b(tx_index, 3) + i2b(output_index, 2)
Esempio n. 2
0
 def encode(val):
     assert val <= 0xffffffffffffffff, "cannot encode bigger than uint64"
     if val < 0xfd:
         return i2b(val, 1)
     if val < 0x10000:
         return i2b(0xfd, 1) + i2b(val, 2)
     if val < 0x100000000:
         return i2b(0xfe, 1) + i2b(val, 4)
     else:
         return i2b(0xff, 1) + i2b(val, 8)
Esempio n. 3
0
 def encode_u64(value):
     return i2b(value, 8)
Esempio n. 4
0
 def encode_u32(value):
     return i2b(value, 4)
Esempio n. 5
0
 def encode_u16(value):
     return i2b(value, 2)
Esempio n. 6
0
 def encode_u8(value):
     return i2b(value, 1)
Esempio n. 7
0
 def encode_tu(value):
     n_bytes = Namespace.minimal_tu_bytes(value)
     if n_bytes == 0:
         return b''
     return i2b(value, n_bytes)