mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Trustedcoin: prepaid-only billing
This commit is contained in:
parent
aa6cab37d5
commit
6ca52153c3
2 changed files with 25 additions and 27 deletions
|
@ -142,7 +142,7 @@ class Plugin(TrustedCoinPlugin):
|
||||||
vbox.addLayout(hbox)
|
vbox.addLayout(hbox)
|
||||||
vbox.addStretch(10)
|
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 = QLabel(msg)
|
||||||
label.setWordWrap(1)
|
label.setWordWrap(1)
|
||||||
vbox.addWidget(label)
|
vbox.addWidget(label)
|
||||||
|
@ -152,35 +152,21 @@ class Plugin(TrustedCoinPlugin):
|
||||||
vbox.addLayout(grid)
|
vbox.addLayout(grid)
|
||||||
|
|
||||||
price_per_tx = wallet.price_per_tx
|
price_per_tx = wallet.price_per_tx
|
||||||
v = price_per_tx.get(1)
|
n_prepay = wallet.num_prepay(self.config)
|
||||||
grid.addWidget(QLabel(_("Price per transaction (not prepaid):")), 0, 0)
|
i = 0
|
||||||
grid.addWidget(QLabel(window.format_amount(v) + ' ' + window.base_unit()), 0, 1)
|
|
||||||
|
|
||||||
i = 1
|
|
||||||
|
|
||||||
for k, v in sorted(price_per_tx.items()):
|
for k, v in sorted(price_per_tx.items()):
|
||||||
if k == 1:
|
if k == 1:
|
||||||
continue
|
continue
|
||||||
grid.addWidget(QLabel("Price for %d prepaid transactions:"%k), i, 0)
|
grid.addWidget(QLabel("Pay every %d transactions:"%k), i, 0)
|
||||||
grid.addWidget(QLabel("%d x "%k + window.format_amount(v/k) + ' ' + window.base_unit()), i, 1)
|
grid.addWidget(QLabel(window.format_amount(v/k) + ' ' + window.base_unit() + "/tx"), i, 1)
|
||||||
b = QPushButton(_("Buy"))
|
b = QRadioButton()
|
||||||
b.clicked.connect(lambda b, k=k, v=v: self.on_buy(window, k, v, d))
|
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)
|
grid.addWidget(b, i, 2)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
n = wallet.billing_info.get('tx_remaining', 0)
|
n = wallet.billing_info.get('tx_remaining', 0)
|
||||||
grid.addWidget(QLabel(_("Your wallet has %d prepaid transactions.")%n), i, 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)))
|
vbox.addLayout(Buttons(CloseButton(d)))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ class Wallet_2fa(Multisig_Wallet):
|
||||||
sendable = sum(map(lambda x:x['value'], inputs))
|
sendable = sum(map(lambda x:x['value'], inputs))
|
||||||
for i in inputs:
|
for i in inputs:
|
||||||
self.add_input_info(i)
|
self.add_input_info(i)
|
||||||
xf = self.extra_fee()
|
xf = self.extra_fee(config)
|
||||||
_type, addr = recipient
|
_type, addr = recipient
|
||||||
if xf and sendable >= xf:
|
if xf and sendable >= xf:
|
||||||
billing_address = self.billing_info['billing_address']
|
billing_address = self.billing_info['billing_address']
|
||||||
|
@ -224,22 +224,33 @@ class Wallet_2fa(Multisig_Wallet):
|
||||||
amount = max(0, sendable - fee)
|
amount = max(0, sendable - fee)
|
||||||
return amount, 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():
|
if self.can_sign_without_server():
|
||||||
return 0
|
return 0
|
||||||
if self.billing_info.get('tx_remaining'):
|
if self.billing_info.get('tx_remaining'):
|
||||||
return 0
|
return 0
|
||||||
if self.is_billing:
|
if self.is_billing:
|
||||||
return 0
|
return 0
|
||||||
price = int(self.price_per_tx.get(1))
|
n = self.num_prepay(config)
|
||||||
assert price <= 100000
|
price = int(self.price_per_tx[n])
|
||||||
|
assert price <= 100000 * n
|
||||||
return price
|
return price
|
||||||
|
|
||||||
def make_unsigned_transaction(self, coins, outputs, config,
|
def make_unsigned_transaction(self, coins, outputs, config,
|
||||||
fixed_fee=None, change_addr=None):
|
fixed_fee=None, change_addr=None):
|
||||||
mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction(
|
mk_tx = lambda o: Multisig_Wallet.make_unsigned_transaction(
|
||||||
self, coins, o, config, fixed_fee, change_addr)
|
self, coins, o, config, fixed_fee, change_addr)
|
||||||
fee = self.extra_fee()
|
fee = self.extra_fee(config)
|
||||||
if fee:
|
if fee:
|
||||||
address = self.billing_info['billing_address']
|
address = self.billing_info['billing_address']
|
||||||
fee_output = (TYPE_ADDRESS, address, fee)
|
fee_output = (TYPE_ADDRESS, address, fee)
|
||||||
|
@ -329,6 +340,7 @@ class TrustedCoinPlugin(BasePlugin):
|
||||||
assert billing_address == billing_info['billing_address']
|
assert billing_address == billing_info['billing_address']
|
||||||
wallet.billing_info = billing_info
|
wallet.billing_info = billing_info
|
||||||
wallet.price_per_tx = dict(billing_info['price_per_tx'])
|
wallet.price_per_tx = dict(billing_info['price_per_tx'])
|
||||||
|
wallet.price_per_tx.pop(1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def make_seed(self):
|
def make_seed(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue