Beispiel #1
0
 def select_uncolored_coins(self, colorvalue, use_fee_estimator):
     selected_inputs = []
     selected_value = SimpleColorValue(colordef=UNCOLORED_MARKER,
                                       value=0)
     needed = colorvalue + use_fee_estimator.estimate_required_fee()
     color_id = 0
     if color_id in self.inputs:
         total = SimpleColorValue.sum([cv_u[0]
                                       for cv_u in self.inputs[color_id]])
         needed -= total
         selected_inputs += [cv_u[1]
                            for cv_u in self.inputs[color_id]]
         selected_value += total
     if needed > 0:
         value_limit = SimpleColorValue(colordef=UNCOLORED_MARKER,
                                        value=10000+8192)
         if self.our_value_limit.is_uncolored():
             value_limit += self.our_value_limit
         if needed > value_limit:
             raise InsufficientFundsError("exceeded limits: %s requested, %s found"
                                          % (needed, value_limit))
         our_inputs, our_value = super(OperationalETxSpec, self).\
             select_coins(colorvalue - selected_value, use_fee_estimator)
         selected_inputs += our_inputs
         selected_value += our_value
     return selected_inputs, selected_value
Beispiel #2
0
    def select_coins(self, colorvalue):
        colordef = colorvalue.get_colordef()
        color_id = colordef.get_color_id()

        if color_id in self.inputs:
            total = SimpleColorValue.sum([cv_u[0]
                                          for cv_u in self.inputs[color_id]])
            if total < colorvalue:
                raise InsufficientFundsError('not enough coins: %s requested, %s found'
                                             % (colorvalue, total))
            return [cv_u[1]
                    for cv_u in self.inputs[color_id]], total

        cq = self.model.make_coin_query({"color_id_set": set([color_id])})
        utxo_list = cq.get_result()

        zero = ssum = SimpleColorValue(colordef=colordef, value=0)
        selection = []
        if colorvalue == zero:
            raise ZeroSelectError('cannot select 0 coins')
        for utxo in utxo_list:
            if utxo.colorvalues:
                ssum += utxo.colorvalues[0]
                selection.append(utxo)
                if ssum >= colorvalue:
                    return selection, ssum
        raise InsufficientFundsError('not enough coins: %s requested, %s found'
                                     % (colorvalue, ssum))
Beispiel #3
0
    def select_coins(self, colorvalue, use_fee_estimator=None):
        #FIXME
        if type(colorvalue) is int:
            colorvalue = SimpleColorValue(
                colordef=UNCOLORED_MARKER,
                value=colorvalue
            )
        self._validate_select_coins_parameters(colorvalue, use_fee_estimator)
        colordef = colorvalue.get_colordef()
        if colordef == UNCOLORED_MARKER:
            return self.select_uncolored_coins(colorvalue, use_fee_estimator)

        color_id = colordef.get_color_id()
        if color_id in self.inputs:
            # use inputs provided in proposal
            total = SimpleColorValue.sum([cv_u[0]
                                          for cv_u in self.inputs[color_id]])
            if total < colorvalue:
                raise InsufficientFundsError('not enough coins: %s requested, %s found'
                                             % (colorvalue, total))
            return [cv_u[1] for cv_u in self.inputs[color_id]], total
        
        if colorvalue != self.our_value_limit:
            raise InsufficientFundsError("%s requested, %s found"
                                         % (colorvalue, our_value_limit))
        return super(OperationalETxSpec, self).select_coins(colorvalue)
 def get_balance(self, asset):
     """Returns an integer value corresponding to the total number
     of Satoshis owned of asset/color <asset>.
     """
     cq = self.model.make_coin_query({"asset": asset})
     utxo_list = cq.get_result()
     value_list = [asset.get_colorvalue(utxo) for utxo in utxo_list]
     if len(value_list) == 0:
         return 0
     else:
         return SimpleColorValue.sum(value_list).get_value()
 def get_balance(self, asset):
     """Returns an integer value corresponding to the total number
     of Satoshis owned of asset/color <asset>.
     """
     cq = self.model.make_coin_query({"asset": asset})
     utxo_list = cq.get_result()
     value_list = [asset.get_colorvalue(utxo) for utxo in utxo_list]
     if len(value_list) == 0:
         return 0
     else:
         return SimpleColorValue.sum(value_list).get_value()
Beispiel #6
0
 def _select_enough_coins(self, colordef, utxo_list, required_sum_fn):
     ssum = SimpleColorValue(colordef=colordef, value=0)
     selection = []
     required_sum = None
     for utxo in utxo_list:
         ssum += SimpleColorValue.sum(utxo.colorvalues)
         selection.append(utxo)
         required_sum = required_sum_fn(utxo_list)
         if ssum >= required_sum:
             return selection, ssum
     raise InsufficientFundsError('Not enough coins: %s requested, %s found!'
                                  % (required_sum, ssum))
