From 0c999083cc5046d7517ebdfc2b532a24c325aab5 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 20 Nov 2018 18:21:53 -0500 Subject: [PATCH] added jsonrpc_account_send and dropped torba[server] --- .travis.yml | 13 ++++++++--- lbrynet/extras/daemon/Daemon.py | 39 ++++++++++++++++++++++++++++---- lbrynet/extras/wallet/account.py | 21 +++++++++++++++++ scripts/wine_build.sh | 1 + setup.py | 9 ++------ tox.ini | 2 +- 6 files changed, 69 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93edd1a93..a40bd981e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ jobs: name: "pylint lbrynet" install: - pip install pylint - - pip install git+https://github.com/lbryio/torba.git#egg=torba[server] - - pip install -e .[wallet-server] + - pip install git+https://github.com/lbryio/torba.git#egg=torba + - pip install -e . script: pylint lbrynet - &tests @@ -19,7 +19,7 @@ jobs: name: "Unit Tests w/ Python 3.7" install: - pip install coverage - - pip install git+https://github.com/lbryio/torba.git#egg=torba[server] + - pip install git+https://github.com/lbryio/torba.git#egg=torba - pip install -e .[test] script: - HOME=/tmp coverage run -p --source=lbrynet -m unittest discover -v tests.unit.wallet @@ -97,6 +97,13 @@ jobs: osx_image: xcode9.4 language: generic env: OS=mac + install: + - pip3 install pyinstaller + - git clone https://github.com/lbryio/torba.git --depth 1 + - sed -i -e "s/'plyvel',//" torba/setup.py + - cd torba && pip3 install -e . && cd .. + - python scripts/set_build.py + - pip3 install -e . cache: directories: diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index d63145368..4a0f91d17 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -1439,7 +1439,7 @@ class Daemon(AuthJSONRPCServer): return self.get_account_or_error(account_id).get_max_gap() @requires("wallet") - def jsonrpc_account_fund(self, to_account, from_account, amount='0.0', + def jsonrpc_account_fund(self, to_account=None, from_account=None, amount='0.0', everything=False, outputs=1, broadcast=False): """ Transfer some amount (or --everything) to an account from another @@ -1448,8 +1448,8 @@ class Daemon(AuthJSONRPCServer): be used together with --everything). Usage: - account_fund ( | --to_account=) - ( | --from_account=) + account_fund [ | --to_account=] + [ | --from_account=] ( | --amount= | --everything) [ | --outputs=] [--broadcast] @@ -1466,8 +1466,8 @@ class Daemon(AuthJSONRPCServer): (map) transaction performing requested action """ - to_account = self.get_account_or_error(to_account, 'to_account') - from_account = self.get_account_or_error(from_account, 'from_account') + to_account = self.get_account_or_default(to_account, 'to_account') + from_account = self.get_account_or_default(from_account, 'from_account') amount = self.get_dewies_or_error('amount', amount) if amount else None if not isinstance(outputs, int): raise ValueError("--outputs must be an integer.") @@ -1478,6 +1478,35 @@ class Daemon(AuthJSONRPCServer): outputs=outputs, broadcast=broadcast ) + @requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED]) + async def jsonrpc_account_send(self, amount, addresses, account_id=None, broadcast=False): + """ + Send the same number of credits to multiple addresses. + + Usage: + account_send ... [--account_id=] [--broadcast] + + Options: + --account_id= : (str) account to fund the transaction + --broadcast : (bool) actually broadcast the transaction, default: false. + + Returns: + """ + + amount = self.get_dewies_or_error("amount", amount) + if not amount: + raise NullFundsError + elif amount < 0: + raise NegativeFundsError() + + for address in addresses: + decode_address(address) + + account = self.get_account_or_default(account_id) + result = await account.send_to_addresses(amount, addresses, broadcast) + self.analytics_manager.send_credits_sent() + return result + @requires(WALLET_COMPONENT) def jsonrpc_address_is_mine(self, address, account_id=None): """ diff --git a/lbrynet/extras/wallet/account.py b/lbrynet/extras/wallet/account.py index 045298e08..94bbbe1e2 100644 --- a/lbrynet/extras/wallet/account.py +++ b/lbrynet/extras/wallet/account.py @@ -180,3 +180,24 @@ class Account(BaseAccount): def get_channel_count(self, **constraints): return self.ledger.db.get_channel_count(account=self, **constraints) + + async def send_to_addresses(self, amount, addresses, broadcast=False): + tx_class = self.ledger.transaction_class + tx = await tx_class.create( + inputs=[], + outputs=[ + tx_class.output_class.pay_pubkey_hash(amount, self.ledger.address_to_hash160(address)) + for address in addresses + ], + funding_accounts=[self], + change_account=self + ) + + if broadcast: + await self.ledger.broadcast(tx) + else: + await self.ledger.release_outputs( + [txi.txo_ref.txo for txi in tx.inputs] + ) + + return tx diff --git a/scripts/wine_build.sh b/scripts/wine_build.sh index 14fa2afaf..c38547d1e 100755 --- a/scripts/wine_build.sh +++ b/scripts/wine_build.sh @@ -6,6 +6,7 @@ apt-get -qq update apt-get -qq install -y git git clone https://github.com/lbryio/torba.git --depth 1 +sed -i -e "s/'plyvel',//" torba/setup.py git clone https://github.com/twisted/twisted.git --depth 1 --branch twisted-18.7.0 sed -i -e '172,184{s/^/#/}' twisted/src/twisted/python/_setup.py diff --git a/setup.py b/setup.py index b734071a0..7966d9725 100644 --- a/setup.py +++ b/setup.py @@ -5,11 +5,6 @@ from setuptools import setup, find_packages BASE = os.path.dirname(__file__) README_PATH = os.path.join(BASE, 'README.md') -SERVER_REQUIRES = ( - 'msgpack', - 'torba[server]', -) - setup( name=__name__, version=__version__, @@ -38,6 +33,7 @@ setup( 'jsonrpc', 'cryptography', 'protobuf==3.6.1', + 'msgpack', 'jsonschema', 'ecdsa', 'torba', @@ -50,13 +46,12 @@ setup( 'six' ], extras_require={ - 'wallet-server': SERVER_REQUIRES, 'test': ( 'mock>=2.0,<3.0', 'faker==0.8.17', 'pytest', 'pytest-asyncio', 'pytest-xprocess', - ) + SERVER_REQUIRES, + ) } ) diff --git a/tox.ini b/tox.ini index f9ec177d8..c13aa1f46 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py37-integration [testenv] deps = coverage - ../torba[server] + ../torba extras = test changedir = {toxinidir}/tests setenv =