Exemple #1
0
def read_txhash2log(txhash, cur):
    d = cur.execute(
        """
        SELECT `type`,`user`,`coin_id`,`amount`,`time` FROM `log` WHERE `hash`=?
    """, (txhash, )).fetchall()
    if len(d) == 0:
        return None
    movement = UserCoins()
    _type = _time = None
    for _type, user, coin_id, amount, _time in d:
        movement.add_coins(user, coin_id, amount)
    return MoveLog(txhash, _type, movement, _time, False)
Exemple #2
0
 def affect_new_tx(self, tx, outer_cur=None):
     with closing(create_db(V.DB_ACCOUNT_PATH)) as db:
         cur = outer_cur or db.cursor()
         movement = UserCoins()
         # send_from_applyで登録済み
         if tx.hash in self.memory_movement:
             return
         # memory_movementに追加
         for txhash, txindex in tx.inputs:
             input_tx = tx_builder.get_tx(txhash)
             address, coin_id, amount = input_tx.outputs[txindex]
             user = read_address2user(address, cur)
             if user is not None:
                 movement.add_coins(user, coin_id, -1 * amount)
         for address, coin_id, amount in tx.outputs:
             user = read_address2user(address, cur)
             if user is not None:
                 movement.add_coins(user, coin_id, amount)
         # check
         if len(movement.users) == 0:
             return  # 無関係である
         move_log = MoveLog(tx.hash, tx.type, movement, tx.time, True, tx)
         self.memory_movement[tx.hash] = move_log
         logging.debug("Affect account new tx. {}".format(tx))