forked from LBRYCommunity/lbry-sdk
Merge pull request #670 from lbryio/add_claim_addr
Add claim address as an option to publish
This commit is contained in:
commit
cfcc4205ab
5 changed files with 31 additions and 18 deletions
|
@ -9,7 +9,7 @@ at anytime.
|
|||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
*
|
||||
* Added claim_address option to publish API command
|
||||
*
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -890,7 +890,7 @@ class Wallet(object):
|
|||
defer.returnValue(results)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def claim_name(self, name, bid, metadata, certificate_id=None):
|
||||
def claim_name(self, name, bid, metadata, certificate_id=None, claim_address=None):
|
||||
"""
|
||||
Claim a name, or update if name already claimed by user
|
||||
|
||||
|
@ -898,6 +898,7 @@ class Wallet(object):
|
|||
@param bid: float, bid amount
|
||||
@param metadata: ClaimDict compliant dict
|
||||
@param certificate_id: str (optional), claim id of channel certificate
|
||||
@param claim_address: str (optional), address to send claim to
|
||||
|
||||
@return: Deferred which returns a dict containing below items
|
||||
txid - txid of the resulting transaction
|
||||
|
@ -912,7 +913,8 @@ class Wallet(object):
|
|||
if self.get_balance() < Decimal(bid):
|
||||
raise InsufficientFundsError()
|
||||
|
||||
claim = yield self._send_name_claim(name, serialized.encode('hex'), bid, certificate_id)
|
||||
claim = yield self._send_name_claim(name, serialized.encode('hex'),
|
||||
bid, certificate_id, claim_address)
|
||||
|
||||
if not claim['success']:
|
||||
msg = 'Claim to name {} failed: {}'.format(name, claim['reason'])
|
||||
|
@ -1050,7 +1052,7 @@ class Wallet(object):
|
|||
def _claim_certificate(self, name, amount):
|
||||
return defer.fail(NotImplementedError())
|
||||
|
||||
def _send_name_claim(self, name, val, amount, certificate_id=None):
|
||||
def _send_name_claim(self, name, val, amount, certificate_id=None, claim_address=None):
|
||||
return defer.fail(NotImplementedError())
|
||||
|
||||
def _abandon_claim(self, claim_id):
|
||||
|
@ -1317,10 +1319,12 @@ class LBRYumWallet(Wallet):
|
|||
return self._run_cmd_as_defer_to_thread('getclaimsforname', name)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _send_name_claim(self, name, value, amount, certificate_id=None):
|
||||
def _send_name_claim(self, name, value, amount,
|
||||
certificate_id=None, claim_address=None):
|
||||
log.info("Send claim: %s for %s: %s ", name, amount, value)
|
||||
claim_out = yield self._run_cmd_as_defer_succeed('claim', name, value, amount,
|
||||
certificate_id=certificate_id)
|
||||
certificate_id=certificate_id,
|
||||
claim_addr=claim_address)
|
||||
defer.returnValue(claim_out)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
|
@ -681,7 +681,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
defer.returnValue(result)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _publish_stream(self, name, bid, claim_dict, file_path=None, certificate_id=None):
|
||||
def _publish_stream(self, name, bid, claim_dict,
|
||||
file_path=None, certificate_id=None, claim_address=None):
|
||||
|
||||
publisher = Publisher(self.session, self.lbry_file_manager, self.session.wallet,
|
||||
certificate_id)
|
||||
|
@ -689,9 +690,10 @@ class Daemon(AuthJSONRPCServer):
|
|||
if bid <= 0.0:
|
||||
raise Exception("Invalid bid")
|
||||
if not file_path:
|
||||
claim_out = yield publisher.publish_stream(name, bid, claim_dict)
|
||||
claim_out = yield publisher.publish_stream(name, bid, claim_dict, claim_address)
|
||||
else:
|
||||
claim_out = yield publisher.create_and_publish_stream(name, bid, claim_dict, file_path)
|
||||
claim_out = yield publisher.create_and_publish_stream(name, bid, claim_dict,
|
||||
file_path, claim_address)
|
||||
if conf.settings['reflect_uploads']:
|
||||
d = reupload.reflect_stream(publisher.lbry_file)
|
||||
d.addCallbacks(lambda _: log.info("Reflected new publication to lbry://%s", name),
|
||||
|
@ -1825,7 +1827,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
def jsonrpc_publish(self, name, bid, metadata=None, file_path=None, fee=None, title=None,
|
||||
description=None, author=None, language=None, license=None,
|
||||
license_url=None, thumbnail=None, preview=None, nsfw=None, sources=None,
|
||||
channel_name=None, channel_id=None):
|
||||
channel_name=None, channel_id=None,
|
||||
claim_address=None):
|
||||
"""
|
||||
Make a new name claim and publish associated data to lbrynet,
|
||||
update over existing claim if user already has a claim for name.
|
||||
|
@ -1849,6 +1852,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
[--license=<license>] [--license_url=<license_url>] [--thumbnail=<thumbnail>]
|
||||
[--preview=<preview>] [--nsfw=<nsfw>] [--sources=<sources>]
|
||||
[--channel_name=<channel_name>] [--channel_id=<channel_id>]
|
||||
[--claim_address=<claim_address>]
|
||||
|
||||
Options:
|
||||
--metadata=<metadata> : ClaimDict to associate with the claim.
|
||||
|
@ -1880,6 +1884,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
for channel claim being in the wallet. This allows
|
||||
publishing to a channel where only the certificate
|
||||
private key is in the wallet.
|
||||
--claim_address=<claim_address> : address where the claim is sent to, if not specified
|
||||
new address wil automatically be created
|
||||
|
||||
Returns:
|
||||
(dict) Dictionary containing result of the claim
|
||||
|
@ -1960,6 +1966,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
'name': name,
|
||||
'file_path': file_path,
|
||||
'bid': bid,
|
||||
'claim_address':claim_address,
|
||||
'claim_dict': claim_dict,
|
||||
})
|
||||
|
||||
|
@ -1977,7 +1984,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
else:
|
||||
certificate_id = None
|
||||
|
||||
result = yield self._publish_stream(name, bid, claim_dict, file_path, certificate_id)
|
||||
result = yield self._publish_stream(name, bid, claim_dict, file_path,
|
||||
certificate_id, claim_address)
|
||||
response = yield self._render_response(result)
|
||||
defer.returnValue(response)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Publisher(object):
|
|||
self.lbry_file = None
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def create_and_publish_stream(self, name, bid, claim_dict, file_path):
|
||||
def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None):
|
||||
"""Create lbry file and make claim"""
|
||||
log.info('Starting publish for %s', name)
|
||||
if not os.path.isfile(file_path):
|
||||
|
@ -44,22 +44,23 @@ class Publisher(object):
|
|||
claim_dict['stream']['source']['contentType'] = get_content_type(file_path)
|
||||
claim_dict['stream']['source']['version'] = "_0_0_1" # need current version here
|
||||
|
||||
claim_out = yield self.make_claim(name, bid, claim_dict)
|
||||
claim_out = yield self.make_claim(name, bid, claim_dict, claim_address)
|
||||
self.lbry_file.completed = True
|
||||
yield self.lbry_file.load_file_attributes(sd_hash)
|
||||
yield self.lbry_file.save_status()
|
||||
defer.returnValue(claim_out)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def publish_stream(self, name, bid, claim_dict):
|
||||
def publish_stream(self, name, bid, claim_dict, claim_address=None):
|
||||
"""Make a claim without creating a lbry file"""
|
||||
claim_out = yield self.make_claim(name, bid, claim_dict)
|
||||
claim_out = yield self.make_claim(name, bid, claim_dict, claim_address)
|
||||
defer.returnValue(claim_out)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def make_claim(self, name, bid, claim_dict):
|
||||
def make_claim(self, name, bid, claim_dict, claim_address=None):
|
||||
claim_out = yield self.wallet.claim_name(name, bid, claim_dict,
|
||||
certificate_id=self.certificate_id)
|
||||
certificate_id=self.certificate_id,
|
||||
claim_address=claim_address)
|
||||
defer.returnValue(claim_out)
|
||||
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class WalletTest(unittest.TestCase):
|
|||
self.assertEqual(expected_claim_out['nout'], claim_out['nout'])
|
||||
self.assertEqual(expected_claim_out['txid'], claim_out['txid'])
|
||||
|
||||
def success_send_name_claim(self, name, val, amount, certificate_id=None):
|
||||
def success_send_name_claim(self, name, val, amount, certificate_id=None, claim_address=None):
|
||||
return expected_claim_out
|
||||
|
||||
MocLbryumWallet._send_name_claim = success_send_name_claim
|
||||
|
|
Loading…
Reference in a new issue