Skip to content
Snippets Groups Projects
Commit 02e292c8 authored by inso's avatar inso
Browse files

Parse sources using URL instead of manually

parent a1f2f7c7
No related branches found
No related tags found
No related merge requests found
...@@ -81,8 +81,7 @@ class ConnectionConfigModel(QObject): ...@@ -81,8 +81,7 @@ class ConnectionConfigModel(QObject):
:return: :return:
""" """
log_stream("Parsing sources...") log_stream("Parsing sources...")
await self.app.sources_service.refresh_sources_of_pubkey(self.connection.pubkey, transactions, dividends, await self.app.sources_service.initialize_sources(self.connection.pubkey, log_stream, progress)
None, log_stream, progress)
log_stream("Sources parsed succefully !") log_stream("Sources parsed succefully !")
async def initialize_identity(self, identity, log_stream, progress): async def initialize_identity(self, identity, log_stream, progress):
......
from PyQt5.QtCore import QObject from PyQt5.QtCore import QObject
from duniterpy.api import bma, errors from duniterpy.api import bma, errors
from duniterpy.documents import Transaction as TransactionDoc from duniterpy.documents import Transaction as TransactionDoc
from duniterpy.grammars.output import Condition
from duniterpy.documents import BlockUID from duniterpy.documents import BlockUID
import logging import logging
import pypeg2
from sakia.data.entities import Source, Transaction,Dividend from sakia.data.entities import Source, Transaction,Dividend
import hashlib import hashlib
...@@ -43,7 +45,6 @@ class SourcesServices(QObject): ...@@ -43,7 +45,6 @@ class SourcesServices(QObject):
""" """
txdoc = TransactionDoc.from_signed_raw(transaction.raw) txdoc = TransactionDoc.from_signed_raw(transaction.raw)
for offset, output in enumerate(txdoc.outputs): for offset, output in enumerate(txdoc.outputs):
if output.conditions.left.pubkey == pubkey:
source = Source(currency=self.currency, source = Source(currency=self.currency,
pubkey=pubkey, pubkey=pubkey,
identifier=txdoc.sha_hash, identifier=txdoc.sha_hash,
...@@ -85,6 +86,27 @@ class SourcesServices(QObject): ...@@ -85,6 +86,27 @@ class SourcesServices(QObject):
base=dividend.base) base=dividend.base)
self._sources_processor.insert(source) self._sources_processor.insert(source)
async def initialize_sources(self, pubkey, log_stream, progress):
sources_data = await self._bma_connector.get(self.currency, bma.tx.sources, req_args={'pubkey': pubkey})
nb_sources = len(sources_data["sources"])
for i, s in enumerate(sources_data["sources"]):
log_stream("Parsing source ud/tx {:}/{:}".format(i, nb_sources))
progress(1/nb_sources)
conditions = pypeg2.parse(s["conditions"], Condition)
if conditions.left.pubkey == pubkey:
try:
if conditions.left.pubkey == pubkey:
source = Source(currency=self.currency,
pubkey=pubkey,
identifier=s["identifier"],
type=s["type"],
noffset=s["noffset"],
amount=s["amount"],
base=s["base"])
self._sources_processor.insert(source)
except AttributeError as e:
self._logger.error(str(e))
async def check_destruction(self, pubkey, block_number, unit_base): async def check_destruction(self, pubkey, block_number, unit_base):
amount = self._sources_processor.amount(self.currency, pubkey) amount = self._sources_processor.amount(self.currency, pubkey)
if amount < 100 * 10 ** unit_base: if amount < 100 * 10 ** unit_base:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment