New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include existing claim amount in the max biddable amount for a publish #1108
Conversation
Forgot changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing the balance checks you should update them to use fresh numbers from lbryum. lbrynet.core.Wallet.update_balance
probably is what you're looking for
@@ -715,8 +715,6 @@ def _publish_stream(self, name, bid, claim_dict, file_path=None, certificate_id= | |||
publisher = Publisher(self.session, self.lbry_file_manager, self.session.wallet, | |||
certificate_id) | |||
parse_lbry_uri(name) | |||
if bid <= 0.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this is here is because otherwise we have to possibly make a stream before lbryum would tell us something is wrong
lbrynet/daemon/Daemon.py
Outdated
@@ -1969,10 +1967,6 @@ def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, ti | |||
if bid <= 0.0: | |||
raise Exception("Invalid bid") | |||
|
|||
if bid >= self.session.wallet.get_balance(): | |||
raise InsufficientFundsError('Insufficient funds. ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as the other bid check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this should be formatted as something like:
raise InsufficientFundsError(
'Insufficient funds. Make sure you have enough LBC to deposit.'
)
Or perhaps, if the message is constant it should just be built-in to the InsufficientFundsError. How many different messages do we need for this exception?
lbrynet/daemon/Daemon.py
Outdated
@@ -1969,10 +1967,6 @@ def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, ti | |||
if bid <= 0.0: | |||
raise Exception("Invalid bid") | |||
|
|||
if bid >= self.session.wallet.get_balance(): | |||
raise InsufficientFundsError('Insufficient funds. ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this should be formatted as something like:
raise InsufficientFundsError(
'Insufficient funds. Make sure you have enough LBC to deposit.'
)
Or perhaps, if the message is constant it should just be built-in to the InsufficientFundsError. How many different messages do we need for this exception?
@@ -217,7 +217,7 @@ def update_balance(): | |||
d.addCallback(lambda _: self.assertEqual(5, wallet.get_balance())) | |||
d.addCallback(lambda _: wallet.reserve_points('testid', 2)) | |||
d.addCallback(lambda _: wallet.claim_name('test', 4, test_claim_dict)) | |||
self.assertFailure(d, InsufficientFundsError) | |||
self.assertFailure(d, Exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for Exception
seems a bit dangerous. This would pass the test on any exception, even if it has nothing to do with the error being tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is returned from lbryum I guess, maybe I need to look at the lbryum error messages too.
Also would it be bad practice if I check the error message string and then decide which exception to raise?? Something like
if claim["msg"] == "Insufficient funds":
Raise InsufficientFundsError()
here ^ claim
is the JSON signature returned from lbryum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for an error condition in a response from lbryum and throwing an appropriate exception makes sense to me. Although lbryum is not consistent about the insufficient funds errors, maybe we need to add error codes first as @kauffj suggested in another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the function for checking the above stuff in lbryum is a bit convoluted, with many abstract returns. Maybe I'll check for error message in daemon and raise specific Exceptions for possible cases, and a different but non-generic and descriptive errors for the rest of the cases.
@jackrobison For e.g. I have: |
Perhaps you could add a function to the lbryum wallet to return the maximum spendable amount for an update. Something like:
Then have lbrynet |
27b4d0a
to
a50d6a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor things. Otherwise, LGTM!
lbrynet/core/Wallet.py
Outdated
@defer.inlineCallbacks | ||
def get_max_usable_balance_for_claim(self, claim_name): | ||
amt = yield self._run_cmd_as_defer_to_thread('get_max_spendable_amt_for_claim', claim_name) | ||
defer.returnValue(amt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this to just:
def get_max_usable_balance_for_claim(self, claim_name):
return self._run_cmd_as_defer_to_thread('get_max_spendable_amt_for_claim', claim_name)
@defer.inlineCallbacks
turns a method into something that returns a Deferred
but _run_cmd_as_defer_to_thread()
already returns a Deferred
, so you can skip all the indirection and just return the result of _run_cmd_as_defer_to_thread()
.
lbrynet/daemon/Daemon.py
Outdated
amt = yield self.session.wallet.get_max_usable_balance_for_claim(name) | ||
if bid > amt: | ||
raise InsufficientFundsError( | ||
"Please lower the bid value, the max amount you can specify for this claim is {}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In user facing messages we should spell out 'max' as maximum. If this text doesn't make it to the user then never mind.
Fixes #748 Fixed failing test, Yay! Why CHANGELOG? Why not anarchy?
3559d28
to
99dda5f
Compare
CHANGELOG.md
Outdated
@@ -26,7 +26,8 @@ at anytime. | |||
* `get` failing with a non-useful error message when given a uri for a channel claim | |||
* exception checking in several wallet unit tests | |||
* daemon not erring properly for non-numeric values being passed to the `bid` parameter for the `publish` method | |||
* | |||
* publish command to allow updating claims with bid amount higher than wallet balance(by spending the claimtrietx coin) (https://github.com/lbryio/lbry/issues/748) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commands, classes, functions, and argument names should be decorated with code ( `
) tags. In this entry, publish
and bid
should be decorated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
higher than wallet balance
How much higher? Could be rephrased: with a bid amount higher than the wallet balance, so long as the amount is less than the wallet balance plus the bid amount of the claim being updated
@@ -975,6 +976,9 @@ def _update_balance(self): | |||
lambda result: Decimal(result['confirmed']) + Decimal(result.get('unconfirmed', 0.0))) | |||
return d | |||
|
|||
def get_max_usable_balance_for_claim(self, claim_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a matching dummy method in Wallet
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
99dda5f
to
3754f34
Compare
@jackrobison I made the required changes. Please check. |
Fixes updating a claim when update's bid amount is greater than wallet balance but it can use the claim's original amount to complete the transaction.