diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a2adfda1..3abbb39bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ at anytime. * Refactor some assert statements to accommodate the PYTHONOPTIMIZE flag set for Android. ### Added - * + * Added `wallet_prefill_addresses` command, which creates distributes credits to multiple addresses * ### Removed diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 1d56ae64b..5ebb60d93 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -626,7 +626,7 @@ class Wallet(object): @param reserved_points: ReservedPoints object previously returned by reserve_points @param amount: amount of points to actually send. must be less than or equal to the - amount reselved in reserved_points + amount reserved in reserved_points @return: Deferred which fires when the payment has been scheduled """ @@ -1321,6 +1321,22 @@ class LBRYumWallet(Wallet): else: return Decimal((float(c) + float(u) + float(x)) / COIN) + @defer.inlineCallbacks + def create_addresses_with_balance(self, num_addresses, amount, broadcast=True): + addresses = self.wallet.get_unused_addresses(account=None) + if len(addresses) > num_addresses: + addresses = addresses[:num_addresses] + elif len(addresses) < num_addresses: + for i in range(len(addresses), num_addresses): + address = self.wallet.create_new_address(account=None) + addresses.append(address) + yield self._save_wallet() + + outputs = [[address, amount] for address in addresses] + tx = yield self._run_cmd_as_defer_succeed('paytomany', outputs) + if broadcast and tx['complete']: + tx['txid'] = yield self._broadcast_transaction(tx) + defer.returnValue(tx) # Return an address with no balance in it, if # there is none, create a brand new address @@ -1475,6 +1491,7 @@ class LBRYumWallet(Wallet): def send_claim_to_address(self, claim_id, destination, amount): return self._run_cmd_as_defer_succeed('sendclaimtoaddress', claim_id, destination, amount) + # TODO: get rid of this function. lbryum should take care of it def _save_wallet(self, val=None): self.wallet.storage.write() return defer.succeed(val) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 87d6a54aa..fe7912075 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2377,6 +2377,33 @@ class Daemon(AuthJSONRPCServer): self.analytics_manager.send_claim_action('new_support') defer.returnValue(result) + @AuthJSONRPCServer.auth_required + @defer.inlineCallbacks + @AuthJSONRPCServer.flags(no_broadcast='--no_broadcast') + def jsonrpc_wallet_prefill_addresses(self, num_addresses, amount, no_broadcast=False): + """ + Create new addresses, each containing `amount` credits + + Usage: + wallet_prefill_addresses [--no_broadcast] + ( | --num_addresses=) + ( | --amount=) + + Returns: + (dict) the resulting transaction + """ + + if amount < 0: + raise NegativeFundsError() + elif not amount: + raise NullFundsError() + + broadcast = not no_broadcast + tx = yield self.session.wallet.create_addresses_with_balance( + num_addresses, amount, broadcast=broadcast) + tx['broadcast'] = broadcast + defer.returnValue(tx) + def jsonrpc_block_show(self, blockhash=None, height=None): """ Get contents of a block