Пример #1
0
 def dump (self):
     print 'hash: %s' % (hexify (dhash (self.render())),)
     print 'inputs: %d' % (len(self.inputs))
     for i in range (len (self.inputs)):
         (outpoint, index), script, sequence = self.inputs[i]
         redeem = pprint_script (parse_script (script))
         print '%3d %s:%d %r %d' % (i, hexify(outpoint), index, redeem, sequence)
     print '%d outputs' % (len(self.outputs))
     for i in range (len (self.outputs)):
         value, pk_script = self.outputs[i]
         pk_script = pprint_script (parse_script (pk_script))
         print '%3d %s %r' % (i, bcrepr (value), pk_script)
     print 'lock_time:', self.lock_time
Пример #2
0
 def dump (self):
     print 'hash: %s' % (hexify (dhash (self.render())),)
     print 'inputs: %d' % (len(self.inputs))
     for i in range (len (self.inputs)):
         (outpoint, index), script, sequence = self.inputs[i]
         redeem = pprint_script (parse_script (script))
         print '%3d %s:%d %r %d' % (i, hexify(outpoint), index, redeem, sequence)
     print '%d outputs' % (len(self.outputs))
     for i in range (len (self.outputs)):
         value, pk_script = self.outputs[i]
         pk_script = pprint_script (parse_script (pk_script))
         print '%3d %s %r' % (i, bcrepr (value), pk_script)
     print 'lock_time:', self.lock_time
Пример #3
0
def describe_iscript(p):
    if len(p) == 2 and p[0][0] == 0 and p[1][0] == 0:
        # PUSH PUSH
        pubkey = p[1][1]
        if pubkey[0] in ('\x02', '\x03', '\x04'):
            return key_to_address(rhash(pubkey))
        else:
            return shorthex(pubkey)
    elif p[0] == (0, '', PUSH_OP) and all([x[0] == 0 for x in p[1:]]):
        # p2sh redeem
        sigs = p[1:-1]
        try:
            redeem = parse_script(p[-1][1])
            probe = is_multi_tx(redeem)
            if probe is not None:
                _, val = probe
            else:
                val = repr(probe)
            return 'p2sh (%d sigs):%s' % (len(sigs), val)
        except ScriptError:
            return 'bad p2sh'
    elif len(p) == 1 and p[0][0] == 0:
        return 'sig'
    else:
        return repr(pprint_script(p))
Пример #4
0
def describe_iscript (p):
    if len(p) == 2 and p[0][0] == 0 and p[1][0] == 0:
        # PUSH PUSH
        pubkey = p[1][1]
        if pubkey[0] in ('\x02', '\x03', '\x04'):
            return key_to_address (rhash (pubkey))
        else:
            return shorthex (pubkey)
    elif p[0] == (0, '', PUSH_OP) and all ([x[0] == 0 for x in p[1:]]):
        # p2sh redeem
        sigs = p[1:-1]
        try:
            redeem = parse_script (p[-1][1])
            probe = is_multi_tx (redeem)
            if probe is not None:
                _, val = probe
            else:
                val = repr(probe)
            return 'p2sh (%d sigs):%s' % (len(sigs), val)
        except ScriptError:
            return 'bad p2sh'
    elif len(p) == 1 and p[0][0] == 0:
        return 'sig'
    else:
        return repr (pprint_script (p))
Пример #5
0
 def dump_tx (self, request, tx, tx_num):
     RP = request.push
     RP ('<tr><td>%s</td><td>%s</td>\r\n' % (tx_num, shorthex (dhash (tx.raw))))
     RP ('<td><table>')
     for i in range (len (tx.inputs)):
         (outpoint, index), script, sequence = tx.inputs[i]
         RP ('<tr><td>%3d</td><td>%s:%d</td><td>%s</td></tr>' % (
                 i,
                 shorthex (outpoint),
                 index,
                 shorthex (script),
             ))
     RP ('</table></td><td><table>')
     for i in range (len (tx.outputs)):
         value, pk_script = tx.outputs[i]
         script = parse_script (pk_script)
         parsed = pprint_script (script)
         if is_normal_tx (parsed):
             h = script[2][1]
             k = key_to_address (h)
         elif is_pubkey_tx (parsed):
             pk = script[0][1]
             k = 'pk:' + key_to_address (rhash (pk))
         elif is_p2sh_tx (parsed):
             h = script[1][1]
             k = 'p2sh:' + key_to_address (h, 5)
         else:
             k = parsed
         RP ('<tr><td>%s</td><td>%s</td></tr>' % (bcrepr (value), k))
     # lock time seems to always be zero
     #RP ('</table></td><td>%s</td></tr>' % tx.lock_time,)
     RP ('</table></td></tr>')
