Esempio n. 1
0
    def __init__(self, crypto, hex=None, verbose=False):
        if crypto.lower() in ['nxt']:
            raise NotImplementedError("%s not yet supported" % crypto.upper())

        self.change_address = None
        self.crypto = crypto
        self.fee_satoshi = None
        self.outs = []
        self.ins = []

        self.verbose = verbose

        services = get_optimal_services(self.crypto, 'current_price')
        self.price_getter = CurrentPrice(services=services, verbose=verbose)

        if hex:
            self.hex = hex
Esempio n. 2
0
    def push(self, services=None, redundancy=1):
        if not services:
            services = get_optimal_services(self.crypto, "push_tx")

        self.pushers = []
        pusher = PushTx(services=services, verbose=self.verbose)
        results = [pusher.action(self.crypto, self.get_hex())]

        try:
            for service in services[1:redundancy-1]:
                pusher = PushTx(services=[service], verbose=self.verbose)
                results.append(self.pusher.action(self.crypto, self.get_hex()))
                self.pushers.append(pusher)
        except:
            raise Exception("Partial push. Some services returned success, some failed.")

        return results
Esempio n. 3
0
    def add_inputs(self, private_key=None, address=None, amount='all', password=None, services=None, **modes):
        """
        Make call to external service to get inputs from an address and/or private_key.
        `amount` is the amount of [currency] worth of inputs (in satoshis) to add from
        this address. Pass in 'all' (the default) to use *all* inputs found for this address.
         Returned is the number of units (in satoshis) that were added as inputs to this tx.
        """
        #from ipdb import set_trace; set_trace()
        if private_key:
            if private_key.startswith('6P'):
                if not password:
                    raise Exception("Password required for BIP38 encoded private keys")
                private_key = bip38_decrypt(private_key, password)

            address_from_priv = self.private_key_to_address(private_key)
            if address and address != address_from_priv:
                raise Exception("Invalid Private key")
            address = address_from_priv
            self.change_address = address

        if not services:
            services = get_optimal_services(self.crypto, 'unspent_outputs')

        total_added_satoshi = 0
        ins = []
        for utxo in self._get_utxos(address, services, **modes):
            if (amount == 'all' or total_added_satoshi < amount):
                self.ins.append(
                    dict(input=utxo, private_key=private_key)
                )
                total_added_satoshi += utxo['amount']

        if total_added_satoshi == 0:
            raise Exception("No inputs available for: %s" % address)

        return total_added_satoshi