Exemplo n.º 1
0
 def restore_sources(self, pubkey, tx):
     """
     Restore the sources of a cancelled tx
     :param sakia.entities.Transaction tx:
     """
     txdoc = TransactionDoc.from_signed_raw(tx.raw)
     for offset, output in enumerate(txdoc.outputs):
         if output.conditions.left.pubkey == pubkey:
             source = Source(currency=self.currency,
                             pubkey=pubkey,
                             identifier=txdoc.sha_hash,
                             type='T',
                             noffset=offset,
                             amount=output.amount,
                             base=output.base)
             self._sources_processor.drop(source)
     for index, input in enumerate(txdoc.inputs):
         source = Source(currency=self.currency,
                         pubkey=txdoc.issuers[0],
                         identifier=input.origin_id,
                         type=input.source,
                         noffset=input.index,
                         amount=input.amount,
                         base=input.base)
         if source.pubkey == pubkey:
             self._sources_processor.insert(source)
Exemplo n.º 2
0
def test_add_get_multiple_source(meta_repo):
    sources_repo = SourcesRepo(meta_repo.conn)
    sources_repo.insert(
        Source(
            "testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
            "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843",
            3, "T", 1565, 1))
    sources_repo.insert(
        Source("testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
               "2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK", 22635, "D",
               726946, 1))
    sources = sources_repo.get_all(
        currency="testcurrency",
        pubkey="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn")
    assert "testcurrency" in [s.currency for s in sources]
    assert "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn" in [
        s.pubkey for s in sources
    ]
    assert "2pyPsXM8UCB88jP2NRM4rUHxb63qm89JMEWbpoRrhyDK" in [
        s.identifier for s in sources
    ]
    assert "T" in [s.type for s in sources]
    assert "D" in [s.type for s in sources]
    assert 726946 in [s.amount for s in sources]
    assert 1565 in [s.amount for s in sources]
    assert "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843" in [
        s.identifier for s in sources
    ]
Exemplo n.º 3
0
 def _parse_ud(self, pubkey, dividend):
     """
     :param str pubkey:
     :param sakia.data.entities.Dividend dividend:
     :return:
     """
     source = Source(currency=self.currency,
                     pubkey=pubkey,
                     identifier=pubkey,
                     type='D',
                     noffset=dividend.block_number,
                     amount=dividend.amount,
                     base=dividend.base)
     self._sources_processor.insert(source)
Exemplo n.º 4
0
 def parse_transaction_inputs(self, pubkey, transaction):
     """
     Parse a transaction
     :param sakia.data.entities.Transaction transaction:
     """
     txdoc = TransactionDoc.from_signed_raw(transaction.raw)
     for index, input in enumerate(txdoc.inputs):
         source = Source(currency=self.currency,
                         pubkey=txdoc.issuers[0],
                         identifier=input.origin_id,
                         type=input.source,
                         noffset=input.index,
                         amount=input.amount,
                         base=input.base)
         if source.pubkey == pubkey:
             self._sources_processor.drop(source)
Exemplo n.º 5
0
 def parse_transaction_outputs(self, pubkey, transaction):
     """
     Parse a transaction
     :param sakia.data.entities.Transaction transaction:
     """
     txdoc = TransactionDoc.from_signed_raw(transaction.raw)
     for offset, output in enumerate(txdoc.outputs):
         if output.conditions.left.pubkey == pubkey:
             source = Source(currency=self.currency,
                             pubkey=pubkey,
                             identifier=txdoc.sha_hash,
                             type='T',
                             noffset=offset,
                             amount=output.amount,
                             base=output.base)
             self._sources_processor.insert(source)
Exemplo n.º 6
0
 def commit_outputs_to_self(self, currency, pubkey, txdoc):
     """
     Save outputs to self
     :param str currency:
     :param str pubkey:
     :param TransactionDoc txdoc:
     :return:
     """
     for offset, output in enumerate(txdoc.outputs):
         if output.conditions.left.pubkey == pubkey:
             source = Source(currency=currency,
                             pubkey=pubkey,
                             identifier=txdoc.sha_hash,
                             type='T',
                             noffset=offset,
                             amount=output.amount,
                             base=output.base)
             self._sources_processor.insert(source)
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
def test_add_get_drop_source(meta_repo):
    sources_repo = SourcesRepo(meta_repo.conn)
    sources_repo.insert(
        Source(
            "testcurrency", "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
            "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843",
            3, "T", 1565, 1))
    source = sources_repo.get_one(
        identifier=
        "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843")
    assert source.currency == "testcurrency"
    assert source.pubkey == "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn"
    assert source.type == "T"
    assert source.amount == 1565
    assert source.base == 1
    assert source.noffset == 3

    sources_repo.drop(source)
    source = sources_repo.get_one(
        identifier=
        "0835CEE9B4766B3866DD942971B3EE2CF953599EB9D35BFD5F1345879498B843")
    assert source is None
Exemplo n.º 9
0
 async def refresh_sources_of_pubkey(self, pubkey):
     """
     Refresh the sources for a given pubkey
     :param str pubkey:
     :return: the destruction of sources
     """
     sources_data = await self._bma_connector.get(self.currency, bma.tx.sources, req_args={'pubkey': pubkey})
     self._sources_processor.drop_all_of(self.currency, pubkey)
     for i, s in enumerate(sources_data["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))