Ejemplo n.º 1
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
    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
    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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def add_inputs(self,
                   private_key=None,
                   address=None,
                   amount='all',
                   max_ins=None,
                   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.
        """
        if private_key:
            if private_key.startswith('6P'):
                if not password:
                    raise Exception(
                        "Password required for BIP38 encoded private keys")
                from .bip38 import Bip38EncryptedPrivateKey
                private_key = Bip38EncryptedPrivateKey(
                    self.crypto, private_key).decrypt(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 = 0
        for utxo in self._get_utxos(address, services, **modes):
            if max_ins and ins >= max_ins:
                break
            if (amount == 'all' or total_added_satoshi < amount):
                ins += 1
                self.ins.append(dict(input=utxo, private_key=private_key))
                total_added_satoshi += utxo['amount']

        return total_added_satoshi, ins
Ejemplo n.º 6
0
    def add_inputs(self, private_key=None, address=None, amount='all', max_ins=None, 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.
        """
        if private_key:
            if private_key.startswith('6P'):
                if not password:
                    raise Exception("Password required for BIP38 encoded private keys")
                from .bip38 import Bip38EncryptedPrivateKey
                private_key = Bip38EncryptedPrivateKey(self.crypto, private_key).decrypt(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 = 0
        for utxo in self._get_utxos(address, services, **modes):
            if max_ins and ins >= max_ins:
                break
            if (amount == 'all' or total_added_satoshi < amount):
                ins += 1
                self.ins.append(
                    dict(input=utxo, private_key=private_key)
                )
                total_added_satoshi += utxo['amount']

        return total_added_satoshi, ins