コード例 #1
0
ファイル: ewctrl.py プロジェクト: maraoz/ngcccbase
 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
コード例 #2
0
ファイル: ewctrl.py プロジェクト: maraoz/ngcccbase
    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)
コード例 #3
0
ファイル: ewctrl.py プロジェクト: arichnad/ngcccbase
    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)
コード例 #4
0
ファイル: ewctrl.py プロジェクト: arichnad/ngcccbase
    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))