add wallet_prefill_addresses command

This commit is contained in:
Alex Grintsvayg 2017-10-17 20:25:17 -04:00
parent a212e77a12
commit 2067180467
3 changed files with 46 additions and 2 deletions

View file

@ -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

View file

@ -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,23 @@ 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]
# should this be defer_to_thread or defer_succeed ??
tx = yield self._run_cmd_as_defer_to_thread('paytomany', outputs)
if broadcast and tx['complete']:
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

View file

@ -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> | --num_addresses=<num_addresses>)
(<amount> | --amount=<amount>)
Returns:
(bool) true if addresses were created successfully
"""
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