forked from LBRYCommunity/lbry-sdk
update claim when publishing to an already claimed name
-also save name_metadata for each unique claim rather than for each name
This commit is contained in:
parent
ee9e8b365c
commit
fe39901885
3 changed files with 28 additions and 42 deletions
|
@ -380,7 +380,7 @@ class LBRYWallet(object):
|
|||
return Failure(InvalidStreamInfoError(name))
|
||||
m = Metadata(value_dict)
|
||||
if 'txid' in result:
|
||||
d = self._save_name_metadata(name, m['sources']['lbry_sd_hash'], str(result['txid']))
|
||||
d = self._save_name_metadata(name, str(result['txid']), m['sources']['lbry_sd_hash'])
|
||||
d.addCallback(lambda _: log.info("lbry://%s complies with %s" % (name, m.metaversion)))
|
||||
d.addCallback(lambda _: m)
|
||||
return d
|
||||
|
@ -398,7 +398,8 @@ class LBRYWallet(object):
|
|||
d = self._send_name_claim(name, json.dumps(metadata), bid)
|
||||
|
||||
def _save_metadata(txid):
|
||||
d = self._save_name_metadata(name, metadata['sources']['lbry_sd_hash'], txid)
|
||||
log.info("Saving metadata for claim %s" % txid)
|
||||
d = self._save_name_metadata(name, txid, metadata['sources']['lbry_sd_hash'])
|
||||
d.addCallback(lambda _: txid)
|
||||
return d
|
||||
|
||||
|
@ -443,10 +444,12 @@ class LBRYWallet(object):
|
|||
d.addCallback(self._get_decoded_tx)
|
||||
return d
|
||||
|
||||
def update_name(self, name, value, amount):
|
||||
def update_name(self, name, bid, value, old_txid):
|
||||
d = self._get_value_for_name(name)
|
||||
d.addCallback(lambda r: (self._update_name(r['txid'], json.dumps(value), amount), r['txid']))
|
||||
d.addCallback(lambda (new_txid, old_txid): self._update_name_metadata(name, value['sources']['lbry_sd_hash'], old_txid, new_txid))
|
||||
d.addCallback(lambda r: self.abandon_name(r['txid'] if not old_txid else old_txid))
|
||||
d.addCallback(lambda r: log.info("Abandon claim tx %s" % str(r)))
|
||||
d.addCallback(lambda _: self.claim_name(name, bid, value))
|
||||
|
||||
return d
|
||||
|
||||
def get_name_and_validity_for_sd_hash(self, sd_hash):
|
||||
|
@ -556,19 +559,13 @@ class LBRYWallet(object):
|
|||
" txid text, " +
|
||||
" sd_hash text)")
|
||||
|
||||
def _save_name_metadata(self, name, sd_hash, txid):
|
||||
d = self.db.runQuery("select * from name_metadata where txid=?", (txid,))
|
||||
def _save_name_metadata(self, name, txid, sd_hash):
|
||||
d = self.db.runQuery("select * from name_metadata where name=? and txid=? and sd_hash=?", (name, txid, sd_hash))
|
||||
d.addCallback(lambda r: self.db.runQuery("insert into name_metadata values (?, ?, ?)", (name, txid, sd_hash))
|
||||
if not len(r) else None)
|
||||
|
||||
return d
|
||||
|
||||
def _update_name_metadata(self, name, sd_hash, old_txid, new_txid):
|
||||
d = self.db.runQuery("delete * from name_metadata where txid=? and sd_hash=?", (old_txid, sd_hash))
|
||||
d.addCallback(lambda _: self.db.runQuery("insert into name_metadata values (?, ?, ?)", (name, new_txid, sd_hash)))
|
||||
d.addCallback(lambda _: new_txid)
|
||||
return d
|
||||
|
||||
def _get_claim_metadata_for_sd_hash(self, sd_hash):
|
||||
d = self.db.runQuery("select name, txid from name_metadata where sd_hash=?", (sd_hash,))
|
||||
d.addCallback(lambda r: r[0] if len(r) else None)
|
||||
|
|
|
@ -1899,24 +1899,26 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
file_path = p['file_path']
|
||||
metadata = p['metadata']
|
||||
|
||||
d = defer.succeed(None)
|
||||
update = False
|
||||
|
||||
def _set_address(address, currency):
|
||||
log.info("Generated new address for key fee: " + str(address))
|
||||
metadata['fee'][currency]['address'] = address
|
||||
return defer.succeed(None)
|
||||
|
||||
d = defer.succeed(None)
|
||||
|
||||
if 'fee' in p:
|
||||
metadata['fee'] = p['fee']
|
||||
assert len(metadata['fee']) == 1, "Too many fees"
|
||||
for c in metadata['fee']:
|
||||
if 'address' not in metadata['fee'][c]:
|
||||
d = self.session.wallet.get_new_address()
|
||||
d.addCallback(lambda _: self.session.wallet.get_new_address())
|
||||
d.addCallback(lambda addr: _set_address(addr, c))
|
||||
|
||||
pub = Publisher(self.session, self.lbry_file_manager, self.session.wallet)
|
||||
|
||||
d.addCallback(lambda _: pub.start(name, file_path, bid, metadata))
|
||||
d.addCallback(lambda _: self._get_lbry_file_by_uri(name))
|
||||
d.addCallback(lambda r: pub.start(name, file_path, bid, metadata, r.txid))
|
||||
d.addCallbacks(lambda msg: self._render_response(msg, OK_CODE),
|
||||
lambda err: self._render_response(err.getTraceback(), BAD_REQUEST))
|
||||
|
||||
|
@ -2181,27 +2183,6 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||
return d
|
||||
|
||||
def jsonrpc_update_name(self, p):
|
||||
"""
|
||||
Update name claim
|
||||
|
||||
Args:
|
||||
'name': the uri of the claim to be updated
|
||||
'metadata': new metadata dict
|
||||
'amount': bid amount of updated claim
|
||||
Returns:
|
||||
txid
|
||||
"""
|
||||
|
||||
name = p['name']
|
||||
metadata = p['metadata'] if isinstance(p['metadata'], dict) else json.loads(p['metadata'])
|
||||
amount = p['amount']
|
||||
|
||||
d = self.session.wallet.update_name(name, metadata, amount)
|
||||
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||
|
||||
return d
|
||||
|
||||
def jsonrpc_log(self, p):
|
||||
"""
|
||||
Log message
|
||||
|
|
|
@ -45,7 +45,7 @@ class Publisher(object):
|
|||
self.txid = None
|
||||
self.metadata = {}
|
||||
|
||||
def start(self, name, file_path, bid, metadata):
|
||||
def start(self, name, file_path, bid, metadata, old_txid=None):
|
||||
|
||||
def _show_result():
|
||||
log.info("Published %s --> lbry://%s txid: %s", self.file_name, self.publish_name, self.txid)
|
||||
|
@ -55,6 +55,7 @@ class Publisher(object):
|
|||
self.file_path = file_path
|
||||
self.bid_amount = bid
|
||||
self.metadata = metadata
|
||||
self.old_txid = old_txid
|
||||
|
||||
d = self._check_file_path(self.file_path)
|
||||
d.addCallback(lambda _: create_lbry_file(self.session, self.lbry_file_manager,
|
||||
|
@ -102,9 +103,16 @@ class Publisher(object):
|
|||
self.metadata['content-type'] = mimetypes.guess_type(os.path.join(self.lbry_file.download_directory,
|
||||
self.lbry_file.file_name))[0]
|
||||
self.metadata['ver'] = CURRENT_METADATA_VERSION
|
||||
d = self.wallet.claim_name(self.publish_name,
|
||||
self.bid_amount,
|
||||
Metadata(self.metadata))
|
||||
|
||||
if self.old_txid:
|
||||
d = self.wallet.update_name(self.publish_name,
|
||||
self.bid_amount,
|
||||
Metadata(self.metadata),
|
||||
self.old_txid)
|
||||
else:
|
||||
d = self.wallet.claim_name(self.publish_name,
|
||||
self.bid_amount,
|
||||
Metadata(self.metadata))
|
||||
def set_tx_hash(txid):
|
||||
self.txid = txid
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue