Пример #1
0
 def test_int_to_from_script_bytes(self):
     for i in range(-127, 127):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     for i in range(-1024, 1024, 16):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     for i in range(-1024*1024, 1024*1024, 10000):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     self.assertEqual(int_to_script_bytes(1), b"\1")
     self.assertEqual(int_to_script_bytes(127), b"\x7f")
     self.assertEqual(int_to_script_bytes(128), b"\x80\x00")
Пример #2
0
 def test_int_to_from_script_bytes(self):
     for i in range(-127, 127):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     for i in range(-1024, 1024, 16):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     for i in range(-1024 * 1024, 1024 * 1024, 10000):
         self.assertEqual(int_from_script_bytes(int_to_script_bytes(i)), i)
     self.assertEqual(int_to_script_bytes(1), b"\1")
     self.assertEqual(int_to_script_bytes(127), b"\x7f")
     self.assertEqual(int_to_script_bytes(128), b"\x80\x00")
Пример #3
0
def _parse_sequence_value(opcode, data, disassembled):
    value = None
    if opcode == 0:
        value = 0
    elif 0 < opcode < 76:  # get from data bytes
        value = tools.int_from_script_bytes(data)
    elif 80 < opcode < 97:  # OP_1 - OP_16
        value = opcode - 80
    if not (MAX_SEQUENCE >= value >= 0):
        raise InvalidSequenceValue(disassembled)
    return value
Пример #4
0
def parse_sequence_value(opcode, data, disassembled):
    value = None
    if opcode == 0:
        value = 0
    elif 0 < opcode < 76:  # get from data bytes
        value = tools.int_from_script_bytes(data)
    elif 80 < opcode < 97:  # OP_1 - OP_16
        value = opcode - 80
    else:
        raise ValueError("Invalid expire time: {0}".format(disassembled))
    if value > MAX_SEQUENCE:
        msg = "Max expire time exceeded: {0} > {1}"
        raise ValueError(msg.format(value, MAX_SEQUENCE))
    return value