Beispiel #1
0
 def _save_support(transaction):
     transaction.execute("delete from support where claim_id=?",
                         (claim_id, ))
     for support in supports:
         transaction.execute(
             "insert into support values (?, ?, ?, ?)",
             ("%s:%i" % (support['txid'], support['nout']), claim_id,
              lbc_to_dewies(
                  support['amount']), support.get('address', "")))
Beispiel #2
0
 def _save_support(transaction):
     bind = "({})".format(','.join(['?'] * len(claim_id_to_supports)))
     transaction.execute(f"delete from support where claim_id in {bind}", list(claim_id_to_supports.keys()))
     for claim_id, supports in claim_id_to_supports.items():
         for support in supports:
             transaction.execute(
                 "insert into support values (?, ?, ?, ?)",
                 ("%s:%i" % (support['txid'], support['nout']), claim_id, lbc_to_dewies(support['amount']),
                  support.get('address', ""))
             )
Beispiel #3
0
 def _save_claims(transaction):
     content_claims_to_update = []
     for claim_info in claim_infos:
         outpoint = "%s:%i" % (claim_info['txid'], claim_info['nout'])
         claim_id = claim_info['claim_id']
         name = claim_info['name']
         amount = lbc_to_dewies(claim_info['amount'])
         height = claim_info['height']
         address = claim_info['address']
         sequence = claim_info['claim_sequence']
         certificate_id = claim_info['value'].signing_channel_id
         try:
             source_hash = claim_info['value'].stream.sd_hash
         except (AttributeError, ValueError):
             source_hash = None
         serialized = binascii.hexlify(claim_info['value'].to_bytes())
         transaction.execute(
             "insert or replace into claim values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
             (outpoint, claim_id, name, amount, height, serialized,
              certificate_id, address, sequence))
         # if this response doesn't have support info don't overwrite the existing
         # support info
         if 'supports' in claim_info:
             support_callbacks.append(
                 (claim_id, claim_info['supports']))
         if not source_hash:
             continue
         stream_hash = transaction.execute(
             "select file.stream_hash from stream "
             "inner join file on file.stream_hash=stream.stream_hash where sd_hash=?",
             (source_hash, )).fetchone()
         if not stream_hash:
             continue
         stream_hash = stream_hash[0]
         known_outpoint = transaction.execute(
             "select claim_outpoint from content_claim where stream_hash=?",
             (stream_hash, )).fetchone()
         known_claim_id = transaction.execute(
             "select claim_id from claim "
             "inner join content_claim c3 ON claim.claim_outpoint=c3.claim_outpoint "
             "where c3.stream_hash=?", (stream_hash, )).fetchone()
         if not known_claim_id:
             content_claims_to_update.append((stream_hash, outpoint))
         elif known_outpoint != outpoint:
             content_claims_to_update.append((stream_hash, outpoint))
     for stream_hash, outpoint in content_claims_to_update:
         self._save_content_claim(transaction, outpoint, stream_hash)
         if stream_hash in self.content_claim_callbacks:
             update_file_callbacks.append(
                 self.content_claim_callbacks[stream_hash]())
Beispiel #4
0
def calculate_effective_amount(
        amount: str,
        supports: typing.Optional[typing.List[typing.Dict]] = None) -> str:
    return dewies_to_lbc(
        lbc_to_dewies(amount) +
        sum([lbc_to_dewies(support['amount']) for support in supports]))