예제 #1
0
 def eval(self, script):
     # check script size
     if (cached_serialized_size(script) > 10000):
         raise Exception("Serialized script size > 10000")
     # check disable opcodes
     disabled = [i.opcode for i in script.instructions if i.opcode in self.disabled_opcodes]
     if disabled:
         raise Exception("opcodes disabled: " + ",".join(OPCODE_NAMES[op] for op in disabled))
     self.current_script = script
     for i in script.instructions:
         op = is_pushdata_with_param(i.opcode) and OP_PUSHDATA or i.opcode
         executed = all(self.cond_stack)
         if executed or is_conditionnal(op):
             if op in self.disabled_opcodes:
                 print OPCODE_NAMES[op]
             OPCODE_FUNCTIONS[op](self, i)
         #print "stack:", [hexstr(elm)[:10] for elm in self.stack]  
     if self.cond_stack:
         raise Exception("Conditionals not matching")
예제 #2
0
 def __str__(self):
     if is_pushdata_with_param(self.opcode):
         return self.__pushdata__str__()
     if (self.opcode in OPCODE_NAMES):
         return OPCODE_NAMES[self.opcode]
     return ("UNKNOWN(%d)" % self.opcode)
예제 #3
0
 def __hash__(self):
     if is_pushdata_with_param(self.opcode):
         return hash(self.data)
     return self.opcode
예제 #4
0
 def deserialize(self, data, cursor=0):
     op = ord(data[cursor])
     if is_pushdata_with_param(op):
         return (self._deserialize_pushdata(data, cursor))
     return (Instruction(op), cursor + 1)
예제 #5
0
 def __init__(self, opcode, data=None):
     self.opcode = opcode  #value defined in opcodes.py
     self.data = data  #optional (bytestring for pushdata)
     if is_pushdata_with_param(self.opcode) and len(self.data) > 520:
         raise Exception("PUSH_DATA with >520 bytes")
예제 #6
0
 def get_size(self, instr):
     if is_pushdata_with_param(instr.opcode):
         return self._get_size_pushdata(instr)
     return 1
예제 #7
0
 def serialize(self, instr):
     if is_pushdata_with_param(instr.opcode):
         return self.serialize_pushdata(instr)
     return chr(instr.opcode)
예제 #8
0
 def __hash__(self):
     if is_pushdata_with_param(self.opcode):
         return hash(self.data)
     return self.opcode
예제 #9
0
 def __str__(self):
     if is_pushdata_with_param(self.opcode):
         return self.__pushdata__str__()
     if self.opcode in OPCODE_NAMES:
         return OPCODE_NAMES[self.opcode]
     return "UNKNOWN(%d)" % self.opcode
예제 #10
0
 def __init__(self, opcode, data=None):
     self.opcode = opcode  # value defined in opcodes.py
     self.data = data  # optional (bytestring for pushdata)
     if is_pushdata_with_param(self.opcode) and len(self.data) > 520:
         raise Exception("PUSH_DATA with >520 bytes")