tfchain/TFChainWallet.py
def fund(self, amount, source=None):
        """
        Fund the specified amount with the available outputs of this wallet's balance.
        """
        # collect addresses and multisig addresses
        addresses = set()
        ms_addresses = set()
        refund = None
        if source is None:
            for co in self.outputs_available:
                addresses.add(co.condition.unlockhash)
            for co in self.outputs_unconfirmed_available:
                addresses.add(co.condition.unlockhash)
        else:
            # if only one address is given, transform it into an acceptable list
            if not isinstance(source, list):
                if isinstance(source, str):
                    source = UnlockHash.from_json(source)
                elif not isinstance(source, UnlockHash):
                    raise TypeError("cannot add source address from type {}".format(type(source)))
                source = [source]
            # add one or multiple personal/multisig addresses
            for value in source:
                if isinstance(value, str):
                    value = UnlockHash.from_json(value)
                elif not isinstance(value, UnlockHash):
                    raise TypeError("cannot add source address from type {}".format(type(value)))
                if value.type == UnlockHashType.MULTI_SIG:
                    ms_addresses.add(value)
                elif value.type == UnlockHashType.PUBLIC_KEY:
                    addresses.add(value)
                else:
                    raise TypeError("cannot add source addres with unsupported UnlockHashType {}".format(value.type))
            if len(source) == 1:
                if source[0].type == UnlockHashType.PUBLIC_KEY:
                    refund = ConditionTypes.unlockhash_new(unlockhash=source[0])
                else:
                    addr = str(source[0])
                    if addr in self.wallets:
                        wallet = self.wallets[addr]
                        refund = ConditionTypes.multi_signature_new(min_nr_sig=wallet.signature_count, unlockhashes=wallet.owners)


        # ensure at least one address is defined
        if len(addresses) == 0 and len(ms_addresses) == 0:
            raise tfchain.errors.InsufficientFunds("insufficient funds in this wallet")

        # if personal addresses are given, try to use these first
        # as these are the easiest kind to deal with
        if len(addresses) == 0:
            outputs, collected = ([], Currency()) # start with nothing
        else:
            outputs, collected = self._fund_individual(amount, addresses)

        if collected >= amount:
            # if we already have sufficient, we stop now
            return ([CoinInput.from_coin_output(co) for co in outputs], collected-amount, refund)

        if len(ms_addresses) == 0:
            # if no ms_addresses were defined,
            raise tfchain.errors.InsufficientFunds("not enough funds available in the individual wallet to fund the requested amount")
        # otherwise keep going for multisig addresses
        outputs, collected = self._fund_multisig(amount, ms_addresses, outputs=outputs, collected=collected)

        # if we still didn't manage to fund enough, there is nothing we can do
        if collected < amount:
            raise tfchain.errors.InsufficientFunds("not enough funds available in the wallets to fund the requested amount")
        return ([CoinInput.from_coin_output(co) for co in outputs], collected-amount, refund)

        Fund the specified amount with the available outputs of this wallet's balance.
        
Fund the specified amount with the available outputs of this wallet's balance.
Fund the specified amount with the available outputs of this wallet ' s balance .
def fund(self, amount, source=None):
        addresses = set()
        ms_addresses = set()
        refund = None
        if source is None:
            for co in self.outputs_available:
                addresses.add(co.condition.unlockhash)
            for co in self.outputs_unconfirmed_available:
                addresses.add(co.condition.unlockhash)
        else:
            if not isinstance(source, list):
                if isinstance(source, str):
                    source = UnlockHash.from_json(source)
                elif not isinstance(source, UnlockHash):
                    raise TypeError("cannot add source address from type {}".format(type(source)))
                source = [source]
            for value in source:
                if isinstance(value, str):
                    value = UnlockHash.from_json(value)
                elif not isinstance(value, UnlockHash):
                    raise TypeError("cannot add source address from type {}".format(type(value)))
                if value.type == UnlockHashType.MULTI_SIG:
                    ms_addresses.add(value)
                elif value.type == UnlockHashType.PUBLIC_KEY:
                    addresses.add(value)
                else:
                    raise TypeError("cannot add source addres with unsupported UnlockHashType {}".format(value.type))
            if len(source) == 1:
                if source[0].type == UnlockHashType.PUBLIC_KEY:
                    refund = ConditionTypes.unlockhash_new(unlockhash=source[0])
                else:
                    addr = str(source[0])
                    if addr in self.wallets:
                        wallet = self.wallets[addr]
                        refund = ConditionTypes.multi_signature_new(min_nr_sig=wallet.signature_count, unlockhashes=wallet.owners)
        if len(addresses) == 0 and len(ms_addresses) == 0:
            raise tfchain.errors.InsufficientFunds("insufficient funds in this wallet")
        if len(addresses) == 0:
            outputs, collected = ([], Currency()) 
        else:
            outputs, collected = self._fund_individual(amount, addresses)
        if collected >= amount:
            return ([CoinInput.from_coin_output(co) for co in outputs], collected-amount, refund)
        if len(ms_addresses) == 0:
            raise tfchain.errors.InsufficientFunds("not enough funds available in the individual wallet to fund the requested amount")
        outputs, collected = self._fund_multisig(amount, ms_addresses, outputs=outputs, collected=collected)
        if collected < amount:
            raise tfchain.errors.InsufficientFunds("not enough funds available in the wallets to fund the requested amount")
        return ([CoinInput.from_coin_output(co) for co in outputs], collected-amount, refund)
