Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82cdc8c86a | ||
|
|
3f6493dc5c | ||
|
|
fb4d60f02f | ||
|
|
df60fa7ab2 | ||
|
|
7051c332a1 | ||
|
|
0f2a0b7c97 | ||
|
|
bb6ef42d0c | ||
|
|
3c591d4968 | ||
|
|
cf356a8e35 | ||
|
|
3a0ce58cda | ||
|
|
2d7038dc18 | ||
|
|
25a0e67841 | ||
|
|
be64209292 |
No files matched your search
+4
-128
@@ -5,137 +5,13 @@ python: "3.7"
|
||||
jobs:
|
||||
include:
|
||||
|
||||
- stage: code quality
|
||||
name: "pylint & mypy"
|
||||
install:
|
||||
- make install
|
||||
script: make lint
|
||||
|
||||
- stage: test
|
||||
name: "LBRY Unit Tests"
|
||||
install:
|
||||
- make install
|
||||
script:
|
||||
- cd lbry && HOME=/tmp coverage run -p --source=lbry -m unittest discover -vv tests.unit
|
||||
after_success:
|
||||
- coverage combine lbry/
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
- name: "LBRY Integration Tests"
|
||||
install:
|
||||
- pip install coverage tox-travis
|
||||
- sudo mount -o mode=1777,nosuid,nodev -t tmpfs tmpfs /tmp
|
||||
script: cd lbry && tox
|
||||
after_success:
|
||||
- coverage combine lbry
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
- &torba-tests
|
||||
name: "Torba Unit Tests"
|
||||
env: TESTTYPE=unit
|
||||
install:
|
||||
- pip install coverage tox-travis
|
||||
script: cd torba && tox
|
||||
after_success:
|
||||
- coverage combine torba/tests
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
- <<: *torba-tests
|
||||
name: "Torba Integration Tests"
|
||||
env: TESTTYPE=integration
|
||||
|
||||
- name: "Run Examples"
|
||||
install:
|
||||
- make install
|
||||
script:
|
||||
- cd lbry && HOME=/tmp coverage run -p --source=lbry scripts/generate_json_api.py
|
||||
after_success:
|
||||
- coverage combine lbry
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
- &build
|
||||
stage: build
|
||||
name: "Linux"
|
||||
env: OS=linux
|
||||
install:
|
||||
- pip install pyinstaller awscli
|
||||
- cd torba && pip install -e . && cd ..
|
||||
- cd lbry
|
||||
- python scripts/set_build.py
|
||||
- pip install -e .
|
||||
script:
|
||||
- pyinstaller -F -n lbrynet lbry/extras/cli.py
|
||||
- cd dist
|
||||
- chmod +x lbrynet
|
||||
- zip -j lbrynet-${OS}.zip lbrynet
|
||||
- shasum -a 256 -b lbrynet-${OS}.zip
|
||||
- ./lbrynet --version
|
||||
after_success:
|
||||
- aws configure set aws_access_key_id $ARTIFACTS_KEY
|
||||
- aws configure set aws_secret_access_key $ARTIFACTS_SECRET
|
||||
- aws configure set region us-east-1
|
||||
- export S3_PATH="daemon/build-${TRAVIS_BUILD_NUMBER}_commit-${TRAVIS_COMMIT:0:7}_branch-${TRAVIS_BRANCH}$([ ! -z ${TRAVIS_TAG} ] && echo _tag-${TRAVIS_TAG})"
|
||||
- aws s3 cp lbrynet-${OS}.zip s3://build.lbry.io/${S3_PATH}/lbrynet-${OS}.zip
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: "unnR+aSJ1937Cl1PyBBZzGuZvV5W5TGcXELhXTgyOeeI6FgO/j80qmbNxJDA7qdFH/hvVicQFWoflhZu2dxN5rYP5BQJW3q3XoOLY3XAc1s1vicFkwqn3TIfdFiJTz+/D9eBUBBhHKeYFxm3M+thvklTLgjKl6fflh14NfGuNTevK9yQke8wewW3f9UmFTo1qNOPF1OsTZRbwua6oQYa59P+KukoPt4Dsu1VtILtTkj7hfEsUL79cjotwO3gkhYftxbl/xeDSZWOt+9Nhb8ZKmQG/uDx4JiTMm5lWRk4QB7pUujZ1CftxCYWz/lJx9nuJpdCOgP624tcHymErNlD+vGLwMTNslcXGYkAJH6xvGyxBJ+Obc8vRVnZbRM26BfH34TcPK1ueRxHSrDUbzMIIUsgcoZAxBuim8uDPp+K7bGqiygzSs2vQfr9U5Jhe9/F8sPdtNctfJZEfgmthNTeVFjyNsGIfIt754uGSfACqM7wDLh6fbKx7M+FHlNyOdvYCrbKUOAYXmTikYIpVDvlaaeMO+N+uW8Rhvm1j+JU7CVwhMavLySaPVc6Dt5OxiMMmxw9mVrjW9bBPjS5AkrS5MOA13T5wapoLzH6+gE92U4HzA6ilMcwRaQPSFnK2JU7tzyt2Wy1PH4MjHowXI2WyICG1x510dD3tX1P/1px8ro="
|
||||
file: lbrynet-${OS}.zip
|
||||
skip_cleanup: true
|
||||
overwrite: true
|
||||
draft: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
- <<: *build
|
||||
name: "Mac"
|
||||
os: osx
|
||||
osx_image: xcode8.3
|
||||
language: shell
|
||||
env: OS=mac
|
||||
before_install:
|
||||
- brew uninstall mercurial
|
||||
- brew upgrade python || true
|
||||
- pip3 install --user --upgrade pip virtualenv
|
||||
- /Users/travis/Library/Python/3.7/bin/virtualenv --clear $HOME/venv
|
||||
- source $HOME/venv/bin/activate
|
||||
before_cache:
|
||||
- brew cleanup
|
||||
|
||||
- <<: *build
|
||||
name: "Windows"
|
||||
os: windows
|
||||
language: shell
|
||||
env:
|
||||
- OS=windows
|
||||
- PATH=/c/Python37:/c/Python37/Scripts:/C/Windows/System32/downlevel:$PATH
|
||||
before_install:
|
||||
- choco install python --version=3.7.4 --x86
|
||||
- python -m pip install --upgrade pip
|
||||
- pip install pywin32
|
||||
script:
|
||||
- pyinstaller --additional-hooks-dir=scripts/. --icon=icons/lbry256.ico -F -n lbrynet lbry/extras/cli.py
|
||||
- cd dist
|
||||
- 7z a -tzip lbrynet-windows.zip lbrynet.exe
|
||||
- sha256sum -b lbrynet-windows.zip
|
||||
- ./lbrynet.exe --version
|
||||
- if: tag IS present
|
||||
stage: build
|
||||
name: "Wallet Server Docker Image - Tagged Release"
|
||||
- stage: build
|
||||
name: "Wallet Server Docker Image - Segwit Fix"
|
||||
script:
|
||||
- set -e
|
||||
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
|
||||
- travis_retry docker build -t lbry/wallet-server:$TRAVIS_TAG -f lbry/scripts/Dockerfile.wallet_server .
|
||||
- docker push lbry/wallet-server:$TRAVIS_TAG
|
||||
|
||||
- if: tag IS blank AND branch = master AND NOT type IN (pull_request)
|
||||
stage: build
|
||||
name: "Wallet Server Docker Image - Master"
|
||||
script:
|
||||
- set -e
|
||||
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
|
||||
- travis_retry docker build -t lbry/wallet-server:master -f lbry/scripts/Dockerfile.wallet_server .
|
||||
- docker push lbry/wallet-server:master
|
||||
- travis_retry docker build -t lbry/wallet-server:segwit -f lbry/scripts/Dockerfile.wallet_server .
|
||||
- docker push lbry/wallet-server:segwit
|
||||
|
||||
cache:
|
||||
directories:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__name__ = "lbry"
|
||||
__version__ = "0.45.0"
|
||||
__version__ = "0.46.1"
|
||||
version = tuple(__version__.split('.'))
|
||||
|
||||
@@ -1159,27 +1159,24 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
return wallet
|
||||
|
||||
@requires("wallet")
|
||||
async def jsonrpc_wallet_balance(self, wallet_id=None, confirmations=0, reserved_subtotals=False):
|
||||
async def jsonrpc_wallet_balance(self, wallet_id=None, confirmations=0):
|
||||
"""
|
||||
Return the balance of a wallet
|
||||
|
||||
Usage:
|
||||
wallet_balance [--wallet_id=<wallet_id>] [--confirmations=<confirmations>] [--reserved_subtotals]
|
||||
wallet_balance [--wallet_id=<wallet_id>] [--confirmations=<confirmations>]
|
||||
|
||||
Options:
|
||||
--wallet_id=<wallet_id> : (str) balance for specific wallet
|
||||
--confirmations=<confirmations> : (int) Only include transactions with this many
|
||||
confirmed blocks.
|
||||
--reserved_subtotals : (bool) Include detailed reserved balances on
|
||||
claims, tips and supports.
|
||||
|
||||
Returns:
|
||||
(decimal) amount of lbry credits in wallet
|
||||
"""
|
||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||
balance = await self.ledger.get_detailed_balance(
|
||||
accounts=wallet.accounts, confirmations=confirmations,
|
||||
reserved_subtotals=reserved_subtotals
|
||||
accounts=wallet.accounts, confirmations=confirmations
|
||||
)
|
||||
return dict_values_to_lbc(balance)
|
||||
|
||||
@@ -1362,13 +1359,13 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
return paginate_list(await wallet.get_detailed_accounts(**kwargs), page, page_size)
|
||||
|
||||
@requires("wallet")
|
||||
async def jsonrpc_account_balance(self, account_id=None, wallet_id=None, confirmations=0, reserved_subtotals=False):
|
||||
async def jsonrpc_account_balance(self, account_id=None, wallet_id=None, confirmations=0):
|
||||
"""
|
||||
Return the balance of an account
|
||||
|
||||
Usage:
|
||||
account_balance [<account_id>] [<address> | --address=<address>] [--wallet_id=<wallet_id>]
|
||||
[<confirmations> | --confirmations=<confirmations>] [--reserved_subtotals]
|
||||
[<confirmations> | --confirmations=<confirmations>]
|
||||
|
||||
Options:
|
||||
--account_id=<account_id> : (str) If provided only the balance for this
|
||||
@@ -1376,8 +1373,6 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
--wallet_id=<wallet_id> : (str) balance for specific wallet
|
||||
--confirmations=<confirmations> : (int) Only include transactions with this many
|
||||
confirmed blocks.
|
||||
--reserved_subtotals : (bool) Include detailed reserved balances on
|
||||
claims, tips and supports.
|
||||
|
||||
Returns:
|
||||
(decimal) amount of lbry credits in wallet
|
||||
@@ -1385,7 +1380,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||
account = wallet.get_account_or_default(account_id)
|
||||
balance = await account.get_detailed_balance(
|
||||
confirmations=confirmations, reserved_subtotals=reserved_subtotals
|
||||
confirmations=confirmations, reserved_subtotals=True
|
||||
)
|
||||
return dict_values_to_lbc(balance)
|
||||
|
||||
@@ -3282,7 +3277,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
@requires(WALLET_COMPONENT)
|
||||
async def jsonrpc_support_create(
|
||||
self, claim_id, amount, tip=False, account_id=None, wallet_id=None, funding_account_ids=None,
|
||||
preview=False, blocking=False):
|
||||
channel_id=None, preview=False, blocking=False):
|
||||
"""
|
||||
Create a support or a tip for name claim.
|
||||
|
||||
@@ -3306,6 +3301,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||
assert not wallet.is_locked, "Cannot spend funds with locked wallet, unlock first."
|
||||
funding_accounts = wallet.get_accounts_or_all(funding_account_ids)
|
||||
channel = await self.get_channel_or_none(wallet, None, channel_id, None, for_signing=True)
|
||||
amount = self.get_dewies_or_error("amount", amount)
|
||||
claim = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
|
||||
claim_address = claim.get_address(self.ledger)
|
||||
@@ -3314,7 +3310,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||
claim_address = await account.receiving.get_or_create_usable_address()
|
||||
|
||||
tx = await Transaction.support(
|
||||
claim.claim_name, claim_id, amount, claim_address, funding_accounts, funding_accounts[0]
|
||||
claim.claim_name, claim_id, amount, claim_address, funding_accounts, funding_accounts[0], channel
|
||||
)
|
||||
|
||||
if not preview:
|
||||
|
||||
@@ -3,6 +3,7 @@ __node_cli__ = 'lbrycrd-cli'
|
||||
__node_bin__ = ''
|
||||
__node_url__ = (
|
||||
'https://github.com/lbryio/lbrycrd/releases/download/v0.17.2.1/lbrycrd-linux.zip'
|
||||
# 'https://github.com/lbryio/lbrycrd/releases/download/v0.17.3.1/lbrycrd-linux-1731.zip'
|
||||
)
|
||||
__spvserver__ = 'lbry.wallet.server.coin.LBCRegTest'
|
||||
|
||||
|
||||
@@ -34,9 +34,12 @@ def dewies_to_lbc(dewies) -> str:
|
||||
|
||||
|
||||
def dict_values_to_lbc(d):
|
||||
lbc_dict = {}
|
||||
for key, value in d.items():
|
||||
if isinstance(value, int):
|
||||
d[key] = dewies_to_lbc(value)
|
||||
lbc_dict[key] = dewies_to_lbc(value)
|
||||
elif isinstance(value, dict):
|
||||
dict_values_to_lbc(value)
|
||||
return d
|
||||
lbc_dict[key] = dict_values_to_lbc(value)
|
||||
else:
|
||||
lbc_dict[key] = value
|
||||
return lbc_dict
|
||||
+33
-15
@@ -5,7 +5,8 @@ from functools import partial
|
||||
from typing import Tuple, List
|
||||
from datetime import datetime
|
||||
|
||||
from torba.client.baseledger import BaseLedger
|
||||
import pylru
|
||||
from torba.client.baseledger import BaseLedger, TransactionEvent
|
||||
from torba.client.baseaccount import SingleKey
|
||||
from lbry.schema.result import Outputs
|
||||
from lbry.schema.url import URL
|
||||
@@ -52,6 +53,7 @@ class MainNetLedger(BaseLedger):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fee_per_name_char = self.config.get('fee_per_name_char', self.default_fee_per_name_char)
|
||||
self._balance_cache = pylru.lrucache(100000)
|
||||
|
||||
async def _inflate_outputs(self, query, accounts):
|
||||
outputs = Outputs.from_base64(await query)
|
||||
@@ -105,6 +107,7 @@ class MainNetLedger(BaseLedger):
|
||||
await asyncio.gather(*(a.maybe_migrate_certificates() for a in self.accounts))
|
||||
await asyncio.gather(*(a.save_max_gap() for a in self.accounts))
|
||||
await self._report_state()
|
||||
self.on_transaction.listen(self._reset_balance_cache)
|
||||
|
||||
async def _report_state(self):
|
||||
try:
|
||||
@@ -128,6 +131,14 @@ class MainNetLedger(BaseLedger):
|
||||
'Failed to display wallet state, please file issue '
|
||||
'for this bug along with the traceback you see below:')
|
||||
|
||||
async def _reset_balance_cache(self, e: TransactionEvent):
|
||||
account_ids = [
|
||||
r['account'] for r in await self.db.get_addresses(('account',), address=e.address)
|
||||
]
|
||||
for account_id in account_ids:
|
||||
if account_id in self._balance_cache:
|
||||
del self._balance_cache[account_id]
|
||||
|
||||
@staticmethod
|
||||
def constraint_spending_utxos(constraints):
|
||||
constraints['txo_type'] = 0
|
||||
@@ -288,21 +299,28 @@ class MainNetLedger(BaseLedger):
|
||||
def get_transaction_history_count(self, **constraints):
|
||||
return self.db.get_transaction_count(**constraints)
|
||||
|
||||
@staticmethod
|
||||
async def get_detailed_balance(accounts, confirmations=0, reserved_subtotals=False):
|
||||
result = {}
|
||||
async def get_detailed_balance(self, accounts, confirmations=0):
|
||||
result = {
|
||||
'total': 0,
|
||||
'available': 0,
|
||||
'reserved': 0,
|
||||
'reserved_subtotals': {
|
||||
'claims': 0,
|
||||
'supports': 0,
|
||||
'tips': 0
|
||||
}
|
||||
}
|
||||
for account in accounts:
|
||||
balance = await account.get_detailed_balance(confirmations, reserved_subtotals)
|
||||
if result:
|
||||
for key, value in balance.items():
|
||||
if key == 'reserved_subtotals':
|
||||
if value is not None:
|
||||
for subkey, subvalue in value.items():
|
||||
result['reserved_subtotals'][subkey] += subvalue
|
||||
else:
|
||||
result[key] += value
|
||||
else:
|
||||
result = balance
|
||||
balance = self._balance_cache.get(account.id)
|
||||
if not balance:
|
||||
balance = self._balance_cache[account.id] =\
|
||||
await account.get_detailed_balance(confirmations, reserved_subtotals=True)
|
||||
for key, value in balance.items():
|
||||
if key == 'reserved_subtotals':
|
||||
for subkey, subvalue in value.items():
|
||||
result['reserved_subtotals'][subkey] += subvalue
|
||||
else:
|
||||
result[key] += value
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,17 @@ class OutputScript(BaseOutputScript):
|
||||
SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||
))
|
||||
|
||||
SUPPORT_CLAIM_DATA_OPCODES = (
|
||||
OP_SUPPORT_CLAIM, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim_id'), PUSH_SINGLE('support'),
|
||||
OP_2DROP, OP_2DROP
|
||||
)
|
||||
SUPPORT_CLAIM_DATA_PUBKEY = Template('support_claim+data+pay_pubkey_hash', (
|
||||
SUPPORT_CLAIM_DATA_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
|
||||
))
|
||||
SUPPORT_CLAIM_DATA_SCRIPT = Template('support_claim+data+pay_script_hash', (
|
||||
SUPPORT_CLAIM_DATA_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||
))
|
||||
|
||||
UPDATE_CLAIM_OPCODES = (
|
||||
OP_UPDATE_CLAIM, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim_id'), PUSH_SINGLE('claim'),
|
||||
OP_2DROP, OP_2DROP
|
||||
@@ -73,6 +84,8 @@ class OutputScript(BaseOutputScript):
|
||||
CLAIM_NAME_SCRIPT,
|
||||
SUPPORT_CLAIM_PUBKEY,
|
||||
SUPPORT_CLAIM_SCRIPT,
|
||||
SUPPORT_CLAIM_DATA_PUBKEY,
|
||||
SUPPORT_CLAIM_DATA_SCRIPT,
|
||||
UPDATE_CLAIM_PUBKEY,
|
||||
UPDATE_CLAIM_SCRIPT,
|
||||
SELL_CLAIM, SELL_SCRIPT,
|
||||
@@ -104,6 +117,16 @@ class OutputScript(BaseOutputScript):
|
||||
'pubkey_hash': pubkey_hash
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def pay_support_data_pubkey_hash(
|
||||
cls, claim_name: bytes, claim_id: bytes, support: bytes, pubkey_hash: bytes):
|
||||
return cls(template=cls.SUPPORT_CLAIM_DATA_PUBKEY, values={
|
||||
'claim_name': claim_name,
|
||||
'claim_id': claim_id,
|
||||
'support': support,
|
||||
'pubkey_hash': pubkey_hash
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def sell_script(cls, price):
|
||||
return cls(template=cls.SELL_SCRIPT, values={
|
||||
|
||||
@@ -5,6 +5,7 @@ from torba.server.script import ScriptPubKey, OpCodes
|
||||
from torba.server.util import cachedproperty
|
||||
from torba.server.hash import hash_to_hex_str, HASHX_LEN
|
||||
from torba.server.coins import Coin, CoinError
|
||||
from torba.server.tx import DeserializerSegWit
|
||||
|
||||
from lbry.wallet.script import OutputScript
|
||||
from .session import LBRYElectrumX, LBRYSessionManager
|
||||
@@ -18,6 +19,7 @@ class LBC(Coin):
|
||||
SESSIONCLS = LBRYElectrumX
|
||||
BLOCK_PROCESSOR = LBRYBlockProcessor
|
||||
SESSION_MANAGER = LBRYSessionManager
|
||||
DESERIALIZER = DeserializerSegWit
|
||||
DB = LBRYDB
|
||||
NAME = "LBRY"
|
||||
SHORTNAME = "LBC"
|
||||
|
||||
@@ -649,7 +649,7 @@ class SQLDB:
|
||||
body_timer = timer.add_timer('body')
|
||||
for position, (etx, txid) in enumerate(all_txs):
|
||||
tx = timer.run(
|
||||
Transaction, etx.serialize(), height=height, position=position
|
||||
Transaction, etx.raw, height=height, position=position
|
||||
)
|
||||
# Inputs
|
||||
spent_claims, spent_supports, spent_others = timer.run(
|
||||
|
||||
@@ -16,6 +16,7 @@ from lbry.wallet.server.db.writer import LBRYDB
|
||||
from lbry.wallet.server.db import reader
|
||||
from lbry.wallet.server.websocket import AdminWebSocket
|
||||
from lbry.wallet.server.metrics import ServerLoadData, APICallMetrics
|
||||
from lbry import __version__ as sdk_version
|
||||
|
||||
|
||||
class ResultCacheItem:
|
||||
@@ -94,6 +95,7 @@ class LBRYElectrumX(ElectrumX):
|
||||
PROTOCOL_MIN = (0, 0) # temporary, for supporting 0.10 protocol
|
||||
max_errors = math.inf # don't disconnect people for errors! let them happen...
|
||||
session_mgr: LBRYSessionManager
|
||||
version = sdk_version
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@@ -194,6 +194,14 @@ class Output(BaseOutput):
|
||||
script = cls.script_class.pay_support_pubkey_hash(claim_name.encode(), unhexlify(claim_id)[::-1], pubkey_hash)
|
||||
return cls(amount, script)
|
||||
|
||||
@classmethod
|
||||
def pay_support_data_pubkey_hash(
|
||||
cls, amount: int, claim_name: str, claim_id: str, support: bytes, pubkey_hash: bytes) -> 'Output':
|
||||
script = OutputScript.pay_support_data_pubkey_hash(
|
||||
claim_name.encode(), unhexlify(claim_id)[::-1], support, pubkey_hash
|
||||
)
|
||||
return cls(amount, script)
|
||||
|
||||
@classmethod
|
||||
def add_purchase_data(cls, purchase: Purchase) -> 'Output':
|
||||
script = cls.script_class.return_data(purchase)
|
||||
@@ -287,11 +295,16 @@ class Transaction(BaseTransaction):
|
||||
|
||||
@classmethod
|
||||
def support(cls, claim_name: str, claim_id: str, amount: int, holding_address: str,
|
||||
funding_accounts: List[Account], change_account: Account):
|
||||
funding_accounts: List[Account], change_account: Account, signing_channel: Output = None):
|
||||
ledger, wallet = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||
support_output = Output.pay_support_pubkey_hash(
|
||||
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
if signing_channel:
|
||||
support_output = Output.pay_support_data_pubkey_hash(
|
||||
amount, claim_name, claim_id, b'beef', ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
else:
|
||||
support_output = Output.pay_support_pubkey_hash(
|
||||
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
return cls.create([], [support_output], funding_accounts, change_account)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -37,7 +37,7 @@ def variance(times):
|
||||
async def wait_for_done(conf, claim_name, timeout):
|
||||
blobs_completed, last_completed = 0, time.perf_counter()
|
||||
while True:
|
||||
file = (await daemon_rpc(conf, "file_list", claim_name=claim_name))[0]
|
||||
file = (await daemon_rpc(conf, "file_list", claim_name=claim_name))['items'][0]
|
||||
if file['status'] in ['finished', 'stopped']:
|
||||
return True, file['blobs_completed'], file['blobs_in_stream']
|
||||
elif blobs_completed < int(file['blobs_completed']):
|
||||
|
||||
@@ -6,7 +6,7 @@ SNAPSHOT_URL="${SNAPSHOT_URL:-}" #off by default. latest snapshot at https://lbr
|
||||
|
||||
if [[ -n "$SNAPSHOT_URL" ]] && [[ ! -f /database/claims.db ]]; then
|
||||
echo "Downloading wallet snapshot from $SNAPSHOT_URL"
|
||||
wget -O wallet_snapshot.tar.bz2 "$SNAPSHOT_URL"
|
||||
wget --no-verbose -O wallet_snapshot.tar.bz2 "$SNAPSHOT_URL"
|
||||
echo "Extracting snapshot..."
|
||||
tar xvjf wallet_snapshot.tar.bz2 --directory /database
|
||||
rm wallet_snapshot.tar.bz2
|
||||
|
||||
@@ -1211,3 +1211,11 @@ class SupportCommands(CommandTestCase):
|
||||
self.assertFalse(txs2[0]['support_info'][0]['is_tip'])
|
||||
self.assertEqual(txs2[0]['value'], '0.0')
|
||||
self.assertEqual(txs2[0]['fee'], '-0.0001415')
|
||||
|
||||
async def test_signed_supports(self):
|
||||
channel_id = self.get_claim_id(await self.channel_create())
|
||||
stream_id = self.get_claim_id(await self.stream_create())
|
||||
await self.support_create(stream_id, '0.3', channel_id=channel_id)
|
||||
supports = await self.daemon.jsonrpc_support_list()
|
||||
self.assertEqual(1, len(supports['items']))
|
||||
self.assertEqual(supports['items'][0].script.values['support'], b'beef')
|
||||
@@ -36,112 +36,3 @@ class TransactionCommandsTestCase(CommandTestCase):
|
||||
await self.assertBalance(self.account, '0.0')
|
||||
await self.daemon.jsonrpc_utxo_release()
|
||||
await self.assertBalance(self.account, '11.0')
|
||||
|
||||
async def test_granular_balances(self):
|
||||
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||
|
||||
account_balance = self.daemon.jsonrpc_account_balance
|
||||
wallet_balance = self.daemon.jsonrpc_wallet_balance
|
||||
|
||||
expected = {
|
||||
'total': '10.0',
|
||||
'available': '10.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': None
|
||||
}
|
||||
self.assertEqual(await account_balance(reserved_subtotals=False), expected)
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=False), expected)
|
||||
|
||||
expected = {
|
||||
'total': '10.0',
|
||||
'available': '10.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||
}
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), expected)
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), expected)
|
||||
|
||||
# claim with update + supporting our own claim
|
||||
stream1 = await self.stream_create('granularity', '3.0')
|
||||
await self.stream_update(self.get_claim_id(stream1), data=b'news', bid='1.0')
|
||||
await self.support_create(self.get_claim_id(stream1), '2.0')
|
||||
expected = {
|
||||
'total': '9.977534',
|
||||
'available': '6.977534',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
}
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), expected)
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), expected)
|
||||
|
||||
address2 = await self.daemon.jsonrpc_address_unused(account2.id)
|
||||
|
||||
# send lbc to someone else
|
||||
tx = await self.daemon.jsonrpc_account_send('1.0', address2)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '8.97741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), {
|
||||
'total': '9.97741',
|
||||
'available': '6.97741',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
# tip received
|
||||
support1 = await self.support_create(
|
||||
self.get_claim_id(stream1), '0.3', tip=True, funding_account_ids=[account2.id]
|
||||
)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.27741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), {
|
||||
'total': '9.977268',
|
||||
'available': '6.677268',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
|
||||
# tip claimed
|
||||
tx = await self.daemon.jsonrpc_support_abandon(txid=support1['txid'], nout=0)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.277303',
|
||||
'available': '6.277303',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), {
|
||||
'total': '9.977161',
|
||||
'available': '6.977161',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
stream2 = await self.stream_create(
|
||||
'granularity-is-cool', '0.1', account_id=account2.id, funding_account_ids=[account2.id]
|
||||
)
|
||||
|
||||
# tip another claim
|
||||
await self.support_create(
|
||||
self.get_claim_id(stream2), '0.2', tip=True, funding_account_ids=[self.account.id]
|
||||
)
|
||||
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||
'total': '9.077157',
|
||||
'available': '6.077157',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(reserved_subtotals=True), {
|
||||
'total': '9.938908',
|
||||
'available': '6.638908',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.1', 'supports': '2.0', 'tips': '0.2'}
|
||||
})
|
||||
@@ -1,7 +1,9 @@
|
||||
import asyncio
|
||||
import json
|
||||
from lbry.testcase import CommandTestCase
|
||||
|
||||
from torba.client.wallet import ENCRYPT_ON_DISK
|
||||
from lbry.testcase import CommandTestCase
|
||||
from lbry.wallet.dewies import dict_values_to_lbc
|
||||
|
||||
|
||||
class WalletCommands(CommandTestCase):
|
||||
@@ -16,6 +18,154 @@ class WalletCommands(CommandTestCase):
|
||||
await self.daemon.jsonrpc_wallet_add(wallet.id)
|
||||
self.assertEqual(len(session.hashX_subs), 28)
|
||||
|
||||
async def test_balance_caching(self):
|
||||
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||
address2 = await self.daemon.jsonrpc_address_unused(account2.id)
|
||||
sendtxid = await self.blockchain.send_to_address(address2, 10)
|
||||
await self.confirm_tx(sendtxid)
|
||||
await self.generate(1)
|
||||
|
||||
wallet_balance = self.daemon.jsonrpc_wallet_balance
|
||||
ledger = self.ledger
|
||||
query_count = self.ledger.db.db.query_count
|
||||
|
||||
expected = {
|
||||
'total': '20.0',
|
||||
'available': '20.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||
}
|
||||
self.assertIsNone(ledger._balance_cache.get(self.account.id))
|
||||
|
||||
query_count += 6
|
||||
self.assertEqual(await wallet_balance(), expected)
|
||||
self.assertEqual(self.ledger.db.db.query_count, query_count)
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(self.account.id))['total'], '10.0')
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(account2.id))['total'], '10.0')
|
||||
|
||||
# calling again uses cache
|
||||
self.assertEqual(await wallet_balance(), expected)
|
||||
self.assertEqual(self.ledger.db.db.query_count, query_count)
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(self.account.id))['total'], '10.0')
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(account2.id))['total'], '10.0')
|
||||
|
||||
await self.stream_create()
|
||||
await self.generate(1)
|
||||
|
||||
expected = {
|
||||
'total': '19.979893',
|
||||
'available': '18.979893',
|
||||
'reserved': '1.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '0.0', 'tips': '0.0'}
|
||||
}
|
||||
# on_transaction event reset balance cache
|
||||
query_count = self.ledger.db.db.query_count
|
||||
self.assertEqual(await wallet_balance(), expected)
|
||||
query_count += 3 # only one of the accounts changed
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(self.account.id))['total'], '9.979893')
|
||||
self.assertEqual(dict_values_to_lbc(ledger._balance_cache.get(account2.id))['total'], '10.0')
|
||||
self.assertEqual(self.ledger.db.db.query_count, query_count)
|
||||
|
||||
async def test_granular_balances(self):
|
||||
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||
|
||||
account_balance = self.daemon.jsonrpc_account_balance
|
||||
wallet_balance = self.daemon.jsonrpc_wallet_balance
|
||||
|
||||
expected = {
|
||||
'total': '10.0',
|
||||
'available': '10.0',
|
||||
'reserved': '0.0',
|
||||
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||
}
|
||||
self.assertEqual(await account_balance(), expected)
|
||||
self.assertEqual(await wallet_balance(), expected)
|
||||
|
||||
# claim with update + supporting our own claim
|
||||
stream1 = await self.stream_create('granularity', '3.0')
|
||||
await self.stream_update(self.get_claim_id(stream1), data=b'news', bid='1.0')
|
||||
await self.support_create(self.get_claim_id(stream1), '2.0')
|
||||
expected = {
|
||||
'total': '9.977534',
|
||||
'available': '6.977534',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
}
|
||||
self.assertEqual(await account_balance(), expected)
|
||||
self.assertEqual(await wallet_balance(), expected)
|
||||
|
||||
address2 = await self.daemon.jsonrpc_address_unused(account2.id)
|
||||
|
||||
# send lbc to someone else
|
||||
tx = await self.daemon.jsonrpc_account_send('1.0', address2)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '8.97741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.97741',
|
||||
'available': '6.97741',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
# tip received
|
||||
support1 = await self.support_create(
|
||||
self.get_claim_id(stream1), '0.3', tip=True, funding_account_ids=[account2.id]
|
||||
)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '9.27741',
|
||||
'available': '5.97741',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.977268',
|
||||
'available': '6.677268',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
|
||||
# tip claimed
|
||||
tx = await self.daemon.jsonrpc_support_abandon(txid=support1['txid'], nout=0)
|
||||
await self.confirm_tx(tx.id)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '9.277303',
|
||||
'available': '6.277303',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.977161',
|
||||
'available': '6.977161',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
||||
stream2 = await self.stream_create(
|
||||
'granularity-is-cool', '0.1', account_id=account2.id, funding_account_ids=[account2.id]
|
||||
)
|
||||
|
||||
# tip another claim
|
||||
await self.support_create(
|
||||
self.get_claim_id(stream2), '0.2', tip=True, funding_account_ids=[self.account.id]
|
||||
)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '9.077157',
|
||||
'available': '6.077157',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.938908',
|
||||
'available': '6.638908',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.1', 'supports': '2.0', 'tips': '0.2'}
|
||||
})
|
||||
|
||||
|
||||
class WalletEncryptionAndSynchronization(CommandTestCase):
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ import asyncio
|
||||
import os
|
||||
|
||||
import lbry.wallet
|
||||
from lbry import __version__ as sdk_version
|
||||
from lbry.testcase import CommandTestCase
|
||||
from lbry.extras.daemon.Components import HeadersComponent
|
||||
from torba.client.basenetwork import ClientSession
|
||||
from torba.testcase import IntegrationTestCase
|
||||
|
||||
|
||||
class TestSessionBloat(IntegrationTestCase):
|
||||
class TestSessions(IntegrationTestCase):
|
||||
"""
|
||||
Tests that server cleans up stale connections after session timeout and client times out too.
|
||||
"""
|
||||
@@ -33,6 +34,10 @@ class TestSessionBloat(IntegrationTestCase):
|
||||
self.assertTrue(session.is_closing())
|
||||
self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0)
|
||||
|
||||
async def test_proper_version(self):
|
||||
info = await self.ledger.network.get_server_features()
|
||||
self.assertEqual(sdk_version, info['server_version'])
|
||||
|
||||
|
||||
class TestSegwitServer(IntegrationTestCase):
|
||||
LEDGER = lbry.wallet
|
||||
|
||||
@@ -20,6 +20,7 @@ class AIOSQLite:
|
||||
self.executor = ThreadPoolExecutor(max_workers=1)
|
||||
self.connection: sqlite3.Connection = None
|
||||
self._closing = False
|
||||
self.query_count = 0
|
||||
|
||||
@classmethod
|
||||
async def connect(cls, path: Union[bytes, str], *args, **kwargs):
|
||||
@@ -65,6 +66,7 @@ class AIOSQLite:
|
||||
def __run_transaction(self, fun: Callable[[sqlite3.Connection, Any, Any], Any], *args, **kwargs):
|
||||
self.connection.execute('begin')
|
||||
try:
|
||||
self.query_count += 1
|
||||
result = fun(self.connection, *args, **kwargs) # type: ignore
|
||||
self.connection.commit()
|
||||
return result
|
||||
@@ -605,11 +607,12 @@ class BaseDatabase(SQLiteMixin):
|
||||
'pubkey', 'chain_code', 'n', 'depth'
|
||||
)
|
||||
addresses = rows_to_dict(await self.select_addresses(', '.join(cols), **constraints), cols)
|
||||
for address in addresses:
|
||||
address['pubkey'] = PubKey(
|
||||
self.ledger, address.pop('pubkey'), address.pop('chain_code'),
|
||||
address.pop('n'), address.pop('depth')
|
||||
)
|
||||
if 'pubkey' in cols:
|
||||
for address in addresses:
|
||||
address['pubkey'] = PubKey(
|
||||
self.ledger, address.pop('pubkey'), address.pop('chain_code'),
|
||||
address.pop('n'), address.pop('depth')
|
||||
)
|
||||
return addresses
|
||||
|
||||
async def get_address_count(self, cols=None, **constraints):
|
||||
|
||||
@@ -400,6 +400,9 @@ class BaseOutputScript(Script):
|
||||
PAY_SCRIPT_HASH = Template('pay_script_hash', (
|
||||
OP_HASH160, PUSH_SINGLE('script_hash'), OP_EQUAL
|
||||
))
|
||||
PAY_SEGWIT = Template('pay_script_hash+segwit', (
|
||||
OP_0, PUSH_SINGLE('script_hash')
|
||||
))
|
||||
RETURN_DATA = Template('return_data', (
|
||||
OP_RETURN, PUSH_SINGLE('data')
|
||||
))
|
||||
@@ -408,6 +411,7 @@ class BaseOutputScript(Script):
|
||||
PAY_PUBKEY_FULL,
|
||||
PAY_PUBKEY_HASH,
|
||||
PAY_SCRIPT_HASH,
|
||||
PAY_SEGWIT,
|
||||
RETURN_DATA
|
||||
]
|
||||
|
||||
|
||||
@@ -425,6 +425,10 @@ class BaseTransaction:
|
||||
stream = BCDataStream(self._raw)
|
||||
self.version = stream.read_uint32()
|
||||
input_count = stream.read_compact_size()
|
||||
flag = 0
|
||||
if input_count == 0:
|
||||
flag = stream.read_uint8()
|
||||
input_count = stream.read_compact_size()
|
||||
self._add(self._inputs, [
|
||||
self.input_class.deserialize_from(stream) for _ in range(input_count)
|
||||
])
|
||||
@@ -432,6 +436,12 @@ class BaseTransaction:
|
||||
self._add(self._outputs, [
|
||||
self.output_class.deserialize_from(stream) for _ in range(output_count)
|
||||
])
|
||||
if flag == 1:
|
||||
# drain witness portion of transaction
|
||||
# too many witnesses for no crime
|
||||
for _ in range(input_count):
|
||||
for _ in range(stream.read_compact_size()):
|
||||
stream.read(stream.read_compact_size())
|
||||
self.locktime = stream.read_uint32()
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -618,6 +618,7 @@ class SessionBase(RPCSession):
|
||||
MAX_CHUNK_SIZE = 2016
|
||||
session_counter = itertools.count()
|
||||
request_handlers: typing.Dict[str, typing.Callable] = {}
|
||||
version = '0.5.7'
|
||||
|
||||
def __init__(self, session_mgr, db, mempool, peer_mgr, kind):
|
||||
connection = JSONRPCConnection(JSONRPCAutoDetect)
|
||||
@@ -742,7 +743,7 @@ class ElectrumX(SessionBase):
|
||||
return {
|
||||
'hosts': env.hosts_dict(),
|
||||
'pruning': None,
|
||||
'server_version': torba.__version__,
|
||||
'server_version': cls.version,
|
||||
'protocol_min': min_str,
|
||||
'protocol_max': max_str,
|
||||
'genesis_hash': env.coin.GENESIS_HASH,
|
||||
@@ -758,7 +759,7 @@ class ElectrumX(SessionBase):
|
||||
@classmethod
|
||||
def server_version_args(cls):
|
||||
"""The arguments to a server.version RPC call to a peer."""
|
||||
return [torba.__version__, cls.protocol_min_max_strings()]
|
||||
return [cls.version, cls.protocol_min_max_strings()]
|
||||
|
||||
def protocol_version_string(self):
|
||||
return util.version_string(self.protocol_tuple)
|
||||
@@ -1063,7 +1064,7 @@ class ElectrumX(SessionBase):
|
||||
revision //= 100
|
||||
daemon_version = f'{major:d}.{minor:d}.{revision:d}'
|
||||
for pair in [
|
||||
('$SERVER_VERSION', torba.__version__),
|
||||
('$SERVER_VERSION', self.version),
|
||||
('$DAEMON_VERSION', daemon_version),
|
||||
('$DAEMON_SUBVERSION', network_info['subversion']),
|
||||
('$DONATION_ADDRESS', self.env.donation_address),
|
||||
@@ -1077,7 +1078,7 @@ class ElectrumX(SessionBase):
|
||||
|
||||
async def banner(self):
|
||||
"""Return the server banner text."""
|
||||
banner = f'You are connected to an {torba.__version__} server.'
|
||||
banner = f'You are connected to an {self.version} server.'
|
||||
|
||||
if self.is_tor():
|
||||
banner_file = self.env.tor_banner_file
|
||||
@@ -1147,7 +1148,7 @@ class ElectrumX(SessionBase):
|
||||
f'unsupported protocol version: {protocol_version}')
|
||||
self.set_request_handlers(ptuple)
|
||||
|
||||
return torba.__version__, self.protocol_version_string()
|
||||
return self.version, self.protocol_version_string()
|
||||
|
||||
async def transaction_broadcast(self, raw_tx):
|
||||
"""Broadcast a raw transaction to the network.
|
||||
|
||||
@@ -41,19 +41,9 @@ ZERO = bytes(32)
|
||||
MINUS_1 = 4294967295
|
||||
|
||||
|
||||
class Tx(namedtuple("Tx", "version inputs outputs locktime")):
|
||||
class Tx(namedtuple("Tx", "version inputs outputs locktime raw")):
|
||||
"""Class representing a transaction."""
|
||||
|
||||
def serialize(self):
|
||||
return b''.join((
|
||||
pack_le_int32(self.version),
|
||||
pack_varint(len(self.inputs)),
|
||||
b''.join(tx_in.serialize() for tx_in in self.inputs),
|
||||
pack_varint(len(self.outputs)),
|
||||
b''.join(tx_out.serialize() for tx_out in self.outputs),
|
||||
pack_le_uint32(self.locktime)
|
||||
))
|
||||
|
||||
|
||||
class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")):
|
||||
"""Class representing a transaction input."""
|
||||
@@ -101,14 +91,17 @@ class Deserializer:
|
||||
self.binary = binary
|
||||
self.binary_length = len(binary)
|
||||
self.cursor = start
|
||||
self.flags = 0
|
||||
|
||||
def read_tx(self):
|
||||
"""Return a deserialized transaction."""
|
||||
start = self.cursor
|
||||
return Tx(
|
||||
self._read_le_int32(), # version
|
||||
self._read_inputs(), # inputs
|
||||
self._read_outputs(), # outputs
|
||||
self._read_le_uint32() # locktime
|
||||
self._read_inputs(), # inputs
|
||||
self._read_outputs(), # outputs
|
||||
self._read_le_uint32(), # locktime
|
||||
self.binary[start:self.cursor],
|
||||
)
|
||||
|
||||
def read_tx_and_hash(self):
|
||||
@@ -204,7 +197,7 @@ class Deserializer:
|
||||
|
||||
|
||||
class TxSegWit(namedtuple("Tx", "version marker flag inputs outputs "
|
||||
"witness locktime")):
|
||||
"witness locktime raw")):
|
||||
"""Class representing a SegWit transaction."""
|
||||
|
||||
|
||||
@@ -250,7 +243,7 @@ class DeserializerSegWit(Deserializer):
|
||||
vsize = (3 * base_size + self.binary_length) // 4
|
||||
|
||||
return TxSegWit(version, marker, flag, inputs, outputs, witness,
|
||||
locktime), self.TX_HASH_FN(orig_ser), vsize
|
||||
locktime, orig_ser), self.TX_HASH_FN(orig_ser), vsize
|
||||
|
||||
def read_tx(self):
|
||||
return self._read_tx_parts()[0]
|
||||
|
||||
Reference in new issue
Block a user