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