electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 6ca52153c316fdb46064aaaaeb02d4ba3e824f68
parent aa6cab37d5e23caa3cbbdab11c356b8e7e53c974
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 12 May 2017 15:58:00 +0200

Trustedcoin: prepaid-only billing

Diffstat:
Mplugins/trustedcoin/qt.py | 30++++++++----------------------
Mplugins/trustedcoin/trustedcoin.py | 22+++++++++++++++++-----
2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/plugins/trustedcoin/qt.py b/plugins/trustedcoin/qt.py @@ -142,7 +142,7 @@ class Plugin(TrustedCoinPlugin): vbox.addLayout(hbox) vbox.addStretch(10) - msg = _('TrustedCoin charges a fee per co-signed transaction. You may pay on each transaction (an extra output will be added to your transaction), or you may purchase prepaid transaction using this dialog.') + '<br/>' + msg = _('TrustedCoin charges a small fee to co-sign transactions. The fee depends on how many prepaid transactions you buy. An extra output is added to your transaction everytime you run out of prepaid transactions.') + '<br/>' label = QLabel(msg) label.setWordWrap(1) vbox.addWidget(label) @@ -152,35 +152,21 @@ class Plugin(TrustedCoinPlugin): vbox.addLayout(grid) price_per_tx = wallet.price_per_tx - v = price_per_tx.get(1) - grid.addWidget(QLabel(_("Price per transaction (not prepaid):")), 0, 0) - grid.addWidget(QLabel(window.format_amount(v) + ' ' + window.base_unit()), 0, 1) - - i = 1 - + n_prepay = wallet.num_prepay(self.config) + i = 0 for k, v in sorted(price_per_tx.items()): if k == 1: continue - grid.addWidget(QLabel("Price for %d prepaid transactions:"%k), i, 0) - grid.addWidget(QLabel("%d x "%k + window.format_amount(v/k) + ' ' + window.base_unit()), i, 1) - b = QPushButton(_("Buy")) - b.clicked.connect(lambda b, k=k, v=v: self.on_buy(window, k, v, d)) + grid.addWidget(QLabel("Pay every %d transactions:"%k), i, 0) + grid.addWidget(QLabel(window.format_amount(v/k) + ' ' + window.base_unit() + "/tx"), i, 1) + b = QRadioButton() + b.setChecked(k == n_prepay) + b.clicked.connect(lambda b, k=k: self.config.set_key('trustedcoin_prepay', k, True)) grid.addWidget(b, i, 2) i += 1 n = wallet.billing_info.get('tx_remaining', 0) grid.addWidget(QLabel(_("Your wallet has %d prepaid transactions.")%n), i, 0) - - # tranfer button - #def on_transfer(): - # server.transfer_credit(self.user_id, recipient, otp, signature_callback) - # pass - #b = QPushButton(_("Transfer")) - #b.clicked.connect(on_transfer) - #grid.addWidget(b, 1, 2) - - #grid.addWidget(QLabel(_("Next Billing Address:")), i, 0) - #grid.addWidget(QLabel(self.billing_info['billing_address']), i, 1) vbox.addLayout(Buttons(CloseButton(d))) d.exec_() diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py @@ -209,7 +209,7 @@ class Wallet_2fa(Multisig_Wallet): sendable = sum(map(lambda x:x['value'], inputs)) for i in inputs: self.add_input_info(i) - xf = self.extra_fee() + xf = self.extra_fee(config) _type, addr = recipient if xf and sendable >= xf: billing_address = self.billing_info['billing_address'] @@ -224,22 +224,33 @@ class Wallet_2fa(Multisig_Wallet): amount = max(0, sendable - fee) return amount, fee - def extra_fee(self): + def min_prepay(self): + return min(self.price_per_tx.keys()) + + def num_prepay(self, config): + default = self.min_prepay() + n = config.get('trustedcoin_prepay', default) + if n not in self.price_per_tx: + n = default + return n + + def extra_fee(self, config): if self.can_sign_without_server(): return 0 if self.billing_info.get('tx_remaining'): return 0 if self.is_billing: return 0 - price = int(self.price_per_tx.get(1)) - assert price <= 100000 + n = self.num_prepay(config) + price = int(self.price_per_tx[n]) + assert price <= 100000 * n return price def make_unsigned_transaction(self, coins, outputs, config, fixed_fee=None, change_addr=None): mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction( self, coins, o, config, fixed_fee, change_addr) - fee = self.extra_fee() + fee = self.extra_fee(config) if fee: address = self.billing_info['billing_address'] fee_output = (TYPE_ADDRESS, address, fee) @@ -329,6 +340,7 @@ class TrustedCoinPlugin(BasePlugin): assert billing_address == billing_info['billing_address'] wallet.billing_info = billing_info wallet.price_per_tx = dict(billing_info['price_per_tx']) + wallet.price_per_tx.pop(1) return True def make_seed(self):