lbrynet.extras.wallet.server pylint fixes

This commit is contained in:
Lex Berezhny 2018-11-04 04:57:56 -05:00
parent 8ca2b75c80
commit ee1738da6e
5 changed files with 25 additions and 22 deletions

View file

@ -70,13 +70,13 @@ class LBC(Coin):
}
@cachedproperty
def address_handlers(cls):
def address_handlers(self):
return ScriptPubKey.PayToHandlers(
address=cls.P2PKH_address_from_hash160,
script_hash=cls.P2SH_address_from_hash160,
pubkey=cls.P2PKH_address_from_pubkey,
address=self.P2PKH_address_from_hash160,
script_hash=self.P2SH_address_from_hash160,
pubkey=self.P2PKH_address_from_pubkey,
unspendable=lambda: None,
strange=cls.claim_address_handler,
strange=self.claim_address_handler,
)
@classmethod

View file

@ -10,9 +10,7 @@ def handles_errors(decorated_function):
try:
return await decorated_function(*args, **kwargs)
except DaemonError as daemon_error:
error_dict = daemon_error.args[0]
message, code = error_dict['message'], error_dict['code']
raise RPCError(code=code, message=message)
raise RPCError(1, daemon_error.args[0])
return wrapper

View file

@ -145,7 +145,8 @@ class LBRYDB(DB):
return self.outpoint_to_claim_id_cache.get(key) or self.outpoint_to_claim_id_db.get(key)
def get_claims_for_name(self, name):
if name in self.claims_for_name_cache: return self.claims_for_name_cache[name]
if name in self.claims_for_name_cache:
return self.claims_for_name_cache[name]
db_claims = self.names_db.get(name)
return msgpack.loads(db_claims) if db_claims else {}
@ -159,13 +160,14 @@ class LBRYDB(DB):
self.logger.info("[-] Removing claim from name: {} - {}".format(hash_to_hex_str(claim_id), name))
claims = self.get_claims_for_name(name)
claim_n = claims.pop(claim_id)
for claim_id, number in claims.items():
for _claim_id, number in claims.items():
if number > claim_n:
claims[claim_id] = number - 1
claims[_claim_id] = number - 1
self.claims_for_name_cache[name] = claims
def get_signed_claim_ids_by_cert_id(self, cert_id):
if cert_id in self.claims_signed_by_cert_cache: return self.claims_signed_by_cert_cache[cert_id]
if cert_id in self.claims_signed_by_cert_cache:
return self.claims_signed_by_cert_cache[cert_id]
db_claims = self.signatures_db.get(cert_id)
return msgpack.loads(db_claims, use_list=True) if db_claims else []

View file

@ -84,11 +84,11 @@ def decode_claim_script(bytes_script):
value = None
claim_id = None
claim = None
if not (0 <= decoded_script[op][0] <= opcodes.OP_PUSHDATA4):
if not 0 <= decoded_script[op][0] <= opcodes.OP_PUSHDATA4:
return False
name = decoded_script[op][1]
op += 1
if not (0 <= decoded_script[op][0] <= opcodes.OP_PUSHDATA4):
if not 0 <= decoded_script[op][0] <= opcodes.OP_PUSHDATA4:
return False
if decoded_script[0][0] in [
opcodes.OP_SUPPORT_CLAIM,

View file

@ -4,10 +4,10 @@ from binascii import unhexlify, hexlify
from aiorpcx import RPCError
from torba.server.hash import hash_to_hex_str
from torba.server.session import ElectrumX
import torba.server.util as util
from torba.server import util
from lbrynet.schema.uri import parse_lbry_uri
from lbrynet.schema.error import URIParseError, DecodeError
from lbrynet.schema.error import URIParseError
from .block_processor import LBRYBlockProcessor
from .db import LBRYDB
@ -64,7 +64,7 @@ class LBRYElectrumX(ElectrumX):
if index < 0:
raise ValueError
except ValueError:
raise RPCError("index has to be >= 0 and integer")
raise RPCError(1, "index has to be >= 0 and integer")
raw_tx = await self.daemon_request('getrawtransaction', tx_hash)
if not raw_tx:
return None
@ -175,7 +175,7 @@ class LBRYElectrumX(ElectrumX):
supports = self.format_supports_from_daemon(claim_info.get('supports', [])) # fixme: lbrycrd#124
result['supports'] = supports
else:
self.logger.warning('tx has no claims in db: {} {}'.format(tx_hash, nout))
self.logger.warning('tx has no claims in db: %s %s', tx_hash, nout)
return result
async def claimtrie_getnthclaimforname(self, name, n):
@ -209,7 +209,8 @@ class LBRYElectrumX(ElectrumX):
def format_claim_from_daemon(self, claim, name=None):
'''Changes the returned claim data to the format expected by lbrynet and adds missing fields.'''
if not claim: return {}
if not claim:
return {}
name = name or claim['name']
claim_id = claim['claimId']
raw_claim_id = unhexlify(claim_id)[::-1]
@ -266,7 +267,7 @@ class LBRYElectrumX(ElectrumX):
return
except Exception:
pass
raise RPCError('{} should be a transaction hash'.format(value))
raise RPCError(1, f'{value} should be a transaction hash')
def assert_claim_id(self, value):
'''Raise an RPCError if the value is not a valid claim id
@ -276,7 +277,7 @@ class LBRYElectrumX(ElectrumX):
return
except Exception:
pass
raise RPCError('{} should be a claim id hash'.format(value))
raise RPCError(1, f'{value} should be a claim id hash')
async def slow_get_claim_by_id_using_name(self, claim_id):
# TODO: temporary workaround for a lbrycrd bug on indexing. Should be removed when it gets stable
@ -288,7 +289,9 @@ class LBRYElectrumX(ElectrumX):
for claim in claims['claims']:
if claim['claimId'] == claim_id:
claim['name'] = name
self.logger.warning('Recovered a claim missing from lbrycrd index: {} {}'.format(name, claim_id))
self.logger.warning(
'Recovered a claim missing from lbrycrd index: %s %s', name, claim_id
)
return claim
async def claimtrie_getvalueforuri(self, block_hash, uri, known_certificates=None):