forked from LBRYCommunity/lbry-sdk
use lbryum updateclaim
This commit is contained in:
parent
f3ab38ba8f
commit
4705acba55
3 changed files with 43 additions and 8 deletions
|
@ -90,10 +90,10 @@ class LBRYFeeValidator(dict):
|
|||
|
||||
|
||||
class Metadata(dict):
|
||||
def __init__(self, metadata):
|
||||
def __init__(self, metadata, is_hex=False):
|
||||
dict.__init__(self)
|
||||
self.meta_version = None
|
||||
metadata_to_load = deepcopy(metadata)
|
||||
metadata_to_load = deepcopy(metadata if not is_hex else json.loads(metadata.decode("hex")))
|
||||
|
||||
self._verify_sources(metadata_to_load)
|
||||
self._verify_metadata(metadata_to_load)
|
||||
|
@ -126,3 +126,6 @@ class Metadata(dict):
|
|||
assert self.meta_version == self['ver'], "version mismatch"
|
||||
break
|
||||
assert metadata == {}, "Unknown metadata keys: %s" % json.dumps(metadata.keys())
|
||||
|
||||
def serialize(self):
|
||||
return json.dumps(self).encode("hex")
|
||||
|
|
|
@ -425,12 +425,12 @@ class LBRYWallet(object):
|
|||
return d
|
||||
|
||||
def update_name(self, name, bid, value, old_txid):
|
||||
d = self._get_value_for_name(name)
|
||||
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
|
||||
# d = self._get_value_for_name(name)
|
||||
# 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
|
||||
return defer.fail(NotImplementedError())
|
||||
|
||||
def get_name_and_validity_for_sd_hash(self, sd_hash):
|
||||
d = self._get_claim_metadata_for_sd_hash(sd_hash)
|
||||
|
@ -1063,6 +1063,13 @@ class LBRYumWallet(LBRYWallet):
|
|||
d.addCallback(Decimal)
|
||||
return d
|
||||
|
||||
def update_name(self, name, bid, value, txid):
|
||||
serialized = Metadata(value).serialize()
|
||||
d = self.get_claims_from_tx(txid)
|
||||
d.addCallback(lambda claims: next(claim['claimId'] for claim in claims if claim['name'] == name))
|
||||
d.addCallback(lambda claim_id: self._send_claim_update(txid, bid, name, claim_id, serialized))
|
||||
return d
|
||||
|
||||
def get_new_address(self):
|
||||
d = threads.deferToThread(self.wallet.create_new_address)
|
||||
d.addCallback(self._save_wallet)
|
||||
|
@ -1106,6 +1113,16 @@ class LBRYumWallet(LBRYWallet):
|
|||
d.addCallback(self._broadcast_transaction)
|
||||
return d
|
||||
|
||||
def _send_claim_update(self, txid, amount, name, claim_id, val):
|
||||
def send_claim(address):
|
||||
cmd = known_commands['updateclaim']
|
||||
func = getattr(self.cmd_runner, cmd.name)
|
||||
return threads.deferToThread(func, txid, address, amount, name, claim_id, val)
|
||||
log.info("Update lbry://%s %s %f %s %s" % (name, txid, amount, claim_id, val))
|
||||
d = self.get_new_address()
|
||||
d.addCallback(send_claim)
|
||||
d.addCallback(self._broadcast_transaction)
|
||||
|
||||
def _get_decoded_tx(self, raw_tx):
|
||||
tx = Transaction(raw_tx)
|
||||
decoded_tx = {}
|
||||
|
|
|
@ -2430,6 +2430,21 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
return d
|
||||
|
||||
|
||||
def jsonrpc_update_claim(self, p):
|
||||
def _x(r):
|
||||
log.info(str(r))
|
||||
return r
|
||||
|
||||
metadata = p['metadata']
|
||||
bid = p['bid']
|
||||
name = p['name']
|
||||
tx = p['txid']
|
||||
d = self.session.wallet.update_name(name, bid, metadata, tx)
|
||||
d.addCallback(_x)
|
||||
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||
return d
|
||||
|
||||
|
||||
def get_lbrynet_version_from_github():
|
||||
"""Return the latest released version from github."""
|
||||
response = requests.get('https://api.github.com/repos/lbryio/lbry/releases/latest')
|
||||
|
|
Loading…
Reference in a new issue