Merge pull request #474 from lbryio/fix-update-claim

fix Wallet.claim_name, convert to inlineCallbacks
This commit is contained in:
Jack Robison 2017-02-09 10:23:48 -05:00 committed by GitHub
commit 6b22debb79
2 changed files with 42 additions and 51 deletions

View file

@ -11,11 +11,12 @@ at anytime.
### Changed ### Changed
* add uri to stream reflector to de-obfuscate reflector logs * add uri to stream reflector to de-obfuscate reflector logs
### Fixed ### Fixed
* fix recursion depth error upon failed blob * Fix recursion depth error upon failed blob
* call stopProducing in reflector client file_sender when uploading is done * Call stopProducing in reflector client file_sender when uploading is done
* ensure streams in stream_info_manager are saved in lbry_file_manager * Ensure streams in stream_info_manager are saved in lbry_file_manager
* [#470](https://github.com/lbryio/lbry/issues/470) * Fixed file_delete not deleting data from stream_info_manager [#470](https://github.com/lbryio/lbry/issues/470)
* Fixed upload of bug reports to Slack ([#472](https://github.com/lbryio/lbry/issues/472)) * Fixed upload of bug reports to Slack ([#472](https://github.com/lbryio/lbry/issues/472))
* Fixed claim updates [#473](https://github.com/lbryio/lbry/issues/473)
## [0.8.1] - 2017-02-01 ## [0.8.1] - 2017-02-01
### Changed ### Changed

View file

@ -612,60 +612,50 @@ class Wallet(object):
claim_out['fee'] = float(claim_out['fee']) claim_out['fee'] = float(claim_out['fee'])
return claim_out return claim_out
@defer.inlineCallbacks
def claim_name(self, name, bid, metadata):
""" """
Claim a name, update if name already claimed by user Claim a name, or update if name already claimed by user
@param name: name to claim
@param bid: bid amount @param name: str, name to claim
@param bid: float, bid amount
@param m: metadata @param metadata: Metadata compliant dict
@return: Deferred which returns a dict containing below items @return: Deferred which returns a dict containing below items
txid - txid of the resulting transaction txid - txid of the resulting transaction
nout - nout of the resulting claim nout - nout of the resulting claim
fee - transaction fee paid to make claim fee - transaction fee paid to make claim
claim_id - claim id of the claim claim_id - claim id of the claim
""" """
def claim_name(self, name, bid, m): _metadata = Metadata(metadata)
my_claim = yield self.get_my_claim(name)
def _save_metadata(claim_out, metadata): if my_claim:
if not claim_out['success']: log.info("Updating claim")
msg = 'Claim to name {} failed: {}'.format(name, claim_out['reason']) if self.get_balance() < bid - my_claim['amount']:
raise Exception(msg)
claim_out = self._process_claim_out(claim_out)
claim_outpoint = ClaimOutpoint(claim_out['txid'], claim_out['nout'])
log.info("Saving metadata for claim %s %d",
claim_outpoint['txid'], claim_outpoint['nout'])
d = self._save_name_metadata(name, claim_outpoint, metadata['sources']['lbry_sd_hash'])
d.addCallback(lambda _: claim_out)
return d
def _claim_or_update(claim, metadata, _bid):
if not claim:
log.debug("No own claim yet, making a new one")
if self.get_balance() < _bid:
raise InsufficientFundsError() raise InsufficientFundsError()
return self._send_name_claim(name, metadata, _bid) new_metadata = yield self.update_metadata(_metadata, my_claim['value'])
old_claim_outpoint = ClaimOutpoint(my_claim['txid'], my_claim['nOut'])
claim = yield self._send_name_claim_update(name, my_claim['claim_id'],
old_claim_outpoint, new_metadata, bid)
claim['claim_id'] = my_claim['claim_id']
else: else:
log.debug("Updating over own claim") log.info("Making a new claim")
if self.get_balance() < _bid - claim['amount']: if self.get_balance() < bid:
raise InsufficientFundsError() raise InsufficientFundsError()
d = self.update_metadata(metadata, claim['value']) claim = yield self._send_name_claim(name, _metadata, bid)
claim_outpoint = ClaimOutpoint(claim['txid'], claim['nOut'])
d.addCallback(
lambda new_metadata: self._send_name_claim_update(name, claim['claim_id'],
claim_outpoint,
new_metadata, _bid))
d.addCallback(lambda claim_out: claim_out.update({'claim_id': claim['claim_id']}))
return d
meta = Metadata(m) if not claim['success']:
d = self.get_my_claim(name) msg = 'Claim to name {} failed: {}'.format(name, claim['reason'])
d.addCallback(lambda claim: _claim_or_update(claim, meta, bid)) raise Exception(msg)
d.addCallback(lambda claim_out: _save_metadata(claim_out, meta))
return d claim = self._process_claim_out(claim)
claim_outpoint = ClaimOutpoint(claim['txid'], claim['nout'])
log.info("Saving metadata for claim %s %d", claim['txid'], claim['nout'])
yield self._save_name_metadata(name, claim_outpoint, _metadata['sources']['lbry_sd_hash'])
defer.returnValue(claim)
def abandon_claim(self, txid, nout): def abandon_claim(self, txid, nout):
def _parse_abandon_claim_out(claim_out): def _parse_abandon_claim_out(claim_out):