Beispiel #7
0
 def _select_enough_coins(self, colordef, utxo_list, required_sum_fn):
     ssum = SimpleColorValue(colordef=colordef, value=0)
     selection = []
     required_sum = None
     for utxo in utxo_list:
         ssum += SimpleColorValue.sum(utxo.colorvalues)
         selection.append(utxo)
         required_sum = required_sum_fn(utxo_list)
         if ssum >= required_sum:
             return selection, ssum
     raise InsufficientFundsError(
         'Not enough coins: %s requested, %s found!' % (required_sum, ssum))
Beispiel #8
0
    def select_inputs(self, colorvalue):
        cs = ColorSet.from_color_ids(self.model.get_color_map(),
                                     [colorvalue.get_color_id()])

        cq = self.model.make_coin_query({"color_set": cs})
        utxo_list = cq.get_result()
        selection = []
        csum = SimpleColorValue(colordef=colorvalue.get_colordef(), value=0)

        for utxo in utxo_list:
            csum += SimpleColorValue.sum(utxo.colorvalues)
            selection.append(utxo)
            if csum >= colorvalue:
                break
        if csum < colorvalue:
            raise InsufficientFundsError('not enough money')
        return selection, (csum - colorvalue)
Beispiel #9
0
    def select_coins(self, colorvalue):
        colordef = colorvalue.get_colordef()
        color_id = colordef.get_color_id()
        cq = self.model.make_coin_query({"color_id_set": set([color_id])})
        utxo_list = cq.get_result()

        zero = ssum = SimpleColorValue(colordef=colordef, value=0)
        selection = []
        if colorvalue == zero:
            raise ZeroSelectError('cannot select 0 coins')
        for utxo in utxo_list:
            ssum += SimpleColorValue.sum(utxo.colorvalues)
            selection.append(utxo)
            if ssum >= colorvalue:
                return selection, ssum
        raise InsufficientFundsError(
            'not enough coins: %s requested, %s found' % (colorvalue, ssum))
Beispiel #10
0
    def select_inputs(self, colorvalue):
        cs = ColorSet.from_color_ids(self.model.get_color_map(),
                                     [colorvalue.get_color_id()])

        cq = self.model.make_coin_query({"color_set": cs})
        utxo_list = cq.get_result()
        selection = []
        csum = SimpleColorValue(colordef=colorvalue.get_colordef(), value=0)

        for utxo in utxo_list:
            csum += SimpleColorValue.sum(utxo.colorvalues)
            selection.append(utxo)
            if csum >= colorvalue:
                break
        if csum < colorvalue:
            raise InsufficientFundsError('not enough money')
        return selection, (csum - colorvalue)
Beispiel #11
0
    def select_coins(self, colorvalue, use_fee_estimator=None):
        self._validate_select_coins_parameters(colorvalue, use_fee_estimator)
        colordef = colorvalue.get_colordef()
        if colordef == UNCOLORED_MARKER:
            return self.select_uncolored_coins(colorvalue, use_fee_estimator)

        color_id = colordef.get_color_id()
        if color_id in self.inputs:
            # use inputs provided in proposal
            total = SimpleColorValue.sum([cv_u[0]
                                          for cv_u in self.inputs[color_id]])
            if total < colorvalue:
                raise InsufficientFundsError('not enough coins: %s requested, %s found'
                                             % (colorvalue, total))
            return [cv_u[1] for cv_u in self.inputs[color_id]], total
        
        if colorvalue != self.our_value_limit:
            raise InsufficientFundsError("%s requested, %s found"
                                         % (colorvalue, our_value_limit))
        return super(OperationalETxSpec, self).select_coins(colorvalue)
Beispiel #12
0
    def select_coins(self, colorvalue):
        """Return a list of utxos and sum that corresponds to
        the colored coins identified by <color_def> of amount <colorvalue>
        that we'll be spending from our wallet.
        """
        colordef = colorvalue.get_colordef()
        color_id = colordef.get_color_id()
        cq = self.model.make_coin_query({"color_id_set": set([color_id])})
        utxo_list = cq.get_result()

        zero = ssum = SimpleColorValue(colordef=colordef, value=0)
        selection = []
        if colorvalue == zero:
            raise ZeroSelectError('cannot select 0 coins')
        for utxo in utxo_list:
            ssum += SimpleColorValue.sum(utxo.colorvalues)
            selection.append(utxo)
            if ssum >= colorvalue:
                return selection, ssum
        raise InsufficientFundsError(
            'not enough coins: %s requested, %s found' % (colorvalue, ssum))
Beispiel #13
0
    def select_coins(self, colorvalue):
        """Return a list of utxos and sum that corresponds to
        the colored coins identified by <color_def> of amount <colorvalue>
        that we'll be spending from our wallet.
        """
        colordef = colorvalue.get_colordef()
        color_id = colordef.get_color_id()
        cq = self.model.make_coin_query({"color_id_set": set([color_id])})
        utxo_list = cq.get_result()

        zero = ssum = SimpleColorValue(colordef=colordef, value=0)
        selection = []
        if colorvalue == zero:
            raise ZeroSelectError('cannot select 0 coins')
        for utxo in utxo_list:
            ssum += SimpleColorValue.sum(utxo.colorvalues)
            selection.append(utxo)
            if ssum >= colorvalue:
                return selection, ssum
        raise InsufficientFundsError('not enough coins: %s requested, %s found'
                                     % (colorvalue, ssum))