コード例 #1
0
 def source_fee(self):
     claim = self.protobuf
     if not CLAIM_TYPE_NAMES[claim.claimType] == "stream":
         return None
     if claim.stream.metadata.HasField("fee"):
         return Fee.load_protobuf(claim.stream.metadata.fee)
     return None
コード例 #2
0
    def check_fee_and_convert(self, fee):
        from_currency = self.max_key_fee['currency']
        to_currency = 'LBC'
        amount = self.max_key_fee['amount']

        convert_fee = self.exchange_rate_manager.convert_currency
        max_key_fee_amount = convert_fee(from_currency,
                                         to_currency,
                                         amount)
        converted_fee_amount = convert_fee(fee.currency,
                                           to_currency,
                                           fee.amount)

        if converted_fee_amount > (yield f2d(self.wallet.default_account.get_balance())):
            raise InsufficientFundsError(f"Unable to pay the key fee of "
                                         f"{converted_fee_amount}")
        if converted_fee_amount > max_key_fee_amount and amount >= 0:
            raise KeyFeeAboveMaxAllowed(f"Key fee {converted_fee_amount} above "
                                        f"max allowed {max_key_fee_amount}")
        converted_fee = {
            'currency': 'LBC',
            'amount': converted_fee_amount,
            'address': fee.address
        }
        return Fee(converted_fee)
コード例 #3
0
 def test_fee_zero(self):
     fee_dict = {
         'currency': 'LBC',
         'amount': 0.0,
         'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
     }
     fee = Fee(fee_dict)
     self.assertEqual(0.0, fee['amount'])
     self.assertEqual('LBC', fee['currency'])
コード例 #4
0
 def test_fee_created_with_correct_inputs(self):
     fee_dict = {
         'currency': 'USD',
         'amount': 10.0,
         'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
     }
     fee = Fee(fee_dict)
     self.assertEqual(10.0, fee['amount'])
     self.assertEqual('USD', fee['currency'])
コード例 #5
0
    def test_missing_feed(self):
        # test when a feed is missing for conversion
        fee = Fee({
            'currency':'USD',
            'amount': 1.0,
            'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
            })

        rates = {
            'BTCLBC': {'spot': 1.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1},
        }
        market_feeds = [BTCLBCFeed()]
        manager = DummyExchangeRateManager(market_feeds, rates)
        with self.assertRaises(Exception):
            manager.convert_currency(fee.currency, "LBC", fee.amount)
コード例 #6
0
    def test_fee_converts_to_lbc(self):
        fee = Fee({
            'currency': 'USD',
            'amount': 10.0,
            'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
            })

        rates = {
            'BTCLBC': {'spot': 3.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1},
            'USDBTC': {'spot': 2.0, 'ts': test_utils.DEFAULT_ISO_TIME + 2}
        }

        market_feeds = [BTCLBCFeed(), USDBTCFeed()]
        manager = DummyExchangeRateManager(market_feeds, rates)
        result = manager.convert_currency(fee.currency, "LBC", fee.amount)
        self.assertEqual(60.0, result)
コード例 #7
0
 def check_fee_and_convert(self, fee):
     max_key_fee_amount = self.convert_max_fee()
     converted_fee_amount = self.exchange_rate_manager.convert_currency(
         fee.currency, "LBC", fee.amount)
     if converted_fee_amount > (yield f2d(
             self.wallet.default_account.get_balance())):
         raise InsufficientFundsError('Unable to pay the key fee of %s' %
                                      converted_fee_amount)
     if converted_fee_amount > max_key_fee_amount and not self.disable_max_key_fee:
         raise KeyFeeAboveMaxAllowed(
             'Key fee {} above max allowed {}'.format(
                 converted_fee_amount, max_key_fee_amount))
     converted_fee = {
         'currency': 'LBC',
         'amount': converted_fee_amount,
         'address': fee.address
     }
     return Fee(converted_fee)