From 9c88f820f93c97f41c5eba798e7b55a4883ff701 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 12 Jun 2017 13:32:01 -0400 Subject: [PATCH] add change_address param to publish --- CHANGELOG.md | 2 +- lbrynet/core/Wallet.py | 14 +++++++++----- lbrynet/lbrynet_daemon/Daemon.py | 22 ++++++++++++---------- lbrynet/lbrynet_daemon/Publisher.py | 14 ++++++++------ requirements.txt | 2 +- setup.py | 2 +- tests/unit/core/test_Wallet.py | 3 ++- 7 files changed, 34 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e9808ba..b94eda05c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ at anytime. ## [Unreleased] ### Added * Add `claim_send_to_address` - * + * Add `change_address` argument to `publish` ### Changed * Support resolution of multiple uris with `resolve`, all results are keyed by uri diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 1dce56bfe..90ba050c2 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -898,7 +898,8 @@ class Wallet(object): defer.returnValue(results) @defer.inlineCallbacks - def claim_name(self, name, bid, metadata, certificate_id=None, claim_address=None): + def claim_name(self, name, bid, metadata, certificate_id=None, claim_address=None, + change_address=None): """ Claim a name, or update if name already claimed by user @@ -907,6 +908,7 @@ class Wallet(object): @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 + @param change_address: str (optional), address to send change @return: Deferred which returns a dict containing below items txid - txid of the resulting transaction @@ -922,7 +924,7 @@ class Wallet(object): raise InsufficientFundsError() claim = yield self._send_name_claim(name, serialized.encode('hex'), - bid, certificate_id, claim_address) + bid, certificate_id, claim_address, change_address) if not claim['success']: msg = 'Claim to name {} failed: {}'.format(name, claim['reason']) @@ -1060,7 +1062,8 @@ class Wallet(object): def _claim_certificate(self, name, amount): return defer.fail(NotImplementedError()) - def _send_name_claim(self, name, val, amount, certificate_id=None, claim_address=None): + def _send_name_claim(self, name, val, amount, certificate_id=None, claim_address=None, + change_address=None): return defer.fail(NotImplementedError()) def _abandon_claim(self, claim_id): @@ -1334,11 +1337,12 @@ class LBRYumWallet(Wallet): @defer.inlineCallbacks def _send_name_claim(self, name, value, amount, - certificate_id=None, claim_address=None): + certificate_id=None, claim_address=None, change_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, - claim_addr=claim_address) + claim_addr=claim_address, + change_addr=change_address) defer.returnValue(claim_out) @defer.inlineCallbacks diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index 5e20097dc..9301daa0f 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -681,8 +681,8 @@ class Daemon(AuthJSONRPCServer): defer.returnValue(result) @defer.inlineCallbacks - def _publish_stream(self, name, bid, claim_dict, - file_path=None, certificate_id=None, claim_address=None): + def _publish_stream(self, name, bid, claim_dict, file_path=None, certificate_id=None, + claim_address=None, change_address=None): publisher = Publisher(self.session, self.lbry_file_manager, self.session.wallet, certificate_id) @@ -690,10 +690,11 @@ 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_address) + claim_out = yield publisher.publish_stream(name, bid, claim_dict, claim_address, + change_address) else: - claim_out = yield publisher.create_and_publish_stream(name, bid, claim_dict, - file_path, claim_address) + claim_out = yield publisher.create_and_publish_stream(name, bid, claim_dict, file_path, + claim_address, change_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), @@ -1686,7 +1687,7 @@ class Daemon(AuthJSONRPCServer): 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, - claim_address=None): + claim_address=None, change_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. @@ -1710,7 +1711,7 @@ class Daemon(AuthJSONRPCServer): [--license=] [--license_url=] [--thumbnail=] [--preview=] [--nsfw=] [--sources=] [--channel_name=] [--channel_id=] - [--claim_address=] + [--claim_address=] [--change_address=] Options: --metadata= : ClaimDict to associate with the claim. @@ -1825,7 +1826,8 @@ class Daemon(AuthJSONRPCServer): 'name': name, 'file_path': file_path, 'bid': bid, - 'claim_address':claim_address, + 'claim_address': claim_address, + 'change_address': change_address, 'claim_dict': claim_dict, }) @@ -1843,8 +1845,8 @@ class Daemon(AuthJSONRPCServer): else: certificate_id = None - result = yield self._publish_stream(name, bid, claim_dict, file_path, - certificate_id, claim_address) + result = yield self._publish_stream(name, bid, claim_dict, file_path, certificate_id, + claim_address, change_address) response = yield self._render_response(result) defer.returnValue(response) diff --git a/lbrynet/lbrynet_daemon/Publisher.py b/lbrynet/lbrynet_daemon/Publisher.py index 34cfd7e31..5c7ebe4e6 100644 --- a/lbrynet/lbrynet_daemon/Publisher.py +++ b/lbrynet/lbrynet_daemon/Publisher.py @@ -21,7 +21,8 @@ class Publisher(object): self.lbry_file = None @defer.inlineCallbacks - def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None): + def create_and_publish_stream(self, name, bid, claim_dict, file_path, claim_address=None, + change_address=None): """Create lbry file and make claim""" log.info('Starting publish for %s', name) if not os.path.isfile(file_path): @@ -44,23 +45,24 @@ 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_address) + claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_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, claim_address=None): + def publish_stream(self, name, bid, claim_dict, claim_address=None, change_address=None): """Make a claim without creating a lbry file""" - claim_out = yield self.make_claim(name, bid, claim_dict, claim_address) + claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address) defer.returnValue(claim_out) @defer.inlineCallbacks - def make_claim(self, name, bid, claim_dict, claim_address=None): + def make_claim(self, name, bid, claim_dict, claim_address=None, change_address=None): claim_out = yield self.wallet.claim_name(name, bid, claim_dict, certificate_id=self.certificate_id, - claim_address=claim_address) + claim_address=claim_address, + change_address=change_address) defer.returnValue(claim_out) diff --git a/requirements.txt b/requirements.txt index c2cea2fa3..348875812 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ jsonrpc==1.2 jsonrpclib==0.1.7 jsonschema==2.5.1 git+https://github.com/lbryio/lbryschema.git@v0.0.7#egg=lbryschema -git+https://github.com/lbryio/lbryum.git@v2.8.0#egg=lbryum +git+https://github.com/lbryio/lbryum.git@v2.8.1#egg=lbryum miniupnpc==1.9 pbkdf2==1.3 pycrypto==2.6.1 diff --git a/setup.py b/setup.py index d6211d25d..eb01faaf8 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ requires = [ 'envparse', 'jsonrpc', 'jsonschema', - 'lbryum==2.8.0', + 'lbryum==2.8.1', 'lbryschema==0.0.7', 'miniupnpc', 'pycrypto', diff --git a/tests/unit/core/test_Wallet.py b/tests/unit/core/test_Wallet.py index bb1f332eb..0cfbd89d4 100644 --- a/tests/unit/core/test_Wallet.py +++ b/tests/unit/core/test_Wallet.py @@ -67,7 +67,8 @@ 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, claim_address=None): + def success_send_name_claim(self, name, val, amount, certificate_id=None, + claim_address=None, change_address=None): return expected_claim_out MocLbryumWallet._send_name_claim = success_send_name_claim