forked from LBRYCommunity/lbry-sdk
Merge branch 'prefill_addresses'
* prefill_addresses: changes that jack pointed out add wallet_prefill_addresses command
This commit is contained in:
commit
beca640f89
3 changed files with 46 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
(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
|
||||
|
|
Loading…
Reference in a new issue