def fund ( self , amount , source = None ) : addresses = set ( ) ms_addresses = set ( ) refund = None if source is None : for co in self . outputs_available : addresses . add ( co . condition . unlockhash ) for co in self . outputs_unconfirmed_available : addresses . add ( co . condition . unlockhash ) else : if not isinstance ( source , list ) : if isinstance ( source , str ) : source = UnlockHash . from_json ( source ) elif not isinstance ( source , UnlockHash ) : raise TypeError ( "cannot add source address from type {}" . format ( type ( source ) ) ) source = [ source ] for value in source : if isinstance ( value , str ) : value = UnlockHash . from_json ( value ) elif not isinstance ( value , UnlockHash ) : raise TypeError ( "cannot add source address from type {}" . format ( type ( value ) ) ) if value . type == UnlockHashType . MULTI_SIG : ms_addresses . add ( value ) elif value . type == UnlockHashType . PUBLIC_KEY : addresses . add ( value ) else : raise TypeError ( "cannot add source addres with unsupported UnlockHashType {}" . format ( value . type ) ) if len ( source ) == 1 : if source [ 0 ] . type == UnlockHashType . PUBLIC_KEY : refund = ConditionTypes . unlockhash_new ( unlockhash = source [ 0 ] ) else : addr = str ( source [ 0 ] ) if addr in self . wallets : wallet = self . wallets [ addr ] refund = ConditionTypes . multi_signature_new ( min_nr_sig = wallet . signature_count , unlockhashes = wallet . owners ) if len ( addresses ) == 0 and len ( ms_addresses ) == 0 : raise tfchain . errors . InsufficientFunds ( "insufficient funds in this wallet" ) if len ( addresses ) == 0 : outputs , collected = ( [ ] , Currency ( ) ) else : outputs , collected = self . _fund_individual ( amount , addresses ) if collected >= amount : return ( [ CoinInput . from_coin_output ( co ) for co in outputs ] , collected - amount , refund ) if len ( ms_addresses ) == 0 : raise tfchain . errors . InsufficientFunds ( "not enough funds available in the individual wallet to fund the requested amount" ) outputs , collected = self . _fund_multisig ( amount , ms_addresses , outputs = outputs , collected = collected ) if collected < amount : raise tfchain . errors . InsufficientFunds ( "not enough funds available in the wallets to fund the requested amount" ) return ( [ CoinInput . from_coin_output ( co ) for co in outputs ] , collected - amount , refund )
Fund the specified amount with the available outputs of this wallet's balance.
Fund the specified amount with the available outputs of this wallet ' s balance .
"""
        Fund the specified amount with the available outputs of this wallet's balance.
        """ # collect addresses and multisig addresses # if only one address is given, transform it into an acceptable list # add one or multiple personal/multisig addresses # ensure at least one address is defined # if personal addresses are given, try to use these first # as these are the easiest kind to deal with # start with nothing # if we already have sufficient, we stop now # if no ms_addresses were defined, # otherwise keep going for multisig addresses # if we still didn't manage to fund enough, there is nothing we can do
self
amount
source