fix rebase

This commit is contained in:
Victor Shyba 2020-12-20 21:06:08 -03:00
parent 3b9e312615
commit 21a2e67755
2 changed files with 27 additions and 46 deletions

View file

@ -770,18 +770,13 @@ class Ledger(metaclass=LedgerRegistry):
include_is_my_output=False, include_is_my_output=False,
include_sent_supports=False, include_sent_supports=False,
include_sent_tips=False, include_sent_tips=False,
include_received_tips=False, include_received_tips=False) -> Tuple[List[Output], dict, int, int]:
session_override=None) -> Tuple[List[Output], dict, int, int]:
encoded_outputs = await query encoded_outputs = await query
outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None? outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None?
txs = [] txs: List[Transaction] = []
if len(outputs.txs) > 0: if len(outputs.txs) > 0:
txs: List[Transaction] = [] async for tx in self.request_transactions(tuple(outputs.txs)):
if session_override: txs.append(tx)
async for tx in self.request_transactions(tuple(outputs.txs), session_override):
txs.append(tx)
else:
txs.extend((await asyncio.gather(*(self.cache_transaction(*tx) for tx in outputs.txs))))
_txos, blocked = outputs.inflate(txs) _txos, blocked = outputs.inflate(txs)
@ -856,25 +851,17 @@ class Ledger(metaclass=LedgerRegistry):
async def resolve(self, accounts, urls, new_sdk_server=None, **kwargs): async def resolve(self, accounts, urls, new_sdk_server=None, **kwargs):
txos = [] txos = []
urls_copy = list(urls) urls_copy = list(urls)
if new_sdk_server: if new_sdk_server:
resolve = partial(self.network.new_resolve, new_sdk_server) resolve = partial(self.network.new_resolve, new_sdk_server)
while urls_copy:
batch, urls_copy = urls_copy[:500], urls_copy[500:]
txos.extend(
(await self._inflate_outputs(
resolve(batch), accounts, **kwargs
))[0]
)
else: else:
async with self.network.single_call_context(self.network.resolve) as (resolve, session): resolve = partial(self.network.retriable_call, self.network.resolve)
while urls_copy: while urls_copy:
batch, urls_copy = urls_copy[:500], urls_copy[500:] batch, urls_copy = urls_copy[:100], urls_copy[100:]
txos.extend( txos.extend(
(await self._inflate_outputs( (await self._inflate_outputs(
resolve(batch), accounts, session_override=session, **kwargs resolve(batch), accounts, **kwargs
))[0] ))[0]
) )
assert len(urls) == len(txos), "Mismatch between urls requested for resolve and responses received." assert len(urls) == len(txos), "Mismatch between urls requested for resolve and responses received."
result = {} result = {}
@ -896,17 +883,13 @@ class Ledger(metaclass=LedgerRegistry):
new_sdk_server=None, **kwargs) -> Tuple[List[Output], dict, int, int]: new_sdk_server=None, **kwargs) -> Tuple[List[Output], dict, int, int]:
if new_sdk_server: if new_sdk_server:
claim_search = partial(self.network.new_claim_search, new_sdk_server) claim_search = partial(self.network.new_claim_search, new_sdk_server)
return await self._inflate_outputs( else:
claim_search(**kwargs), accounts, claim_search = self.network.claim_search
include_purchase_receipt=include_purchase_receipt, return await self._inflate_outputs(
include_is_my_output=include_is_my_output, claim_search(**kwargs), accounts,
) include_purchase_receipt=include_purchase_receipt,
async with self.network.single_call_context(self.network.claim_search) as (claim_search, session): include_is_my_output=include_is_my_output,
return await self._inflate_outputs( )
claim_search(**kwargs), accounts, session_override=session,
include_purchase_receipt=include_purchase_receipt,
include_is_my_output=include_is_my_output,
)
async def get_claim_by_claim_id(self, accounts, claim_id, **kwargs) -> Output: async def get_claim_by_claim_id(self, accounts, claim_id, **kwargs) -> Output:
for claim in (await self.claim_search(accounts, claim_id=claim_id, **kwargs))[0]: for claim in (await self.claim_search(accounts, claim_id=claim_id, **kwargs))[0]:
@ -1011,7 +994,7 @@ class Ledger(metaclass=LedgerRegistry):
return self.db.get_channel_count(**constraints) return self.db.get_channel_count(**constraints)
async def resolve_collection(self, collection, offset=0, page_size=1): async def resolve_collection(self, collection, offset=0, page_size=1):
claim_ids = collection.claim.collection.claims.ids[offset:page_size+offset] claim_ids = collection.claim.collection.claims.ids[offset:page_size + offset]
try: try:
resolve_results, _, _, _ = await self.claim_search([], claim_ids=claim_ids) resolve_results, _, _, _ = await self.claim_search([], claim_ids=claim_ids)
except Exception as err: except Exception as err:
@ -1060,7 +1043,7 @@ class Ledger(metaclass=LedgerRegistry):
'txid': tx.id, 'txid': tx.id,
'timestamp': ts, 'timestamp': ts,
'date': datetime.fromtimestamp(ts).isoformat(' ')[:-3] if tx.height > 0 else None, 'date': datetime.fromtimestamp(ts).isoformat(' ')[:-3] if tx.height > 0 else None,
'confirmations': (headers.height+1) - tx.height if tx.height > 0 else 0, 'confirmations': (headers.height + 1) - tx.height if tx.height > 0 else 0,
'claim_info': [], 'claim_info': [],
'update_info': [], 'update_info': [],
'support_info': [], 'support_info': [],
@ -1070,7 +1053,7 @@ class Ledger(metaclass=LedgerRegistry):
is_my_inputs = all([txi.is_my_input for txi in tx.inputs]) is_my_inputs = all([txi.is_my_input for txi in tx.inputs])
if is_my_inputs: if is_my_inputs:
# fees only matter if we are the ones paying them # fees only matter if we are the ones paying them
item['value'] = dewies_to_lbc(tx.net_account_balance+tx.fee) item['value'] = dewies_to_lbc(tx.net_account_balance + tx.fee)
item['fee'] = dewies_to_lbc(-tx.fee) item['fee'] = dewies_to_lbc(-tx.fee)
else: else:
# someone else paid the fees # someone else paid the fees
@ -1093,13 +1076,13 @@ class Ledger(metaclass=LedgerRegistry):
if txi.txo_ref.txo is not None: if txi.txo_ref.txo is not None:
other_txo = txi.txo_ref.txo other_txo = txi.txo_ref.txo
if (other_txo.is_claim or other_txo.script.is_support_claim) \ if (other_txo.is_claim or other_txo.script.is_support_claim) \
and other_txo.claim_id == txo.claim_id: and other_txo.claim_id == txo.claim_id:
previous = other_txo previous = other_txo
break break
if previous is not None: if previous is not None:
item['update_info'].append({ item['update_info'].append({
'address': txo.get_address(self), 'address': txo.get_address(self),
'balance_delta': dewies_to_lbc(previous.amount-txo.amount), 'balance_delta': dewies_to_lbc(previous.amount - txo.amount),
'amount': dewies_to_lbc(txo.amount), 'amount': dewies_to_lbc(txo.amount),
'claim_id': txo.claim_id, 'claim_id': txo.claim_id,
'claim_name': txo.claim_name, 'claim_name': txo.claim_name,
@ -1177,7 +1160,7 @@ class Ledger(metaclass=LedgerRegistry):
for account in accounts: for account in accounts:
balance = self._balance_cache.get(account.id) balance = self._balance_cache.get(account.id)
if not balance: if not balance:
balance = self._balance_cache[account.id] =\ balance = self._balance_cache[account.id] = \
await account.get_detailed_balance(confirmations, reserved_subtotals=True) await account.get_detailed_balance(confirmations, reserved_subtotals=True)
for key, value in balance.items(): for key, value in balance.items():
if key == 'reserved_subtotals': if key == 'reserved_subtotals':
@ -1187,7 +1170,6 @@ class Ledger(metaclass=LedgerRegistry):
result[key] += value result[key] += value
return result return result
class TestNetLedger(Ledger): class TestNetLedger(Ledger):
network_name = 'testnet' network_name = 'testnet'
pubkey_address_prefix = bytes((111,)) pubkey_address_prefix = bytes((111,))
@ -1196,7 +1178,6 @@ class TestNetLedger(Ledger):
extended_private_key_prefix = unhexlify('04358394') extended_private_key_prefix = unhexlify('04358394')
checkpoints = {} checkpoints = {}
class RegTestLedger(Ledger): class RegTestLedger(Ledger):
network_name = 'regtest' network_name = 'regtest'
headers_class = UnvalidatedHeaders headers_class = UnvalidatedHeaders

View file

@ -260,9 +260,9 @@ class Network:
restricted = known_height in (None, -1, 0) or 0 > known_height > self.remote_height - 10 restricted = known_height in (None, -1, 0) or 0 > known_height > self.remote_height - 10
return self.rpc('blockchain.transaction.get', [tx_hash], restricted) return self.rpc('blockchain.transaction.get', [tx_hash], restricted)
def get_transaction_batch(self, txids, restricted=True, session=None): def get_transaction_batch(self, txids, restricted=True):
# use any server if its old, otherwise restrict to who gave us the history # use any server if its old, otherwise restrict to who gave us the history
return self.rpc('blockchain.transaction.get_batch', txids, restricted, session) return self.rpc('blockchain.transaction.get_batch', txids, restricted)
def get_transaction_and_merkle(self, tx_hash, known_height=None): def get_transaction_and_merkle(self, tx_hash, known_height=None):
# use any server if its old, otherwise restrict to who gave us the history # use any server if its old, otherwise restrict to who gave us the history