added jsonrpc_account_send and dropped torba[server]

This commit is contained in:
Lex Berezhny 2018-11-20 18:21:53 -05:00
parent 561215db8a
commit 0c999083cc
6 changed files with 69 additions and 16 deletions

View file

@ -10,8 +10,8 @@ jobs:
name: "pylint lbrynet" name: "pylint lbrynet"
install: install:
- pip install pylint - pip install pylint
- 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 .[wallet-server] - pip install -e .
script: pylint lbrynet script: pylint lbrynet
- &tests - &tests
@ -19,7 +19,7 @@ jobs:
name: "Unit Tests w/ Python 3.7" name: "Unit Tests w/ Python 3.7"
install: install:
- pip install coverage - 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] - pip install -e .[test]
script: script:
- HOME=/tmp coverage run -p --source=lbrynet -m unittest discover -v tests.unit.wallet - HOME=/tmp coverage run -p --source=lbrynet -m unittest discover -v tests.unit.wallet
@ -97,6 +97,13 @@ jobs:
osx_image: xcode9.4 osx_image: xcode9.4
language: generic language: generic
env: OS=mac 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: cache:
directories: directories:

View file

@ -1439,7 +1439,7 @@ class Daemon(AuthJSONRPCServer):
return self.get_account_or_error(account_id).get_max_gap() return self.get_account_or_error(account_id).get_max_gap()
@requires("wallet") @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): everything=False, outputs=1, broadcast=False):
""" """
Transfer some amount (or --everything) to an account from another Transfer some amount (or --everything) to an account from another
@ -1448,8 +1448,8 @@ class Daemon(AuthJSONRPCServer):
be used together with --everything). be used together with --everything).
Usage: Usage:
account_fund (<to_account> | --to_account=<to_account>) account_fund [<to_account> | --to_account=<to_account>]
(<from_account> | --from_account=<from_account>) [<from_account> | --from_account=<from_account>]
(<amount> | --amount=<amount> | --everything) (<amount> | --amount=<amount> | --everything)
[<outputs> | --outputs=<outputs>] [<outputs> | --outputs=<outputs>]
[--broadcast] [--broadcast]
@ -1466,8 +1466,8 @@ class Daemon(AuthJSONRPCServer):
(map) transaction performing requested action (map) transaction performing requested action
""" """
to_account = self.get_account_or_error(to_account, 'to_account') to_account = self.get_account_or_default(to_account, 'to_account')
from_account = self.get_account_or_error(from_account, 'from_account') from_account = self.get_account_or_default(from_account, 'from_account')
amount = self.get_dewies_or_error('amount', amount) if amount else None amount = self.get_dewies_or_error('amount', amount) if amount else None
if not isinstance(outputs, int): if not isinstance(outputs, int):
raise ValueError("--outputs must be an integer.") raise ValueError("--outputs must be an integer.")
@ -1478,6 +1478,35 @@ class Daemon(AuthJSONRPCServer):
outputs=outputs, broadcast=broadcast 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 <amount> <addresses>... [--account_id=<account_id>] [--broadcast]
Options:
--account_id=<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) @requires(WALLET_COMPONENT)
def jsonrpc_address_is_mine(self, address, account_id=None): def jsonrpc_address_is_mine(self, address, account_id=None):
""" """

View file

@ -180,3 +180,24 @@ class Account(BaseAccount):
def get_channel_count(self, **constraints): def get_channel_count(self, **constraints):
return self.ledger.db.get_channel_count(account=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

View file

@ -6,6 +6,7 @@ apt-get -qq update
apt-get -qq install -y git apt-get -qq install -y git
git clone https://github.com/lbryio/torba.git --depth 1 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 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 sed -i -e '172,184{s/^/#/}' twisted/src/twisted/python/_setup.py

View file

@ -5,11 +5,6 @@ from setuptools import setup, find_packages
BASE = os.path.dirname(__file__) BASE = os.path.dirname(__file__)
README_PATH = os.path.join(BASE, 'README.md') README_PATH = os.path.join(BASE, 'README.md')
SERVER_REQUIRES = (
'msgpack',
'torba[server]',
)
setup( setup(
name=__name__, name=__name__,
version=__version__, version=__version__,
@ -38,6 +33,7 @@ setup(
'jsonrpc', 'jsonrpc',
'cryptography', 'cryptography',
'protobuf==3.6.1', 'protobuf==3.6.1',
'msgpack',
'jsonschema', 'jsonschema',
'ecdsa', 'ecdsa',
'torba', 'torba',
@ -50,13 +46,12 @@ setup(
'six' 'six'
], ],
extras_require={ extras_require={
'wallet-server': SERVER_REQUIRES,
'test': ( 'test': (
'mock>=2.0,<3.0', 'mock>=2.0,<3.0',
'faker==0.8.17', 'faker==0.8.17',
'pytest', 'pytest',
'pytest-asyncio', 'pytest-asyncio',
'pytest-xprocess', 'pytest-xprocess',
) + SERVER_REQUIRES, )
} }
) )

View file

@ -4,7 +4,7 @@ envlist = py37-integration
[testenv] [testenv]
deps = deps =
coverage coverage
../torba[server] ../torba
extras = test extras = test
changedir = {toxinidir}/tests changedir = {toxinidir}/tests
setenv = setenv =