publish accepts channel_id or channel_name
This commit is contained in:
parent
91405ef232
commit
88bad1f868
3 changed files with 35 additions and 20 deletions
|
@ -2305,6 +2305,10 @@ class Daemon(AuthJSONRPCServer):
|
|||
# waiting to find out when we go to publish the claim (after having made the stream)
|
||||
raise Exception("invalid publish metadata: %s" % err.message)
|
||||
|
||||
certificate = None
|
||||
if channel_id or channel_name:
|
||||
certificate = yield self.get_channel_or_error(channel_id, channel_name)
|
||||
|
||||
log.info("Publish: %s", {
|
||||
'name': name,
|
||||
'file_path': file_path,
|
||||
|
@ -2316,19 +2320,9 @@ class Daemon(AuthJSONRPCServer):
|
|||
'channel_name': channel_name
|
||||
})
|
||||
|
||||
certificate = None
|
||||
if channel_name:
|
||||
certificates = yield self.wallet_manager.get_certificates(channel_name)
|
||||
for cert in certificates:
|
||||
if cert.claim_id == channel_id:
|
||||
certificate = cert
|
||||
break
|
||||
if certificate is None:
|
||||
raise Exception("Cannot publish using channel %s" % channel_name)
|
||||
|
||||
result = yield self._publish_stream(name, amount, claim_dict, file_path, certificate,
|
||||
claim_address, change_address)
|
||||
defer.returnValue(result)
|
||||
return result
|
||||
|
||||
@requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED])
|
||||
@defer.inlineCallbacks
|
||||
|
@ -3338,6 +3332,20 @@ class Daemon(AuthJSONRPCServer):
|
|||
response['head_blob_availability'].get('is_available')
|
||||
defer.returnValue(response)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_channel_or_error(self, channel_id: str = None, name: str = None):
|
||||
if channel_id is not None:
|
||||
certificates = yield self.wallet_manager.get_certificates(claim_id=channel_id)
|
||||
if not certificates:
|
||||
raise ValueError("Couldn't find channel with claim_id '{}'." .format(channel_id))
|
||||
return certificates[0]
|
||||
if name is not None:
|
||||
certificates = yield self.wallet_manager.get_certificates(name=name)
|
||||
if not certificates:
|
||||
raise ValueError("Couldn't find channel with name '{}'.".format(name))
|
||||
return certificates[0]
|
||||
raise ValueError("Couldn't find channel because a channel name or channel_id was not provided.")
|
||||
|
||||
def get_account_or_error(self, argument: str, account_id: str, lbc_only=True):
|
||||
for account in self.default_wallet.accounts:
|
||||
if account.id == account_id:
|
||||
|
|
|
@ -49,14 +49,23 @@ class WalletDatabase(BaseDatabase):
|
|||
return row
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_certificates(self, name, private_key_accounts=None, exclude_without_key=False):
|
||||
def get_certificates(self, name=None, claim_id=None, private_key_accounts=None, exclude_without_key=False):
|
||||
if name is not None:
|
||||
filter_sql = 'claim_name=?'
|
||||
filter_value = name
|
||||
elif claim_id is not None:
|
||||
filter_sql = 'claim_id=?'
|
||||
filter_value = claim_id
|
||||
else:
|
||||
raise ValueError("'name' or 'claim_id' is required")
|
||||
|
||||
txos = yield self.db.runQuery(
|
||||
"""
|
||||
SELECT tx.txid, txo.position, txo.claim_id
|
||||
FROM txo JOIN tx ON tx.txid=txo.txid
|
||||
WHERE claim_name=? AND (is_claim OR is_update)
|
||||
WHERE {} AND (is_claim OR is_update)
|
||||
GROUP BY txo.claim_id ORDER BY tx.height DESC;
|
||||
""", (name,)
|
||||
""".format(filter_sql), (filter_value,)
|
||||
)
|
||||
|
||||
certificates = []
|
||||
|
@ -70,11 +79,9 @@ class WalletDatabase(BaseDatabase):
|
|||
certificates.append(Certificate(txid, nout, claim_id, name, private_key))
|
||||
|
||||
if exclude_without_key:
|
||||
defer.returnValue([
|
||||
c for c in certificates if c.private_key is not None
|
||||
])
|
||||
return [c for c in certificates if c.private_key is not None]
|
||||
|
||||
defer.returnValue(certificates)
|
||||
return certificates
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_claim(self, account, claim_id):
|
||||
|
|
|
@ -284,8 +284,8 @@ class LbryWalletManager(BaseWalletManager):
|
|||
def channel_list(self):
|
||||
return self.default_account.get_channels()
|
||||
|
||||
def get_certificates(self, name):
|
||||
return self.db.get_certificates(name, self.accounts, exclude_without_key=True)
|
||||
def get_certificates(self, name=None, claim_id=None):
|
||||
return self.db.get_certificates(name, claim_id, self.accounts, exclude_without_key=True)
|
||||
|
||||
def update_peer_address(self, peer, address):
|
||||
pass # TODO: Data payments is disabled
|
||||
|
|
Loading…
Reference in a new issue