Esempio n. 1
0
    def signrawtransaction(self, tx, input_info, private_keys, password):
        unspent_coins = self.get_unspent_coins()
        seed = self.decode_seed(password)

        # convert private_keys to dict
        pk = {}
        for sec in private_keys:
            address = address_from_private_key(sec)
            pk[address] = sec
        private_keys = pk

        for txin in tx.inputs:
            # convert to own format
            txin['tx_hash'] = txin['prevout_hash']
            txin['index'] = txin['prevout_n']

            for item in input_info:
                if item.get('txid') == txin['tx_hash'] and item.get(
                        'vout') == txin['index']:
                    txin['raw_output_script'] = item['scriptPubKey']
                    txin['redeemScript'] = item.get('redeemScript')
                    txin['KeyID'] = item.get('KeyID')
                    break
            else:
                for item in unspent_coins:
                    if txin['tx_hash'] == item['tx_hash'] and txin[
                            'index'] == item['index']:
                        txin['raw_output_script'] = item['raw_output_script']
                        break
                else:
                    # if neither, we might want to get it from the server..
                    raise

            # find the address:
            if txin.get('KeyID'):
                account, name, sequence = txin.get('KeyID')
                if name != 'Electrum': continue
                sec = self.sequences[account].get_private_key(sequence, seed)
                addr = self.sequences[account].get_address(sequence)
                txin['address'] = addr
                private_keys[addr] = sec

            elif txin.get("redeemScript"):
                txin['address'] = hash_160_to_bc_address(
                    hash_160(txin.get("redeemScript").decode('hex')), 5)

            elif txin.get("raw_output_script"):
                import deserialize
                addr = deserialize.get_address_from_output_script(
                    txin.get("raw_output_script").decode('hex'))
                sec = self.get_private_key(addr, password)
                if sec:
                    private_keys[addr] = sec
                    txin['address'] = addr

        tx.sign(private_keys)
Esempio n. 2
0
    def signrawtransaction(self, tx, input_info, private_keys, password):
        unspent_coins = self.get_unspent_coins()
        seed = self.decode_seed(password)

        # convert private_keys to dict
        pk = {}
        for sec in private_keys:
            address = address_from_private_key(sec)
            pk[address] = sec
        private_keys = pk

        for txin in tx.inputs:
            # convert to own format
            txin["tx_hash"] = txin["prevout_hash"]
            txin["index"] = txin["prevout_n"]

            for item in input_info:
                if item.get("txid") == txin["tx_hash"] and item.get("vout") == txin["index"]:
                    txin["raw_output_script"] = item["scriptPubKey"]
                    txin["redeemScript"] = item.get("redeemScript")
                    txin["KeyID"] = item.get("KeyID")
                    break
            else:
                for item in unspent_coins:
                    if txin["tx_hash"] == item["tx_hash"] and txin["index"] == item["index"]:
                        txin["raw_output_script"] = item["raw_output_script"]
                        break
                else:
                    # if neither, we might want to get it from the server..
                    raise

            # find the address:
            if txin.get("KeyID"):
                account, name, sequence = txin.get("KeyID")
                if name != "Electrum":
                    continue
                sec = self.sequences[account].get_private_key(sequence, seed)
                addr = self.sequences[account].get_address(sequence)
                txin["address"] = addr
                private_keys[addr] = sec

            elif txin.get("redeemScript"):
                txin["address"] = hash_160_to_bc_address(hash_160(txin.get("redeemScript").decode("hex")), 5)

            elif txin.get("raw_output_script"):
                import deserialize

                addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode("hex"))
                sec = self.get_private_key(addr, password)
                if sec:
                    private_keys[addr] = sec
                    txin["address"] = addr

        tx.sign(private_keys)
Esempio n. 3
0
    def signrawtransaction(self, tx, input_info, private_keys, password):
        unspent_coins = self.get_unspent_coins()
        seed = self.decode_seed(password)

        # convert private_keys to dict 
        pk = {}
        for sec in private_keys:
            address = address_from_private_key(sec)
            pk[address] = sec
        private_keys = pk

        for txin in tx.inputs:
            # convert to own format
            txin['tx_hash'] = txin['prevout_hash']
            txin['index'] = txin['prevout_n']

            for item in input_info:
                if item.get('txid') == txin['tx_hash'] and item.get('vout') == txin['index']:
                    txin['raw_output_script'] = item['scriptPubKey']
                    txin['redeemScript'] = item.get('redeemScript')
                    txin['electrumKeyID'] = item.get('electrumKeyID')
                    break
            else:
                for item in unspent_coins:
                    if txin['tx_hash'] == item['tx_hash'] and txin['index'] == item['index']:
                        txin['raw_output_script'] = item['raw_output_script']
                        break
                else:
                    # if neither, we might want to get it from the server..
                    raise

            # find the address:
            if txin.get('electrumKeyID'):
                n, for_change = txin.get('electrumKeyID')
                sec = self.sequence.get_private_key(n, for_change, seed)
                address = address_from_private_key(sec)
                txin['address'] = address
                private_keys[address] = sec

            elif txin.get("redeemScript"):
                txin['address'] = hash_160_to_bc_address(hash_160(txin.get("redeemScript").decode('hex')), 5)

            elif txin.get("raw_output_script"):
                import deserialize
                addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex'))
                sec = self.get_private_key(addr, password)
                if sec: 
                    private_keys[addr] = sec
                    txin['address'] = addr

        tx.sign( private_keys )
Esempio n. 4
0
import deserialize
import utils
import sys

#script="534104c46d6462f67f990211d3a7077f005e67154f5f785b3edc06af3de62649a15bad35905fa7af9f272f80379a41525ad57a2245c2edc4807e3e49f43eb1c1b119794104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af53ae"
script = "76a91469d28eb9a311256338d281025a7437096149472c88ac61"
#script="76a9145f8b65a4064ef5c071c382d594b55d94bd31ec3a88ac";
#script="76a914c6b72811560b8c6ba897580754ba60d99c2094ed88ac";

script = sys.argv[1]

addr = deserialize.get_address_from_output_script(script.decode('hex'))
#print addr.encode('hex');

if addr == None:
    print addr
else:
    print utils.bc_address_to_hash_160(addr).encode('hex')
Esempio n. 5
0
import deserialize
import utils
import sys

#script="534104c46d6462f67f990211d3a7077f005e67154f5f785b3edc06af3de62649a15bad35905fa7af9f272f80379a41525ad57a2245c2edc4807e3e49f43eb1c1b119794104cc71eb30d653c0c3163990c47b976f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381354d80e550078cb532a34bfa2fcfdeb7d76519aecc62770f5b0e4ef8551946d8a540911abe3e7854a26f39f58b25c15342af53ae"
script="76a91469d28eb9a311256338d281025a7437096149472c88ac61"
#script="76a9145f8b65a4064ef5c071c382d594b55d94bd31ec3a88ac";
#script="76a914c6b72811560b8c6ba897580754ba60d99c2094ed88ac";

script=sys.argv[1]

addr=deserialize.get_address_from_output_script(script.decode('hex'))
#print addr.encode('hex');

if addr == None:
  print addr
else:
  print utils.bc_address_to_hash_160(addr).encode('hex')