예제 #1
0
    def sweep(cls, privkeys, network, to_address, fee):
        inputs = []
        keypairs = {}
        for privkey in privkeys:
            pubkey = public_key_from_private_key(privkey)
            address = address_from_private_key(privkey)
            u = network.synchronous_get(
                ('blockchain.address.listunspent', [address]))
            pay_script = cls.pay_script(TYPE_ADDRESS, address)
            for item in u:
                item['scriptPubKey'] = pay_script
                item['redeemPubkey'] = pubkey
                item['address'] = address
                item['prevout_hash'] = item['tx_hash']
                item['prevout_n'] = item['tx_pos']
                item['pubkeys'] = [pubkey]
                item['x_pubkeys'] = [pubkey]
                item['signatures'] = [None]
                item['num_sig'] = 1
            inputs += u
            keypairs[pubkey] = privkey

        if not inputs:
            return

        total = sum(i.get('value') for i in inputs) - fee
        outputs = [(TYPE_ADDRESS, to_address, total)]
        self = cls.from_io(inputs, outputs)
        self.sign(keypairs)
        return self
예제 #2
0
 def get_private_key(self, sequence, wallet, password):
     for_change, i = sequence
     assert for_change == 0
     address = self.get_addresses(0)[i]
     pk = pw_decode(self.keypairs[address][1], password)
     # this checks the password
     if address != address_from_private_key(pk):
         raise ParamsError('51001')
     return [pk]
예제 #3
0
 def test_privkey_to_addr(self):
     """Test privkey to address"""
     result = address_from_private_key(self._privk)
     expected = self._addr
     self.assertEqual(expected, result)