# Path: bitcoinpy/lib/script.py
# class CScript(object):
#     def __init__(self, vch=None):
#         self.vch = vch
# 
#         self.reset()
# 
#     def reset(self):
#         self.pc = 0
#         if self.vch is None:
#             self.pend = 0
#         else:
#             self.pend = len(self.vch)
#         self.pbegincodehash = 0
#         self.sop = None
# 
#     def getchars(self, n):
#         if (self.pc + n) > self.pend:
#             return None
# 
#         s = self.vch[self.pc:self.pc+n]
#         self.pc += n
# 
#         return s
# 
#     def getop(self):
#         s = self.getchars(1)
#         if s is None:
#             return False
#         opcode = ord(s)
# 
#         sop = CScriptOp()
#         sop.op = opcode
#         sop.ser_len = 1
# 
#         if opcode > OP_PUSHDATA4:
#             if opcode not in VALID_OPCODES:
#                 return False
#             self.sop = sop
#             return True
# 
#         if opcode < OP_PUSHDATA1:
#             datasize = opcode
# 
#         elif opcode == OP_PUSHDATA1:
#             sop.ser_len += 1
#             s = self.getchars(1)
#             if s is None:
#                 return False
#             datasize = ord(s)
# 
#         elif opcode == OP_PUSHDATA2:
#             sop.ser_len += 2
#             s = self.getchars(2)
#             if s is None:
#                 return False
#             datasize = struct.unpack(b"<H", s)[0]
# 
#         elif opcode == OP_PUSHDATA4:
#             sop.ser_len += 4
#             s = self.getchars(4)
#             if s is None:
#                 return False
#             datasize = struct.unpack(b"<I", s)[0]
# 
#         sop.ser_len += datasize
#         sop.data = self.getchars(datasize)
#         if sop.data is None:
#             return False
# 
#         self.sop = sop
#         return True
# 
#     def tokenize(self, vch_in=None):
#         if vch_in is not None:
#             self.vch = vch_in
# 
#         self.reset()
#         while self.pc < self.pend:
#             if not self.getop():
#                 return False
# 
#         return True
# 
#     def match_temp(self, template, vch_in=None):
#         l = []
#         i = 0
# 
#         if vch_in is not None:
#             self.vch = vch_in
# 
#         self.reset()
#         while self.pc < self.pend:
#             if i >= len(template):
#                 return None
#             if not self.getop():
#                 return None
# 
#             expected_op = template[i]
#             if expected_op == OP_PUBKEYHASH or expected_op == OP_PUBKEY:
#                 if self.sop.op > OP_PUSHDATA4:
#                     return None
#                 l.append(self.sop.data)
# 
#             elif self.sop.op != expected_op:
#                 return None
# 
#             i += 1
# 
#         return l
# 
#     def match_alltemp(self, vch_in=None):
#         for temp in TEMPLATES:
#             l = self.match_temp(temp, vch_in)
#             if l is not None:
#                 return l
#         return None
# 
#     def __repr__(self):
#         return "CScript(vchsz %d)" % (len(self.vch),)


import struct
import socket
import binascii
import time
import hashlib
from bitcoinpy.lib.serialize import *
from bitcoinpy.lib.coredefs import *
from bitcoinpy.lib.script import CScript
        return (self.nSequence == 0xffffffff)
    def is_valid(self):
        script = CScript()
        if not script.tokenize(self.scriptSig):
            return False
        return True
    def copy(self, old_txin):
        self.prevout = COutPoint()
        self.prevout.copy(old_txin.prevout)
        self.scriptSig = old_txin.scriptSig
        self.nSequence = old_txin.nSequence
    def __repr__(self):
        return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" % (repr(self.prevout), binascii.hexlify(self.scriptSig), self.nSequence)

class CTxOut(object):
    def __init__(self):
        self.nValue = -1
        self.scriptPubKey = b""
    def deserialize(self, f):
        self.nValue = struct.unpack(b"<q", f.read(8))[0]
        self.scriptPubKey = deser_string(f)
    def serialize(self):
        r = b""
        r += struct.pack(b"<q", self.nValue)
        r += ser_string(self.scriptPubKey)
        return r
    def is_valid(self):
        if not MoneyRange(self.nValue):
            print("invalid money range")
            return False

