Пример #1
0
def lookup_unspent_outputs(bitcoin_addresses):
    conn = HTTPConnection('blockchain.info')
    conn.request('GET', '/unspent?active={}'.format('|'.join(bitcoin_addresses)))
    result = json.loads(conn.getresponse().read().decode('utf8'))
    unspent = defaultdict(list)

    for u in result['unspent_outputs']:
        program_bytes = Bitcoin.hexstring_to_bytes(u['script'], reverse=False)
        scriptPubKey, _ = script.Script.unserialize(program_bytes, len(program_bytes))
        address = None

        # Try to extract the address from the scriptpubkey program
        if len(scriptPubKey.program) == 6 and \
           scriptPubKey.program[0][0] == script.OP_DUP and scriptPubKey.program[1][0] == script.OP_HASH160 and \
           scriptPubKey.program[2][0] == 20 and \
           scriptPubKey.program[4][0] == script.OP_EQUALVERIFY and scriptPubKey.program[5][0] == script.OP_CHECKSIG:
                address = scriptPubKey.program[3]
        elif len(scriptPubKey.program) == 3 and scriptPubKey.program[2][0] == script.OP_CHECKSIG:
            if scriptPubKey.program[2][0] in (0x04, 0x03, 0x02):
                address = base58.decode_to_bytes(addressgen.generate_address(scriptPubKey.program[1], version=0))[-24:-4]

        if address is not None:
            i = 0
            while address[i] == 0:
                i += 1
            address = '1' + ('1' * i) + addressgen.base58_check(address, version=0)
            unspent[address].append(u)
    return unspent
Пример #2
0
def lookup_unspent_outputs(bitcoin_addresses):
    conn = HTTPConnection('blockchain.info')
    conn.request('GET',
                 '/unspent?active={}'.format('|'.join(bitcoin_addresses)))
    result = json.loads(conn.getresponse().read().decode('utf8'))
    unspent = defaultdict(list)

    for u in result['unspent_outputs']:
        program_bytes = Bitcoin.hexstring_to_bytes(u['script'], reverse=False)
        scriptPubKey, _ = script.Script.unserialize(program_bytes,
                                                    len(program_bytes))
        address = None

        # Try to extract the address from the scriptpubkey program
        if len(scriptPubKey.program) == 6 and \
           scriptPubKey.program[0][0] == script.OP_DUP and scriptPubKey.program[1][0] == script.OP_HASH160 and \
           scriptPubKey.program[2][0] == 20 and \
           scriptPubKey.program[4][0] == script.OP_EQUALVERIFY and scriptPubKey.program[5][0] == script.OP_CHECKSIG:
            address = scriptPubKey.program[3]
        elif len(scriptPubKey.program
                 ) == 3 and scriptPubKey.program[2][0] == script.OP_CHECKSIG:
            if scriptPubKey.program[2][0] in (0x04, 0x03, 0x02):
                address = base58.decode_to_bytes(
                    addressgen.generate_address(scriptPubKey.program[1],
                                                version=0))[-24:-4]

        if address is not None:
            i = 0
            while address[i] == 0:
                i += 1
            address = '1' + ('1' * i) + addressgen.base58_check(address,
                                                                version=0)
            unspent[address].append(u)
    return unspent
Пример #3
0
    def getBitcoinAddress(self):
        if self.address is None:
            return None

        j = 0
        while j < len(self.address) and self.address[j] == 0:
            j += 1

        return ('1' + ('1' * j) + addressgen.base58_check(self.address))
Пример #4
0
    def getBitcoinAddress(self):
        j = 0
        while self.address[j] == 0:
            j += 1

        return ('1' + ('1' * j) + addressgen.base58_check(self.address)) if self.address is not None else None