Пример #6
0
 def dump_tx(self, request, tx, tx_num):
     RP = request.push
     RP('<tr><td>%s</td><td>%s</td>\r\n' %
        (tx_num, shorthex(dhash(tx.raw))))
     RP('<td><table>')
     for i in range(len(tx.inputs)):
         (outpoint, index), script, sequence = tx.inputs[i]
         RP('<tr><td>%3d</td><td>%s:%d</td><td>%s</td></tr>' % (
             i,
             shorthex(outpoint),
             index,
             shorthex(script),
         ))
     RP('</table></td><td><table>')
     for i in range(len(tx.outputs)):
         value, pk_script = tx.outputs[i]
         script = parse_script(pk_script)
         parsed = pprint_script(script)
         if is_normal_tx(parsed):
             h = script[2][1]
             k = key_to_address(h)
         elif is_pubkey_tx(parsed):
             pk = script[0][1]
             k = 'pk:' + key_to_address(rhash(pk))
         elif is_p2sh_tx(parsed):
             h = script[1][1]
             k = 'p2sh:' + key_to_address(h, 5)
         else:
             k = parsed
         RP('<tr><td>%s</td><td>%s</td></tr>' % (bcrepr(value), k))
     # lock time seems to always be zero
     #RP ('</table></td><td>%s</td></tr>' % tx.lock_time,)
     RP('</table></td></tr>')
Пример #7
0
 def dump(self, fout=sys.stdout):
     D = fout.write
     D('hash: %s\n' % (hexify(dhash(self.render())), ))
     D('inputs: %d\n' % (len(self.inputs)))
     for i in range(len(self.inputs)):
         (outpoint, index), script, sequence = self.inputs[i]
         try:
             redeem = pprint_script(parse_script(script))
         except ScriptError:
             redeem = script.encode('hex')
         D('%3d %064x:%d %r %d\n' % (i, outpoint, index, redeem, sequence))
     D('outputs: %d\n' % (len(self.outputs), ))
     for i in range(len(self.outputs)):
         value, pk_script = self.outputs[i]
         pk_script = pprint_script(parse_script(pk_script))
         D('%3d %s %r\n' % (i, bcrepr(value), pk_script))
     D('lock_time: %s\n' % (self.lock_time, ))
Пример #8
0
 def dump (self, fout=sys.stdout):
     D = fout.write
     D ('hash: %s\n' % (hexify (dhash (self.render())),))
     D ('inputs: %d\n' % (len(self.inputs)))
     for i in range (len (self.inputs)):
         (outpoint, index), script, sequence = self.inputs[i]
         try:
             redeem = pprint_script (parse_script (script))
         except ScriptError:
             redeem = script.encode ('hex')
         D ('%3d %064x:%d %r %d\n' % (i, outpoint, index, redeem, sequence))
     D ('outputs: %d\n' % (len(self.outputs),))
     for i in range (len (self.outputs)):
         value, pk_script = self.outputs[i]
         pk_script = pprint_script (parse_script (pk_script))
         D ('%3d %s %r\n' % (i, bcrepr (value), pk_script))
     D ('lock_time: %s\n' % (self.lock_time,))
Пример #9
0
def get_output_addr (pk_script):
    if len(pk_script) > 500:
        return 'big', ''
    try:
        script = parse_script (pk_script)
        probe = is_normal_tx (script)
        if not probe:
            probe = is_pubkey_tx (script)
            if not probe:
                probe = is_p2sh_tx (script)
                if not probe:
                    probe = is_multi_tx (script)
        if probe:
            return probe
        else:
            return 'other', repr (pprint_script (script))
    except:
        return 'bad', pk_script.encode ('hex')
Пример #10
0
# -*- Mode: Python -*-

from scan_utxo import gen_utxo
from caesure.script import parse_script, pprint_script, ScriptError, OPCODES, PUSH_OP
from caesure._script import ScriptError

def is_p2sh (s):
    return (
        len(s) == 3
        and s[0] == (2, OPCODES.OP_HASH160)
        and s[2] == (2, OPCODES.OP_EQUAL)
        and s[1][0] == 0
        and s[1][2] == PUSH_OP
        and len(s[1][1]) == 20
    )

for txname, index, amt, script in gen_utxo():
    try:
        script = parse_script (script)
        if is_p2sh (script):
            print pprint_script (script)
    except ScriptError:
        # there are quite a few broken outpoint scripts in the utxo set.
        pass
        
    
Пример #11
0
# -*- Mode: Python -*-

from scan_utxo import gen_utxo
from caesure.script import parse_script, pprint_script, ScriptError, OPCODES
from caesure._script import ScriptError


def is_p2sh(s):
    return (len(s) == 3 and s[0] == (2, OPCODES.OP_HASH160)
            and s[2] == (2, OPCODES.OP_EQUAL) and s[1][0] == 0
            and len(s[1][1]) == 20)


for txname, outputs in gen_utxo():
    for (index, amt, script) in outputs:
        try:
            script = parse_script(script)
            if is_p2sh(script):
                print pprint_script(script)
        except ScriptError:
            # there are quite a few broken outpoint scripts in the utxo set.
            pass