示例#1
0
 def test_int_to_from_script_bytes(self):
     for i in range(-127, 127):
         self.assertEqual(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     for i in range(-1024, 1024, 16):
         self.assertEqual(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     for i in range(-1024*1024, 1024*1024, 10000):
         self.assertEqual(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     self.assertEqual(IntStreamer.int_to_script_bytes(1), b"\1")
     self.assertEqual(IntStreamer.int_to_script_bytes(127), b"\x7f")
     self.assertEqual(IntStreamer.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(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     for i in range(-1024, 1024, 16):
         self.assertEqual(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     for i in range(-1024*1024, 1024*1024, 10000):
         self.assertEqual(IntStreamer.int_from_script_bytes(IntStreamer.int_to_script_bytes(i)), i)
     self.assertEqual(IntStreamer.int_to_script_bytes(1), b"\1")
     self.assertEqual(IntStreamer.int_to_script_bytes(127), b"\x7f")
     self.assertEqual(IntStreamer.int_to_script_bytes(128), b"\x80\x00")
示例#3
0
class BitcoinVM(VM):
    IntStreamer = IntStreamer

    VM_FALSE = IntStreamer.int_to_script_bytes(0)
    VM_TRUE = IntStreamer.int_to_script_bytes(1)

    INSTRUCTION_LOOKUP = make_instruction_lookup(opcodes.OPCODE_LIST)
    ScriptStreamer = BitcoinScriptStreamer

    def pop_int(self):
        return self.IntStreamer.int_from_script_bytes(self.pop(), require_minimal=self.flags & VERIFY_MINIMALDATA)

    def pop_nonnegative(self):
        v = self.pop_int()
        if v < 0:
            raise ScriptError("unexpectedly got negative value", errno.INVALID_STACK_OPERATION)
        return v

    def push_int(self, v):
        self.append(self.IntStreamer.int_to_script_bytes(v))

    @classmethod
    def bool_from_script_bytes(class_, v, require_minimal=False):
        v = class_.IntStreamer.int_from_script_bytes(v, require_minimal=require_minimal)
        if require_minimal:
            if v not in (class_.VM_FALSE, class_.VM_TRUE):
                raise ScriptError("non-minimally encoded", errno.UNKNOWN_ERROR)
        return bool(v)

    @classmethod
    def bool_to_script_bytes(class_, v):
        return class_.VM_TRUE if v else class_.VM_FALSE

    @classmethod
    def generator_for_signature_type(class_, signature_type):
        return secp256k1_generator
示例#4
0
 def test_val(n):
     as_bytes = IntStreamer.int_to_script_bytes(n)
     test_bytes(as_bytes)
示例#5
0
 def test_val(n):
     as_bytes = IntStreamer.int_to_script_bytes(n)
     test_bytes(as_bytes)
示例#6
0
def make_opcode_const_list():
    return [
        ("OP_%d" % i, IntStreamer.int_to_script_bytes(i)) for i in range(17)
    ] + [("OP_1NEGATE", IntStreamer.int_to_script_bytes(-1))]
示例#7
0
def make_opcode_const_list():
    return [("OP_%d" % i, IntStreamer.int_to_script_bytes(i)) for i in range(17)] + [
            ("OP_1NEGATE", IntStreamer.int_to_script_bytes(-1))]