# Path: bitcoinpy/lib/script.py
# class CScript(object):
#     def __init__(self, vch=None):
#         self.vch = vch
# 
#         self.reset()
# 
#     def reset(self):
#         self.pc = 0
#         if self.vch is None:
#             self.pend = 0
#         else:
#             self.pend = len(self.vch)
#         self.pbegincodehash = 0
#         self.sop = None
# 
#     def getchars(self, n):
#         if (self.pc + n) > self.pend:
#             return None
# 
#         s = self.vch[self.pc:self.pc+n]
#         self.pc += n
# 
#         return s
# 
#     def getop(self):
#         s = self.getchars(1)
#         if s is None:
#             return False
#         opcode = ord(s)
# 
#         sop = CScriptOp()
#         sop.op = opcode
#         sop.ser_len = 1
# 
#         if opcode > OP_PUSHDATA4:
#             if opcode not in VALID_OPCODES:
#                 return False
#             self.sop = sop
#             return True
# 
#         if opcode < OP_PUSHDATA1:
#             datasize = opcode
# 
#         elif opcode == OP_PUSHDATA1:
#             sop.ser_len += 1
#             s = self.getchars(1)
#             if s is None:
#                 return False
#             datasize = ord(s)
# 
#         elif opcode == OP_PUSHDATA2:
#             sop.ser_len += 2
#             s = self.getchars(2)
#             if s is None:
#                 return False
#             datasize = struct.unpack(b"<H", s)[0]
# 
#         elif opcode == OP_PUSHDATA4:
#             sop.ser_len += 4
#             s = self.getchars(4)
#             if s is None:
#                 return False
#             datasize = struct.unpack(b"<I", s)[0]
# 
#         sop.ser_len += datasize
#         sop.data = self.getchars(datasize)
#         if sop.data is None:
#             return False
# 
#         self.sop = sop
#         return True
# 
#     def tokenize(self, vch_in=None):
#         if vch_in is not None:
#             self.vch = vch_in
# 
#         self.reset()
#         while self.pc < self.pend:
#             if not self.getop():
#                 return False
# 
#         return True
# 
#     def match_temp(self, template, vch_in=None):
#         l = []
#         i = 0
# 
#         if vch_in is not None:
#             self.vch = vch_in
# 
#         self.reset()
#         while self.pc < self.pend:
#             if i >= len(template):
#                 return None
#             if not self.getop():
#                 return None
# 
#             expected_op = template[i]
#             if expected_op == OP_PUBKEYHASH or expected_op == OP_PUBKEY:
#                 if self.sop.op > OP_PUSHDATA4:
#                     return None
#                 l.append(self.sop.data)
# 
#             elif self.sop.op != expected_op:
#                 return None
# 
#             i += 1
# 
#         return l
# 
#     def match_alltemp(self, vch_in=None):
#         for temp in TEMPLATES:
#             l = self.match_temp(temp, vch_in)
#             if l is not None:
#                 return l
#         return None
# 
#     def __repr__(self):
#         return "CScript(vchsz %d)" % (len(self.vch),)


# Path: bitcoinpy/lib/core.py
import struct
import socket
import binascii
import time
import hashlib
from bitcoinpy.lib.serialize import *
from bitcoinpy.lib.coredefs import *
from bitcoinpy.lib.script import CScript

        return (self.nSequence == 0xffffffff)
    def is_valid(self):
        script = CScript()
        if not script.tokenize(self.scriptSig):
            return False
        return True
    def copy(self, old_txin):
        self.prevout = COutPoint()
        self.prevout.copy(old_txin.prevout)
        self.scriptSig = old_txin.scriptSig
        self.nSequence = old_txin.nSequence
    def __repr__(self):
        return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" % (repr(self.prevout), binascii.hexlify(self.scriptSig), self.nSequence)

class CTxOut(object):
    def __init__(self):
        self.nValue = -1
        self.scriptPubKey = b""
    def deserialize(self, f):
        self.nValue = struct.unpack(b"<q", f.read(8))[0]
        self.scriptPubKey = deser_string(f)
    def serialize(self):
        r = b""
        r += struct.pack(b"<q", self.nValue)
        r += ser_string(self.scriptPubKey)
        return r
    def is_valid(self):
        if not MoneyRange(self.nValue):
            print("invalid money range")
            return False

        script = CScript()